WindturbineInfoSvc.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using IntelligentControlForsx.MyControls;
  8. using IntelligentControlForsx.MyControls.windturbine;
  9. using WisdomClient;
  10. using WisdomClient.data;
  11. namespace IntelligentControlForsx.Service.WindturbineInfo
  12. {
  13. public class WindturbineInfoSvc
  14. {
  15. #region 单例
  16. private WindturbineInfoSvc()
  17. {
  18. }
  19. public static WindturbineInfoSvc Instance
  20. {
  21. get { return SingletonCreator.instance; }
  22. }
  23. class SingletonCreator
  24. {
  25. internal static readonly WindturbineInfoSvc instance = new WindturbineInfoSvc();
  26. }
  27. #endregion
  28. public static string ControlBasicInfo = "BasicInfo";
  29. public static string ControlAlternatorInfo = "AlternatorInfo";
  30. public static string ControlGearBoxInfo = "GearBoxInfo";
  31. public static string ControlChangePadleInfo = "ChangePadleInfo";
  32. public static string ControlYawInfo = "YawInfo";
  33. public static string ControlPressureInfo = "PressureInfo";
  34. public static string ControlRoomInfo = "RoomInfo";
  35. private static IList<UniformCodeInfo> infoDataList = new List<UniformCodeInfo>();
  36. /// <summary>
  37. /// 刷新测点数据
  38. /// </summary>
  39. /// <param name="stationId">场站编号</param>
  40. /// <param name="windturbineId">风机编号</param>
  41. /// <param name="modelId">风机型号</param>
  42. /// /// <param name="control">所属模块</param>
  43. public void RefreshPointValue(string stationId, string windturbineId, string modelId, string control)
  44. {
  45. IList<UniformCodeInfo> infoList = UniformCodeInfoSvc.GetUniformCode(stationId, modelId, control);
  46. string[] uniformCodeArr = infoList.Select(s => s.UniformCode).ToList().ToArray();
  47. Dictionary<string, TsData> dic = RestfulClient.findLatestByThingCodes("windturbine", windturbineId, uniformCodeArr);
  48. if (dic != null)
  49. {
  50. foreach (var tsData in dic)
  51. {
  52. var data = infoList.Where(s => s.UniformCode == tsData.Key).FirstOrDefault();
  53. if (data != null)
  54. {
  55. double pointValue = 0.0;
  56. bool isNum = IsNum(tsData.Value.getValue(), out pointValue);
  57. if (isNum)
  58. {
  59. data.PointValue = pointValue.ToString("f2");
  60. }
  61. data.WindturbineId = windturbineId;
  62. data.ModelId = modelId;
  63. }
  64. }
  65. infoDataList = infoList;
  66. }
  67. }
  68. public void RefreshPointValue(IList<UniformCodeInfo> infoList, string windturbineId)
  69. {
  70. DateTime st = DateTime.Now;
  71. string[] uniformCodeArr = infoList.Select(s => s.UniformCode).ToList().ToArray();
  72. Dictionary<string, TsData> dic = RestfulClient.findLatestByThingCodes("windturbine", windturbineId, uniformCodeArr);
  73. foreach (var tsData in dic)
  74. {
  75. var data = infoList.Where(s => s.UniformCode == tsData.Key).FirstOrDefault();
  76. if (data != null)
  77. {
  78. double pointValue = 0.0;
  79. bool isNum = IsNum(tsData.Value.getValue(), out pointValue);
  80. if (isNum)
  81. {
  82. data.PointValue = pointValue.ToString("f2");
  83. }
  84. }
  85. }
  86. infoDataList = infoList;
  87. DateTime et = DateTime.Now;
  88. TimeSpan sp = et - st;
  89. Console.WriteLine("访问数据时间:" + sp.TotalMilliseconds);
  90. }
  91. public IList<UniformCodeInfo> GetPointData()
  92. {
  93. return infoDataList;
  94. }
  95. private bool IsNum(string s, out double num)
  96. {
  97. try
  98. {
  99. if (s == "True" || s == "true")
  100. num = 1;
  101. else if (s == "false" || s == "False")
  102. num = 0;
  103. else
  104. {
  105. num = Convert.ToDouble(s);
  106. }
  107. return true;
  108. }
  109. catch (Exception)
  110. {
  111. num = 0.0;
  112. return false;
  113. }
  114. }
  115. }
  116. }