Api修改
This commit is contained in:
@ -10,7 +10,7 @@ using System.Collections;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using HTCoreServiceApp.Controllers;
|
using HTCoreServiceApp.WebApi;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.DataHandle
|
namespace HTCoreServiceApp.DataHandle
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ using System.Collections;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using HTCoreServiceApp.Controllers;
|
using HTCoreServiceApp.WebApi;
|
||||||
using HTCoreServiceApp.Communicate.AllenBradleyEIP;
|
using HTCoreServiceApp.Communicate.AllenBradleyEIP;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.DataHandle
|
namespace HTCoreServiceApp.DataHandle
|
||||||
|
@ -10,7 +10,7 @@ using System.Collections;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using HTCoreServiceApp.Controllers;
|
using HTCoreServiceApp.WebApi;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.DataHandle
|
namespace HTCoreServiceApp.DataHandle
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ using System.Collections;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using HTCoreServiceApp.Controllers;
|
using HTCoreServiceApp.WebApi;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.DataHandle
|
namespace HTCoreServiceApp.DataHandle
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ using System.Collections;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using HTCoreServiceApp.Controllers;
|
using HTCoreServiceApp.WebApi;
|
||||||
using HTCoreServiceApp.Communicate.AllenBradleyEIP;
|
using HTCoreServiceApp.Communicate.AllenBradleyEIP;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.DataHandle
|
namespace HTCoreServiceApp.DataHandle
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Remove="WebApis\ValuesController.cs" />
|
||||||
<Compile Remove="DataHandle\DataExtractOpc.cs" />
|
<Compile Remove="DataHandle\DataExtractOpc.cs" />
|
||||||
<Compile Remove="Models\HT_Service_Log.cs" />
|
<Compile Remove="Models\HT_Service_Log.cs" />
|
||||||
<Compile Remove="Models\LogAlarm.cs" />
|
<Compile Remove="Models\LogAlarm.cs" />
|
||||||
|
@ -1,11 +1,47 @@
|
|||||||
@HTCoreServiceApp_HostAddress = http://localhost:5162
|
@HTCoreServiceApp_HostAddress = http://localhost:8040
|
||||||
|
|
||||||
GET {{HTCoreServiceApp_HostAddress}}/todos/
|
GET {{HTCoreServiceApp_HostAddress}}/todos/
|
||||||
Accept: application/json
|
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
|
Accept: application/json
|
||||||
|
|
||||||
###
|
###
|
@ -1,4 +1,7 @@
|
|||||||
using HTCoreServiceApp.Common;
|
using HTCoreServiceApp.Common;
|
||||||
|
using HTCoreServiceApp.WebApi;
|
||||||
|
using Microsoft.AspNetCore.Http.Headers;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
@ -35,10 +38,45 @@ namespace HTCoreServiceApp
|
|||||||
options.InstanceName = "test";
|
options.InstanceName = "test";
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
//builder.Services.AddEndpointsApiExplorer();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<DataLiveCache>();
|
||||||
|
builder.Services.AddScoped<DeviceControl>();
|
||||||
|
|
||||||
var app = builder.Build();
|
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[] {
|
var sampleTodos = new Todo[] {
|
||||||
new(1, "Walk the dog"),
|
new(1, "Walk the dog"),
|
||||||
new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
|
new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"applicationUrl": "http://localhost:5162"
|
"applicationUrl": "http://localhost:8040"
|
||||||
},
|
},
|
||||||
"Docker": {
|
"Docker": {
|
||||||
"commandName": "Docker",
|
"commandName": "Docker",
|
||||||
|
@ -3,39 +3,48 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Newtonsoft.Json;
|
//using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.Controllers
|
namespace HTCoreServiceApp.WebApi
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
//[Route("[controller]/[action]")]
|
||||||
public class DataLiveCache : ControllerBase
|
public class DataLiveCache //: ControllerBase
|
||||||
{
|
{
|
||||||
|
|
||||||
[HttpGet]
|
//[HttpGet]
|
||||||
public string Get() //请求方法行为
|
public async Task<string?> Get() //请求方法行为
|
||||||
{
|
{
|
||||||
return "hello,这里是恒拓实时服务!";
|
return "hello,这里是恒拓实时服务!";
|
||||||
}
|
}
|
||||||
[HttpGet]
|
//[HttpGet]
|
||||||
public string Getname(string name) //请求方法行为
|
public async Task<string> GetName(string Name) //请求方法行为
|
||||||
{
|
{
|
||||||
return $"服务器收到字符串:{name}";
|
return $"服务器收到字符串:{Name}";
|
||||||
}
|
}
|
||||||
[HttpGet]
|
//[HttpGet]
|
||||||
public string GetLiveGroupData(string groupName)
|
public async Task<string> GetLiveGroupData(string groupName)
|
||||||
{
|
{
|
||||||
//var cache = StaticLibrary.MemoryCacheHelper.Get<List<LiveGroupDictionary>>(driverName).Where(x=>x.GroupName == groupName).First();
|
//var cache = StaticLibrary.MemoryCacheHelper.Get<List<LiveGroupDictionary>>(driverName).Where(x=>x.GroupName == groupName).First();
|
||||||
//var val = new List<LiveGroupDictionary>();
|
//var val = new List<LiveGroupDictionary>();
|
||||||
//StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val);
|
//StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val);
|
||||||
//return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault());
|
//return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault());
|
||||||
|
|
||||||
|
//public static string StringToJson(string JsonString)
|
||||||
|
//{ // string 转换成Json JsonDocument jsonDocument = JsonDocument.Parse(JsonString);//这里序列化成json return JsonSerializer.Serialize(jsonDocument.RootElement); }//在main中调用
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//var result = StaticLibrary.MemoryCacheHelper.GetString(groupName);
|
||||||
|
|
||||||
|
//Console.WriteLine(result);
|
||||||
|
//return result;
|
||||||
|
//return valueJson.ToString();
|
||||||
return StaticLibrary.MemoryCacheHelper.GetString(groupName);
|
return StaticLibrary.MemoryCacheHelper.GetString(groupName);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -43,13 +52,17 @@ namespace HTCoreServiceApp.Controllers
|
|||||||
return ex.Message;
|
return ex.Message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpGet]
|
//[HttpGet]
|
||||||
public string GetLiveTagData(string groupName, string tagName)
|
public async Task<string> GetLiveTagData(string groupName, string tagName)
|
||||||
{
|
{
|
||||||
//var cache = StaticLibrary.MemoryCacheHelper.Get<List<LiveGroupDictionary>>(driverName).Where(x=>x.GroupName == groupName).First();
|
//var cache = StaticLibrary.MemoryCacheHelper.Get<List<LiveGroupDictionary>>(driverName).Where(x=>x.GroupName == groupName).First();
|
||||||
//var val = new List<LiveGroupDictionary>();
|
//var val = new List<LiveGroupDictionary>();
|
||||||
//StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val);
|
//StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val);
|
||||||
//return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault());
|
//return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault());
|
||||||
|
|
||||||
|
|
||||||
|
//!!!!重要,校验有无groupName
|
||||||
|
|
||||||
string value = "";
|
string value = "";
|
||||||
if (tagName != null && tagName != "")
|
if (tagName != null && tagName != "")
|
||||||
{
|
{
|
@ -16,11 +16,11 @@ using System.Linq.Expressions;
|
|||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.Controllers
|
namespace HTCoreServiceApp.WebApi
|
||||||
{
|
{
|
||||||
[ApiController]
|
//[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
//[Route("[controller]/[action]")]
|
||||||
public class DeviceControl : ControllerBase
|
public class DeviceControl // : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly DriverService _driverService;
|
private readonly DriverService _driverService;
|
||||||
private readonly List<MetaGroup> metaGroups;
|
private readonly List<MetaGroup> metaGroups;
|
||||||
@ -36,25 +36,28 @@ namespace HTCoreServiceApp.Controllers
|
|||||||
metaTags = db.Queryable<MetaTag>().ToList(); //db.MetaTags.ToList();
|
metaTags = db.Queryable<MetaTag>().ToList(); //db.MetaTags.ToList();
|
||||||
db.Dispose();
|
db.Dispose();
|
||||||
}
|
}
|
||||||
[HttpGet]
|
//[HttpGet]
|
||||||
public string Get() //请求方法行为
|
public async Task<string> Get() //请求方法行为
|
||||||
{
|
{
|
||||||
return "hello,这里是恒拓设备实时控制服务!";
|
return "hello,这里是恒拓设备实时控制服务!";
|
||||||
}
|
}
|
||||||
[HttpGet]
|
//[HttpGet]
|
||||||
public string Getname(string name) //请求方法行为
|
public async Task<string> GetName(string Name) //请求方法行为
|
||||||
{
|
{
|
||||||
return $"服务器收到字符串:{name}";
|
return $"服务器收到字符串:{Name}";
|
||||||
}
|
}
|
||||||
[HttpGet]
|
//[HttpGet]
|
||||||
public int SetDeviceData(string groupName,string tagName,string value)
|
public async Task<string> SetDeviceData(string groupName,string tagName,string value)
|
||||||
{
|
{
|
||||||
var ip = HttpContext.GetClientUserIp();
|
|
||||||
|
//var ip = HttpContext.GetClientUserIp();
|
||||||
//var cache = StaticLibrary.MemoryCacheHelper.Get<List<LiveGroupDictionary>>(driverName).Where(x=>x.GroupName == groupName).First();
|
//var cache = StaticLibrary.MemoryCacheHelper.Get<List<LiveGroupDictionary>>(driverName).Where(x=>x.GroupName == groupName).First();
|
||||||
//var val = new List<LiveGroupDictionary>();
|
//var val = new List<LiveGroupDictionary>();
|
||||||
//StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val);
|
//StaticLibrary.MemoryCacheHelper.TryGetValue(driverName,out val);
|
||||||
//return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault());
|
//return LiveJsonIntegrate.MetaValues2Json(val.FirstOrDefault());
|
||||||
|
|
||||||
|
//var userAgent = HttpContext.
|
||||||
|
|
||||||
int reCode = 0;
|
int reCode = 0;
|
||||||
|
|
||||||
//直接返回,取消后续写入步骤
|
//直接返回,取消后续写入步骤
|
||||||
@ -73,7 +76,7 @@ namespace HTCoreServiceApp.Controllers
|
|||||||
if(writeAddress == ""|| writeAddress == null)
|
if(writeAddress == ""|| writeAddress == null)
|
||||||
{
|
{
|
||||||
reCode = 1;
|
reCode = 1;
|
||||||
return reCode;
|
return reCode.ToString();
|
||||||
}
|
}
|
||||||
var windex = writeAddress.IndexOf(".");
|
var windex = writeAddress.IndexOf(".");
|
||||||
writeAddress = writeAddress.Remove(windex, 1).Insert(windex, ",");
|
writeAddress = writeAddress.Remove(windex, 1).Insert(windex, ",");
|
||||||
@ -122,7 +125,7 @@ namespace HTCoreServiceApp.Controllers
|
|||||||
{
|
{
|
||||||
reCode = 1;
|
reCode = 1;
|
||||||
}
|
}
|
||||||
return reCode;
|
return reCode.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ using System.Linq;
|
|||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.Controllers
|
namespace HTCoreServiceApp.WebApi
|
||||||
{
|
{
|
||||||
public static class Extension
|
public static class Extension
|
||||||
{
|
{
|
@ -3,16 +3,15 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
|
|
||||||
namespace HTCoreServiceApp.Controllers
|
namespace HTCoreServiceApp.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
|
||||||
[Route("[controller]/[action]")]
|
|
||||||
public class ValuesController : ControllerBase
|
public class ValuesController : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet]
|
|
||||||
public string Get() //请求方法行为
|
public string Get() //请求方法行为
|
||||||
{
|
{
|
||||||
return "hello,这里是恒拓实时服务测试!";
|
return "hello,这里是恒拓实时服务测试!";
|
||||||
}
|
}
|
||||||
[HttpGet]
|
|
||||||
public string Getname(string name) //请求方法行为
|
public string Getname(string name) //请求方法行为
|
||||||
{
|
{
|
||||||
return $"服务器收到字符串:{name}";
|
return $"服务器收到字符串:{name}";
|
Reference in New Issue
Block a user