修改自動運行

This commit is contained in:
cesar liu 2022-11-15 14:08:34 +08:00
parent fa6b26df81
commit 637409f817
19 changed files with 167 additions and 90 deletions

View File

@ -46,8 +46,10 @@
"SMTPConfig": {
"Host": "smtp.gmail.com",
"Port": 25,
"UserName": "ficgreen01@gmail.com",
"Password": "opuisjyxgyjbjtha", //2022-09-02 update by jiahao
"UserName": "shanghohui@gmail.com",
"Password": "wswgnluvoodfexrb",
//"UserName": "ficgreen01@gmail.com",
//"Password": "opuisjyxgyjbjtha", //2022-09-02 update by jiahao
"EnableSsl": true
},
"ExceptionTimes": 240, //<EFBFBD><EFBFBD><EFBFBD>`<EFBFBD>q<EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><EFBFBD>A<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)

View File

@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SolarPower", "SolarPower\So
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "solarApp", "solarApp\solarApp.csproj", "{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "winService", "winService\winService.csproj", "{132A1CF9-2C64-493D-8F8E-1F86AA595D14}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "solarService", "solarService\solarService.csproj", "{CBD09B63-979E-4723-BC88-035DAEC6B0E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -23,10 +23,10 @@ Global
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Release|Any CPU.Build.0 = Release|Any CPU
{132A1CF9-2C64-493D-8F8E-1F86AA595D14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{132A1CF9-2C64-493D-8F8E-1F86AA595D14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{132A1CF9-2C64-493D-8F8E-1F86AA595D14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{132A1CF9-2C64-493D-8F8E-1F86AA595D14}.Release|Any CPU.Build.0 = Release|Any CPU
{CBD09B63-979E-4723-BC88-035DAEC6B0E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBD09B63-979E-4723-BC88-035DAEC6B0E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBD09B63-979E-4723-BC88-035DAEC6B0E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBD09B63-979E-4723-BC88-035DAEC6B0E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -759,7 +759,7 @@ namespace solarApp
this.ClientSize = new System.Drawing.Size(1782, 953);
this.Controls.Add(this.tabControl1);
this.Name = "fmArchive";
this.Text = "fmArchive 1020";
this.Text = "fmArchive 11-15";
this.Load += new System.EventHandler(this.fmArchive_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);

View File

@ -84,11 +84,11 @@ namespace solarApp
#endregion
#region
//_timer = new System.Timers.Timer();
//_timer.Interval = 10000;
//_timer.SynchronizingObject = this;
//_timer.Elapsed += _timer_Elapsed;
//_timer.Start();
_timer = new System.Timers.Timer();
_timer.Interval = 10000;
_timer.SynchronizingObject = this;
_timer.Elapsed += _timer_Elapsed;
_timer.Start();
#endregion
// dtselect_station1.Value = DateTime.Today.AddDays(-1);
@ -107,46 +107,46 @@ namespace solarApp
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//lbMsgStatus.Text = (autoTask) ? "autoTask = true" : "autoTask = false";
//lbMsgStatus.Text += " timespan = " + (DateTime.Now - doTimerTaskTime).TotalMinutes.ToString();
lbMsgStatus.Text = (autoTask) ? "autoTask = true" : "autoTask = false";
lbMsgStatus.Text += " timespan = " + (DateTime.Now - doTimerTaskTime).TotalMinutes.ToString();
//if (DateTime.Now.Hour >= 2 && DateTime.Now.Minute == 0)
//{
// doTimerTaskTime = DateTime.Now;
// autoTask = false;
//}
if (DateTime.Now.Hour >= 2 && DateTime.Now.Minute == 0)
{
doTimerTaskTime = DateTime.Now;
autoTask = false;
}
//// 凌晨 2點後如果間隔30分鐘 沒有跑異常同步 就啟動啟動
//doTaskDuratin = DateTime.Now - doTimerTaskTime; //
//if (DateTime.Now.Hour >= 2 && doTaskDuratin.TotalMinutes > 15 && (autoTask == true))
//{
// doTimerTaskTime = DateTime.Now;
// autoTask = false;
//}
////每日歸檔
//if (DateTime.Now.Hour == 00 && DateTime.Now.Minute == 15 )
//{
// //MessageBox.Show("ok");
// autoTask = true;
// lbMsgTitle.Text = DateTime.Now.ToString() + " timer start";
// dtSelect1.Value = System.DateTime.Now.AddDays(-1);
// dtSelect2.Value = System.DateTime.Now.AddDays(-1);
// bt_archive.PerformClick();
// autoTask = false;
// //bt_archive_Click.PerformClick();
//}
// 凌晨 2點後如果間隔30分鐘 沒有跑異常同步 就啟動啟動
doTaskDuratin = DateTime.Now - doTimerTaskTime; //
if (DateTime.Now.Hour >= 2 && doTaskDuratin.TotalMinutes > 15 && (autoTask == true))
{
doTimerTaskTime = DateTime.Now;
autoTask = false;
}
//每日歸檔
if (DateTime.Now.Hour == 00 && DateTime.Now.Minute == 15)
{
//MessageBox.Show("ok");
autoTask = true;
lbMsgTitle.Text = DateTime.Now.ToString() + " timer start";
dtSelect1.Value = System.DateTime.Now.AddDays(-1);
dtSelect2.Value = System.DateTime.Now.AddDays(-1);
bt_archive.PerformClick();
autoTask = false;
//bt_archive_Click.PerformClick();
}
////異常處理 每 5分鐘跑一次
//if ((DateTime.Now.Minute % 5) == 0 && (DateTime.Now.Second) < 30 && (autoTask == false))
//{
// doTimerTaskTime = DateTime.Now;
// autoTask = true;
// lbMsgTitle.Text = "異常處理 " + DateTime.Now.ToString() + " timer start";
// btSyncErr.PerformClick();
// lbMsgTitle.Text = "異常處理 done" + DateTime.Now.ToString() ;
// autoTask = false;
// //bt_archive_Click.PerformClick();
//}
//異常處理 每 5分鐘跑一次
if ((DateTime.Now.Minute % 5) == 0 && (DateTime.Now.Second) < 30 && (autoTask == false))
{
doTimerTaskTime = DateTime.Now;
autoTask = true;
lbMsgTitle.Text = "異常處理 " + DateTime.Now.ToString() + " timer start";
btSyncErr.PerformClick();
lbMsgTitle.Text = "異常處理 done" + DateTime.Now.ToString();
autoTask = false;
//bt_archive_Click.PerformClick();
}
//臨時的 累計日照
@ -644,7 +644,7 @@ namespace solarApp
if (CanDoSend)
{
SMTPConfig smtp = new SMTPConfig(); ;
smtp.Host = "smtp.gmail.com";
smtp.Host = "msr.hinet.net";
//smtp.UserName = "ficgreen01@gmail.com";
//smtp.Password = "qwe2015qwe";
//smtp.UserName = "ficgreen02@gmail.com";

View File

@ -1711,7 +1711,6 @@ namespace solarApp
//
// button1
//
this.button1.Cursor = System.Windows.Forms.Cursors.Arrow;
this.button1.Location = new System.Drawing.Point(1603, 51);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(94, 29);
@ -1740,7 +1739,6 @@ namespace solarApp
//
// btLoadData
//
this.btLoadData.Cursor = System.Windows.Forms.Cursors.Arrow;
this.btLoadData.Location = new System.Drawing.Point(34, 21);
this.btLoadData.Name = "btLoadData";
this.btLoadData.Size = new System.Drawing.Size(94, 29);
@ -1785,7 +1783,6 @@ namespace solarApp
dataGridViewCellStyle54.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.gv_all_data.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle54;
this.gv_all_data.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gv_all_data.Cursor = System.Windows.Forms.Cursors.Arrow;
dataGridViewCellStyle55.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle55.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle55.Font = new System.Drawing.Font("Microsoft JhengHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
@ -1819,7 +1816,6 @@ namespace solarApp
dataGridViewCellStyle57.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.gv_notice_data.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle57;
this.gv_notice_data.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gv_notice_data.Cursor = System.Windows.Forms.Cursors.Arrow;
dataGridViewCellStyle58.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle58.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle58.Font = new System.Drawing.Font("Microsoft JhengHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

View File

@ -1,7 +1,6 @@
using winService;
using solarService;
IHost host = Host.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();

View File

@ -1,6 +1,6 @@
{
"profiles": {
"winService": {
"solarService": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {

21
solarService/Worker.cs Normal file
View File

@ -0,0 +1,21 @@
namespace solarService
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(1000, stoppingToken);
}
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-solarService-2179A249-99D7-4FA2-AFD2-32FA4EA04A9E</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
</ItemGroup>
</Project>

14
solarService2/Program.cs Normal file
View File

@ -0,0 +1,14 @@
using solarService;
IHost host = Host.CreateDefaultBuilder(args)
.UseWindowsService(options =>
{
options.ServiceName = "solar_archive_service";
})
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
})
.Build();
await host.RunAsync();

View File

@ -0,0 +1,11 @@
{
"profiles": {
"solarService": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -45,10 +45,10 @@ namespace winService
public Worker(ILogger<Worker> logger)
{
_logger = logger;
xdoc = XDocument.Load("../solarApp/App.config");
xdoc = XDocument.Load("../solarApp/App.config");
string conStr = Xdoc.Element("configuration").Element("connectionStrings").Element("add").Attribute("connectionString").Value;
stationSvc = new getStationSvc(conStr);
svc = new procSyncError(conStr); // ±`¸ê®Æ¦P¨B
stationSvc = new getStationSvc(conStr);
svc = new procSyncError(conStr); // ±`¸ê®Æ¦P¨B
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@ -98,7 +98,18 @@ namespace winService
}
}
void archiveAllStation() {
// ªA°È°±¤î®É
public override async Task StopAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Service stopped");
//Log("Service stopped");
//cpuLogger.Dispose();
//cpuLogger = null!;
await base.StopAsync(stoppingToken);
}
void archiveAllStation()
{
var site_list = stationSvc.get_station_list();
procSensorSvc sensorSvc = new procSensorSvc();
procInvSvc invSvc = new procInvSvc();

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@ -1,18 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-winService-78282A39-DE2D-4E5B-806B-31D6FE6D57E7</UserSecretsId>
<StartupObject></StartupObject>
<OutputType>WinExe</OutputType>
<UseWindowsForms>False</UseWindowsForms>
<UserSecretsId>dotnet-solarService-DE237DB4-CE53-4A5A-A2CA-F28052220202</UserSecretsId>
<OutputType>exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"mySql": "server=60.251.164.103;user=webuser;Database=solar_master;Port=11306;password=FICadmin99;charset='utf8';pooling=true;sslmode=none;"
}

View File

@ -1,10 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"mySql": "server=60.251.164.103;user=webuser;Database=solar_master;Port=11306;password=FICadmin99;charset='utf8';pooling=true;sslmode=none;"
}