|
|
@ -1,35 +1,52 @@
|
|
|
|
using System.Diagnostics;
|
|
|
|
using Aspose.Cells;
|
|
|
|
using Txgy.RBS.Framework.Api;
|
|
|
|
|
|
|
|
using Txgy.RBS.Framework;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using ServiceStack;
|
|
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
using System.Data;
|
|
|
|
using System.Data;
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
using Txgy.RBS.DTO;
|
|
|
|
using Txgy.RBS.DTO;
|
|
|
|
using Aspose.Cells;
|
|
|
|
using Txgy.RBS.Framework;
|
|
|
|
|
|
|
|
using Txgy.RBS.Framework.Api;
|
|
|
|
|
|
|
|
using Txgy.RBS.Framework.FileWatcherHelper;
|
|
|
|
using Txgy.RBS.Framework.Models;
|
|
|
|
using Txgy.RBS.Framework.Models;
|
|
|
|
|
|
|
|
using Txgy.RBS.Framework.RedisHelper.Service;
|
|
|
|
|
|
|
|
using Txgy.RBS.IServices;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Txgy.RBS.Services
|
|
|
|
namespace Txgy.RBS.Services
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class ProcessManagerService
|
|
|
|
public class ProcessManagerService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IMemoryCache _cache;
|
|
|
|
private readonly IMemoryCache _cache;
|
|
|
|
|
|
|
|
private readonly RedisListService _redisList;
|
|
|
|
|
|
|
|
private readonly IResultInfoService _resultInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
public ProcessManagerService( IMemoryCache cache)
|
|
|
|
public ProcessManagerService(RedisListService redisList, IResultInfoService resultInfoService, IMemoryCache cache)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_cache = cache;
|
|
|
|
|
|
|
|
MoniTimer.Interval = 10000;
|
|
|
|
MoniTimer.Interval = 10000;
|
|
|
|
MoniTimer.Elapsed += MoniTimer_Elapsed;
|
|
|
|
MoniTimer.Elapsed += MoniTimer_Elapsed;
|
|
|
|
MoniTimer.Start();
|
|
|
|
MoniTimer.Start();
|
|
|
|
|
|
|
|
this._redisList = redisList;
|
|
|
|
|
|
|
|
this._resultInfoService = resultInfoService;
|
|
|
|
|
|
|
|
_cache = cache;
|
|
|
|
|
|
|
|
RedisServer = new ProcessInfo()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ProName = "server",
|
|
|
|
|
|
|
|
StartTime = DateTime.Now,
|
|
|
|
|
|
|
|
State = true
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ProcessInfo RedisServer { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
private void MoniTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
|
|
|
private void MoniTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var item in ProjectMonitor)
|
|
|
|
foreach (var item in ProjectMonitor)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_redisList.Publish(CommonData.RedisPublish, Newtonsoft.Json.JsonConvert.SerializeObject(new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
projectName = item.Key,
|
|
|
|
|
|
|
|
ProName = RedisServer.ProName,
|
|
|
|
|
|
|
|
RunState = RedisServer.State?1:0,
|
|
|
|
|
|
|
|
RunTime = (DateTime.Now - RedisServer.StartTime).TotalSeconds,
|
|
|
|
|
|
|
|
}));
|
|
|
|
foreach (var proValue in item.Value.GetType().GetProperties())
|
|
|
|
foreach (var proValue in item.Value.GetType().GetProperties())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var pro = proValue.GetValue(item.Value) as ProcessInfo;
|
|
|
|
var pro = proValue.GetValue(item.Value) as ProcessInfo;
|
|
|
@ -38,10 +55,22 @@ namespace Txgy.RBS.Services
|
|
|
|
int sfp = FindProcess(pro);
|
|
|
|
int sfp = FindProcess(pro);
|
|
|
|
if (sfp != 0)
|
|
|
|
if (sfp != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine($"{pro.ProName}程序重启中,path:{pro.ProPath}");
|
|
|
|
pro.State = false;
|
|
|
|
|
|
|
|
Console.WriteLine($"{pro.ProName}程序重启中, path:{pro.ProPath}");
|
|
|
|
StartProcess(pro);
|
|
|
|
StartProcess(pro);
|
|
|
|
Thread.Sleep(20);
|
|
|
|
Thread.Sleep(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pro.State = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_redisList.Publish(CommonData.RedisPublish, Newtonsoft.Json.JsonConvert.SerializeObject(new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
projectName=item.Key,
|
|
|
|
|
|
|
|
ProName = pro.ProName,
|
|
|
|
|
|
|
|
RunState = sfp == 0 ? 1 : 0,
|
|
|
|
|
|
|
|
RunTime = (DateTime.Now - pro.StartTime).TotalSeconds,
|
|
|
|
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -54,6 +83,9 @@ namespace Txgy.RBS.Services
|
|
|
|
if (!ProjectMonitor.ContainsKey(projectName))
|
|
|
|
if (!ProjectMonitor.ContainsKey(projectName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ProjectMonitor.TryAdd(projectName, processInfo);
|
|
|
|
ProjectMonitor.TryAdd(projectName, processInfo);
|
|
|
|
|
|
|
|
processInfo.FilesWatcherService.InitializeParams();
|
|
|
|
|
|
|
|
processInfo.FilesWatcherService.Start();
|
|
|
|
|
|
|
|
processInfo.FilesWatcherService.WatcherFileChanged = WatcherChanged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.Timers.Timer MoniTimer { get; set; } = new System.Timers.Timer();
|
|
|
|
System.Timers.Timer MoniTimer { get; set; } = new System.Timers.Timer();
|
|
|
@ -61,16 +93,60 @@ namespace Txgy.RBS.Services
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (ProjectMonitor.ContainsKey(projectName))
|
|
|
|
if (ProjectMonitor.ContainsKey(projectName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ProjectMonitor.TryRemove(projectName, out ProcessConfig pro);
|
|
|
|
ProjectMonitor.TryRemove(projectName, out ProcessConfig process);
|
|
|
|
|
|
|
|
process.FilesWatcherService.Stop();
|
|
|
|
|
|
|
|
foreach (var proValue in process.GetType().GetProperties())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var pro = proValue.GetValue(process) as ProcessInfo;
|
|
|
|
|
|
|
|
if (pro != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_redisList.Publish(CommonData.RedisPublish, Newtonsoft.Json.JsonConvert.SerializeObject(new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
projectName = projectName,
|
|
|
|
|
|
|
|
ProName = pro.ProName,
|
|
|
|
|
|
|
|
RunState = 0,
|
|
|
|
|
|
|
|
RunTime = (DateTime.Now - pro.StartTime).TotalSeconds,
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WatcherChanged(MsEventModel msEvent, FileSystemEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_resultInfoService.AddResultInfo(new ResultDTO
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
project_id = msEvent.ProjectId,
|
|
|
|
|
|
|
|
otime = msEvent.OriginTime.ToString("O"),
|
|
|
|
|
|
|
|
xlon = msEvent.EastCoordinate,
|
|
|
|
|
|
|
|
ylat = msEvent.NorthCoordinate,
|
|
|
|
|
|
|
|
depth = msEvent.Depth,
|
|
|
|
|
|
|
|
ml = msEvent.ML,
|
|
|
|
|
|
|
|
energy = msEvent.Energy,
|
|
|
|
|
|
|
|
// rms=msEvent.
|
|
|
|
|
|
|
|
phases_count = msEvent.PhasesCount,
|
|
|
|
|
|
|
|
amps_count = msEvent.AmpsCount,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
_redisList.Publish($"{msEvent.ProjectName}result", Newtonsoft.Json.JsonConvert.SerializeObject(new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
projectName = msEvent.ProjectName,
|
|
|
|
|
|
|
|
ProName = msEvent.OriginTime,
|
|
|
|
|
|
|
|
message = msEvent.ToString(),
|
|
|
|
|
|
|
|
jsonStr = ""
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 方法
|
|
|
|
#region 方法
|
|
|
|
|
|
|
|
|
|
|
|
public ApiResult StartProject(string projectName, ProcessConfig processConfig)
|
|
|
|
public ApiResult StartProject(string projectName, ProcessConfig processConfig)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
int res = 0;
|
|
|
|
if (ProjectMonitor.ContainsKey(projectName)) new ApiResult();
|
|
|
|
if (ProjectMonitor.ContainsKey(projectName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new ApiResult();
|
|
|
|
|
|
|
|
}
|
|
|
|
foreach (var item in processConfig.GetType().GetProperties())
|
|
|
|
foreach (var item in processConfig.GetType().GetProperties())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var pro = item.GetValue(processConfig) as ProcessInfo;
|
|
|
|
var pro = item.GetValue(processConfig) as ProcessInfo;
|
|
|
@ -79,11 +155,11 @@ namespace Txgy.RBS.Services
|
|
|
|
res = StartProcess(pro);
|
|
|
|
res = StartProcess(pro);
|
|
|
|
if (res != 0)
|
|
|
|
if (res != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pro.StartTime = DateTime.Now;
|
|
|
|
pro.StartTime = DateTime.Now;
|
|
|
|
pro.State = true;
|
|
|
|
pro.State = true;
|
|
|
|
_cache.Set(pro.ProPath, pro);
|
|
|
|
// _cache.Set(pro.ProPath, pro);
|
|
|
|
Thread.Sleep(10);
|
|
|
|
Thread.Sleep(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -113,7 +189,7 @@ namespace Txgy.RBS.Services
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pro.State = false;
|
|
|
|
pro.State = false;
|
|
|
|
_cache.Set(pro.ProPath, pro);
|
|
|
|
// _cache.Set(pro.ProPath, pro);
|
|
|
|
Thread.Sleep(10);
|
|
|
|
Thread.Sleep(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -246,7 +322,15 @@ namespace Txgy.RBS.Services
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var pro= localByName.Where(p => p.MainModule.FileName.Contains(processInfo.ProPath));
|
|
|
|
List<Process> pro = null;
|
|
|
|
|
|
|
|
if (processInfo.ProName == "server")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pro = localByName.Where(p => p.MainModule.FileName.Contains(processInfo.ProName)).ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pro = localByName.Where(p => p.MainModule.FileName.Contains(processInfo.ProPath)).ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!pro.Any())
|
|
|
|
if (!pro.Any())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ri = 1;
|
|
|
|
ri = 1;
|
|
|
@ -265,9 +349,14 @@ namespace Txgy.RBS.Services
|
|
|
|
|
|
|
|
|
|
|
|
public ApiResult GetState(string projectName, int id)
|
|
|
|
public ApiResult GetState(string projectName, int id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
ProcessInfo pro = null;
|
|
|
|
|
|
|
|
if(id==1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pro = this.RedisServer;
|
|
|
|
|
|
|
|
}
|
|
|
|
ProjectMonitor.TryGetValue(projectName, out ProcessConfig process);
|
|
|
|
ProjectMonitor.TryGetValue(projectName, out ProcessConfig process);
|
|
|
|
if (process == null|| (id<1 || id>3)) { return new ApiResult(); }
|
|
|
|
if (process == null || (id < 1|| id > 3)) { return new ApiResult(); }
|
|
|
|
ProcessInfo pro = id == 1 ? process.Server : id == 2 ? process.Apms : process.RecvMqtt;
|
|
|
|
pro = id == 1 ?pro:(id==2)? process.Apms : process.RecvMqtt;
|
|
|
|
int sfp = FindProcess(pro);
|
|
|
|
int sfp = FindProcess(pro);
|
|
|
|
if (sfp != 0)
|
|
|
|
if (sfp != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -275,12 +364,13 @@ namespace Txgy.RBS.Services
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ApiResult
|
|
|
|
return new ApiResult
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Code = System.Net.HttpStatusCode.OK, Data = new
|
|
|
|
Code = System.Net.HttpStatusCode.OK,
|
|
|
|
|
|
|
|
Data = new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name=pro.ProName,
|
|
|
|
name = pro.ProName,
|
|
|
|
state= sfp == 0 ? 1 : 0,
|
|
|
|
state = sfp == 0 ? 1 : 0,
|
|
|
|
start_time=pro.StartTime,
|
|
|
|
start_time = pro.StartTime,
|
|
|
|
running_time=(DateTime.Now-pro.StartTime).TotalSeconds,
|
|
|
|
running_time = (DateTime.Now - pro.StartTime).TotalSeconds,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|