using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using IntelligentControlForsx.MyControls; using IntelligentControlForsx.MyControls.windturbine; using WisdomClient; using WisdomClient.data; namespace IntelligentControlForsx.Service.WindturbineInfo { public class WindturbineInfoSvc { #region 单例 private WindturbineInfoSvc() { } public static WindturbineInfoSvc Instance { get { return SingletonCreator.instance; } } class SingletonCreator { internal static readonly WindturbineInfoSvc instance = new WindturbineInfoSvc(); } #endregion public static string ControlBasicInfo = "BasicInfo"; public static string ControlAlternatorInfo = "AlternatorInfo"; public static string ControlGearBoxInfo = "GearBoxInfo"; public static string ControlChangePadleInfo = "ChangePadleInfo"; public static string ControlYawInfo = "YawInfo"; public static string ControlPressureInfo = "PressureInfo"; public static string ControlRoomInfo = "RoomInfo"; private static IList infoDataList = new List(); /// /// 刷新测点数据 /// /// 场站编号 /// 风机编号 /// 风机型号 /// /// 所属模块 public void RefreshPointValue(string stationId, string windturbineId, string modelId, string control) { IList infoList = UniformCodeInfoSvc.GetUniformCode(stationId, modelId, control); string[] uniformCodeArr = infoList.Select(s => s.UniformCode).ToList().ToArray(); Dictionary dic = RestfulClient.findLatestByThingCodes("windturbine", windturbineId, uniformCodeArr); if (dic != null) { foreach (var tsData in dic) { var data = infoList.Where(s => s.UniformCode == tsData.Key).FirstOrDefault(); if (data != null) { double pointValue = 0.0; bool isNum = IsNum(tsData.Value.getValue(), out pointValue); if (isNum) { data.PointValue = pointValue.ToString("f2"); } data.WindturbineId = windturbineId; data.ModelId = modelId; } } infoDataList = infoList; } } public void RefreshPointValue(IList infoList, string windturbineId) { DateTime st = DateTime.Now; string[] uniformCodeArr = infoList.Select(s => s.UniformCode).ToList().ToArray(); Dictionary dic = RestfulClient.findLatestByThingCodes("windturbine", windturbineId, uniformCodeArr); foreach (var tsData in dic) { var data = infoList.Where(s => s.UniformCode == tsData.Key).FirstOrDefault(); if (data != null) { double pointValue = 0.0; bool isNum = IsNum(tsData.Value.getValue(), out pointValue); if (isNum) { data.PointValue = pointValue.ToString("f2"); } } } infoDataList = infoList; DateTime et = DateTime.Now; TimeSpan sp = et - st; Console.WriteLine("访问数据时间:" + sp.TotalMilliseconds); } public IList GetPointData() { return infoDataList; } private bool IsNum(string s, out double num) { try { if (s == "True" || s == "true") num = 1; else if (s == "false" || s == "False") num = 0; else { num = Convert.ToDouble(s); } return true; } catch (Exception) { num = 0.0; return false; } } } }