debug 後台同步 niagara 資料
This commit is contained in:
parent
b146283d13
commit
e3700b63b8
@ -820,8 +820,7 @@ namespace Backend.Controllers
|
||||
//更新device資料表 room_dbid 欄位
|
||||
string sql = @"
|
||||
SET SQL_SAFE_UPDATES = 0;
|
||||
UPDATE
|
||||
device AS de,
|
||||
UPDATE device AS de,
|
||||
(
|
||||
select f.room_id, f.room_name from forge_room f
|
||||
join device d ON f.room_name = d.room_name
|
||||
|
@ -15,6 +15,8 @@ using Ubiety.Dns.Core;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Repository.Models.CodeBeautify;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
|
||||
namespace Backend.Services.Implement
|
||||
{
|
||||
@ -163,12 +165,11 @@ namespace Backend.Services.Implement
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(responseString);
|
||||
|
||||
string jsonText = JsonConvert.SerializeXmlNode(xmlDoc);
|
||||
var data = Welcome.FromJson(jsonText);
|
||||
|
||||
foreach (var item in data.Obj.Ref)
|
||||
//ref https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c
|
||||
foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
|
||||
{
|
||||
String API_Url2 = urlString + "/" + item.Name;
|
||||
string stationName = node.Attributes["name"].InnerText; // WSP_Supervisor
|
||||
String API_Url2 = urlString + "/" + stationName; // http://192.168.0.136:8081/obix/histories/WSP_Supervisor
|
||||
|
||||
HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2);
|
||||
Postrequest2.Method = "GET";
|
||||
@ -181,32 +182,117 @@ namespace Backend.Services.Implement
|
||||
XmlDocument xmlDoc2 = new XmlDocument();
|
||||
xmlDoc2.LoadXml(responseString2);
|
||||
|
||||
string jsonText2 = JsonConvert.SerializeXmlNode(xmlDoc2);
|
||||
var data2 = Welcome.FromJson(jsonText2);
|
||||
|
||||
foreach (var item2 in data2.Obj.Ref)
|
||||
foreach (XmlNode node2 in xmlDoc2.DocumentElement.ChildNodes)
|
||||
{
|
||||
if (item2.Name.Split('_').Length == 9)
|
||||
string tagName = node2.Attributes["name"].InnerText;
|
||||
if (tagName.Split('_').Length == 9)
|
||||
{
|
||||
ImpNiaItem row = new ImpNiaItem();
|
||||
row.device_area_tag = item2.Name.Split('_')[0];
|
||||
row.device_building_tag = item2.Name.Split('_')[1];
|
||||
row.device_system_tag = item2.Name.Split('_')[2];
|
||||
row.device_name_tag = item2.Name.Split('_')[3];
|
||||
row.device_point_name = item2.Name.Split('_')[8];
|
||||
row.parent_path = item.Name;
|
||||
row.device_area_tag = tagName.Split('_')[0];
|
||||
row.device_building_tag = tagName.Split('_')[1];
|
||||
row.device_system_tag = tagName.Split('_')[2];
|
||||
row.device_name_tag = tagName.Split('_')[3];
|
||||
row.device_point_name = tagName.Split('_')[8];
|
||||
row.parent_path = stationName;
|
||||
|
||||
//full_name 其實是點位名稱 point_name
|
||||
row.full_name = conPoint.Where(x => x.name == item2.Name).Select(x => x.displayName).FirstOrDefault();
|
||||
row.full_name = conPoint.Where(x => x.name == tagName).Select(x => x.displayName).FirstOrDefault();
|
||||
|
||||
result.Add(row);
|
||||
|
||||
} else if (tagName.Split('_').Length == 6)
|
||||
{ //巨蛋 tag 5 段版本
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
return result;
|
||||
}
|
||||
//private static void getRefData(string urlString, string encoded, List<control_point> conPoint, List<ImpNiaItem> result, Welcome data ) //obixHistory data
|
||||
//{
|
||||
// foreach (var item in data.Obj.Ref)
|
||||
// {
|
||||
// //var item = data.Obj.Ref;
|
||||
// String API_Url2 = urlString + "/" + item.Name;
|
||||
|
||||
// HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2);
|
||||
// Postrequest2.Method = "GET";
|
||||
// Postrequest2.Headers.Add("Authorization", "Basic " + encoded);
|
||||
// Postrequest2.PreAuthenticate = true;
|
||||
|
||||
// HttpWebResponse response2 = (HttpWebResponse)Postrequest2.GetResponse();
|
||||
// var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd();
|
||||
|
||||
// XmlDocument xmlDoc2 = new XmlDocument();
|
||||
// xmlDoc2.LoadXml(responseString2);
|
||||
|
||||
// string jsonText2 = JsonConvert.SerializeXmlNode(xmlDoc2);
|
||||
// var data2 = Welcome.FromJson(jsonText2);
|
||||
|
||||
// foreach (var item2 in data2.Obj.Ref)
|
||||
// {
|
||||
// if (item2.Name.Split('_').Length == 9)
|
||||
// {
|
||||
// ImpNiaItem row = new ImpNiaItem();
|
||||
// row.device_area_tag = item2.Name.Split('_')[0];
|
||||
// row.device_building_tag = item2.Name.Split('_')[1];
|
||||
// row.device_system_tag = item2.Name.Split('_')[2];
|
||||
// row.device_name_tag = item2.Name.Split('_')[3];
|
||||
// row.device_point_name = item2.Name.Split('_')[8];
|
||||
// row.parent_path = item.Name;
|
||||
|
||||
// //full_name 其實是點位名稱 point_name
|
||||
// row.full_name = conPoint.Where(x => x.name == item2.Name).Select(x => x.displayName).FirstOrDefault();
|
||||
|
||||
// result.Add(row);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//private static void getRefData(string urlString, string encoded, List<control_point> conPoint, List<ImpNiaItem> result, Welcome4 data)
|
||||
//{
|
||||
// foreach (var item in data.Obj.Ref)
|
||||
// {
|
||||
// String API_Url2 = urlString + "/" + item.Name;
|
||||
|
||||
// HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2);
|
||||
// Postrequest2.Method = "GET";
|
||||
// Postrequest2.Headers.Add("Authorization", "Basic " + encoded);
|
||||
// Postrequest2.PreAuthenticate = true;
|
||||
|
||||
// HttpWebResponse response2 = (HttpWebResponse)Postrequest2.GetResponse();
|
||||
// var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd();
|
||||
|
||||
// XmlDocument xmlDoc2 = new XmlDocument();
|
||||
// xmlDoc2.LoadXml(responseString2);
|
||||
|
||||
// string jsonText2 = JsonConvert.SerializeXmlNode(xmlDoc2);
|
||||
// var data2 = Welcome.FromJson(jsonText2);
|
||||
|
||||
// foreach (var item2 in data2.Obj.Ref)
|
||||
// {
|
||||
// if (item2.Name.Split('_').Length == 9)
|
||||
// {
|
||||
// ImpNiaItem row = new ImpNiaItem();
|
||||
// row.device_area_tag = item2.Name.Split('_')[0];
|
||||
// row.device_building_tag = item2.Name.Split('_')[1];
|
||||
// row.device_system_tag = item2.Name.Split('_')[2];
|
||||
// row.device_name_tag = item2.Name.Split('_')[3];
|
||||
// row.device_point_name = item2.Name.Split('_')[8];
|
||||
// row.parent_path = item.Name;
|
||||
|
||||
// //full_name 其實是點位名稱 point_name
|
||||
// row.full_name = conPoint.Where(x => x.name == item2.Name).Select(x => x.displayName).FirstOrDefault();
|
||||
|
||||
// result.Add(row);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//public void getObix()
|
||||
//{
|
||||
|
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 222 KiB |
167
Repository/Models/obixHistory.cs
Normal file
167
Repository/Models/obixHistory.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json;
|
||||
using System.Globalization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace Repository.Models.CodeBeautify
|
||||
{
|
||||
//public class obixHistory
|
||||
//{
|
||||
//}
|
||||
public partial class obixHistory
|
||||
{
|
||||
[JsonProperty("obj")]
|
||||
public Objs Obj { get; set; }
|
||||
}
|
||||
|
||||
public class Objs
|
||||
{
|
||||
[JsonProperty("ref")]
|
||||
public Refs Ref { get; set; }
|
||||
|
||||
[JsonProperty("_xmlns")]
|
||||
public Uri Xmlns { get; set; }
|
||||
|
||||
[JsonProperty("_xmlns:xsi")]
|
||||
public Uri XmlnsXsi { get; set; }
|
||||
|
||||
[JsonProperty("_href")]
|
||||
public Uri Href { get; set; }
|
||||
|
||||
[JsonProperty("_display")]
|
||||
public string Display { get; set; }
|
||||
|
||||
[JsonProperty("_icon")]
|
||||
public string Icon { get; set; }
|
||||
|
||||
[JsonProperty("_xsi:schemaLocation")]
|
||||
public Uri XsiSchemaLocation { get; set; }
|
||||
}
|
||||
|
||||
public class Refs
|
||||
{
|
||||
[JsonProperty("_name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("_href")]
|
||||
public string Href { get; set; }
|
||||
|
||||
[JsonProperty("_display")]
|
||||
public string Display { get; set; }
|
||||
|
||||
[JsonProperty("_icon")]
|
||||
public string Icon { get; set; }
|
||||
}
|
||||
|
||||
public partial class obixHistory
|
||||
{
|
||||
public static obixHistory FromJson(string json) => JsonConvert.DeserializeObject<obixHistory>(json, CodeBeautify.Converter.Settings);
|
||||
}
|
||||
|
||||
public static class Serialize
|
||||
{
|
||||
public static string ToJson(this obixHistory self) => JsonConvert.SerializeObject(self, CodeBeautify.Converter.Settings);
|
||||
}
|
||||
|
||||
internal static class Converter
|
||||
{
|
||||
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||
DateParseHandling = DateParseHandling.None,
|
||||
Converters =
|
||||
{
|
||||
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// <auto-generated />
|
||||
//
|
||||
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
|
||||
//
|
||||
// using CodeBeautify;
|
||||
//
|
||||
// var welcome4 = Welcome4.FromJson(jsonString);
|
||||
|
||||
//namespace CodeBeautify
|
||||
//{
|
||||
// using System;
|
||||
// using System.Collections.Generic;
|
||||
|
||||
// using System.Globalization;
|
||||
// using Newtonsoft.Json;
|
||||
// using Newtonsoft.Json.Converters;
|
||||
|
||||
// public partial class Welcome4
|
||||
// {
|
||||
// [JsonProperty("obj")]
|
||||
// public Obj Obj { get; set; }
|
||||
// }
|
||||
|
||||
// public partial class Obj
|
||||
// {
|
||||
// [JsonProperty("ref")]
|
||||
// public Ref Ref { get; set; }
|
||||
|
||||
// [JsonProperty("_xmlns")]
|
||||
// public Uri Xmlns { get; set; }
|
||||
|
||||
// [JsonProperty("_xmlns:xsi")]
|
||||
// public Uri XmlnsXsi { get; set; }
|
||||
|
||||
// [JsonProperty("_href")]
|
||||
// public Uri Href { get; set; }
|
||||
|
||||
// [JsonProperty("_display")]
|
||||
// public string Display { get; set; }
|
||||
|
||||
// [JsonProperty("_icon")]
|
||||
// public string Icon { get; set; }
|
||||
|
||||
// [JsonProperty("_xsi:schemaLocation")]
|
||||
// public Uri XsiSchemaLocation { get; set; }
|
||||
// }
|
||||
|
||||
// public partial class Ref
|
||||
// {
|
||||
// [JsonProperty("_name")]
|
||||
// public string Name { get; set; }
|
||||
|
||||
// [JsonProperty("_href")]
|
||||
// public string Href { get; set; }
|
||||
|
||||
// [JsonProperty("_display")]
|
||||
// public string Display { get; set; }
|
||||
|
||||
// [JsonProperty("_icon")]
|
||||
// public string Icon { get; set; }
|
||||
// }
|
||||
|
||||
// public partial class Welcome4
|
||||
// {
|
||||
// public static Welcome4 FromJson(string json) => JsonConvert.DeserializeObject<Welcome4>(json, CodeBeautify.Converter.Settings);
|
||||
// }
|
||||
|
||||
// public static class Serialize
|
||||
// {
|
||||
// public static string ToJson(this Welcome4 self) => JsonConvert.SerializeObject(self, CodeBeautify.Converter.Settings);
|
||||
// }
|
||||
|
||||
// internal static class Converter
|
||||
// {
|
||||
// public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||
// {
|
||||
// MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||
// DateParseHandling = DateParseHandling.None,
|
||||
// Converters =
|
||||
// {
|
||||
// new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
//}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
@ -19,6 +20,11 @@ namespace Repository.Models
|
||||
|
||||
public partial class Obj
|
||||
{
|
||||
[JsonProperty("@href")]
|
||||
public string? href { get; set; }
|
||||
[JsonProperty("@icon")]
|
||||
public string? icon { get; set; }
|
||||
|
||||
[JsonProperty("@display")]
|
||||
public string Display { get; set; }
|
||||
|
||||
@ -36,6 +42,7 @@ namespace Repository.Models
|
||||
|
||||
[JsonProperty("ref")]
|
||||
public Str[] Ref { get; set; }
|
||||
//public Ref Ref { get; set; }
|
||||
}
|
||||
|
||||
public partial class Str
|
||||
@ -48,15 +55,25 @@ namespace Repository.Models
|
||||
|
||||
[JsonProperty("@href")]
|
||||
public string Href { get; set; }
|
||||
[JsonProperty("@display")]
|
||||
public string display { get; set; }
|
||||
[JsonProperty("@_icon")]
|
||||
public string _icon { get; set; }
|
||||
}
|
||||
|
||||
public partial class Ref
|
||||
public class Ref
|
||||
{
|
||||
[JsonProperty("@name")]
|
||||
[JsonProperty("_name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("@href")]
|
||||
[JsonProperty("_href")]
|
||||
public string Href { get; set; }
|
||||
|
||||
[JsonProperty("_display")]
|
||||
public string Display { get; set; }
|
||||
|
||||
[JsonProperty("_icon")]
|
||||
public string Icon { get; set; }
|
||||
}
|
||||
|
||||
public partial class Xml
|
||||
|
Loading…
Reference in New Issue
Block a user