StartUp.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. try
  42. {
  43. GopTimeCalc.ChangeData(dataList);
  44. }
  45. catch (Exception e)
  46. {
  47. XTrace.Log.Error(e.ToString());
  48. }
  49. };
  50. _scada.Start();
  51. Thread.Sleep(3000);
  52. GopTimeCalc.Load(config, sqlConn, GetAllData());
  53. _isStart = true;
  54. }
  55. private static List<Model.Data> GetAllData()
  56. {
  57. return _scada.GetAllData().Select(c => new Model.Data
  58. {
  59. BatchNum = c.batchNum,
  60. DataType = c.dataType,
  61. DateTime1 = c.DateTime1.ToString("yyyy-MM-dd HH:mm:ss"),
  62. Id = c.id,
  63. ItemId = c.itemID,
  64. TimeStamp = c.timeStamp,
  65. Value = c.value
  66. }).ToList();
  67. }
  68. }
  69. }