diff --git a/Txgy.RBS.DTO/RedisInfoDTO.cs b/Txgy.RBS.DTO/RedisInfoDTO.cs
new file mode 100644
index 0000000..06bc67a
--- /dev/null
+++ b/Txgy.RBS.DTO/RedisInfoDTO.cs
@@ -0,0 +1,47 @@
+using SqlSugar;
+using System;
+using System.Linq;
+using System.Text;
+
+namespace Txgy.RBS.DTO
+{
+ ///
+ ///
+ ///
+ public class RedisInfoDTO
+ {
+ public RedisInfoDTO()
+ {
+
+
+ }
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public int id { get; set; }
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public string name { get; set; }
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public string url { get; set; }
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public int port { get; set; }
+
+ }
+}
diff --git a/Txgy.RBS.DTO/ResultDTO.cs b/Txgy.RBS.DTO/ResultDTO.cs
index 8e46042..67b7c24 100644
--- a/Txgy.RBS.DTO/ResultDTO.cs
+++ b/Txgy.RBS.DTO/ResultDTO.cs
@@ -35,6 +35,12 @@ namespace Txgy.RBS.DTO
///
public string otime { get; set; }
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public double? xlon { get; set; }
///
/// Desc:
/// Default:
@@ -99,5 +105,6 @@ namespace Txgy.RBS.DTO
///
public double? seismic_direction { get; set; }
+ public string json_str { set; get; }
}
}
diff --git a/Txgy.RBS.DbModel/Models/project_info.cs b/Txgy.RBS.DbModel/Models/project_info.cs
index 231a9a0..fab34ae 100644
--- a/Txgy.RBS.DbModel/Models/project_info.cs
+++ b/Txgy.RBS.DbModel/Models/project_info.cs
@@ -1,6 +1,8 @@
using SqlSugar;
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
+using System.Runtime.Serialization;
using System.Text;
namespace Txgy.RBS.DbModel.Models
@@ -182,10 +184,11 @@ namespace Txgy.RBS.DbModel.Models
public int push_wx_company_id { get; set; }
[Navigate(NavigateType.OneToOne, nameof(project_id))]
- public station_file stationFile { get; set; }
+ // [SugarColumn(IsIgnore = true)]
+ public station_file station_file { get; set; }
[Navigate(NavigateType.OneToOne, nameof(project_id))]
- public time_tab time_tab { get; set; }
+ public time_tab time_tab { get; set; }
}
}
diff --git a/Txgy.RBS.DbModel/Models/redis_server.cs b/Txgy.RBS.DbModel/Models/redis_server.cs
new file mode 100644
index 0000000..fc90aa4
--- /dev/null
+++ b/Txgy.RBS.DbModel/Models/redis_server.cs
@@ -0,0 +1,48 @@
+using SqlSugar;
+using System;
+using System.Linq;
+using System.Text;
+
+namespace Txgy.RBS.DbModel.Models
+{
+ ///
+ ///
+ ///
+ public class redis_server
+ {
+ public redis_server()
+ {
+
+
+ }
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
+ public int id { get; set; }
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public string name { get; set; }
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public string url { get; set; }
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public int port { get; set; }
+
+ }
+}
diff --git a/Txgy.RBS.DbModel/Models/station_file.cs b/Txgy.RBS.DbModel/Models/station_file.cs
index 0a64b1c..dd54158 100644
--- a/Txgy.RBS.DbModel/Models/station_file.cs
+++ b/Txgy.RBS.DbModel/Models/station_file.cs
@@ -15,7 +15,7 @@ namespace Txgy.RBS.DbModel.Models
/// Default:
/// Nullable:True
///
- [SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
+ [SugarColumn(IsPrimaryKey = true)]
public int id { get; set; }
///
diff --git a/Txgy.RBS.DbModel/Models/time_tab.cs b/Txgy.RBS.DbModel/Models/time_tab.cs
index 19e6f01..29d15b2 100644
--- a/Txgy.RBS.DbModel/Models/time_tab.cs
+++ b/Txgy.RBS.DbModel/Models/time_tab.cs
@@ -8,7 +8,7 @@ namespace Txgy.RBS.DbModel.Models
///
///
///
- public partial class time_tab
+ public class time_tab
{
public time_tab()
{
@@ -20,7 +20,7 @@ namespace Txgy.RBS.DbModel.Models
/// Default:
/// Nullable:True
///
- [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ [SugarColumn(IsPrimaryKey = true)]
public int id { get; set; }
///
@@ -28,7 +28,7 @@ namespace Txgy.RBS.DbModel.Models
/// Default:
/// Nullable:True
///
- public int? project_id { get; set; }
+ public int project_id { get; set; }
///
/// Desc:
diff --git a/Txgy.RBS.Framework/CommonData.cs b/Txgy.RBS.Framework/CommonData.cs
index 461a8d7..5356d83 100644
--- a/Txgy.RBS.Framework/CommonData.cs
+++ b/Txgy.RBS.Framework/CommonData.cs
@@ -10,9 +10,13 @@ namespace Txgy.RBS.Framework
public class CommonData
{
public static string BaseProjectPath { get; set; } = "d:\\Project";
+ public static string RedisDefaultPath { get; set; } = "program\\server";
+
public static string ApmsDefaultPath { get; set; } = "program\\apms\\gw.apms.json";
public static string RecvDefaultPath { get; set; } = "program\\recvmqtt\\gw.recvmqtt.json";
+ public static string RedisPublish { get; set; } = "server_status";
+
/// //From:www.13le.com
/// 复制文件夹下所有文件
diff --git a/Txgy.RBS.Framework/FileWatcherHelper/FilesWatcherService.cs b/Txgy.RBS.Framework/FileWatcherHelper/FilesWatcherService.cs
new file mode 100644
index 0000000..014caaf
--- /dev/null
+++ b/Txgy.RBS.Framework/FileWatcherHelper/FilesWatcherService.cs
@@ -0,0 +1,155 @@
+using ServiceStack.Messaging;
+using System;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text.Encodings.Web;
+using System.Text.Json;
+using System.Text.Unicode;
+using Txgy.RBS.Framework.Models;
+
+namespace Txgy.RBS.Framework.FileWatcherHelper
+{
+ public class FilesWatcherService
+ {
+ public FilesWatcherService(int proId, string projectName, string path)
+ {
+ projectId = proId;
+ proName = projectName;
+ watcherPath = path;
+ // string filter = "*.txt";
+ // WatcherPath = AppDomain.CurrentDomain.BaseDirectory;
+ // InitializeParams(filter, watcherPath);
+ }
+ private string watcherPath;
+
+ public string WatcherPath
+ {
+ get { return watcherPath; }
+ }
+ private string proName;
+
+ public string ProName
+ {
+ get { return proName; }
+ }
+ private int projectId;
+
+ public int ProjectId
+ {
+ get { return projectId; }
+ }
+
+ public DateTime StartTime { get; set; }
+
+ public void Start()
+ {
+ WatchStartOrSopt(true);
+ StartTime = DateTime.Now;
+ }
+
+ public void Stop()
+ {
+ WatchStartOrSopt(false);
+
+ }
+ public Action WatcherFileChanged;
+ public void InitializeParams(string fileFilter="*.index")
+ {
+
+ //如果设置的目录不存在设置到根目录
+ if (!File.Exists(watcherPath))
+ {
+ Directory.CreateDirectory(watcherPath);
+ // watcherPath = AppDomain.CurrentDomain.BaseDirectory;
+ }
+ watcher = new FileSystemWatcher();
+ //初始化监听
+ watcher.BeginInit();
+
+ //设置需要监听的更改类型(如:文件或者文件夹的属性,文件或者文件夹的创建时间;NotifyFilters枚举的内容)
+ watcher.NotifyFilter = NotifyFilters.Attributes
+ | NotifyFilters.CreationTime
+ | NotifyFilters.DirectoryName
+ | NotifyFilters.FileName
+ | NotifyFilters.LastAccess
+ | NotifyFilters.LastWrite
+ | NotifyFilters.Security
+ | NotifyFilters.Size;
+ //设置监听的路径
+ watcher.Path = watcherPath;
+ watcher.Changed += new FileSystemEventHandler(Watcher_Changed);
+ // watcher.Created += Watcher_Created;
+ watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted);
+ watcher.Renamed += new RenamedEventHandler(Watcher_Renamed);
+ watcher.Error += OnError;
+
+ //设置监听文件类型
+ watcher.Filter = fileFilter;
+ //设置是否监听子目录
+ watcher.IncludeSubdirectories = false;
+ //设置是否启用监听
+ watcher.EnableRaisingEvents = false;
+ watcher.EndInit();
+
+ }
+
+ private void OnError(object sender, ErrorEventArgs e)
+ {
+
+ }
+ private void Watcher_Changed(object sender, FileSystemEventArgs e)
+ {
+ Thread.Sleep(100);
+ // string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
+ DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath);
+ watcher.EnableRaisingEvents = false;
+ Debug.WriteLine($"最后修改时间:{lastWriteTime}");
+ string lastLine = File.ReadLines(e.FullPath).Last().Trim();
+ var msEvent = new MsEventModel(lastLine) { CurrentTime = DateTime.Now };
+ msEvent.ProjectId = this.ProjectId;
+ msEvent.ProjectName = this.ProName;
+ WatcherFileChanged?.Invoke(msEvent, e);
+ watcher.EnableRaisingEvents = true;
+ }
+
+ private void Watcher_Renamed(object sender, RenamedEventArgs e)
+ {
+
+ DateTime dt = DateTime.Now;
+ string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
+ tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ;
+ tmp += "文件全称:" + e.FullPath + "\r\n";
+ }
+
+ private void Watcher_Created(object sender, FileSystemEventArgs e)
+ {
+ DateTime dt = DateTime.Now;
+ string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
+ tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ;
+ tmp += "文件全称:" + e.FullPath + "\r\n";
+ }
+
+ private void Watcher_Deleted(object sender, FileSystemEventArgs e)
+ {
+
+ DateTime dt = DateTime.Now;
+ string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
+ tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ;
+ tmp += "文件全称:" + e.FullPath + "\r\n";
+
+ }
+
+ ///
+ /// 启动或者停止监听
+ ///
+ /// True:启用监听,False:关闭监听
+ private void WatchStartOrSopt(bool IsEnableRaising)
+ {
+ watcher.EnableRaisingEvents = IsEnableRaising;
+ }
+
+ private FileSystemWatcher watcher = new FileSystemWatcher();
+ }
+}
diff --git a/Txgy.RBS.Framework/Models/MsEventModel.cs b/Txgy.RBS.Framework/Models/MsEventModel.cs
index 7b5fe2a..e7167fb 100644
--- a/Txgy.RBS.Framework/Models/MsEventModel.cs
+++ b/Txgy.RBS.Framework/Models/MsEventModel.cs
@@ -5,7 +5,8 @@ namespace Txgy.RBS.Framework.Models
{
public class MsEventModel
{
- public int ID { get; set; }
+ public int ProjectId { get; set; }
+ public string ProjectName { get; set; }
public DateTime CurrentTime { get; set; }
public DateTime OriginTime { get; set; }
public double EastCoordinate { get; set; }
@@ -14,7 +15,8 @@ namespace Txgy.RBS.Framework.Models
public double ML { get; set; }
public double Energy { get; set; }
-
+ public int PhasesCount { get; set; }
+ public int AmpsCount { get; set; }
public int EarthquakeSource { get; set; }
public bool IsSend { get => isSend; set => isSend = value; }
diff --git a/Txgy.RBS.Framework/ProcessConfig.cs b/Txgy.RBS.Framework/ProcessConfig.cs
index f246270..94ed6ca 100644
--- a/Txgy.RBS.Framework/ProcessConfig.cs
+++ b/Txgy.RBS.Framework/ProcessConfig.cs
@@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Text.Json.Serialization;
using System.Threading.Tasks;
+using Txgy.RBS.Framework.FileWatcherHelper;
namespace Txgy.RBS.Framework
{
@@ -11,7 +13,7 @@ namespace Txgy.RBS.Framework
///
/// server程序
///
- public ProcessInfo Server { get; set; }
+ // public ProcessInfo Server { get; set; }
///
/// Recv程序
///
@@ -21,5 +23,9 @@ namespace Txgy.RBS.Framework
///
public ProcessInfo Apms { get; set; }
+
+
+ [JsonIgnore]
+ public FilesWatcherService FilesWatcherService { get; set; }
}
}
diff --git a/Txgy.RBS.Framework/RedisHelper/Init/RedisManager.cs b/Txgy.RBS.Framework/RedisHelper/Init/RedisManager.cs
index 0c92439..8077634 100644
--- a/Txgy.RBS.Framework/RedisHelper/Init/RedisManager.cs
+++ b/Txgy.RBS.Framework/RedisHelper/Init/RedisManager.cs
@@ -38,6 +38,7 @@ namespace Txgy.RBS.Framework.RedisHelper.Init
MaxWritePoolSize = RedisConfigInfo.MaxWritePoolSize,
MaxReadPoolSize = RedisConfigInfo.MaxReadPoolSize,
AutoStart = RedisConfigInfo.AutoStart,
+ DefaultDb=2
});
}
diff --git a/Txgy.RBS.IServices/AutoMapObject.cs b/Txgy.RBS.IServices/AutoMapObject.cs
index b88ed01..f63ab9a 100644
--- a/Txgy.RBS.IServices/AutoMapObject.cs
+++ b/Txgy.RBS.IServices/AutoMapObject.cs
@@ -14,13 +14,14 @@ namespace Txgy.RBS.IServices
CreateMap().ReverseMap();
CreateMap()
.ForMember(p => p.timeTab, pd => pd.MapFrom(s => s.time_tab))
- .ForMember(p => p.stationFile, pd => pd.MapFrom(s => s.stationFile)).ReverseMap();
+ .ForMember(p => p.stationFile, pd => pd.MapFrom(s => s.station_file)).ReverseMap();
CreateMap().ReverseMap();
CreateMap().ReverseMap();
CreateMap().ReverseMap();
CreateMap().ReverseMap();
CreateMap().ReverseMap();
CreateMap().ReverseMap();
+ CreateMap().ReverseMap();
}
}
}
diff --git a/Txgy.RBS.IServices/IResultInfoService.cs b/Txgy.RBS.IServices/IResultInfoService.cs
index fa2649f..efabf4d 100644
--- a/Txgy.RBS.IServices/IResultInfoService.cs
+++ b/Txgy.RBS.IServices/IResultInfoService.cs
@@ -19,8 +19,20 @@ namespace Txgy.RBS.IServices
ApiResult UpdateResultInfo(ResultDTO resultJsonDTO);
ResultDTO GetResultInfo(int id);
-
+
+ List GetResultInfo(string projectName, DateTime startTime,DateTime endTime);
+
List GetAllResultInfo();
-
+
+ List GetAllRidesInfo();
+
+ ApiResult AddRedisInfo(RedisInfoDTO redisServerDTO);
+
+ ApiResult DeleteRedisInfo(int id);
+
+ ApiResult UpdateRedisInfo(RedisInfoDTO redisServerDTO);
+
+ RedisInfoDTO GetRedisInfo(int id);
+
}
}
diff --git a/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs b/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs
index ecdb3bc..6f2ee82 100644
--- a/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs
+++ b/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs
@@ -32,6 +32,12 @@ namespace Txgy.RBS.Server.WebApi.Controllers
[HttpPost]
public ApiResult AddProjectInfo(ProjectInfoDTO project)
{
+ //var pro= _projectInfoService.GetProjectInfo(1);
+ // pro.id=project.id;
+ // pro.project_id = project.project_id;
+ // pro.project_name = project.project_name;
+ // pro.moni_layer = project.moni_layer;
+ // pro.moni_num = project.moni_num;
return _projectInfoService.AddProjectInfo(project);
}
@@ -144,8 +150,8 @@ namespace Txgy.RBS.Server.WebApi.Controllers
System.IO.File.WriteAllText(Path.Combine(path, CommonData.RecvDefaultPath), recvJson);
_processConfig.RecvMqtt.ProPath = Path.Combine(path, _processConfig.RecvMqtt.ProPath);
}
- _processConfig.Server.ProPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _processConfig.Server.ProPath);
- res= _projectInfoService.StartProject(curProject.project_name, _processConfig);
+ _processConfig.FilesWatcherService = new Framework.FileWatcherHelper.FilesWatcherService(curProject.project_id,curProject.project_name,apm.savepath);
+ res= _projectInfoService.StartProject(curProject.project_name, _processConfig);
res.Data = curProject;
}
return res;
diff --git a/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs b/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs
index fde3b5b..0848081 100644
--- a/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs
+++ b/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs
@@ -19,7 +19,7 @@ namespace Txgy.RBS.Server.WebApi.Controllers
this._resultInfoService = resultInfoService;
}
[HttpPost]
- public ApiResult AddProjectInfo(ResultDTO resultDTO)
+ public ApiResult AddResultInfo(ResultDTO resultDTO)
{
return _resultInfoService.AddResultInfo(resultDTO);
}
@@ -41,11 +41,40 @@ namespace Txgy.RBS.Server.WebApi.Controllers
{
return _resultInfoService.GetResultInfo(id);
}
+ [HttpGet]
+ public List GetResultInfo(string projectName, DateTime startTime, DateTime endTime)
+ {
+ return _resultInfoService.GetResultInfo(projectName.Trim(), startTime, endTime);
+ }
[HttpGet]
public List GetAllResultInfo()
{
return _resultInfoService.GetAllResultInfo();
}
+
+ [HttpPost]
+ public ApiResult AddRedisInfo(RedisInfoDTO redisDTO)
+ {
+ return _resultInfoService.AddRedisInfo(redisDTO);
+ }
+
+ [HttpDelete("{id}")]
+ public ApiResult DeleteRedisInfo(int id)
+ {
+ return _resultInfoService.DeleteRedisInfo(id);
+ }
+
+ [HttpPost]
+ public ApiResult UpdateRedisInfo(RedisInfoDTO redisDTO)
+ {
+ return _resultInfoService.UpdateRedisInfo(redisDTO);
+ }
+
+ [HttpGet]
+ public List GetAllRedisInfo()
+ {
+ return _resultInfoService.GetAllRidesInfo();
+ }
}
}
diff --git a/Txgy.RBS.Server.WebApi/Program.cs b/Txgy.RBS.Server.WebApi/Program.cs
index 69a7765..f34533d 100644
--- a/Txgy.RBS.Server.WebApi/Program.cs
+++ b/Txgy.RBS.Server.WebApi/Program.cs
@@ -7,9 +7,6 @@ using Txgy.RBS.Server.WebApi.Register;
var builder = WebApplication.CreateBuilder(args);
-// Add services to the container.
-
-builder.Register(); //ҵע
//֧Automapperӳ
builder.Services.AddAutoMapper(typeof(AutoMapObject));
@@ -19,6 +16,10 @@ builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// ñػ
builder.Services.AddMemoryCache();
+
+//ҵע
+builder.Register();
+
var app = builder.Build();
// Configure the HTTP request pipeline.
diff --git a/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs b/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs
index 5869b67..cc3c21a 100644
--- a/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs
+++ b/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs
@@ -3,8 +3,10 @@ using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using SqlSugar;
+using System.Diagnostics;
using System.Reflection;
using Txgy.RBS.Framework;
+using Txgy.RBS.Framework.RedisHelper.Init;
using Txgy.RBS.Framework.RedisHelper.Service;
using Txgy.RBS.Services;
@@ -14,7 +16,6 @@ namespace Txgy.RBS.Server.WebApi.Register
{
public static void Register(this WebApplicationBuilder applicationBuilder)
{
-
//替换容器Autofac
applicationBuilder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
applicationBuilder.Host.ConfigureContainer(ConfigurationBinder =>
@@ -26,7 +27,7 @@ namespace Txgy.RBS.Server.WebApi.Register
Assembly serviceAssembly = Assembly.Load("Txgy.RBS.IServices");
ConfigurationBinder.RegisterAssemblyTypes(interfaceAssembly, serviceAssembly).AsImplementedInterfaces();
#endregion
- var pro= applicationBuilder.Configuration.GetSection("process").Get();
+ var pro = applicationBuilder.Configuration.GetSection("process").Get();
ConfigurationBinder.RegisterType().SingleInstance();
#region 注册每个控制器和抽象之间的关系
var controllerBaseType = typeof(ControllerBase);
@@ -37,7 +38,7 @@ namespace Txgy.RBS.Server.WebApi.Register
#region 注册SqlSugar
ConfigurationBinder.Register(context =>
{
- SqlSugarClient client = new SqlSugarClient(new ConnectionConfig()
+ SqlSugarClient client = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = applicationBuilder.Configuration.GetConnectionString("ConnectionSqlite"), // "Data Source=DESKTOP-T2D6ILD;Initial Catalog=LiveBackgroundManagementNew;Persist Security Info=True;User ID=sa;Password=sa123",
DbType = DbType.Sqlite,
@@ -68,11 +69,40 @@ namespace Txgy.RBS.Server.WebApi.Register
ConfigurationBinder.RegisterType();
ConfigurationBinder.RegisterType();
ConfigurationBinder.RegisterType();
- }
- #endregion
+ //启动redis服务
+ {
+ //* Create your Process
+ Process process = new Process();
+ process.Exited += Process_Exited;
+ process.EnableRaisingEvents = true;
+ process.StartInfo.FileName = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CommonData.RedisDefaultPath, "server.exe"));
+ process.StartInfo.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CommonData.RedisDefaultPath);
+ // process.StartInfo.Arguments = "service.conf";
+ Debug.WriteLine($"*******ProcessName:{process.StartInfo.FileName}, arguments:{process.StartInfo.Arguments}*********");
+ process.StartInfo.UseShellExecute = true;
+ process.StartInfo.CreateNoWindow = false;
+ //* Start process and handlers
+ Process[] localByName = Process.GetProcessesByName("server");
+
+ if (localByName.Length != 0)
+ {
+ localByName[0].Exited += Process_Exited;
+ localByName[0].EnableRaisingEvents = true;
+ process = localByName[0];
+ return;
+ }
+ bool res = process.Start();
+ }
+ }
+ #endregion
});
+ applicationBuilder.Services.Configure(applicationBuilder.Configuration.GetSection("RedisConfigInfo"));
+ }
+
+ private static void Process_Exited(object? sender, EventArgs e)
+ {
}
}
}
diff --git a/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj b/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj
index 11418b6..08874fb 100644
--- a/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj
+++ b/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj
@@ -22,7 +22,7 @@
- PreserveNewest
+ Never
diff --git a/Txgy.RBS.Server.WebApi/appsettings.json b/Txgy.RBS.Server.WebApi/appsettings.json
index cfff6b9..41f5c20 100644
--- a/Txgy.RBS.Server.WebApi/appsettings.json
+++ b/Txgy.RBS.Server.WebApi/appsettings.json
@@ -46,5 +46,15 @@
"ShowState": 0
}
},
+ "RedisConfigInfo": {
+ "WriteServerList": "127.0.0.1:6379",
+ "ReadServerList": "127.0.0.1:6379",
+ "MaxWritePoolSize": 60,
+ "MaxReadPoolSize": 60,
+ "LocalCacheTime": 180,
+ "AutoStart": true,
+ "RecordeLog": true
+
+ },
"AllowedHosts": "*"
}
diff --git a/Txgy.RBS.Server.WebApi/rbs_server_db.db b/Txgy.RBS.Server.WebApi/rbs_server_db.db
index 8325613..a902ced 100644
Binary files a/Txgy.RBS.Server.WebApi/rbs_server_db.db and b/Txgy.RBS.Server.WebApi/rbs_server_db.db differ
diff --git a/Txgy.RBS.Services/ProcessManagerService.cs b/Txgy.RBS.Services/ProcessManagerService.cs
index a437174..4b6b8f4 100644
--- a/Txgy.RBS.Services/ProcessManagerService.cs
+++ b/Txgy.RBS.Services/ProcessManagerService.cs
@@ -1,35 +1,52 @@
-using System.Diagnostics;
-using Txgy.RBS.Framework.Api;
-using Txgy.RBS.Framework;
+using Aspose.Cells;
using Microsoft.Extensions.Caching.Memory;
using System.Collections.Concurrent;
-using ServiceStack;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Serialization;
-using Newtonsoft.Json.Linq;
using System.Data;
+using System.Diagnostics;
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.RedisHelper.Service;
+using Txgy.RBS.IServices;
namespace Txgy.RBS.Services
{
public class ProcessManagerService
{
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.Elapsed += MoniTimer_Elapsed;
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)
- {
+ {
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())
{
var pro = proValue.GetValue(item.Value) as ProcessInfo;
@@ -38,15 +55,27 @@ namespace Txgy.RBS.Services
int sfp = FindProcess(pro);
if (sfp != 0)
{
- Console.WriteLine($"{pro.ProName}程序重启中,path:{pro.ProPath}");
+ pro.State = false;
+ Console.WriteLine($"{pro.ProName}程序重启中, path:{pro.ProPath}");
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,
+ }));
}
- }
+ }
}
}
-
+
public ConcurrentDictionary ProjectMonitor = new ConcurrentDictionary();
public void StartMointor(string projectName, ProcessConfig processInfo)
@@ -54,6 +83,9 @@ namespace Txgy.RBS.Services
if (!ProjectMonitor.ContainsKey(projectName))
{
ProjectMonitor.TryAdd(projectName, processInfo);
+ processInfo.FilesWatcherService.InitializeParams();
+ processInfo.FilesWatcherService.Start();
+ processInfo.FilesWatcherService.WatcherFileChanged = WatcherChanged;
}
}
System.Timers.Timer MoniTimer { get; set; } = new System.Timers.Timer();
@@ -61,16 +93,60 @@ namespace Txgy.RBS.Services
{
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 方法
public ApiResult StartProject(string projectName, ProcessConfig processConfig)
{
int res = 0;
- if (ProjectMonitor.ContainsKey(projectName)) new ApiResult();
+ if (ProjectMonitor.ContainsKey(projectName))
+ {
+ return new ApiResult();
+ }
foreach (var item in processConfig.GetType().GetProperties())
{
var pro = item.GetValue(processConfig) as ProcessInfo;
@@ -79,11 +155,11 @@ namespace Txgy.RBS.Services
res = StartProcess(pro);
if (res != 0)
{
- break;
+ continue;
}
pro.StartTime = DateTime.Now;
pro.State = true;
- _cache.Set(pro.ProPath, pro);
+ // _cache.Set(pro.ProPath, pro);
Thread.Sleep(10);
}
}
@@ -113,7 +189,7 @@ namespace Txgy.RBS.Services
break;
}
pro.State = false;
- _cache.Set(pro.ProPath, pro);
+ // _cache.Set(pro.ProPath, pro);
Thread.Sleep(10);
}
}
@@ -246,7 +322,15 @@ namespace Txgy.RBS.Services
}
else
{
- var pro= localByName.Where(p => p.MainModule.FileName.Contains(processInfo.ProPath));
+ List 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())
{
ri = 1;
@@ -265,9 +349,14 @@ namespace Txgy.RBS.Services
public ApiResult GetState(string projectName, int id)
{
+ ProcessInfo pro = null;
+ if(id==1)
+ {
+ pro = this.RedisServer;
+ }
ProjectMonitor.TryGetValue(projectName, out ProcessConfig process);
- if (process == null|| (id<1 || id>3)) { return new ApiResult(); }
- ProcessInfo pro = id == 1 ? process.Server : id == 2 ? process.Apms : process.RecvMqtt;
+ if (process == null || (id < 1|| id > 3)) { return new ApiResult(); }
+ pro = id == 1 ?pro:(id==2)? process.Apms : process.RecvMqtt;
int sfp = FindProcess(pro);
if (sfp != 0)
{
@@ -275,13 +364,14 @@ namespace Txgy.RBS.Services
}
return new ApiResult
{
- Code = System.Net.HttpStatusCode.OK, Data = new
+ Code = System.Net.HttpStatusCode.OK,
+ Data = new
{
- name=pro.ProName,
- state= sfp == 0 ? 1 : 0,
- start_time=pro.StartTime,
- running_time=(DateTime.Now-pro.StartTime).TotalSeconds,
- }
+ name = pro.ProName,
+ state = sfp == 0 ? 1 : 0,
+ start_time = pro.StartTime,
+ running_time = (DateTime.Now - pro.StartTime).TotalSeconds,
+ }
};
}
diff --git a/Txgy.RBS.Services/ProjectInfoService.cs b/Txgy.RBS.Services/ProjectInfoService.cs
index 879c5e6..e2fd343 100644
--- a/Txgy.RBS.Services/ProjectInfoService.cs
+++ b/Txgy.RBS.Services/ProjectInfoService.cs
@@ -1,4 +1,5 @@
-using AutoMapper;
+using Aspose.Cells;
+using AutoMapper;
using Microsoft.Extensions.Caching.Memory;
using SqlSugar;
using System;
@@ -29,20 +30,31 @@ namespace Txgy.RBS.Services
public ApiResult AddProjectInfo(ProjectInfoDTO project)
{
- project_info project_Info = _iMapper.Map(project);
-
- var pro = _Client.InsertNav(project_Info).Include(p=>p.stationFile).ThenInclude(t=>t.stations)
- .Include(time => time.time_tab).ExecuteCommand();
- if (pro)
+ try
{
- return new ApiResult();
+ _Client.Ado.BeginTran();
+ var projectInfo = _iMapper.Map(project);
+ //project_id要手动赋值
+ projectInfo.project_id= _Client.Queryable().Max(p=>p.project_id)+1;
+ projectInfo.station_file.project_id= projectInfo.project_id;
+ projectInfo.time_tab.project_id = projectInfo.project_id;
+ var pro = _Client.InsertNav(projectInfo).Include(p => p.station_file).ThenInclude(t => t.stations)
+ .Include(time => time.time_tab).ExecuteCommand();
+
+ _Client.Ado.CommitTran();
+ }
+ catch (Exception ex)
+ {
+ _Client.Ado.RollbackTran();
+ return new ApiResult() { Message = $"添加失败,{ex}" };
}
- return new ApiResult() { Message = "添加失败" };
+ return new ApiResult();
+
}
public ApiResult DeleteProjectInfo(int id)
{
- var res = _Client.DeleteNav(p => p.id == id).Include(p => p.stationFile).ThenInclude(t => t.stations)
+ var res = _Client.DeleteNav(p => p.id == id).Include(p => p.station_file).ThenInclude(t => t.stations)
.Include(time => time.time_tab).ExecuteCommand();
if (res)
{
@@ -53,7 +65,7 @@ namespace Txgy.RBS.Services
public List GetAllProjectInfo()
{
- var projects = _Client.Queryable().Includes(x => x.stationFile, t=>t.stations)
+ var projects = _Client.Queryable().Includes(x => x.station_file, t=>t.stations)
.Includes(ti=>ti.time_tab).ToList();
var projectDTOs= _iMapper.Map>(projects);
return projectDTOs;
@@ -69,7 +81,7 @@ namespace Txgy.RBS.Services
public ApiResult UpdateProjectInfo(ProjectInfoDTO project)
{
project_info projectInfo = _iMapper.Map(project);
- var res = _Client.UpdateNav(projectInfo).Include(p => p.stationFile).ThenInclude(t => t.stations)
+ var res = _Client.UpdateNav(projectInfo).Include(p => p.station_file).ThenInclude(t => t.stations)
.Include(time => time.time_tab).ExecuteCommand();
if (res)
{
@@ -80,19 +92,8 @@ namespace Txgy.RBS.Services
public ProjectInfoDTO GetProjectInfo(int id)
{
- project_info projectInfo = _Client.Queryable().Includes(x => x.stationFile, t => t.stations).Includes(ti => ti.time_tab).Where(p => p.id == id).First();
- ProjectInfoDTO projectInfoDTO = _iMapper.Map(projectInfo);
-
- //test
- //if (projectInfoDTO != null)
- //{
- // projectInfoDTO.id = 6;
- // projectInfoDTO.project_id = 9;
- // projectInfoDTO.project_name = "tea";
- // projectInfoDTO.moni_layer = 1;
- // projectInfoDTO.moni_num = 8;
- // var a = UpdateProjectInfo(projectInfoDTO);
- //}
+ var projectInfo = _Client.Queryable().Where(p => p.project_id == id).Includes(p=>p.station_file, s=>s.stations).Includes(p=>p.time_tab).ToList();
+ ProjectInfoDTO projectInfoDTO = _iMapper.Map(projectInfo[0]);
return projectInfoDTO;
}
@@ -120,7 +121,6 @@ namespace Txgy.RBS.Services
}
public ApiResult GetState(string projectName, int id)
{
-
return _processManager.GetState(projectName, id);
}
diff --git a/Txgy.RBS.Services/ResultInfoService.cs b/Txgy.RBS.Services/ResultInfoService.cs
index 647411e..8eadbad 100644
--- a/Txgy.RBS.Services/ResultInfoService.cs
+++ b/Txgy.RBS.Services/ResultInfoService.cs
@@ -21,6 +21,19 @@ namespace Txgy.RBS.Services
this._iMapper = iMapper;
}
+ public ApiResult AddRedisInfo(RedisInfoDTO redisServerDTO)
+ {
+ int res = 0;
+ var redisServer = _iMapper.Map(redisServerDTO);
+
+ res = _Client.Insertable(redisServer).ExecuteCommand();
+ if (res > 0)
+ {
+ return new ApiResult();
+ }
+ return new ApiResult() { Message = "添加失败" };
+ }
+
public ApiResult AddResultInfo(ResultDTO resultJsonDTO)
{
int res = 0;
@@ -34,6 +47,16 @@ namespace Txgy.RBS.Services
return new ApiResult() { Message = "添加失败" };
}
+ public ApiResult DeleteRedisInfo(int id)
+ {
+ int res = _Client.Deleteable(p => p.id == id).ExecuteCommand();
+ if (res > 0)
+ {
+ return new ApiResult();
+ }
+ return new ApiResult() { Message = "删除失败" };
+ }
+
public ApiResult DeleteResultInfo(int id)
{
int res= _Client.Deleteable(p=>p.id==id).ExecuteCommand();
@@ -49,7 +72,18 @@ namespace Txgy.RBS.Services
var projects = _Client.Queryable().ToList();
return _iMapper.Map>(projects);
}
+ public List GetAllRidesInfo()
+ {
+ var projects = _Client.Queryable().ToList();
+ return _iMapper.Map>(projects);
+ }
+ public RedisInfoDTO GetRedisInfo(int id)
+ {
+ var RedisServer = _Client.Queryable().First(c => c.id == id);
+ var redisServerDTO = _iMapper.Map(RedisServer);
+ return redisServerDTO;
+ }
public ResultDTO GetResultInfo(int id)
{
@@ -58,6 +92,29 @@ namespace Txgy.RBS.Services
return resultJsonDTO;
}
+ public List GetResultInfo(string projectName, DateTime startTime, DateTime endTime)
+ {
+ var pro= _Client.Queryable().Where(p => p.project_name == projectName).First();
+ if (pro == null)
+ {
+ return new List();
+ }
+ var results= _Client.Queryable().Where(r => r.project_id == pro.project_id
+ && (startTime < Convert.ToDateTime(r.otime) && Convert.ToDateTime(r.otime) < endTime)).ToList();
+ return _iMapper.Map>(results);
+ }
+
+ public ApiResult UpdateRedisInfo(RedisInfoDTO redisServerDTO)
+ {
+ var redisServer = _iMapper.Map(redisServerDTO);
+ int res = _Client.Updateable(redisServer).ExecuteCommand();
+ if (res > 0)
+ {
+ return new ApiResult();
+ }
+ return new ApiResult() { Message = "更新失败" };
+ }
+
public ApiResult UpdateResultInfo(ResultDTO resultJsonDTO)
{
result result_Json = _iMapper.Map (resultJsonDTO);
diff --git a/program/server/server_log.txt b/program/server/server_log.txt
index b3167ca..357c7b8 100644
--- a/program/server/server_log.txt
+++ b/program/server/server_log.txt
@@ -66,3 +66,35 @@
[37440] 17 Apr 14:21:54.835 * Running mode=standalone, port=6379.
[37440] 17 Apr 14:21:54.835 # Server initialized
[37440] 17 Apr 14:21:54.836 * Ready to accept connections
+[7448] 23 Apr 21:40:46.856 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
+[7448] 23 Apr 21:40:46.865 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=7448, just started
+[7448] 23 Apr 21:40:46.865 # Configuration loaded
+[7448] 23 Apr 21:40:46.870 * Running mode=standalone, port=6379.
+[7448] 23 Apr 21:40:46.870 # Server initialized
+[7448] 23 Apr 21:40:46.870 * Ready to accept connections
+[35352] 23 Apr 21:42:21.915 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
+[35352] 23 Apr 21:42:21.916 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=35352, just started
+[35352] 23 Apr 21:42:21.916 # Configuration loaded
+[35352] 23 Apr 21:42:21.919 * Running mode=standalone, port=6379.
+[35352] 23 Apr 21:42:21.919 # Server initialized
+[35352] 23 Apr 21:42:21.919 * Ready to accept connections
+[30100] 23 Apr 21:42:47.458 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
+[30100] 23 Apr 21:42:47.459 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=30100, just started
+[30100] 23 Apr 21:42:47.460 # Configuration loaded
+[30100] 23 Apr 21:42:47.462 * Running mode=standalone, port=6379.
+[30100] 23 Apr 21:42:47.462 # Server initialized
+[30100] 23 Apr 21:42:47.463 * Ready to accept connections
+[29296] 23 Apr 21:43:12.174 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
+[29296] 23 Apr 21:43:12.175 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=29296, just started
+[29296] 23 Apr 21:43:12.175 # Configuration loaded
+[29296] 23 Apr 21:43:12.177 * Running mode=standalone, port=6379.
+[29296] 23 Apr 21:43:12.177 # Server initialized
+[29296] 23 Apr 21:43:12.178 * Ready to accept connections
+[29296] 23 Apr 21:43:54.627 # User requested shutdown...
+[29296] 23 Apr 21:43:54.629 # Redis is now ready to exit, bye bye...
+[14828] 23 Apr 21:45:11.834 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
+[14828] 23 Apr 21:45:11.834 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=14828, just started
+[14828] 23 Apr 21:45:11.835 # Configuration loaded
+[14828] 23 Apr 21:45:11.837 * Running mode=standalone, port=6379.
+[14828] 23 Apr 21:45:11.837 # Server initialized
+[14828] 23 Apr 21:45:11.837 * Ready to accept connections