diff --git a/SolarPower/appsettings.json b/SolarPower/appsettings.json index 4949fa1..a64521e 100644 --- a/SolarPower/appsettings.json +++ b/SolarPower/appsettings.json @@ -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, //���`�q���ɶ��A���(����) diff --git a/slnSolarPower.sln b/slnSolarPower.sln index 672742a..c96ce9d 100644 --- a/slnSolarPower.sln +++ b/slnSolarPower.sln @@ -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 diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index 86aba0b..b8971d1 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -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); diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index 78cbe2b..6348702 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -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"; diff --git a/solarApp/fmMain.Designer.cs b/solarApp/fmMain.Designer.cs index 962dce4..9200a31 100644 --- a/solarApp/fmMain.Designer.cs +++ b/solarApp/fmMain.Designer.cs @@ -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); diff --git a/winService/Program.cs b/solarService/Program.cs similarity index 80% rename from winService/Program.cs rename to solarService/Program.cs index 202bc9d..5f38f2a 100644 --- a/winService/Program.cs +++ b/solarService/Program.cs @@ -1,7 +1,6 @@ -using winService; +using solarService; IHost host = Host.CreateDefaultBuilder(args) - .UseWindowsService() .ConfigureServices(services => { services.AddHostedService(); diff --git a/winService/Properties/launchSettings.json b/solarService/Properties/launchSettings.json similarity index 89% rename from winService/Properties/launchSettings.json rename to solarService/Properties/launchSettings.json index 7aaa119..a8d36a1 100644 --- a/winService/Properties/launchSettings.json +++ b/solarService/Properties/launchSettings.json @@ -1,6 +1,6 @@ { "profiles": { - "winService": { + "solarService": { "commandName": "Project", "dotnetRunMessages": true, "environmentVariables": { diff --git a/solarService/Worker.cs b/solarService/Worker.cs new file mode 100644 index 0000000..ddc79e3 --- /dev/null +++ b/solarService/Worker.cs @@ -0,0 +1,21 @@ +namespace solarService +{ + public class Worker : BackgroundService + { + private readonly ILogger _logger; + + public Worker(ILogger 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); + } + } + } +} \ No newline at end of file diff --git a/solarService/appsettings.Development.json b/solarService/appsettings.Development.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/solarService/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/solarService/appsettings.json b/solarService/appsettings.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/solarService/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/solarService/solarService.csproj b/solarService/solarService.csproj new file mode 100644 index 0000000..d231007 --- /dev/null +++ b/solarService/solarService.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + dotnet-solarService-2179A249-99D7-4FA2-AFD2-32FA4EA04A9E + + + + + + diff --git a/solarService2/Program.cs b/solarService2/Program.cs new file mode 100644 index 0000000..d5788f3 --- /dev/null +++ b/solarService2/Program.cs @@ -0,0 +1,14 @@ +using solarService; + +IHost host = Host.CreateDefaultBuilder(args) + .UseWindowsService(options => + { + options.ServiceName = "solar_archive_service"; + }) + .ConfigureServices(services => + { + services.AddHostedService(); + }) + .Build(); + +await host.RunAsync(); diff --git a/solarService2/Properties/launchSettings.json b/solarService2/Properties/launchSettings.json new file mode 100644 index 0000000..a8d36a1 --- /dev/null +++ b/solarService2/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "solarService": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/winService/Worker.cs b/solarService2/Worker.cs similarity index 90% rename from winService/Worker.cs rename to solarService2/Worker.cs index b127080..31cddf8 100644 --- a/winService/Worker.cs +++ b/solarService2/Worker.cs @@ -32,7 +32,7 @@ namespace winService private readonly ILogger _logger; XDocument xdoc; public XDocument Xdoc { get => xdoc; set => xdoc = value; } - + getStationSvc stationSvc; System.Timers.Timer _timer; bool autoTask = false; //զ۰ʶ] irrDayHour ֭pӤpɮt @@ -40,15 +40,15 @@ namespace winService DateTime doTimerTaskTime = DateTime.Now; TimeSpan doTaskDuratin; - + public Worker(ILogger 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); // `ƦPB + stationSvc = new getStationSvc(conStr); + svc = new procSyncError(conStr); // `ƦPB } 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(); @@ -107,7 +118,7 @@ namespace winService string date2 = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); foreach (var item in site_list) - { + { foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) { sensorSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); diff --git a/solarService2/appsettings.Development.json b/solarService2/appsettings.Development.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/solarService2/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/solarService2/appsettings.json b/solarService2/appsettings.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/solarService2/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/winService/winService.csproj b/solarService2/solarService.csproj similarity index 54% rename from winService/winService.csproj rename to solarService2/solarService.csproj index b06c857..38a1051 100644 --- a/winService/winService.csproj +++ b/solarService2/solarService.csproj @@ -1,18 +1,15 @@  - net6.0-windows10.0.17763.0 + net6.0-windows10.0.22000.0 enable enable - dotnet-winService-78282A39-DE2D-4E5B-806B-31D6FE6D57E7 - - WinExe - False + dotnet-solarService-DE237DB4-CE53-4A5A-A2CA-F28052220202 + exe - diff --git a/winService/appsettings.Development.json b/winService/appsettings.Development.json deleted file mode 100644 index 92d108d..0000000 --- a/winService/appsettings.Development.json +++ /dev/null @@ -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;" -} diff --git a/winService/appsettings.json b/winService/appsettings.json deleted file mode 100644 index 93ff8ee..0000000 --- a/winService/appsettings.json +++ /dev/null @@ -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;" - -}