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("删除完成"); } } }