123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- 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<UniformCodeInfo> infoDataList = new List<UniformCodeInfo>();
- /// <summary>
- /// 刷新测点数据
- /// </summary>
- /// <param name="stationId">场站编号</param>
- /// <param name="windturbineId">风机编号</param>
- /// <param name="modelId">风机型号</param>
- /// /// <param name="control">所属模块</param>
- public void RefreshPointValue(string stationId, string windturbineId, string modelId, string control)
- {
- IList<UniformCodeInfo> infoList = UniformCodeInfoSvc.GetUniformCode(stationId, modelId, control);
- string[] uniformCodeArr = infoList.Select(s => s.UniformCode).ToList().ToArray();
- Dictionary<string, TsData> 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<UniformCodeInfo> infoList, string windturbineId)
- {
- DateTime st = DateTime.Now;
- string[] uniformCodeArr = infoList.Select(s => s.UniformCode).ToList().ToArray();
- Dictionary<string, TsData> 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<UniformCodeInfo> 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;
- }
- }
- }
- }
|