diff --git a/HTCoreServiceApp/DataHandle/DataExtract.cs b/HTCoreServiceApp/DataHandle/DataExtract.cs index a08612e..b3285ca 100644 --- a/HTCoreServiceApp/DataHandle/DataExtract.cs +++ b/HTCoreServiceApp/DataHandle/DataExtract.cs @@ -10,7 +10,7 @@ using System.Collections; using System.Text.RegularExpressions; using System.Diagnostics; using System.Reflection; -using HTCoreServiceApp.Controllers; +using HTCoreServiceApp.WebApi; namespace HTCoreServiceApp.DataHandle { diff --git a/HTCoreServiceApp/DataHandle/DataExtractAB.cs b/HTCoreServiceApp/DataHandle/DataExtractAB.cs index 8efdbff..e6a2796 100644 --- a/HTCoreServiceApp/DataHandle/DataExtractAB.cs +++ b/HTCoreServiceApp/DataHandle/DataExtractAB.cs @@ -10,7 +10,7 @@ using System.Collections; using System.Text.RegularExpressions; using System.Diagnostics; using System.Reflection; -using HTCoreServiceApp.Controllers; +using HTCoreServiceApp.WebApi; using HTCoreServiceApp.Communicate.AllenBradleyEIP; namespace HTCoreServiceApp.DataHandle diff --git a/HTCoreServiceApp/DataHandle/DataExtractMB.cs b/HTCoreServiceApp/DataHandle/DataExtractMB.cs index 11c4af0..088fd11 100644 --- a/HTCoreServiceApp/DataHandle/DataExtractMB.cs +++ b/HTCoreServiceApp/DataHandle/DataExtractMB.cs @@ -10,7 +10,7 @@ using System.Collections; using System.Text.RegularExpressions; using System.Diagnostics; using System.Reflection; -using HTCoreServiceApp.Controllers; +using HTCoreServiceApp.WebApi; namespace HTCoreServiceApp.DataHandle { diff --git a/HTCoreServiceApp/DataHandle/DataExtractNMB.cs b/HTCoreServiceApp/DataHandle/DataExtractNMB.cs index 2fe9016..980ba3f 100644 --- a/HTCoreServiceApp/DataHandle/DataExtractNMB.cs +++ b/HTCoreServiceApp/DataHandle/DataExtractNMB.cs @@ -10,7 +10,7 @@ using System.Collections; using System.Text.RegularExpressions; using System.Diagnostics; using System.Reflection; -using HTCoreServiceApp.Controllers; +using HTCoreServiceApp.WebApi; namespace HTCoreServiceApp.DataHandle { diff --git a/HTCoreServiceApp/DataHandle/DataExtractTAB.cs b/HTCoreServiceApp/DataHandle/DataExtractTAB.cs index a7666a4..e833002 100644 --- a/HTCoreServiceApp/DataHandle/DataExtractTAB.cs +++ b/HTCoreServiceApp/DataHandle/DataExtractTAB.cs @@ -10,7 +10,7 @@ using System.Collections; using System.Text.RegularExpressions; using System.Diagnostics; using System.Reflection; -using HTCoreServiceApp.Controllers; +using HTCoreServiceApp.WebApi; using HTCoreServiceApp.Communicate.AllenBradleyEIP; namespace HTCoreServiceApp.DataHandle diff --git a/HTCoreServiceApp/HTCoreServiceApp.csproj b/HTCoreServiceApp/HTCoreServiceApp.csproj index c322119..ce195a5 100644 --- a/HTCoreServiceApp/HTCoreServiceApp.csproj +++ b/HTCoreServiceApp/HTCoreServiceApp.csproj @@ -18,6 +18,7 @@ + diff --git a/HTCoreServiceApp/HTCoreServiceApp.http b/HTCoreServiceApp/HTCoreServiceApp.http index 271f4ad..8108251 100644 --- a/HTCoreServiceApp/HTCoreServiceApp.http +++ b/HTCoreServiceApp/HTCoreServiceApp.http @@ -1,11 +1,47 @@ -@HTCoreServiceApp_HostAddress = http://localhost:5162 +@HTCoreServiceApp_HostAddress = http://localhost:8040 GET {{HTCoreServiceApp_HostAddress}}/todos/ Accept: application/json ### -GET {{HTCoreServiceApp_HostAddress}}/todos/1 +GET {{HTCoreServiceApp_HostAddress}}/todos/2 Accept: application/json ### + + +GET {{HTCoreServiceApp_HostAddress}}/DataLiveCache/Get +Accept: application/json + +### + +GET {{HTCoreServiceApp_HostAddress}}/DataLiveCache/1 +Accept: application/json + +### + +GET {{HTCoreServiceApp_HostAddress}}/DataLiveCache/GetLiveGroupData/groupName=MW3200 +Accept: application/json + +### + +GET {{HTCoreServiceApp_HostAddress}}/DataLiveCache/GetLiveTagData/groupName=MW3200&tagName=T2_PT_PV +Accept: application/json + +### + +GET {{HTCoreServiceApp_HostAddress}}/DeviceControl/Get +Accept: application/json + +### + +GET {{HTCoreServiceApp_HostAddress}}/DeviceControl/1 +Accept: application/json + +### + +GET {{HTCoreServiceApp_HostAddress}}/DeviceControl/SetDeviceData/groupName=MW3200&tagName=T2_PT_PV&value=88.0 +Accept: application/json + +### \ No newline at end of file diff --git a/HTCoreServiceApp/Program.cs b/HTCoreServiceApp/Program.cs index a56e4b9..bef5425 100644 --- a/HTCoreServiceApp/Program.cs +++ b/HTCoreServiceApp/Program.cs @@ -1,4 +1,7 @@ using HTCoreServiceApp.Common; +using HTCoreServiceApp.WebApi; +using Microsoft.AspNetCore.Http.Headers; +using Microsoft.AspNetCore.Http.HttpResults; using SqlSugar; using System.Text.Json.Serialization; @@ -35,10 +38,45 @@ namespace HTCoreServiceApp options.InstanceName = "test"; }); - builder.Services.AddEndpointsApiExplorer(); + //builder.Services.AddEndpointsApiExplorer(); + + builder.Services.AddScoped(); + builder.Services.AddScoped(); var app = builder.Build(); + var dataLiveCacheApi = app.MapGroup("/DataLiveCache"); + var deviceControl = app.MapGroup("/DeviceControl"); + + dataLiveCacheApi.MapGet("/Get", + async(DataLiveCache dlc) + => Results.Content(await dlc.Get())); + + dataLiveCacheApi.MapGet("/{Name}", + async (string Name, DataLiveCache dlc) + => Results.Content(await dlc.GetName(Name))); + //tagName + dataLiveCacheApi.MapGet("/GetLiveGroupData/groupName={groupName}", + async (string groupName, DataLiveCache dlc) + => Results.Content(await dlc.GetLiveGroupData(groupName))); + + dataLiveCacheApi.MapGet("/GetLiveTagData/groupName={groupName}&tagName={tagName}", + async (string groupName, string tagName, DataLiveCache dlc) + => Results.Content(await dlc.GetLiveTagData(groupName,tagName))); + + + deviceControl.MapGet("/Get", + async (DeviceControl dc) + => Results.Content(await dc.Get())); + + deviceControl.MapGet("/{Name}", + async (string Name, DeviceControl dc) + => Results.Content(await dc.GetName(Name))); + + deviceControl.MapGet("/SetDeviceData/groupName={groupName}&tagName={tagName}&value={value}", + async (string groupName, string tagName ,string value,DeviceControl dc) + => Results.Content(await dc.SetDeviceData(groupName, tagName, value))); + var sampleTodos = new Todo[] { new(1, "Walk the dog"), new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)), diff --git a/HTCoreServiceApp/Properties/launchSettings.json b/HTCoreServiceApp/Properties/launchSettings.json index ba9a11c..040c23e 100644 --- a/HTCoreServiceApp/Properties/launchSettings.json +++ b/HTCoreServiceApp/Properties/launchSettings.json @@ -8,7 +8,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, - "applicationUrl": "http://localhost:5162" + "applicationUrl": "http://localhost:8040" }, "Docker": { "commandName": "Docker", diff --git a/HTCoreServiceApp/Controllers/DataLiveCache.cs b/HTCoreServiceApp/WebApis/DataLiveCache.cs similarity index 54% rename from HTCoreServiceApp/Controllers/DataLiveCache.cs rename to HTCoreServiceApp/WebApis/DataLiveCache.cs index 8297f84..4b0da38 100644 --- a/HTCoreServiceApp/Controllers/DataLiveCache.cs +++ b/HTCoreServiceApp/WebApis/DataLiveCache.cs @@ -3,39 +3,48 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; -using Newtonsoft.Json; +//using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; -namespace HTCoreServiceApp.Controllers +namespace HTCoreServiceApp.WebApi { [ApiController] - [Route("[controller]/[action]")] - public class DataLiveCache : ControllerBase + //[Route("[controller]/[action]")] + public class DataLiveCache //: ControllerBase { - [HttpGet] - public string Get() //请求方法行为 + //[HttpGet] + public async Task Get() //请求方法行为 { return "hello,这里是恒拓实时服务!"; } - [HttpGet] - public string Getname(string name) //请求方法行为 + //[HttpGet] + public async Task GetName(string Name) //请求方法行为 { - return $"服务器收到字符串:{name}"; + return $"服务器收到字符串:{Name}"; } - [HttpGet] - public string GetLiveGroupData(string groupName) + //[HttpGet] + public async Task GetLiveGroupData(string groupName) { - //var cache = StaticLibrary.MemoryCacheHelper.Get>(driverName).Where(x=>x.GroupName == groupName).First(); - //var val = new List(); - //StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val); - //return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault()); + //var cache = StaticLibrary.MemoryCacheHelper.Get>(driverName).Where(x=>x.GroupName == groupName).First(); + //var val = new List(); + //StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val); + //return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault()); - try + //public static string StringToJson(string JsonString) + //{ // string 转换成Json JsonDocument jsonDocument = JsonDocument.Parse(JsonString);//这里序列化成json return JsonSerializer.Serialize(jsonDocument.RootElement); }//在main中调用 + + try { + //var result = StaticLibrary.MemoryCacheHelper.GetString(groupName); + + //Console.WriteLine(result); + //return result; + //return valueJson.ToString(); return StaticLibrary.MemoryCacheHelper.GetString(groupName); } catch (Exception ex) @@ -43,13 +52,17 @@ namespace HTCoreServiceApp.Controllers return ex.Message; } } - [HttpGet] - public string GetLiveTagData(string groupName, string tagName) + //[HttpGet] + public async Task GetLiveTagData(string groupName, string tagName) { //var cache = StaticLibrary.MemoryCacheHelper.Get>(driverName).Where(x=>x.GroupName == groupName).First(); //var val = new List(); //StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val); //return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault()); + + + //!!!!重要,校验有无groupName + string value = ""; if (tagName != null && tagName != "") { diff --git a/HTCoreServiceApp/Controllers/DeviceController.cs b/HTCoreServiceApp/WebApis/DeviceController.cs similarity index 87% rename from HTCoreServiceApp/Controllers/DeviceController.cs rename to HTCoreServiceApp/WebApis/DeviceController.cs index 827584f..47befe8 100644 --- a/HTCoreServiceApp/Controllers/DeviceController.cs +++ b/HTCoreServiceApp/WebApis/DeviceController.cs @@ -16,11 +16,11 @@ using System.Linq.Expressions; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; -namespace HTCoreServiceApp.Controllers +namespace HTCoreServiceApp.WebApi { - [ApiController] - [Route("[controller]/[action]")] - public class DeviceControl : ControllerBase + //[ApiController] + //[Route("[controller]/[action]")] + public class DeviceControl // : ControllerBase { private readonly DriverService _driverService; private readonly List metaGroups; @@ -36,25 +36,28 @@ namespace HTCoreServiceApp.Controllers metaTags = db.Queryable().ToList(); //db.MetaTags.ToList(); db.Dispose(); } - [HttpGet] - public string Get() //请求方法行为 + //[HttpGet] + public async Task Get() //请求方法行为 { return "hello,这里是恒拓设备实时控制服务!"; } - [HttpGet] - public string Getname(string name) //请求方法行为 + //[HttpGet] + public async Task GetName(string Name) //请求方法行为 { - return $"服务器收到字符串:{name}"; + return $"服务器收到字符串:{Name}"; } - [HttpGet] - public int SetDeviceData(string groupName,string tagName,string value) + //[HttpGet] + public async Task SetDeviceData(string groupName,string tagName,string value) { - var ip = HttpContext.GetClientUserIp(); + + //var ip = HttpContext.GetClientUserIp(); //var cache = StaticLibrary.MemoryCacheHelper.Get>(driverName).Where(x=>x.GroupName == groupName).First(); //var val = new List(); //StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val); //return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault()); + //var userAgent = HttpContext. + int reCode = 0; //直接返回,取消后续写入步骤 @@ -73,7 +76,7 @@ namespace HTCoreServiceApp.Controllers if(writeAddress == ""|| writeAddress == null) { reCode = 1; - return reCode; + return reCode.ToString(); } var windex = writeAddress.IndexOf("."); writeAddress = writeAddress.Remove(windex, 1).Insert(windex, ","); @@ -122,7 +125,7 @@ namespace HTCoreServiceApp.Controllers { reCode = 1; } - return reCode; + return reCode.ToString(); } } } diff --git a/HTCoreServiceApp/Controllers/Extension.cs b/HTCoreServiceApp/WebApis/Extension.cs similarity index 93% rename from HTCoreServiceApp/Controllers/Extension.cs rename to HTCoreServiceApp/WebApis/Extension.cs index 770c622..d9b9137 100644 --- a/HTCoreServiceApp/Controllers/Extension.cs +++ b/HTCoreServiceApp/WebApis/Extension.cs @@ -3,7 +3,7 @@ using System.Linq; using Microsoft.AspNetCore.Mvc.ModelBinding; using System.Collections.Generic; -namespace HTCoreServiceApp.Controllers +namespace HTCoreServiceApp.WebApi { public static class Extension { diff --git a/HTCoreServiceApp/Controllers/ValuesController.cs b/HTCoreServiceApp/WebApis/ValuesController.cs similarity index 83% rename from HTCoreServiceApp/Controllers/ValuesController.cs rename to HTCoreServiceApp/WebApis/ValuesController.cs index a41fb28..4401dbd 100644 --- a/HTCoreServiceApp/Controllers/ValuesController.cs +++ b/HTCoreServiceApp/WebApis/ValuesController.cs @@ -3,16 +3,15 @@ using Microsoft.AspNetCore.Mvc; namespace HTCoreServiceApp.Controllers { - [ApiController] - [Route("[controller]/[action]")] + public class ValuesController : ControllerBase { - [HttpGet] + public string Get() //请求方法行为 { return "hello,这里是恒拓实时服务测试!"; } - [HttpGet] + public string Getname(string name) //请求方法行为 { return $"服务器收到字符串:{name}"; diff --git a/README.md b/README.md index 6ebf7ba..56f02a9 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# HTCoreServiceApp \ No newline at end of file +# HTCoreServiceApp +V8 \ No newline at end of file