StartUp.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Configuration;
  3. using NewLife.Data;
  4. using NewLife.Serialization;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7. using System.Threading;
  8. using NewLife.Log;
  9. using OPC_Client;
  10. using Pas.ScadaService.Core;
  11. using System.Web.UI.WebControls;
  12. namespace Pas.ScadaService
  13. {
  14. public class StartUp
  15. {
  16. private static Core.ScadaService _scada;
  17. private static bool _isStart;
  18. public static void Start()
  19. {
  20. var serverName = ConfigurationManager.AppSettings["ServerName"];
  21. var pointFile = ConfigurationManager.AppSettings["PointFile"];
  22. var config = ConfigurationManager.AppSettings["ConfigFile"];
  23. var sqlConn = ConfigurationManager.AppSettings["SqlConn"];
  24. _scada = new Core.ScadaService(serverName, pointFile);
  25. _scada.ChangeEvent += (data, changeItems) =>
  26. {
  27. if (!_isStart) return;
  28. var dataList =
  29. data.Where(c => changeItems.Contains(c.Key))
  30. .Select(c => new Model.Data
  31. {
  32. BatchNum = c.Value.batchNum,
  33. DataType = c.Value.dataType,
  34. DateTime1 = c.Value.DateTime1.ToString("yyyy-MM-dd HH:mm:ss"),
  35. Id = c.Value.id,
  36. ItemId = c.Value.itemID,
  37. TimeStamp = c.Value.timeStamp,
  38. Value = c.Value.value
  39. })
  40. .ToList();
  41. GopTimeCalc.ChangeData(dataList);
  42. };
  43. _scada.Start();
  44. Thread.Sleep(3000);
  45. GopTimeCalc.Load(config, sqlConn, GetAllData());
  46. _isStart = true;
  47. }
  48. private static List<Model.Data> GetAllData()
  49. {
  50. return _scada.GetAllData().Select(c => new Model.Data
  51. {
  52. BatchNum = c.batchNum,
  53. DataType = c.dataType,
  54. DateTime1 = c.DateTime1.ToString("yyyy-MM-dd HH:mm:ss"),
  55. Id = c.id,
  56. ItemId = c.itemID,
  57. TimeStamp = c.timeStamp,
  58. Value = c.value
  59. }).ToList();
  60. }
  61. }
  62. }