DeviceController.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. using Microsoft.AspNetCore.Mvc;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Net;
  7. using System.Net.Http;
  8. using System.Net.Http.Headers;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Microsoft.AspNetCore.SignalR;
  12. using Microsoft.Extensions.Logging;
  13. using Ropin.Environmentally.WebScada.Hubs;
  14. using Microsoft.AspNet.SignalR.Client;
  15. using Microsoft.AspNetCore.SignalR.Client;
  16. using FBoxClientDriver.Contract;
  17. using System.Threading;
  18. using Microsoft.AspNetCore.Http;
  19. using Serilog;
  20. using Microsoft.AspNetCore.NodeServices;
  21. using InfluxData.Net.InfluxDb;
  22. using InfluxData.Net.Common.Enums;
  23. using System.Linq;
  24. namespace Ropin.Environmentally.WebScada
  25. {
  26. public class DeviceController : Controller
  27. {
  28. private readonly IHubContext<MyHub> _hubContext;
  29. private readonly ILogger<DeviceController> _logger;
  30. private Microsoft.AspNetCore.SignalR.Client.HubConnection _hubConnection;
  31. private readonly INodeServices _services;
  32. private InfluxDbClient clientDb;
  33. public DeviceController(ILogger<DeviceController> logger, INodeServices services,IHubContext<MyHub> hubContext)
  34. {
  35. _logger = logger;
  36. _hubContext = hubContext;
  37. _services = services;
  38. }
  39. [HttpGet]
  40. public async Task<string> GetName()
  41. {
  42. string greetingMessage = await _services.InvokeAsync<string>("./scripts/greeter", "yandaniu");
  43. // string fun = @"function (callback, name) {
  44. // var greet = function (name) {
  45. // return 'Hello,Are you ' + name + '?';
  46. // }
  47. // callback(null, greet(name));
  48. //}
  49. //";
  50. // string greetingMessage = await _services.InvokeAsync<string>(fun, "yandaniu");
  51. return greetingMessage;
  52. }
  53. public TokenResult GetToken(AccessUser accessUser)
  54. {
  55. var url = "https://fbox360.com/idserver/core/connect/token";
  56. TokenResult token;
  57. Dictionary<string, object> data = new Dictionary<string, object>();
  58. try
  59. {
  60. if (accessUser == null)
  61. {
  62. throw new Exception("参数为空");
  63. }
  64. else
  65. {
  66. Dictionary<string, string> dict = new Dictionary<string, string>();
  67. if (!string.IsNullOrEmpty(accessUser.refresh_token))
  68. {
  69. dict["grant_type"] = "refresh_token";
  70. dict["refresh_token"] = accessUser.refresh_token;
  71. }
  72. else
  73. {
  74. dict["grant_type"] = "client_credentials";
  75. dict["client_id"] = accessUser.client_id;
  76. dict["client_secret"] = accessUser.client_secret;
  77. dict["scope"] = "fbox";
  78. }
  79. using (HttpClient http = new HttpClient())
  80. {
  81. using (var content = new FormUrlEncodedContent(dict))
  82. {
  83. var msg = http.PostAsync(url, content);
  84. if (msg.IsFaulted)
  85. {
  86. return null;
  87. }
  88. else
  89. {
  90. var result = msg.Result.Content.ReadAsStringAsync().Result;
  91. token = JsonConvert.DeserializeObject<TokenResult>(result);
  92. }
  93. //return Content(result, "application/json");
  94. }
  95. }
  96. }
  97. return token;
  98. }
  99. catch (Exception ex)
  100. {
  101. return null;
  102. }
  103. }
  104. DeviceValueModel device = new DeviceValueModel();
  105. private void _fbox_DataMonitorValueChanged(object sender, IList<DataMonitorValueChangedArgs> e)
  106. {
  107. foreach (var dmon in e)
  108. {
  109. var deviceValue = $"dmv:{dmon.Uid},Value:{dmon.Value},Status:{dmon.Status},BoxNo:{dmon.BoxNo},Name:{dmon.Name},BoxId:{dmon.BoxId},GroupName:{dmon.GroupName},Timestamp:{dmon.Timestamp}";
  110. //Console.WriteLine(deviceValue);
  111. //logger.Error($"uid:{dmon.Uid},value:{dmon.Value},Status:{dmon.Status},BoxNo:{dmon.BoxNo},BoxId:{dmon.BoxId},GroupName:{dmon.GroupName},Timestamp:{dmon.Timestamp},Name:{dmon.Name}");
  112. System.DateTime currentTime = new System.DateTime();
  113. currentTime = System.DateTime.Now;
  114. Console.WriteLine(currentTime);
  115. //Clients.All.SendAsync("UpdateData", deviceValue);
  116. switch (dmon.Uid)
  117. {
  118. case 224873575130485457:
  119. device.Value = dmon.Value?.ToString();
  120. device.Name = dmon.Name;
  121. break;
  122. case 225981652471795782:
  123. device.Value10 = dmon.Value?.ToString();
  124. device.Name10 = dmon.Name;
  125. break;
  126. case 224873679711261516:
  127. device.Value11 = dmon.Value?.ToString();
  128. device.Name11 = dmon.Name;
  129. break;
  130. case 225975315764502499:
  131. device.Value12 = dmon.Value?.ToString();
  132. device.Name12 = dmon.Name;
  133. break;
  134. case 225975390380118077:
  135. device.Value13 = dmon.Value?.ToString();
  136. device.Name13 = dmon.Name;
  137. break;
  138. case 224872713744176788:
  139. device.Value14 = dmon.Value?.ToString();
  140. device.Name14 = dmon.Name;
  141. break;
  142. default:
  143. break;
  144. }
  145. //Clients.All.SendAsync("UpdateDeviceData", new MsgInfo { MsgContent = dmon.Value.ToString(), Title = dmon.Name } );
  146. //Clients.All.SendAsync("UpdateData", new MsgInfo { Title = dmon.Value.ToString(), MsgContent = dmon.Name });
  147. //Clients.All.SendAsync("ShowMsg", new MsgInfo { Title = "DeviceTitle", MsgContent = deviceValue });
  148. //logger.Info("时间" + currentTime + "Uid" + dmon.Uid + "名称:" + dmon.Name + "值:" + dmon.Value + "状态:" + dmon.Status + "盒子号:" + dmon.BoxNo + "分组名称:" + dmon.GroupName + "时间" + dmon.Timestamp);
  149. }
  150. _hubContext.Clients.All.SendAsync("UpdateDeviceData", device);
  151. //Clients.All.SendAsync("UpdateDeviceData", device);
  152. //接收数据,先存数据,再把数据显示到页面上
  153. }
  154. void devRun()
  155. {
  156. using (var dmon = new demo())
  157. {
  158. dmon._fbox.DataMonitorValueChanged += _fbox_DataMonitorValueChanged;
  159. dmon.Start().Wait();
  160. string ln = "aa";
  161. do
  162. {
  163. ln = Console.ReadLine();
  164. } while (ln != "quit");
  165. }
  166. }
  167. public void js()
  168. {
  169. // 添加引用 using Microsoft.JScript;
  170. string jsStr = "var i=100; i++; i=i*100; var obj = {a:i};";
  171. //Stopwatch sw = new Stopwatch();
  172. //sw.Start();
  173. object ret1 = null;
  174. try
  175. {
  176. //ret1 = Eval.JScriptEvaluate(jsStr, VsaEngine.CreateEngine());
  177. }
  178. catch (Exception ex)
  179. {
  180. //MessageBox.Show(ex.StackTrace.ToString(), "执行失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
  181. return;
  182. }
  183. //sw.Stop();
  184. //string res = "";
  185. //if (ret1 is ArrayObject)
  186. //{
  187. // // 数组
  188. // ArrayObject arr = (ArrayObject)ret1;
  189. // res = arr[0].ToString();
  190. //}
  191. //else if (ret1 is JSObject)
  192. //{
  193. // // 对象
  194. // JSObject obj = (JSObject)ret1;
  195. // res = obj["a"].ToString();
  196. //}
  197. //else
  198. //{
  199. // // 单值
  200. // res = ret1.ToString();
  201. //}
  202. //MessageBox.Show(res + " 用时:" + sw.ElapsedMilliseconds.ToString() + "ms");
  203. }
  204. public async Task<object> GetDevSpotSeries()
  205. {
  206. IniInflux();
  207. //传入查询命令,支持多条
  208. var queries = new[]
  209. {
  210. " SELECT * FROM fanyidev WHERE time > now() - 5m"
  211. };
  212. var dbName = "fanyidb";
  213. //从指定库中查询数据
  214. var response = await clientDb.Client.QueryAsync(queries, dbName);
  215. //得到Serie集合对象(返回执行多个查询的结果)
  216. var series = response.ToList();
  217. //取出第一条命令的查询结果,是一个集合
  218. var list = series[0].Values;
  219. //从集合中取出第一条数据
  220. //var info_model = list.FirstOrDefault();
  221. return list;
  222. }
  223. /// <summary>
  224. /// 条件获取历史数据
  225. /// </summary>
  226. /// <param name="point"></param>
  227. /// <param name="start"></param>
  228. /// <param name="end"></param>
  229. /// <returns></returns>
  230. public async Task<object> GetDevSpotSeriesAsync(string[] point,DateTime start,DateTime end)
  231. {
  232. if (point?.Length == 0)
  233. {
  234. return null;
  235. }
  236. string strStart = start.ToString("yyyy-MM-ddTHH:mm:ssZ");
  237. string strEnd = end.ToString("yyyy-MM-ddTHH:mm:ssZ");
  238. string strId = point[0];
  239. IniInflux();
  240. //传入查询命令,支持多条
  241. var queries = new[]
  242. {
  243. //" SELECT * FROM fanyidev WHERE time > now() - 5m"
  244. //SELECT * FROM "fanyidev" WHERE time > now() - 535m AND time < now() -10m and Id = '224257795187691889'
  245. //SELECT * FROM "fanyidev" WHERE time>'2023-01-10T10:07:00Z' and time<'2023-10-25T17:58:00Z' and Id = '224257795187691889' order by time desc limit 10
  246. "SELECT * FROM fanyidev WHERE time>"+strStart+" and time< "+strEnd + " and Id = "+strId+" order by time desc limit 10"
  247. };
  248. var dbName = "fanyidb";
  249. //从指定库中查询数据
  250. var response = await clientDb.Client.QueryAsync(queries, dbName);
  251. //得到Serie集合对象(返回执行多个查询的结果)
  252. var series = response.ToList();
  253. //取出第一条命令的查询结果,是一个集合
  254. var list = series[0].Values;
  255. //从集合中取出第一条数据
  256. //var info_model = list.FirstOrDefault();
  257. return list;
  258. }
  259. private void IniInflux()
  260. {
  261. //连接InfluxDb的API地址、账号、密码
  262. var infuxUrl = "http://60.204.212.71:8085/";
  263. var infuxUser = "admin";
  264. var infuxPwd = "123456";
  265. //创建InfluxDbClient实例
  266. clientDb = new InfluxDbClient(infuxUrl, infuxUser, infuxPwd, InfluxDbVersion.Latest);
  267. }
  268. public async Task<IActionResult> Index()
  269. {
  270. //QueryString queryString = Request.QueryString; // ?a=1
  271. string id = Request.Query["id"]; //1
  272. //Thread t = new Thread(devRun);//1创建线程对象
  273. //t.Start();//2从这里开始
  274. //t.IsBackground = true;//规定t为后台线程后台线程会在前台线程结束时结束
  275. //_hubConnection = new HubConnectionBuilder()
  276. // //.WithUrl("https://www.ropiniot.com/DigitalEnvironmentallyWebScadaTest/myhub") //
  277. // .WithUrl("http://localhost:5000/myhub")
  278. // .WithAutomaticReconnect()//wait 0, 2, 10, and 30 seconds
  279. // .Build();
  280. //_hubConnection.On<DeviceValueModel>("UpdateDataServer", (msg) =>
  281. //{
  282. // DeviceValueModel value = msg;
  283. //});
  284. //await _hubConnection.StartAsync();
  285. //await _hubConnection.InvokeAsync("UpdateDataServer",
  286. // new DataStatus { Status1 = "", Status2 = "" });
  287. //await _hubConnection.InvokeAsync("UpdateDataServer",
  288. // new DataStatus { Status1 = txtStatus1.Text, Status2 = txtStatus2.Text });
  289. //await _hubContext.Clients.All.SendAsync("ShowMsg", new MsgInfo { Title = "TestTitle", MsgContent = content + count++ });
  290. DeviceValueModel model = new DeviceValueModel();
  291. TokenResult tokenResult = GetToken(new AccessUser { client_id = "b19d14eeacb74522bd29627b79c18ab8", client_secret = "7b89e021586c43d3b79440ba6eea0b67" });
  292. using (HttpClient client = new HttpClient())
  293. {
  294. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  295. var requestt = new HttpRequestMessage(HttpMethod.Get, "https://fbox360.com/api/client/box/grouped");
  296. requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  297. var response = await client.SendAsync(requestt);
  298. string result = await response.Content.ReadAsStringAsync();
  299. if (response.StatusCode != HttpStatusCode.OK)
  300. {
  301. }
  302. else
  303. {
  304. //todo
  305. }
  306. }
  307. goto getDeviceValue;
  308. using (HttpClient client = new HttpClient())
  309. {
  310. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  311. var requestt = new HttpRequestMessage(HttpMethod.Get, " https://fbox360.com/api/v2/box/4316279314564828131/dmon/grouped");
  312. requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  313. var response = await client.SendAsync(requestt);
  314. string result = await response.Content.ReadAsStringAsync();
  315. if (response.StatusCode == HttpStatusCode.OK)
  316. {
  317. List<Device> deviceVueList = JsonConvert.DeserializeObject<List<Device>>(result);
  318. model.Name = deviceVueList[0].items[0].grpName + deviceVueList[0].items[0].name;
  319. model.Value = deviceVueList[0].items[0].intDigits;
  320. model.Name10 = deviceVueList[0].items[1].grpName + deviceVueList[0].items[1].name;
  321. model.Value10 = deviceVueList[0].items[1].intDigits;
  322. model.Name11 = deviceVueList[0].items[2].grpName + deviceVueList[0].items[2].name;
  323. model.Value11 = deviceVueList[0].items[2].intDigits;
  324. model.Name12 = deviceVueList[0].items[3].grpName + deviceVueList[0].items[3].name;
  325. model.Value12 = deviceVueList[0].items[3].intDigits;
  326. model.Name13 = deviceVueList[0].items[4].grpName + deviceVueList[0].items[4].name;
  327. model.Value13 = deviceVueList[0].items[4].intDigits;
  328. //deviceVueList
  329. //string strName = deviceVueList..name;
  330. }
  331. else
  332. {
  333. //todo
  334. }
  335. }
  336. getDeviceValue:
  337. using (HttpClient client = new HttpClient())
  338. {
  339. string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new
  340. {
  341. //names= new List<string> { "\"数据块_1\".运行时间记录_M", "蜂窝沸石转筒电子差压计D4实际值", "\"数据块_1\".运行时间记录_M", "蜂窝沸石转筒电子差压计D4实际值", "前处理过滤箱电子差压计D3实际值" }, //, "主加热器1", "辅助加热器1"
  342. //groupnames = new List<string> { "喷漆房1", "喷漆房1", "喷漆房4", "喷漆房4", "喷漆房4" }, //, "喷漆房1" , "喷漆房1"
  343. //ids = new List<string> { "224275280344535204"}, \"数据块_1\".运行时间记录_D
  344. names = new List<string> {
  345. "自动油雾过滤器电子差压计D0实际值",
  346. "前处理过滤箱电子差压计D2实际值",
  347. "前处理过滤箱电子差压计D3实际值",
  348. "蜂窝沸石转筒电子差压计D4实际值",
  349. "\"数据块_1\".运行时间记录_D",
  350. "\"数据块_1\".运行时间记录_H",
  351. "\"数据块_1\".运行时间记录_M",
  352. "报警1",
  353. "主加热器1",
  354. "辅助加热器1",
  355. "主风机1"},
  356. groupnames = new List<string> {
  357. "喷漆房1",
  358. "喷漆房1",
  359. "喷漆房1",
  360. "喷漆房1",
  361. "喷漆房1",
  362. "喷漆房1",
  363. "喷漆房1",
  364. "喷漆房1",
  365. "喷漆房1",
  366. "喷漆房1",
  367. "喷漆房1"},
  368. timeOut = 6000
  369. });
  370. //string s = @"{\"ids\":[\"224275280344535204\"]}";
  371. #region ceshi
  372. using (var httpClient = new HttpClient())
  373. {
  374. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  375. httpClient.BaseAddress = new Uri("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300220010352");
  376. httpClient.DefaultRequestHeaders.Accept.Clear();
  377. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  378. var jsonString = postData;
  379. HttpResponseMessage esponse = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(jsonString, Encoding.UTF8, "application/json"));
  380. if (esponse.IsSuccessStatusCode)
  381. {
  382. string json = await esponse.Content.ReadAsStringAsync();
  383. //List<DeviceVlue> deviceVueList = JsonConvert.DeserializeObject<List<DeviceVlue>>(json);
  384. //model.Name = "自动油雾过滤器电子差压计D0实值";
  385. //model.Value = deviceVueList[0].value.ToString().Split('.')[0];
  386. //model.Name10 = deviceVueList[1].name;
  387. //model.Value10 = deviceVueList[1].value.ToString().Split('.')[0];
  388. //model.Name11 = deviceVueList[2].name;
  389. //model.Value11 = deviceVueList[2].value.ToString().Split('.')[0];
  390. //model.Name12 = deviceVueList[3].name;
  391. //model.Value12 = deviceVueList[3].value.ToString().Split('.')[0];
  392. //model.Name13 = "运行时间"; //(天)
  393. //model.Value13 = deviceVueList[4].value.ToString().Split('.')[0];
  394. //model.Name14 = "运行时间"; //(时)
  395. //model.Value14 = deviceVueList[5].value.ToString().Split('.')[0];
  396. //model.Name15 = "运行时间";//((分))
  397. //model.Value15 = deviceVueList[6].value.ToString().Split('.')[0];
  398. //model.Name16 = deviceVueList[7].name;//报警
  399. //model.Value16 = deviceVueList[7].value.ToString().Split('.')[0];
  400. //model.Name17 = "主加热器";//主加热器1
  401. //model.Value17 = deviceVueList[8].value.ToString().Split('.')[0];
  402. //model.Name18 = "辅助加热器";//辅助加热器1
  403. //model.Value18 = deviceVueList[9].value.ToString();
  404. //model.Name19 = "主风机";//主风机1
  405. //model.Value19 = deviceVueList[10].value.ToString().Split('.')[0];
  406. }
  407. }
  408. //Dictionary<string, string> dict = new Dictionary<string, string>();
  409. //dict["grant_type"] = "refresh_token";
  410. //using (HttpClient http = new HttpClient())
  411. //{
  412. // http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  413. // using (var content = new FormUrlEncodedContent(dict))
  414. // {
  415. // var msg = http.PostAsync("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300221100748", content);
  416. // if (msg.IsFaulted)
  417. // {
  418. // return null;
  419. // }
  420. // else
  421. // {
  422. // var result = msg.Result.Content.ReadAsStringAsync().Result;
  423. // }
  424. // }
  425. //}
  426. #endregion
  427. //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  428. ////var requestt = new HttpRequestMessage(HttpMethod.Post, "http://fbcs101.fbox360.com/api/v2/box/4316279314564828131/dmon/value/get");
  429. //var requestt = new HttpRequestMessage(HttpMethod.Post, "http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300221100748");
  430. //requestt.Content = new StringContent(postData);
  431. //requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  432. //var response = await client.SendAsync(requestt);
  433. //string result = await response.Content.ReadAsStringAsync();
  434. //if (response.StatusCode == HttpStatusCode.OK)
  435. //{
  436. // List<Device> deviceVueList = JsonConvert.DeserializeObject<List<Device>>(result);
  437. // model.Name = deviceVueList[0].items[0].grpName + deviceVueList[0].items[0].name;
  438. // model.Value = deviceVueList[0].items[0].intDigits;
  439. // model.Name10 = deviceVueList[0].items[1].grpName + deviceVueList[0].items[1].name;
  440. // model.Value10 = deviceVueList[0].items[1].intDigits;
  441. // model.Name11 = deviceVueList[0].items[2].grpName + deviceVueList[0].items[2].name;
  442. // model.Value11 = deviceVueList[0].items[2].intDigits;
  443. // model.Name12 = deviceVueList[0].items[3].grpName + deviceVueList[0].items[3].name;
  444. // model.Value12 = deviceVueList[0].items[3].intDigits;
  445. // model.Name13 = deviceVueList[0].items[4].grpName + deviceVueList[0].items[4].name;
  446. // model.Value13 = deviceVueList[0].items[4].intDigits;
  447. // //deviceVueList
  448. // //string strName = deviceVueList..name;
  449. //}
  450. //else
  451. //{
  452. // //todo
  453. //}
  454. }
  455. model.Id = id;
  456. return View(model);
  457. }
  458. #region 喷漆房2
  459. public async Task<IActionResult> PaintRoom2()
  460. {
  461. //string id = Request.Query["id"]; //2
  462. DeviceValueModel model = new DeviceValueModel();
  463. TokenResult tokenResult = GetToken(new AccessUser { client_id = "b19d14eeacb74522bd29627b79c18ab8", client_secret = "7b89e021586c43d3b79440ba6eea0b67" });
  464. using (HttpClient client = new HttpClient())
  465. {
  466. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  467. var requestt = new HttpRequestMessage(HttpMethod.Get, "https://fbox360.com/api/client/box/grouped");
  468. requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  469. var response = await client.SendAsync(requestt);
  470. string result = await response.Content.ReadAsStringAsync();
  471. if (response.StatusCode != HttpStatusCode.OK)
  472. {
  473. }
  474. else
  475. {
  476. //todo
  477. }
  478. }
  479. using (HttpClient client = new HttpClient())
  480. {
  481. string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new
  482. {
  483. names = new List<string> {
  484. "自动油雾过滤器电子差压计D0实际值",
  485. "自动油雾过滤器电子差压计D1实际值",
  486. "\"前处理过滤箱电子差压计D3实际值\"",
  487. "蜂窝沸石转筒电子差压计D4实际值",
  488. "\"数据块_2\".运行时间记录_D",
  489. "\"数据块_2\".运行时间记录_H",
  490. "\"数据块_3\".运行时间记录_M",
  491. "报警2",
  492. "主加热器2",
  493. "辅助加热器2",
  494. "主风机2"},
  495. groupnames = new List<string> {
  496. "喷漆房2",
  497. "喷漆房2",
  498. "喷漆房2",
  499. "喷漆房2",
  500. "喷漆房2",
  501. "喷漆房2",
  502. "喷漆房2",
  503. "喷漆房2",
  504. "喷漆房2",
  505. "喷漆房2",
  506. "喷漆房2"},
  507. timeOut = 6000
  508. });
  509. //string s = @"{\"ids\":[\"224275280344535204\"]}";
  510. #region ceshi
  511. using (var httpClient = new HttpClient())
  512. {
  513. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  514. httpClient.BaseAddress = new Uri("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300220010352");
  515. httpClient.DefaultRequestHeaders.Accept.Clear();
  516. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  517. var jsonString = postData;
  518. HttpResponseMessage esponse = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(jsonString, Encoding.UTF8, "application/json"));
  519. if (esponse.IsSuccessStatusCode)
  520. {
  521. string json = await esponse.Content.ReadAsStringAsync();
  522. List<DeviceVlue> deviceVueList = JsonConvert.DeserializeObject<List<DeviceVlue>>(json);
  523. model.Name = "自动油雾过滤器电子差压计D0实值";
  524. model.Value = deviceVueList[0].value.ToString().Split('.')[0];
  525. model.Name10 = deviceVueList[1].name;
  526. model.Value10 = deviceVueList[1].value.ToString().Split('.')[0];
  527. model.Name11 = "前处理过滤箱电子差压计D3实际值";
  528. model.Value11 = deviceVueList[2].value.ToString().Split('.')[0];
  529. model.Name12 = deviceVueList[3].name;
  530. model.Value12 = deviceVueList[3].value.ToString().Split('.')[0];
  531. model.Name13 = "运行时间"; //(天)
  532. model.Value13 = deviceVueList[4].value.ToString().Split('.')[0];
  533. model.Name14 = "运行时间"; //(时)
  534. model.Value14 = deviceVueList[5].value.ToString().Split('.')[0];
  535. model.Name15 = "运行时间";//((分))
  536. model.Value15 = deviceVueList[6].value.ToString().Split('.')[0];
  537. model.Name16 = deviceVueList[7].name;//报警
  538. model.Value16 = deviceVueList[7].value.ToString().Split('.')[0];
  539. model.Name17 = "主加热器";//主加热器1
  540. model.Value17 = deviceVueList[8].value.ToString().Split('.')[0];
  541. model.Name18 = "辅助加热器";//辅助加热器1
  542. model.Value18 = deviceVueList[9].value.ToString();
  543. model.Name19 = "主风机";//主风机1
  544. model.Value19 = deviceVueList[10].value.ToString().Split('.')[0];
  545. }
  546. }
  547. #endregion
  548. }
  549. //model.Id = id;
  550. return View(model);
  551. }
  552. #endregion
  553. #region 喷漆房3
  554. public async Task<IActionResult> PaintRoom3()
  555. {
  556. DeviceValueModel model = new DeviceValueModel();
  557. TokenResult tokenResult = GetToken(new AccessUser { client_id = "b19d14eeacb74522bd29627b79c18ab8", client_secret = "7b89e021586c43d3b79440ba6eea0b67" });
  558. using (HttpClient client = new HttpClient())
  559. {
  560. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  561. var requestt = new HttpRequestMessage(HttpMethod.Get, "https://fbox360.com/api/client/box/grouped");
  562. requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  563. var response = await client.SendAsync(requestt);
  564. string result = await response.Content.ReadAsStringAsync();
  565. if (response.StatusCode != HttpStatusCode.OK)
  566. {
  567. }
  568. else
  569. {
  570. //todo
  571. }
  572. }
  573. using (HttpClient client = new HttpClient())
  574. {
  575. string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new
  576. {
  577. names = new List<string> {
  578. "自动油雾过滤器电子差压计D0实际值",
  579. "前处理过滤箱电子差压计D2实际值",
  580. "前处理过滤箱电子差压计D3实际值",
  581. "蜂窝沸石转筒电子差压计D4实际值",
  582. "\"数据块_3\".运行时间记录_D",
  583. "\"数据块_3\".运行时间记录_H",
  584. "\"数据块_3\".运行时间记录_M",
  585. "报警3",
  586. "主加热器3",
  587. "辅助加热器3",
  588. "主风机3"},
  589. groupnames = new List<string> {
  590. "喷漆房3",
  591. "喷漆房3",
  592. "喷漆房3",
  593. "喷漆房3",
  594. "喷漆房3",
  595. "喷漆房3",
  596. "喷漆房3",
  597. "喷漆房3",
  598. "喷漆房3",
  599. "喷漆房3",
  600. "喷漆房3"},
  601. timeOut = 6000
  602. });
  603. #region ceshi
  604. using (var httpClient = new HttpClient())
  605. {
  606. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  607. httpClient.BaseAddress = new Uri("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300220010352");
  608. httpClient.DefaultRequestHeaders.Accept.Clear();
  609. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  610. var jsonString = postData;
  611. HttpResponseMessage esponse = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(jsonString, Encoding.UTF8, "application/json"));
  612. if (esponse.IsSuccessStatusCode)
  613. {
  614. string json = await esponse.Content.ReadAsStringAsync();
  615. List<DeviceVlue> deviceVueList = JsonConvert.DeserializeObject<List<DeviceVlue>>(json);
  616. model.Name = "自动油雾过滤器电子差压计D0实值";
  617. model.Value = deviceVueList[0].value.ToString().Split('.')[0];
  618. model.Name10 = deviceVueList[1].name;
  619. model.Value10 = deviceVueList[1].value.ToString().Split('.')[0];
  620. model.Name11 = deviceVueList[2].name;
  621. model.Value11 = deviceVueList[2].value.ToString().Split('.')[0];
  622. model.Name12 = deviceVueList[3].name;
  623. model.Value12 = deviceVueList[3].value.ToString().Split('.')[0];
  624. model.Name13 = "运行时间"; //(天)
  625. model.Value13 = deviceVueList[4].value.ToString().Split('.')[0];
  626. model.Name14 = "运行时间"; //(时)
  627. model.Value14 = deviceVueList[5].value.ToString().Split('.')[0];
  628. model.Name15 = "运行时间";//((分))
  629. model.Value15 = deviceVueList[6].value.ToString().Split('.')[0];
  630. model.Name16 = deviceVueList[7].name;//报警
  631. model.Value16 = deviceVueList[7].value.ToString().Split('.')[0];
  632. model.Name17 = "主加热器";//主加热器1
  633. model.Value17 = deviceVueList[8].value.ToString().Split('.')[0];
  634. model.Name18 = "辅助加热器";//辅助加热器1
  635. model.Value18 = deviceVueList[9].value.ToString();
  636. model.Name19 = "主风机";//主风机1
  637. model.Value19 = deviceVueList[10].value.ToString().Split('.')[0];
  638. }
  639. }
  640. #endregion
  641. }
  642. return View(model);
  643. }
  644. #endregion
  645. #region 喷漆房4
  646. public async Task<IActionResult> PaintRoom4()
  647. {
  648. DeviceValueModel model = new DeviceValueModel();
  649. TokenResult tokenResult = GetToken(new AccessUser { client_id = "b19d14eeacb74522bd29627b79c18ab8", client_secret = "7b89e021586c43d3b79440ba6eea0b67" });
  650. using (HttpClient client = new HttpClient())
  651. {
  652. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  653. var requestt = new HttpRequestMessage(HttpMethod.Get, "https://fbox360.com/api/client/box/grouped");
  654. requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  655. var response = await client.SendAsync(requestt);
  656. string result = await response.Content.ReadAsStringAsync();
  657. if (response.StatusCode != HttpStatusCode.OK)
  658. {
  659. }
  660. else
  661. {
  662. //todo
  663. }
  664. }
  665. using (HttpClient client = new HttpClient())
  666. {
  667. string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new
  668. {
  669. names = new List<string> {
  670. "自动油雾过滤器电子差压计D0实际值",
  671. "前处理过滤箱电子差压计D2实际值",
  672. "前处理过滤箱电子差压计D3实际值",
  673. "蜂窝沸石转筒电子差压计D4实际值",
  674. "\"数据块_1\".运行时间记录_D",
  675. "\"数据块_1\".运行时间记录_H",
  676. "\"数据块_1\".运行时间记录_M",
  677. "报警4",
  678. "主加热器4",
  679. "辅助加热器4",
  680. "主风机4"},
  681. groupnames = new List<string> {
  682. "喷漆房4",
  683. "喷漆房4",
  684. "喷漆房4",
  685. "喷漆房4",
  686. "喷漆房4",
  687. "喷漆房4",
  688. "喷漆房4",
  689. "喷漆房4",
  690. "喷漆房4",
  691. "喷漆房4",
  692. "喷漆房4"},
  693. timeOut = 6000
  694. });
  695. //string s = @"{\"ids\":[\"224275280344535204\"]}";
  696. #region ceshi
  697. using (var httpClient = new HttpClient())
  698. {
  699. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  700. httpClient.BaseAddress = new Uri("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300220010352");
  701. httpClient.DefaultRequestHeaders.Accept.Clear();
  702. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  703. var jsonString = postData;
  704. HttpResponseMessage esponse = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(jsonString, Encoding.UTF8, "application/json"));
  705. if (esponse.IsSuccessStatusCode)
  706. {
  707. string json = await esponse.Content.ReadAsStringAsync();
  708. List<DeviceVlue> deviceVueList = JsonConvert.DeserializeObject<List<DeviceVlue>>(json);
  709. model.Name = "自动油雾过滤器电子差压计D0实值";
  710. model.Value = deviceVueList[0].value.ToString().Split('.')[0];
  711. model.Name10 = deviceVueList[1].name;
  712. model.Value10 = deviceVueList[1].value.ToString().Split('.')[0];
  713. model.Name11 = deviceVueList[2].name;
  714. model.Value11 = deviceVueList[2].value.ToString().Split('.')[0];
  715. model.Name12 = deviceVueList[3].name;
  716. model.Value12 = deviceVueList[3].value.ToString().Split('.')[0];
  717. model.Name13 = "运行时间"; //(天)
  718. model.Value13 = deviceVueList[4].value.ToString().Split('.')[0];
  719. model.Name14 = "运行时间"; //(时)
  720. model.Value14 = deviceVueList[5].value.ToString().Split('.')[0];
  721. model.Name15 = "运行时间";//((分))
  722. model.Value15 = deviceVueList[6].value.ToString().Split('.')[0];
  723. model.Name16 = deviceVueList[7].name;//报警
  724. model.Value16 = deviceVueList[7].value.ToString().Split('.')[0];
  725. model.Name17 = "主加热器";//主加热器1
  726. model.Value17 = deviceVueList[8].value.ToString().Split('.')[0];
  727. model.Name18 = "辅助加热器";//辅助加热器1
  728. model.Value18 = deviceVueList[9].value.ToString();
  729. model.Name19 = "主风机";//主风机1
  730. model.Value19 = deviceVueList[10].value.ToString().Split('.')[0];
  731. }
  732. }
  733. #endregion
  734. //using (var httpClient = new HttpClient())
  735. //{
  736. // httpClient.DefaultRequestHeaders.Accept.Clear();
  737. // httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  738. // HttpResponseMessage response = await httpClient.GetAsync("https://www.ropiniot.com/DigitalEnvironmentTest/api/TdevWebScada/GetWebScadaAsync/d4f4f4ac-3248-418a-a489-498478665539", HttpCompletionOption.ResponseHeadersRead);
  739. // if (response.IsSuccessStatusCode)
  740. // {
  741. // Console.WriteLine($"Response Status Code: {(int)response.StatusCode} " + $"{response.ReasonPhrase}");
  742. // var result = await response.Content.ReadAsStringAsync();
  743. // DataResult devWebScada = JsonConvert.DeserializeObject<DataResult>(result);
  744. // model.Html = devWebScada.data.C_Content;
  745. // }
  746. //}
  747. }
  748. return View(model);
  749. }
  750. #endregion
  751. #region 喷漆房5
  752. public async Task<IActionResult> PaintRoom5()
  753. {
  754. DeviceValueModel model = new DeviceValueModel();
  755. TokenResult tokenResult = GetToken(new AccessUser { client_id = "b19d14eeacb74522bd29627b79c18ab8", client_secret = "7b89e021586c43d3b79440ba6eea0b67" });
  756. using (HttpClient client = new HttpClient())
  757. {
  758. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  759. var requestt = new HttpRequestMessage(HttpMethod.Get, "https://fbox360.com/api/client/box/grouped");
  760. requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  761. var response = await client.SendAsync(requestt);
  762. string result = await response.Content.ReadAsStringAsync();
  763. if (response.StatusCode != HttpStatusCode.OK)
  764. {
  765. }
  766. else
  767. {
  768. //todo
  769. }
  770. }
  771. using (HttpClient client = new HttpClient())
  772. {
  773. string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new
  774. {
  775. names = new List<string> {
  776. "非甲烷总烃",
  777. "非甲烷总烃排放速率",
  778. "废气温度",
  779. "废气压力",
  780. "废气流速",
  781. "废气湿度",
  782. "废气标态流量",
  783. "甲烷",
  784. "总烃",
  785. "苯",
  786. "甲苯",
  787. "二甲苯",
  788. "氧气"},
  789. groupnames = new List<string> {
  790. "Default Group",
  791. "Default Group",
  792. "Default Group",
  793. "Default Group",
  794. "Default Group",
  795. "Default Group",
  796. "Default Group",
  797. "Default Group",
  798. "Default Group",
  799. "Default Group",
  800. "Default Group",
  801. "Default Group",
  802. "Default Group"},
  803. timeOut = 6000
  804. });
  805. //string s = @"{\"ids\":[\"224275280344535204\"]}";
  806. #region ceshi
  807. using (var httpClient = new HttpClient())
  808. {
  809. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  810. httpClient.BaseAddress = new Uri("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300221100748");
  811. httpClient.DefaultRequestHeaders.Accept.Clear();
  812. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  813. var jsonString = postData;
  814. HttpResponseMessage esponse = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(jsonString, Encoding.UTF8, "application/json"));
  815. if (esponse.IsSuccessStatusCode)
  816. {
  817. string json = await esponse.Content.ReadAsStringAsync();
  818. List<DeviceVlue> deviceVueList = JsonConvert.DeserializeObject<List<DeviceVlue>>(json);
  819. model.NameE = deviceVueList[0].name;
  820. model.ValueE = deviceVueList[0].value.ToString().Split('.')[0];
  821. model.NameE10 = deviceVueList[1].name;
  822. model.ValueE10 = deviceVueList[1].value.ToString().Split('.')[0];
  823. model.NameE11 = deviceVueList[2].name;
  824. model.ValueE11 = deviceVueList[2].value.ToString().Split('.')[0];
  825. model.NameE12 = deviceVueList[3].name;
  826. model.ValueE12 = deviceVueList[3].value.ToString().Split('.')[0];
  827. model.NameE13 = deviceVueList[4].name;
  828. model.ValueE13 = deviceVueList[4].value.ToString().Split('.')[0];
  829. model.NameE14 = deviceVueList[5].name;
  830. model.ValueE14 = deviceVueList[5].value.ToString().Split('.')[0];
  831. model.NameE15 = deviceVueList[6].name;
  832. model.ValueE15 = deviceVueList[6].value.ToString().Split('.')[0];
  833. model.NameE16 = deviceVueList[7].name;
  834. model.ValueE16 = deviceVueList[7].value.ToString().Split('.')[0];
  835. model.NameE17 = deviceVueList[8].name;
  836. model.ValueE17 = deviceVueList[8].value.ToString().Split('.')[0];
  837. model.NameE18 = deviceVueList[9].name;
  838. model.ValueE18 = deviceVueList[9].value.ToString();
  839. model.NameE19 = deviceVueList[10].name;
  840. model.ValueE19 = deviceVueList[10].value.ToString().Split('.')[0];
  841. }
  842. }
  843. #endregion
  844. //using (var httpClient = new HttpClient())
  845. //{
  846. // httpClient.DefaultRequestHeaders.Accept.Clear();
  847. // httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  848. // HttpResponseMessage response = await httpClient.GetAsync("https://www.ropiniot.com/DigitalEnvironmentTest/api/TdevWebScada/GetWebScadaAsync/d4f4f4ac-3248-418a-a489-498478665539", HttpCompletionOption.ResponseHeadersRead);
  849. // if (response.IsSuccessStatusCode)
  850. // {
  851. // Console.WriteLine($"Response Status Code: {(int)response.StatusCode} " + $"{response.ReasonPhrase}");
  852. // var result = await response.Content.ReadAsStringAsync();
  853. // DataResult devWebScada = JsonConvert.DeserializeObject<DataResult>(result);
  854. // model.Html = devWebScada.data.C_Content;
  855. // }
  856. //}
  857. }
  858. return View(model);
  859. }
  860. #endregion
  861. /// <summary>
  862. /// WebScada
  863. /// </summary>
  864. /// <returns></returns>
  865. public async Task<IActionResult> WebScada()
  866. {
  867. DeviceValueModel model = new DeviceValueModel();
  868. TokenResult tokenResult = GetToken(new AccessUser { client_id = "b19d14eeacb74522bd29627b79c18ab8", client_secret = "7b89e021586c43d3b79440ba6eea0b67" });
  869. using (HttpClient client = new HttpClient())
  870. {
  871. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  872. var requestt = new HttpRequestMessage(HttpMethod.Get, "https://fbox360.com/api/client/box/grouped");
  873. requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  874. var response = await client.SendAsync(requestt);
  875. string result = await response.Content.ReadAsStringAsync();
  876. if (response.StatusCode != HttpStatusCode.OK)
  877. {
  878. }
  879. else
  880. {
  881. //todo
  882. }
  883. }
  884. using (HttpClient client = new HttpClient())
  885. {
  886. string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new
  887. {
  888. names = new List<string> {
  889. "自动油雾过滤器电子差压计D0实际值",
  890. "前处理过滤箱电子差压计D2实际值",
  891. "前处理过滤箱电子差压计D3实际值",
  892. "蜂窝沸石转筒电子差压计D4实际值",
  893. "\"数据块_1\".运行时间记录_D",
  894. "\"数据块_1\".运行时间记录_H",
  895. "\"数据块_1\".运行时间记录_M",
  896. "报警4",
  897. "主加热器4",
  898. "辅助加热器4",
  899. "主风机4"},
  900. groupnames = new List<string> {
  901. "喷漆房4",
  902. "喷漆房4",
  903. "喷漆房4",
  904. "喷漆房4",
  905. "喷漆房4",
  906. "喷漆房4",
  907. "喷漆房4",
  908. "喷漆房4",
  909. "喷漆房4",
  910. "喷漆房4",
  911. "喷漆房4"},
  912. timeOut = 6000
  913. });
  914. #region ceshi
  915. using (var httpClient = new HttpClient())
  916. {
  917. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.access_token);
  918. httpClient.BaseAddress = new Uri("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300220010352");
  919. httpClient.DefaultRequestHeaders.Accept.Clear();
  920. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  921. var jsonString = postData;
  922. HttpResponseMessage esponse = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(jsonString, Encoding.UTF8, "application/json"));
  923. if (esponse.IsSuccessStatusCode)
  924. {
  925. string json = await esponse.Content.ReadAsStringAsync();
  926. List<DeviceVlue> deviceVueList = JsonConvert.DeserializeObject<List<DeviceVlue>>(json);
  927. model.Name = "自动油雾过滤器电子差压计D0实值";
  928. model.Value = deviceVueList[0].value.ToString().Split('.')[0];
  929. model.Name10 = deviceVueList[1].name;
  930. model.Value10 = deviceVueList[1].value.ToString().Split('.')[0];
  931. model.Name11 = deviceVueList[2].name;
  932. model.Value11 = deviceVueList[2].value.ToString().Split('.')[0];
  933. model.Name12 = deviceVueList[3].name;
  934. model.Value12 = deviceVueList[3].value.ToString().Split('.')[0];
  935. model.Name13 = "运行时间"; //(天)
  936. model.Value13 = deviceVueList[4].value.ToString().Split('.')[0];
  937. model.Name14 = "运行时间"; //(时)
  938. model.Value14 = deviceVueList[5].value.ToString().Split('.')[0];
  939. model.Name15 = "运行时间";//((分))
  940. model.Value15 = deviceVueList[6].value.ToString().Split('.')[0];
  941. model.Name16 = deviceVueList[7].name;//报警
  942. model.Value16 = deviceVueList[7].value.ToString().Split('.')[0];
  943. model.Name17 = "主加热器";//主加热器1
  944. model.Value17 = deviceVueList[8].value.ToString().Split('.')[0];
  945. model.Name18 = "辅助加热器";//辅助加热器1
  946. model.Value18 = deviceVueList[9].value.ToString();
  947. model.Name19 = "主风机";//主风机1
  948. model.Value19 = deviceVueList[10].value.ToString().Split('.')[0];
  949. }
  950. }
  951. #endregion
  952. }
  953. using (var httpClient = new HttpClient())
  954. {
  955. httpClient.DefaultRequestHeaders.Accept.Clear();
  956. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  957. HttpResponseMessage response = await httpClient.GetAsync("https://www.ropiniot.com/DigitalEnvironmentTest/api/TdevWebScada/GetWebScadaAsync/d4f4f4ac-3248-418a-a489-498478665539", HttpCompletionOption.ResponseHeadersRead);
  958. if (response.IsSuccessStatusCode)
  959. {
  960. var result = await response.Content.ReadAsStringAsync();
  961. DataResult devWebScada = JsonConvert.DeserializeObject<DataResult>(result);
  962. model.Html = devWebScada.data.C_Content;
  963. }
  964. }
  965. return View(model);
  966. }
  967. }
  968. public class DataResult
  969. {
  970. public TDEV_WebScada data { get; set; }
  971. public string code { get; set; }
  972. public string message { get; set; }
  973. }
  974. public class TDEV_WebScada
  975. {
  976. public string C_ID { get; set; }
  977. public string C_Name { get; set; }
  978. public string C_DevCode { get; set; }
  979. public string C_Content { get; set; }
  980. public string C_Remark { get; set; }
  981. public Guid C_CreateBy { get; set; }
  982. public DateTime D_CreateOn { get; set; }
  983. public Guid? C_LastUpdatedBy { get; set; }
  984. public DateTime? D_LastUpdatedOn { get; set; }
  985. public string C_Status { get; set; }
  986. }
  987. public class AccessUser
  988. {
  989. public string client_id { get; set; }
  990. public string client_secret { get; set; }
  991. public string refresh_token { get; set; }
  992. }
  993. public class TokenResult
  994. {
  995. public string access_token { get; set; }
  996. /// <summary>
  997. /// 有效期
  998. /// </summary>
  999. public int expires_in { get; set; }
  1000. public string refresh_token { get; set; }
  1001. public string token_type { get; set; }
  1002. /// <summary>
  1003. /// invalid_grant过期
  1004. /// </summary>
  1005. public string error { get; set; }
  1006. }
  1007. public class items
  1008. {
  1009. public string id { get; set; }
  1010. public string grpId { get; set; }
  1011. public string grpName { get; set; }
  1012. public string name { get; set; }
  1013. public string intDigits { get; set; }
  1014. public string fracDigits { get; set; }
  1015. public string privilege { get; set; }
  1016. public string trafficSaving { get; set; }
  1017. public string deadValue { get; set; }
  1018. }
  1019. public class Device
  1020. {
  1021. public string id { get; set; }
  1022. public string name { get; set; }
  1023. public List<items> items { get; set; }
  1024. }
  1025. public class DeviceVlue
  1026. {
  1027. public string id { get; set; }
  1028. public string timestamp { get; set; }
  1029. public int dataType { get; set; }
  1030. public string name { get; set; }
  1031. public double? value { get; set; }
  1032. public string boxId { get; set; }
  1033. public int status { get; set; }
  1034. public int connState { get; set; }
  1035. public string connStateTimestamp { get; set; }
  1036. }
  1037. }