123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Test
- {
- class Program
- {
- private static string Process_Bus_Weighting_LoadFile(string path, ref long length)
- {
- try
- {
- if (!string.IsNullOrEmpty(path))
- {
- path = path.Replace("/", "\\");
- if (System.IO.File.Exists(path))
- {
- var buffer = new byte[1024 * 4];
- using (var stream = new System.IO.MemoryStream())
- {
- using (var fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
- {
- int len = 0;
- while ((len = fs.Read(buffer, 0, buffer.Length)) != 0)
- {
- stream.Write(buffer, 0, len);
- }
- fs.Close();
- }
- var temp = stream.ToArray();
- length = temp.Length;
- return Convert.ToBase64String(temp, 0, temp.Length);
- }
- }
- }
- }
- catch
- {
- }
- return null;
- }
- static void Main(string[] args)
- {
- var service = new MSHO.Collection.Service.ClearHistoryFileService();
- service.Start();
- Console.ReadLine();
- return;
- long file_length = 0;
- var fileStreamBase64 = Process_Bus_Weighting_LoadFile(@"C:\temp\192.168.101.166_20181120160822502_Plate.mp4", ref file_length);
- if (fileStreamBase64 != null)
- {
- //var buffer = Convert.FromBase64String(base64);
- System.IO.MemoryStream fileStream = null;
- //System.IO.File.WriteAllBytes(@"C:\temp\192.mp4", buffer);
- using (var connection = new HK.File.Client.FileClientConnection("Data Source=localhost;Initial Catalog=MSHO;buffer size=524288;"))
- {
- connection.Open();
- var trans = connection.BeginTransaction();
- try
- {
- var cmd = connection.CreateCommand(HK.File.Client.Command.CommandType.InsertFile) as HK.File.Client.Command.InsertFileCommand;
- cmd.FileName = "192.168.101.166_20181120160822502_Plate.mp4";
- cmd.FileDescription = ".mp4";
- cmd.FolderPath = "video";
- cmd.Transaction = trans;
- MSHO.Collection.DataAccess.Helper.FileService.CreateFolder(connection, "video");
- if (fileStream == null)
- {
- var fileInfo = new System.IO.FileInfo("192.168.101.166_20181120160822502_Plate.mp4");
- var buffer = Convert.FromBase64String(fileStreamBase64);
- if (file_length > 0)
- {
- if (file_length != buffer.LongLength)
- {
- //return false;
- }
- }
- {
- fileStream = new System.IO.MemoryStream(buffer, 0, buffer.Length);
- }
- }
- if (fileStream != null)
- {
- fileStream.Seek(0, System.IO.SeekOrigin.Begin);
- cmd.Stream = fileStream;
- }
- if (cmd.Execute())
- {
- var fileServerID = cmd.UniqueID;
- fileStream.Seek(0, System.IO.SeekOrigin.Begin);
- trans.Commit();
- trans = null;
- }
- }
- catch (Exception ex)
- {
- MSHO.Collection.DataAccess.MSHOService.Instance.SaveSystemLog("MSHO.Collection.Service", "MSHOService.SaveWeightingFile", ex);
- trans.Rollback();
- trans = null;
- }
- finally
- {
- if (trans != null)
- {
- trans.Rollback();
- trans = null;
- }
- }
- connection.Close();
- }
- }
- //remove_repeat();
- return;
- var config = MSHO.Collection.Service.Configuration.Instance;
- var server = new MSHO.Collection.Service.IO.IOServer(config.IP, config.Port, config.MaxConnection, config.BufferSize);
- server.Start();
- Console.WriteLine("Server Starting.........");
- Console.ReadLine();
- server.Stop();
- }
- static void remove_repeat()
- {
- decimal rate = (decimal)0.3;
- var query = MSHO.Collection.DataAccess.MSHOService.Instance.GetAllWeightings();
- var ids = (from o in query
- where (o.DeviceID == 5 || o.DeviceID == 12) && o.OverloadRate >= rate
- select o.ID).ToArray();
- foreach (var id in ids) {
- MSHO.Collection.DataAccess.MSHOService.Instance.DeleteWeighting(id);
- Console.WriteLine("删除 {0}", id);
- }
- Console.WriteLine("删除完成");
- }
- }
- }
|