|
@@ -16,9 +16,7 @@ using DevExpress.XtraEditors;
|
|
|
using ExtensionsDev;
|
|
|
using DevExpress.XtraBars.Forms;
|
|
|
using DW5S.App.CorTools;
|
|
|
-using System.Data.Entity;
|
|
|
using System.IO;
|
|
|
-using System.Data.Entity.Migrations;
|
|
|
using DW5S.DTO;
|
|
|
using DW5S.Entity;
|
|
|
using DW5S.Repostory;
|
|
@@ -37,13 +35,20 @@ using System.Runtime.InteropServices;
|
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
|
using DevExpress.LookAndFeel.Design;
|
|
|
using System.Configuration;
|
|
|
-using DW5S.Framework;
|
|
|
-using DW5S.UI.Lib;
|
|
|
+
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using DW5S.Service;
|
|
|
|
|
|
namespace DW5S
|
|
|
{
|
|
|
public partial class MainForm : DevExpress.XtraBars.Ribbon.RibbonForm
|
|
|
{
|
|
|
+ [Autowired]
|
|
|
+ private readonly ILogger logger;
|
|
|
+
|
|
|
+ [Autowired]
|
|
|
+ private readonly UnitOfWork unitOfWork;
|
|
|
+
|
|
|
Dictionary<string, Type> ctrlTypes = new Dictionary<string, Type>();
|
|
|
public MainForm()
|
|
|
{
|
|
@@ -71,7 +76,6 @@ namespace DW5S
|
|
|
ctrlTypes.Add("服务状态", typeof(CtrlSvrs));
|
|
|
ctrlTypes.Add("服务日志", typeof(CtrlSvrLog));
|
|
|
DxHelper.WaitHelper.UpdateSplashMessage("正在检查数据库环境...");
|
|
|
- CheckDb();
|
|
|
|
|
|
}
|
|
|
private string text;
|
|
@@ -79,31 +83,11 @@ namespace DW5S
|
|
|
{
|
|
|
this.text = this.Text;
|
|
|
this.HtmlText = $"<size=12>{this.text}";
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- SysConfig.Config = db.SysSetings.FirstOrDefault();
|
|
|
- }
|
|
|
- if (SysConfig.Config != null)
|
|
|
- {
|
|
|
- StartWebApi();
|
|
|
- }
|
|
|
+ var repsSys = unitOfWork.Reps<SysSetings>();
|
|
|
+ var settings = await repsSys.FirstOrDefaultAsync();
|
|
|
btn_ItemClick(null, null);
|
|
|
ServerContext.Instance.Init();
|
|
|
- if (SysConfig.Config == null)
|
|
|
- {
|
|
|
- var size = new Size(500, 600);
|
|
|
- XtraForm frm = new XtraForm() { StartPosition = FormStartPosition.CenterScreen, CloseBox = false, MinimizeBox = false, MaximizeBox = false };
|
|
|
- frm.MinimumSize = frm.MaximumSize = frm.Size = size;
|
|
|
- new CtrlSysSettings() { Dock = DockStyle.Fill, Parent = frm };
|
|
|
- if (frm.ShowDialog() != DialogResult.Cancel)
|
|
|
- StartWebApi();
|
|
|
- else
|
|
|
- {
|
|
|
- this.Close();
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- this.HtmlText = $"<size=12>{text}(<size=9>{SysConfig.Config.TimeZoneDisplayName}</size>)";
|
|
|
+ this.HtmlText = $"<size=12>{text}(<size=9>{settings.TimeZoneDisplayName}</size>)";
|
|
|
Messenger.Defalut.Sub<SysSetings>("时区改变", settings =>
|
|
|
{
|
|
|
this.HtmlText = $"<size=12>{text}(<size=9>{settings.TimeZoneDisplayName}</size>)";
|
|
@@ -129,7 +113,7 @@ namespace DW5S
|
|
|
while (true)
|
|
|
{
|
|
|
//第二章方法获取系统CPU和内存使用情况
|
|
|
- LogUI.Info($"设备CPU:{sys.CpuLoad:f1}%,设备内存:{(sys.PhysicalMemory - sys.MemoryAvailable) / GB_DIV:f2}GB/{sys.PhysicalMemory / (double)GB_DIV:f2}GB,平台内存:{sys.ProcessMemory() / (double)GB_DIV:f2}GB,平台线程:{sys.ProcessThread()}").Wait();
|
|
|
+ logger.LogInformation($"设备CPU:{sys.CpuLoad:f1}%,设备内存:{(sys.PhysicalMemory - sys.MemoryAvailable) / GB_DIV:f2}GB/{sys.PhysicalMemory / (double)GB_DIV:f2}GB,平台内存:{sys.ProcessMemory() / (double)GB_DIV:f2}GB,平台线程:{sys.ProcessThread()}");
|
|
|
Thread.Sleep(interval);
|
|
|
}
|
|
|
}
|
|
@@ -138,92 +122,27 @@ namespace DW5S
|
|
|
});
|
|
|
|
|
|
}
|
|
|
- private void CheckDb()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- if (File.Exists(db.DbFile))
|
|
|
- {
|
|
|
- FileInfo fInfo = new FileInfo(db.DbFile);
|
|
|
- if (fInfo.IsReadOnly)
|
|
|
- {
|
|
|
- fInfo.IsReadOnly = false;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- using (RHDWLogContext db = new RHDWLogContext())
|
|
|
- {
|
|
|
- if (File.Exists(db.DbFile))
|
|
|
- {
|
|
|
- FileInfo fInfo = new FileInfo(db.DbFile);
|
|
|
- if (fInfo.IsReadOnly)
|
|
|
- {
|
|
|
- fInfo.IsReadOnly = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- db.SyncDb();
|
|
|
- }
|
|
|
- using (RHDWLogContext db = new RHDWLogContext())
|
|
|
- {
|
|
|
- db.SyncDb();
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogUI.Error("同步数据库结构异常", ex).Wait(5000);
|
|
|
- }
|
|
|
- }
|
|
|
- private void StartWebApi()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
-
|
|
|
- Startup.Start(SysConfig.Config.HttpPort, $"{Process.GetCurrentProcess().ProcessName}.Xml", "DW5S.Dto.xml", SysConfig.Config.TimeZoneUTC);
|
|
|
- }
|
|
|
- catch (System.Reflection.TargetInvocationException ex)
|
|
|
- {
|
|
|
- DW5S.Framework.LogHelper.Error($"启动Http服务失败!", ex);
|
|
|
- if (ex.InnerException is HttpListenerException)
|
|
|
- {
|
|
|
- DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败,{ex.InnerException.Message}");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败!");
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- DW5S.Framework.LogHelper.Error($"启动Http服务失败!", ex);
|
|
|
- DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败!");
|
|
|
- }
|
|
|
- }
|
|
|
//自动导入Tle
|
|
|
private async Task XlScan()
|
|
|
{
|
|
|
while (true)
|
|
|
{
|
|
|
await Task.Delay(10000);
|
|
|
- if (SysConfig.Config == null
|
|
|
- || string.IsNullOrWhiteSpace(SysConfig.Config.XLDirectory)
|
|
|
- || !Directory.Exists(SysConfig.Config.XLDirectory))
|
|
|
+ var repsSys = unitOfWork.Reps<SysSetings>();
|
|
|
+ var settings = await repsSys.FirstOrDefaultAsync();
|
|
|
+ if (settings == null
|
|
|
+ || string.IsNullOrWhiteSpace(settings.XLDirectory)
|
|
|
+ || !Directory.Exists(settings.XLDirectory))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
- DirectoryInfo dir = new DirectoryInfo(SysConfig.Config.XLDirectory);
|
|
|
- var backupSucceed = Path.Combine(dir.FullName, "Backup","Succeed");
|
|
|
+ DirectoryInfo dir = new DirectoryInfo(settings.XLDirectory);
|
|
|
+ var backupSucceed = Path.Combine(dir.FullName, "Backup", "Succeed");
|
|
|
var backupFailed = Path.Combine(dir.FullName, "Backup", "Failed");
|
|
|
Directory.CreateDirectory(backupSucceed);
|
|
|
Directory.CreateDirectory(backupFailed);
|
|
|
|
|
|
- var files = Directory.EnumerateFiles(SysConfig.Config.XLDirectory, "*", SearchOption.TopDirectoryOnly);
|
|
|
+ var files = Directory.EnumerateFiles(settings.XLDirectory, "*", SearchOption.TopDirectoryOnly);
|
|
|
foreach (string file in files)
|
|
|
{
|
|
|
bool succeed = false;
|
|
@@ -234,7 +153,7 @@ namespace DW5S
|
|
|
var res = await HttpHelper.PostRequestAsync<RecordRes>(SysConfig.GetUrl("Xl/ImportTleAsync"), dto);
|
|
|
if (res.code == 200)
|
|
|
{
|
|
|
- LogUI.Info($"星历文件[{file}]自动导入成功!").Wait(5000);
|
|
|
+ logger.LogInformation($"星历文件[{file}]自动导入成功!");
|
|
|
try
|
|
|
{
|
|
|
//导入完成的文件放在备份目录
|
|
@@ -244,12 +163,12 @@ namespace DW5S
|
|
|
File.Move(file, newFile);
|
|
|
}
|
|
|
catch
|
|
|
- {
|
|
|
+ {
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- LogUI.Error($"星历文件[{file}]自动导入失败.{res.msg}").Wait(5000);
|
|
|
+ logger.LogError($"星历文件[{file}]自动导入失败.{res.msg}");
|
|
|
try
|
|
|
{
|
|
|
//导入完成的文件放在备份目录
|
|
@@ -265,7 +184,7 @@ namespace DW5S
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- LogUI.Error($"星历文件[{file}]自动导入失败", ex).Wait(5000);
|
|
|
+ logger.LogError(ex, $"星历文件[{file}]自动导入失败");
|
|
|
try
|
|
|
{
|
|
|
//导入完成的文件放在备份目录
|
|
@@ -294,21 +213,11 @@ namespace DW5S
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- List<XlInfo> clearData = new List<XlInfo>();
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- DateTime dt = DateTime.Now.AddYears(-1);
|
|
|
- clearData = await db.XlInfos.Where(p => p.UpdateTime < dt).Take(1000).ToListAsync();
|
|
|
- if (clearData.Any())
|
|
|
- {
|
|
|
- db.XlInfos.RemoveRange(clearData);
|
|
|
- await db.SaveChangesAsync();
|
|
|
- }
|
|
|
- }
|
|
|
- if (!clearData.Any())
|
|
|
- {
|
|
|
- await Task.Delay(60 * 1000);
|
|
|
- }
|
|
|
+ var repsXl = unitOfWork.Reps<XlInfo>();
|
|
|
+ DateTime dt = DateTime.Now.AddYears(-1);
|
|
|
+ await repsXl.DeleteAsync(p => p.UpdateTime < dt);
|
|
|
+ await unitOfWork.SaveAsync();
|
|
|
+ await Task.Delay(60 * 1000);
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|