Program.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Test
  7. {
  8. class Program
  9. {
  10. private static string Process_Bus_Weighting_LoadFile(string path, ref long length)
  11. {
  12. try
  13. {
  14. if (!string.IsNullOrEmpty(path))
  15. {
  16. path = path.Replace("/", "\\");
  17. if (System.IO.File.Exists(path))
  18. {
  19. var buffer = new byte[1024 * 4];
  20. using (var stream = new System.IO.MemoryStream())
  21. {
  22. using (var fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
  23. {
  24. int len = 0;
  25. while ((len = fs.Read(buffer, 0, buffer.Length)) != 0)
  26. {
  27. stream.Write(buffer, 0, len);
  28. }
  29. fs.Close();
  30. }
  31. var temp = stream.ToArray();
  32. length = temp.Length;
  33. return Convert.ToBase64String(temp, 0, temp.Length);
  34. }
  35. }
  36. }
  37. }
  38. catch
  39. {
  40. }
  41. return null;
  42. }
  43. static void Main(string[] args)
  44. {
  45. var service = new MSHO.Collection.Service.ClearHistoryFileService();
  46. service.Start();
  47. Console.ReadLine();
  48. return;
  49. long file_length = 0;
  50. var fileStreamBase64 = Process_Bus_Weighting_LoadFile(@"C:\temp\192.168.101.166_20181120160822502_Plate.mp4", ref file_length);
  51. if (fileStreamBase64 != null)
  52. {
  53. //var buffer = Convert.FromBase64String(base64);
  54. System.IO.MemoryStream fileStream = null;
  55. //System.IO.File.WriteAllBytes(@"C:\temp\192.mp4", buffer);
  56. using (var connection = new HK.File.Client.FileClientConnection("Data Source=localhost;Initial Catalog=MSHO;buffer size=524288;"))
  57. {
  58. connection.Open();
  59. var trans = connection.BeginTransaction();
  60. try
  61. {
  62. var cmd = connection.CreateCommand(HK.File.Client.Command.CommandType.InsertFile) as HK.File.Client.Command.InsertFileCommand;
  63. cmd.FileName = "192.168.101.166_20181120160822502_Plate.mp4";
  64. cmd.FileDescription = ".mp4";
  65. cmd.FolderPath = "video";
  66. cmd.Transaction = trans;
  67. MSHO.Collection.DataAccess.Helper.FileService.CreateFolder(connection, "video");
  68. if (fileStream == null)
  69. {
  70. var fileInfo = new System.IO.FileInfo("192.168.101.166_20181120160822502_Plate.mp4");
  71. var buffer = Convert.FromBase64String(fileStreamBase64);
  72. if (file_length > 0)
  73. {
  74. if (file_length != buffer.LongLength)
  75. {
  76. //return false;
  77. }
  78. }
  79. {
  80. fileStream = new System.IO.MemoryStream(buffer, 0, buffer.Length);
  81. }
  82. }
  83. if (fileStream != null)
  84. {
  85. fileStream.Seek(0, System.IO.SeekOrigin.Begin);
  86. cmd.Stream = fileStream;
  87. }
  88. if (cmd.Execute())
  89. {
  90. var fileServerID = cmd.UniqueID;
  91. fileStream.Seek(0, System.IO.SeekOrigin.Begin);
  92. trans.Commit();
  93. trans = null;
  94. }
  95. }
  96. catch (Exception ex)
  97. {
  98. MSHO.Collection.DataAccess.MSHOService.Instance.SaveSystemLog("MSHO.Collection.Service", "MSHOService.SaveWeightingFile", ex);
  99. trans.Rollback();
  100. trans = null;
  101. }
  102. finally
  103. {
  104. if (trans != null)
  105. {
  106. trans.Rollback();
  107. trans = null;
  108. }
  109. }
  110. connection.Close();
  111. }
  112. }
  113. //remove_repeat();
  114. return;
  115. var config = MSHO.Collection.Service.Configuration.Instance;
  116. var server = new MSHO.Collection.Service.IO.IOServer(config.IP, config.Port, config.MaxConnection, config.BufferSize);
  117. server.Start();
  118. Console.WriteLine("Server Starting.........");
  119. Console.ReadLine();
  120. server.Stop();
  121. }
  122. static void remove_repeat()
  123. {
  124. decimal rate = (decimal)0.3;
  125. var query = MSHO.Collection.DataAccess.MSHOService.Instance.GetAllWeightings();
  126. var ids = (from o in query
  127. where (o.DeviceID == 5 || o.DeviceID == 12) && o.OverloadRate >= rate
  128. select o.ID).ToArray();
  129. foreach (var id in ids) {
  130. MSHO.Collection.DataAccess.MSHOService.Instance.DeleteWeighting(id);
  131. Console.WriteLine("删除 {0}", id);
  132. }
  133. Console.WriteLine("删除完成");
  134. }
  135. }
  136. }