FIC_Solar/SolarPower/Services/Implement/SensorHourlyService.cs
2022-08-21 22:32:40 +08:00

108 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using solarApp.Service;
using Microsoft.Extensions.Logging;
using System.Configuration;
namespace SolarPower.Services.Implement
{
public class SensorHourlyService
{
ILogger _logger;
procArchiveSensorHourly sensorSvc;
procArchiveHourly HourSvc;
string Connection1 = string.Empty;
public SensorHourlyService(string Connection_parame = null, ILogger logger = null)
{
if (!string.IsNullOrEmpty(Connection_parame))
{
Connection1 = Connection_parame;
}
else
{
Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
}
sensorSvc = new procArchiveSensorHourly(Connection1);
HourSvc = new procArchiveHourly(Connection1);
if (logger != null)
{
_logger = logger;
}
}
public void ArchiveSensorHourly(string code, string dateTime)
{
#region Sensor
try
{
if (_logger != null)
{
_logger.LogInformation("【SenSorHourlyService】【ArchiveSensorHourly】使用winform開始執行[{0}]在{1}寫入資料", code, dateTime);
}
sensorSvc.insertData(code, dateTime);
if (_logger != null)
{
_logger.LogInformation("【SenSorHourlyService】【ArchiveSensorHourly】完成執行[{0}]在{1}寫入資料", code, dateTime);
}
}
catch (Exception exception)
{
if (_logger != null)
{
_logger.LogError("【SenSorHourlyService】【ArchiveSensorHourly】[Exception] - {0}", exception.Message);
}
if (exception.InnerException != null)
{
if (_logger != null)
{
_logger.LogError("【SenSorHourlyService】【ArchiveSensorHourly】[InnerException] - {0}", exception.InnerException.Message);
}
}
}
#endregion
if (_logger != null)
{
_logger.LogInformation("【SenSorHourlyService】【ArchiveSensorHourly】[執行完成] ");
}
}
public Task<bool> ArchiveStationHourly()
{
bool result = false;
#region Station
try
{
HourSvc.proc_s1_site();
result = true;
}
catch (Exception exception)
{
if (_logger != null)
{
_logger.LogError("【SenSorHourlyService】【ArchiveStationHourly】[Exception] - {0}", exception.Message);
}
if (exception.InnerException != null)
{
if (_logger != null)
{
_logger.LogError("【SenSorHourlyService】【ArchiveStationHourly】[InnerException] - {0}", exception.InnerException.Message);
}
}
}
#endregion
if (_logger != null)
{
_logger.LogInformation("【SenSorHourlyService】【ArchiveStationHourly】[執行完成] ");
}
return Task.FromResult(result);
}
}
}