internal CameraFileTransferer( CameraFileNameConverter cameraFileNameConverter, IFileSystem fileSystem, TransferFiles transferFiles) { _cameraFileNameConverter = cameraFileNameConverter; _fileSystem = fileSystem; _transferFiles = transferFiles; }
public static void getJson(object msg) { Socket s = TransferFiles.Connect(clientIp, ClientPoint); try { new Helper().InsertErrorMsg(s.RemoteEndPoint + "||" + msg.ToString(), "向安卓发消息"); TransferFiles.sendJsonMsg(s, msg.ToString()); } catch (Exception ex) { new Helper().InsertErrorMsg(ex.Message, "连接安卓Socket失败"); } }
/// <summary> /// 接收安卓文件 /// </summary> /// <param name="clientSocket"></param> /// <param name="msg"></param> public static void Create(object clientSocket, string msg) { //FileStream MyFileStream = null; try { new Helper().InsertErrorMsg(msg, "收到安卓文件"); Socket client = clientSocket as Socket; msg = Regex.Split(msg, "0X11:")[1]; string[] fileinfo = Regex.Split(msg, "&");//文件地址& string pp = "Page" + "\\" + fileinfo[0]; string fullPath = Path.Combine(Environment.CurrentDirectory, pp); //string filename = System.IO.Path.GetFileName(fullPath); FileInfo fileInfo = new FileInfo(fullPath); if (File.Exists(fullPath) && !fullPath.ToLower().Contains(".json") && fileInfo.Length != 0) { Message message = new Message() { cbId = "sendFileStatus_n", data = fileinfo[0], Status = true }; string strmessag = JsEvent.EnSerialize <Message>(message); //Thread createThread = new Thread(getJson); //createThread.Start(strmessag); getJson(strmessag); return; } else { Message message = new Message() { cbId = "sendFileStatus_n", data = fileinfo[0], Status = false }; string strmessag = JsEvent.EnSerialize <Message>(message); //Thread createThread = new Thread(getJson); //createThread.Start(strmessag); getJson(strmessag); } long bagSize = Convert.ToInt64(fileinfo[1]); TransferFiles.ReceiveData(client, bagSize, fullPath); IsTime = true; } catch (Exception ex) { new Helper().InsertErrorMsg(ex.Message + "||" + ex.StackTrace, "create收文件异常"); return; } //关闭文件流 //MyFileStream.Close(); //关闭套接字 //client.Close(); }
public static void Message(object clientSocket, string msg) { try { new Helper().InsertErrorMsg(msg, "收到返回消息"); Socket client = clientSocket as Socket; msg = Regex.Split(msg, "0X12:")[1]; long bagSize = Convert.ToInt64(msg); byte[] data = TransferFiles.ReceiveMsg(client, bagSize); string datamsg = Encoding.UTF8.GetString(data, 0, data.Length); JsEvent.SendMsg(datamsg); } catch (Exception ex) { } }
public void RevceiveOrCreate(object clientSocke) { Socket client = clientSocke as Socket; IPEndPoint clientPoint = (IPEndPoint)client.RemoteEndPoint; //获得文件名 string SendFileName = Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(client)); //获得包大小 string bagSize = Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(client)); //获得包总数 int bagCount; int.TryParse(Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(client)), out bagCount); //获得最后一个包的大小 string bagLast = Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(client)); Console.WriteLine("文件名:" + SendFileName + "包大小:" + bagSize + "包总数:" + bagCount + "最后一个包的大小:" + bagLast); //string FullPath = Path.Combine(Environment.CurrentDirectory, SendFileName); string FullPath = @"/Users/mac/Desktop/aaa.mp4"; using (FileStream fileStream = new FileStream(FullPath, FileMode.Create, FileAccess.Write)) { int SendCount = 0; while (true) { byte[] data = TransferFiles.ReceiveVarData(client); //byte[] data = TransferFiles.ReceiveData(client,(int)fileStream.Length); if (data.Length == 0) { break; } else { SendCount++; fileStream.Write(data, 0, data.Length); } } // client.Send(Encoding.Unicode.GetBytes("接收完毕")); client.Close(); } Console.WriteLine(SendFileName + "接收完毕"); }
public bool SendFile(string filePath) { FileInfo fileInfo = new FileInfo(filePath); FileStream fileStream = fileInfo.OpenRead(); int PacketSize = 10000; int packetcount = (int)(fileStream.Length / PacketSize); int lastDataPacket = (int)(fileStream.Length - (PacketSize * packetcount)); //发送文件名到客户端 TransferFiles.SendVarData(clientSocket, Encoding.Unicode.GetBytes(fileStream.Name)); //发送包大小到服务器 TransferFiles.SendVarData(clientSocket, Encoding.Unicode.GetBytes(PacketSize.ToString())); //发送包数量 TransferFiles.SendVarData(clientSocket, Encoding.Unicode.GetBytes(packetcount.ToString())); //发送[最后一个包的大小]到客户端 TransferFiles.SendVarData(clientSocket, Encoding.Unicode.GetBytes(lastDataPacket.ToString())); bool isCut = false; byte[] data = new byte[PacketSize]; for (int i = 0; i < packetcount; i++) { fileStream.Read(data, 0, data.Length); if (TransferFiles.SendVarData(clientSocket, data) == 3) { isCut = true; return(false); } } if (lastDataPacket != 0) { data = new byte[lastDataPacket]; fileStream.Read(data, 0, data.Length); TransferFiles.SendVarData(clientSocket, data); } clientSocket.Close(); fileStream.Close(); if (!isCut) { return(true); } return(false); }
/// <summary> /// socket连接后监听消息 /// </summary> /// <param name="clientSocket"></param> public static void recive(object clientSocket) { while (true) { string msg = TransferFiles.receiveFileMsg((Socket)clientSocket); //new Helper().InsertErrorMsg(msg, "recive收到安卓消息"); if (msg.Contains("0X11")) { Create(clientSocket, msg); } else if (msg.Contains("0X12")) { Message(clientSocket, msg); } else if (msg.Contains("0X13")) { Application.Exit(); } } }
public bool Sendfile(string ip, int port, string fullPath) { FileInfo fileInfo = new FileInfo(fullPath); FileStream fileStream = fileInfo.OpenRead(); int PacketSize = 10000; int packetcount = (int)(fileStream.Length / PacketSize); int lastDataPacket = (int)(fileStream.Length - (PacketSize * packetcount)); IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(ip), port); Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { clientSocket.Connect(endPoint); } catch (Exception) { Console.WriteLine("连接服务器失败"); return(false); } //IPEndPoint clientPoint = (IPEndPoint)clientSocket.RemoteEndPoint; //发送文件名到客户端 TransferFiles.SendVarData(clientSocket, Encoding.Unicode.GetBytes(fileStream.Name)); //发送包大小到服务器 TransferFiles.SendVarData(clientSocket, Encoding.Unicode.GetBytes(PacketSize.ToString())); //发送包数量 TransferFiles.SendVarData(clientSocket, Encoding.Unicode.GetBytes(packetcount.ToString())); //发送[最后一个包的大小]到客户端 TransferFiles.SendVarData(clientSocket, Encoding.Unicode.GetBytes(lastDataPacket.ToString())); bool isCut = false; byte[] data = new byte[PacketSize]; for (int i = 0; i < packetcount; i++) { fileStream.Read(data, 0, data.Length); if (TransferFiles.SendVarData(clientSocket, data) == 3) { isCut = true; return(false); } } if (lastDataPacket != 0) { data = new byte[lastDataPacket]; fileStream.Read(data, 0, data.Length); TransferFiles.SendVarData(clientSocket, data); } //byte[] msg = new byte[1024]; //int count= clientSocket.Receive(msg); //Console.WriteLine(Encoding.Unicode.GetString(msg, 0, count)); clientSocket.Close(); fileStream.Close(); if (!isCut) { return(true); } return(false); }
/// <summary> /// 执行指标测试指令 /// </summary> /// <param name="clientSocket"></param> private static void Excute(object clientSocket) { Socket client = clientSocket as Socket; byte[] ID_buffer = new byte[40]; try { UpdateLog.ClearLog(); Thread.Sleep(100); while (true) { if (client.Available > 0) { UpdateLog.Log("➤ 查询参数"); byte[] res = TransferFiles.ReceiveVarData(client); string Str_NameAndMission = Encoding.UTF8.GetString(res); string stationname = "", Commend = "", st = "", ed = ""; if (Str_NameAndMission != "GetConfig" && Str_NameAndMission != "SetConfig") { string[] array = Str_NameAndMission.Split("#".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); UpdateLog.Log("站名#" + array[0]); UpdateLog.Log("指令#" + array[1]); stationname = array[0]; Commend = array[1]; st = array[2]; ed = array[3]; UpdateLog.Log("时间#" + array[2].Replace("#", " ") + " 至 " + array[3].Replace("#", " ")); } else { //若是【获去配置】或【修改配置】则只包含命令 Commend = Str_NameAndMission; } switch (Commend) { #region 基础数据 case "BaseCount": try { try { UpdateLog.Log("➤ 列车总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetTrainNum(st, ed, li.lid.ToString()); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("列车总数#" + (total)); UpdateLog.Log("数据来源#Train表"); } catch (Exception ex) { UpdateLog.Error("列车总数#" + ex.Message); } try { UpdateLog.Log("➤ 各类列车数量"); foreach (LineInfo li in LineList) { DataTable tmp = IndexTest.GetTyainNumByTrainType(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid); if (tmp != null && tmp.Rows.Count > 0) { for (int i = 0; i < tmp.Rows.Count; i++) { UpdateLog.Log(tmp.Rows[i][0].ToString().Replace("NoTrainType", "列车类型为空") + "#" + tmp.Rows[i][1].ToString()); } } } UpdateLog.Log("数据来源#Train表"); } catch (Exception ex) { UpdateLog.Error("各类列车数量#" + ex.Message); } try { UpdateLog.Log("➤ 车厢总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetCarNumByPeriod(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "#" + tmp); total += tmp; } UpdateLog.Log("车厢总数#" + total); UpdateLog.Log("数据来源#TrainDetail表"); } catch (Exception ex) { UpdateLog.Error("车厢总数#" + ex.Message); } try { UpdateLog.Log("➤ 各类车厢数量"); foreach (LineInfo li in LineList) { UpdateLog.Log("线路" + li.lid); DataTable tmp = IndexTest.GetCarNumByCarKind(st, ed, li.lid.ToString()); if (tmp != null && tmp.Rows.Count > 0) { for (int i = 0; i < tmp.Rows.Count; i++) { UpdateLog.Log(tmp.Rows[i]["vehicletype"].ToString() + "#" + tmp.Rows[i]["KindNum"].ToString()); } } } UpdateLog.Log("数据来源#TrainDetail表"); } catch (Exception ex) { UpdateLog.Error("各类车厢数量#" + ex.Message); } try { UpdateLog.Log("➤ 图像总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_Pic + li.FolderName + "\\", ".jpg"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("图像总数#" + total); UpdateLog.Log("数据来源#.jpg文件个数"); } catch (Exception ex) { UpdateLog.Error("图像总数#" + ex.Message); } try { UpdateLog.Log("➤ 走行部图像总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_ZXPic + li.FolderName + "\\", ".jpg"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("走行部图像总数#" + total); UpdateLog.Log("数据来源#.jpg文件个数"); } catch (Exception ex) { UpdateLog.Error("图像总数#" + ex.Message); } try { UpdateLog.Log("➤ 视频总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_Video + li.FolderName + "\\", ".mp4"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("视频总数#" + total); UpdateLog.Log("数据来源#.mp4文件个数"); } catch (Exception ex) { UpdateLog.Error("视频总数#" + ex.Message); } try { UpdateLog.Log("➤ 声音总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_Voice + li.FolderName + "\\", ".aac"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("声音总数#" + total); UpdateLog.Log("数据来源#.aac文件个数"); } catch (Exception ex) { UpdateLog.Error("声音总数#" + ex.Message); } try { UpdateLog.Log("➤ 所有预警总数"); decimal total = 0; foreach (LineInfo li in LineList) { decimal tmp = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), null, null, null); UpdateLog.Log("线路" + li.lid + "#" + tmp); total += tmp; } UpdateLog.Log("预警总数#" + total); } catch (Exception ex) { UpdateLog.Error("预警总数#" + ex.Message); } try { UpdateLog.Log("➤ 各类别预警数"); int sum_Alarm = 0, sum_Fail = 0; foreach (LineInfo li in LineList) { UpdateLog.Log("线路" + li.lid + ""); UpdateLog.Log("===正常报警:"); DataTable alarm = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), true); if (alarm != null && alarm.Rows.Count > 0) { for (int i = 0; i < alarm.Rows.Count; i++) { UpdateLog.Log(alarm.Rows[i]["ProblemType"].ToString() + "#" + alarm.Rows[i]["AlarmNum"].ToString()); sum_Alarm += int.Parse(alarm.Rows[i]["AlarmNum"].ToString()); } } UpdateLog.Log("===检测失败:"); DataTable fail = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), false); if (fail != null && fail.Rows.Count > 0) { for (int i = 0; i < fail.Rows.Count; i++) { UpdateLog.Log(fail.Rows[i]["ProblemType"].ToString() + "#" + fail.Rows[i]["AlarmNum"].ToString()); sum_Fail += int.Parse(fail.Rows[i]["AlarmNum"].ToString()); } } } UpdateLog.Log("【报警总数】#" + sum_Alarm); UpdateLog.Log("【检测失败】#" + sum_Fail); } catch (Exception ex) { UpdateLog.Error("各类别预警数" + ex.Message); } } catch (Exception ex) { UpdateLog.Error("基础数据异常#" + ex.Message); } break; #endregion #region 丢文件 case "MissFiles": try { UpdateLog.Log("➤ 丢文件检测"); foreach (LineInfo li in LineList) { UpdateLog.Log("=====【线路" + li.lid + "】====="); int Count_Dir; List <DirectoryInfo> list_MissingIndex; List <FileInfo> list_MissingPics; IndexTest.CountMissingPics(st, ed, Common.Default.Path_Pic + li.FolderName + "\\", out Count_Dir, out list_MissingIndex, out list_MissingPics); UpdateLog.Log("共检测了文件夹#" + Count_Dir); UpdateLog.Log("共丢失Index#" + list_MissingIndex.Count); UpdateLog.Log("共丢失图片#" + list_MissingPics.Count); if (list_MissingIndex.Count > 0) { UpdateLog.Log("===Index丢失明细==="); foreach (DirectoryInfo dir in list_MissingIndex) { UpdateLog.Log("Index丢失#" + dir.FullName); } } if (list_MissingPics.Count > 0) { UpdateLog.Log("===图片丢失明细==="); foreach (FileInfo fi in list_MissingPics) { UpdateLog.Log("图片丢失#" + fi.FullName); } } } } catch (Exception ex) { UpdateLog.Error(ex.Message); } try { UpdateLog.Log("➤ 丢文件检测(走形)"); foreach (LineInfo li in LineList) { UpdateLog.Log("=====【线路" + li.lid + "】====="); int Count_Dir; List <DirectoryInfo> list_MissingIndex; List <FileInfo> list_MissingPics; IndexTest.CountMissingPics(st, ed, Common.Default.Path_ZXPic + li.FolderName + "\\", out Count_Dir, out list_MissingIndex, out list_MissingPics); UpdateLog.Log("共检测了文件夹#" + Count_Dir); UpdateLog.Log("共丢失Index#" + list_MissingIndex.Count); UpdateLog.Log("共丢失图片#" + list_MissingPics.Count); if (list_MissingIndex.Count > 0) { UpdateLog.Log("===Index丢失明细==="); foreach (DirectoryInfo dir in list_MissingIndex) { UpdateLog.Log("Index丢失#" + dir.FullName); } } if (list_MissingPics.Count > 0) { UpdateLog.Log("===图片丢失明细==="); foreach (FileInfo fi in list_MissingPics) { UpdateLog.Log("图片丢失#" + fi.FullName); } } } } catch (Exception ex) { UpdateLog.Error(ex.Message); } break; #endregion #region 入库率 case "DBIndex": try { UpdateLog.Log("➤ 列车实时入库率"); double[] all = IndexTest.GetTrainInfoImportDataByFlagRatio(st, ed, "SOCKET", null); foreach (LineInfo li in LineList) { double[] tmp = IndexTest.GetTrainInfoImportDataByFlagRatio(st, ed, "SOCKET", li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "入库率#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 4, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); } UpdateLog.Log("实时入库率(Socket)#" + all[0] + "/" + all[1] + " * 100 = " + (all[1] != 0 ? Math.Round(all[0] / all[1], 4, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#实时入库列车数/过车总数*100%"); } catch (Exception ex) { UpdateLog.Error("热轮总数#" + ex.Message); } try { UpdateLog.Log("➤ 列车补入库率"); double[] all = IndexTest.GetTrainInfoImportDataByFlagRatio(st, ed, "INDEX", null); foreach (LineInfo li in LineList) { double[] tmp = IndexTest.GetTrainInfoImportDataByFlagRatio(st, ed, "INDEX", li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "入库率#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 4, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); } UpdateLog.Log("补入库率(Index)#" + all[0] + "/" + all[1] + " * 100 = " + (all[1] != 0 ? Math.Round(all[0] / all[1], 4, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#Index补入库列车数/过车总数*100%"); } catch (Exception ex) { UpdateLog.Error("入库率#" + ex.Message); } break; #endregion #region 热轮指标 case "HotwheelIndex": try { UpdateLog.Log("➤ 热轮总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_Hotwheel + li.FolderName + "\\", ".HotWheel"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("热轮总数#" + total); UpdateLog.Log("数据来源#.HotWheel文件个数"); } catch (Exception ex) { UpdateLog.Error("热轮总数#" + ex.Message); } try { UpdateLog.Log("➤ 热轮接入率"); double[] total = new double[2]; foreach (LineInfo li in LineList) { try { double[] tmp = IndexTest.GetHotWheelFileStatisicsRatio(st, ed, li.FolderName); UpdateLog.Log("线路" + li.lid + "接入率#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); total[0] += tmp[0]; total[1] += tmp[1]; } catch (Exception e) { UpdateLog.Error(e.Message); } } UpdateLog.Log("热轮接入率#" + total[0] + "/" + total[1] + " * 100 = " + (total[0] != 0 ? Math.Round((total[0]) / (total[1]), 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#接入热轮文件数/过车总数*100%"); } catch (Exception ex) { UpdateLog.Error("热轮接入率#" + ex.Message); } try { UpdateLog.Log("➤ 热轮匹配率"); double[] total = new double[2]; foreach (LineInfo li in LineList) { try { double[] tmp = IndexTest.GetHotWheelFileMatchRatio(st, ed, li.FolderName); UpdateLog.Log("线路" + li.lid + "匹配率#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); total[0] += tmp[0]; total[1] += tmp[1]; } catch (Exception e) { UpdateLog.Error(e.Message); } } UpdateLog.Log("热轮匹配率#" + total[0] + "/" + total[1] + " * 100 = " + (total[0] != 0 ? Math.Round((total[0]) / (total[1]), 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#匹配成功的热轮文件数/接入的热轮文件数*100%"); } catch (Exception ex) { UpdateLog.Error("热轮匹配率#" + ex.Message); } break; #endregion #region 确报指标 case "QBIndex": try { UpdateLog.Log("➤ 确报总数"); int total = 0; foreach (LineInfo li in LineList) { DataTable tmpdt = IndexTest.GetAllQBNumByPeriod(st, ed, li.lid.ToString()); int tmp = 0; int.TryParse(tmpdt.Rows[0][0]?.ToString(), out tmp); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("确报总数#" + total); } catch (Exception ex) { UpdateLog.Error("确报总数#" + ex.Message); } try { UpdateLog.Log("➤ 确报接入率"); foreach (LineInfo li in LineList) { double[] tmp = IndexTest.GetQBRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); } double[] all = IndexTest.GetQBRatio(st, ed, null); UpdateLog.Log("确报总接入率#" + all[0] + "/" + all[1] + " * 100 = " + (all[1] != 0 ? Math.Round(all[0] / all[1], 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#确报主表中的数值/非客过车总数*100%"); } catch (Exception ex) { UpdateLog.Error("确报接入率#" + ex.Message); } try { UpdateLog.Log("➤ 确报车号利用率"); foreach (LineInfo li in LineList) { double tmp = IndexTest.GetQBUseRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "利用率#" + tmp + "%"); } double all = IndexTest.GetQBUseRatio(st, ed, null); UpdateLog.Log("确报车号利用率#" + all + "%"); UpdateLog.Log("公式#确报弥补的车号数/车号识别短少的车号数*100%"); } catch (Exception ex) { UpdateLog.Error("确报车号利用率#" + ex.Message); } break; #endregion #region 车号识别率 case "CheckTrainNum": try { UpdateLog.Log("➤ 车号识别率"); foreach (LineInfo li in LineList) { double tmp = IndexTest.GetVisionCarNoRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "识别率#" + tmp + "%"); } double all = IndexTest.GetVisionCarNoRatio(st, ed, null); UpdateLog.Log("车号识别率#" + all + "%"); UpdateLog.Log("公式#车号正常车辆数/所有过车车辆数*100% [依据数据库计算]"); } catch (Exception ex) { UpdateLog.Error(ex.Message); } break; #endregion #region 丢轴 case "MissAxle": try { UpdateLog.Log("➤ 丢轴"); foreach (LineInfo li in LineList) { double tmp = IndexTest.GetUnusualAlexTrainRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "丢轴率#" + tmp + "%"); } double all = IndexTest.GetUnusualAlexTrainRatio(st, ed, null); UpdateLog.Log("总丢轴率#" + all + "%"); UpdateLog.Log("公式#丟轴、多轴列数/实际过车列数*100%"); UpdateLog.Log("*注#以算法返回的-11为基准,业务上发生的丢轴、多轴均视为丢轴"); } catch (Exception ex) { UpdateLog.Error(ex.Message); } break; #endregion #region 音视频生成率 case "GenerateRate_Audio_Video": try { UpdateLog.Log("➤ 音频生成率 和 视频生成率"); decimal total_audio = 0, total_video = 0, total_video2 = 0, total_Dir = 0; foreach (LineInfo li in LineList) { UpdateLog.Log("【线路" + li.lid + "】"); List <string> MissingAudio, MissingVideo, MissingVideo2; int DirCount; IndexTest.GenerateRate_Audio_Video(st, ed, Common.Default.Path_Pic + li.FolderName, out MissingAudio, out MissingVideo, out MissingVideo2, out DirCount); UpdateLog.Log("检测文件夹数#" + DirCount); total_Dir += DirCount; decimal rate_audio = DirCount != 0 ? Math.Round((DirCount - MissingAudio.Count) / Convert.ToDecimal(DirCount), 4, MidpointRounding.AwayFromZero) * 100 : 0; total_audio += DirCount - MissingAudio.Count; UpdateLog.Log("音频生成率#" + rate_audio); UpdateLog.Log("公式#音频生成率 = 生成主音频文件数/列车文件夹数*100%\r\n"); decimal rate_video = DirCount != 0 ? Math.Round((DirCount - MissingVideo.Count) / Convert.ToDecimal(DirCount), 4, MidpointRounding.AwayFromZero) * 100 : 0; total_video += DirCount - MissingVideo.Count; UpdateLog.Log("视频生成率#" + rate_video); UpdateLog.Log("公式#视频生成率 = 生成主视频文件数/列车文件夹数*100%\r\n"); decimal rate_video2 = DirCount != 0 ? Math.Round((DirCount - MissingVideo2.Count) / Convert.ToDecimal(DirCount), 4, MidpointRounding.AwayFromZero) * 100 : 0; total_video2 += DirCount - MissingVideo2.Count; UpdateLog.Log("视频生成率(辅)#" + rate_video2); UpdateLog.Log("公式#视频生成率 = 生成主视频文件数/列车文件夹数*100%\r\n"); UpdateLog.Log("丢失音频明细"); foreach (string i in MissingAudio) { UpdateLog.Log(i); } UpdateLog.Log("丢失视频明细"); foreach (string i in MissingVideo) { UpdateLog.Log(i); } UpdateLog.Log("丢失视频明细(辅)"); foreach (string i in MissingVideo2) { UpdateLog.Log(i); } } UpdateLog.Log("音频总生成率#" + Math.Round(total_audio / total_Dir, 4, MidpointRounding.AwayFromZero) * 100); UpdateLog.Log("视频总生成率#" + Math.Round(total_video / total_Dir, 4, MidpointRounding.AwayFromZero) * 100); UpdateLog.Log("视频总生成率(辅)#" + Math.Round(total_video / total_Dir, 4, MidpointRounding.AwayFromZero) * 100); } catch (Exception ex) { UpdateLog.Error("音频生成率 和 视频生成率异常#" + ex.Message); } break; #endregion #region 图像检测率 case "CallRate_Image": try { UpdateLog.Log("➤ 图像检测率"); foreach (LineInfo li in LineList) { double[] tmp = IndexTest.GetImageCheckRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "检测率#" + tmp[0] + "/" + tmp[1] + "=" + tmp[2] + "%"); } double[] all_Rate = IndexTest.GetImageCheckRatio(st, ed, null); UpdateLog.Log("图像检测率#" + all_Rate[0] + "/" + all_Rate[1] + "=" + all_Rate[2] + "%"); UpdateLog.Log("公式#主服务成功调用算法的个数/所有过车图片数*100%"); } catch (Exception ex) { UpdateLog.Error("图像检测率#" + ex.Message); } break; #endregion #region 图像算法调用及时性 case "Timely_Image": try { UpdateLog.Log(IndexTest.GetTimely(st, ed)); } catch (Exception ex) { UpdateLog.Error("图像算法调用的及时性异常#" + ex.Message); } break; #endregion #region 图像报警准确率 case "AccuracyRate_Image": try { foreach (LineInfo li in LineList) { UpdateLog.Log("【线路" + li.lid + "】"); decimal true_pic = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), true, true, "pic"); decimal false_pic = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), false, true, "pic"); decimal all_pic = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), null, true, "pic"); UpdateLog.Log("➤ 真实报警率#" + true_pic + "/" + all_pic + "=" + (all_pic != 0 ? (Math.Round(true_pic / all_pic, 4) * 100) : 0) + "%"); UpdateLog.Log("➤ 误报率#" + false_pic + "/" + all_pic + "=" + (all_pic != 0 ? (Math.Round(false_pic / all_pic, 4) * 100) : 0) + "%"); UpdateLog.Log("*注#基于人工处理后数据才有意义"); } } catch (Exception ex) { UpdateLog.Error("图像报警准确率#" + ex.Message); } break; #endregion #region 视频检测率 case "CheckRate_Video": try { UpdateLog.Log("此功能暂不实现"); } catch (Exception ex) { UpdateLog.Error("视频检测率#" + ex.Message); } break; #endregion #region 视频算法调用的及时性 case "Timely_Video": try { UpdateLog.Log("此功能暂不实现"); } catch (Exception ex) { UpdateLog.Error("视频算法调用的及时性#" + ex.Message); } break; #endregion #region 9个检测项独立统计【报喜不报忧模式】 case "Custom4Client": try { UpdateLog.Log("➤ 各类检测项统计"); int total_Alarm = 0; foreach (LineInfo li in LineList) { UpdateLog.Log("【线路" + li.lid + "】"); DataTable tmp = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), true); if (tmp != null && tmp.Rows.Count > 0) { for (int i = 0; i < tmp.Rows.Count; i++) { UpdateLog.Log(tmp.Rows[i]["ProblemType"].ToString() + "#" + tmp.Rows[i]["AlarmNum"].ToString()); total_Alarm += int.Parse(tmp.Rows[i]["AlarmNum"]?.ToString()); } } } UpdateLog.Log("报警总数#" + total_Alarm); } catch (Exception ex) { UpdateLog.Error("各类别预警数" + ex.Message); } break; #endregion default: break; } TransferFiles.SendVarData(client, Encoding.UTF8.GetBytes(UpdateLog.OutputLog_IntoString(false))); break; } else { Thread.Sleep(0); continue; } } } catch (Exception ex) { ///当网络异常中断#拔网线等触发,接受为0字节,但是并不认为是异常,因此需要添加心跳机制; UpdateLog.Error("接受失败#" + ex.Message); } finally { //输出日志文件 UpdateLog.OutputLog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TOEC Index Test"), "TOEC Index Test"); //关闭套接字 client.Close(); } }
private void test() { string FileLastName; //是否修改文件名 bool EditEx = false; //MessageBox.Show(DelOldFileTime.ToString()); //try //{ //获取线程ID string ThID = Thread.CurrentThread.ManagedThreadId.ToString(); IPEndPoint clientep = (IPEndPoint)socket.RemoteEndPoint; //显示服务端信息 //开始接受数据 //接受文件名 string fileName = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(socket)); //接受文件大小 string fileSize = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(socket)); //接受包的大小 string filebagSize = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(socket)); //接受包的数量 string filebagCount = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(socket)); //接受最后一个包的大小 string fileLastbagSize = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(socket)); //接受文件MD5值 //string fileMD5 = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(socket)); if (fileName != "" && fileSize != "") { _objForm.SetListBoxMsg = "开始接受数据!"; _objForm.SetListBoxMsg = "线程[" + ThID + "]文件名为:【" + fileName + "】"; _objForm.SetListBoxMsg = "线程[" + ThID + "]文件大小:【" + fileSize + "】字节"; _objForm.SetListBoxMsg = "线程[" + ThID + "]单个包大小:【" + filebagSize + "】字节"; _objForm.SetListBoxMsg = "线程[" + ThID + "]共发送:【" + filebagCount + "】个数据包"; _objForm.SetListBoxMsg = "线程[" + ThID + "]最后一个包:【" + fileLastbagSize + "】字节"; //_objForm.SetListBoxMsg = "发送文件MD5值:[" + fileMD5 + "]"; //获取文件后缀名 FileLastName = fileName.Substring(fileName.LastIndexOf(".")); string SaveFile = saveFilePath + "\\" + fileName.Substring(0, fileName.LastIndexOf(".")) + ".SDM"; //判断是否按发送时间另存文件 if (SaveASSate == "Checked") { SaveFile = saveFilePath + "\\" + fileName.Substring(0, fileName.LastIndexOf(".")) + "-" + System.DateTime.Now.ToString().Replace(":", "").Replace("-", "").Replace(" ", "") + "-" + Tools.GetRandomStringOnly(5) + ".SDM"; //设置修改文件名 EditEx = true; //MessageBox.Show(SaveFile); } else { //当文件以覆盖形式保存时,直接使用原始文件名及后缀 SaveFile = saveFilePath + "\\" + fileName.Substring(0, fileName.LastIndexOf(".")) + FileLastName; } System.IO.FileStream _myFileStream = new System.IO.FileStream(SaveFile, System.IO.FileMode.Create, System.IO.FileAccess.Write); int SendBagCount = 0; _objForm.SetListBoxMsg = "线程[" + ThID + "][" + System.DateTime.Now.ToString() + "]:【" + fileName + "】正在接收中..."; while (true) { byte[] data = TransferFiles.ReceiveVarData(socket); if (data.Length == 0) { break; } else { SendBagCount++; _myFileStream.Write(data, 0, data.Length); //_objForm.SetListBoxMsg = "已经接收" + SendBagCount.ToString() + "个数据包"; } if (Convert.ToInt64(_myFileStream.Length) == Convert.ToInt64(fileSize)) { ////接受文件MD5值 //OldFileMD5 = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(socket)); //_objForm.SetListBoxMsg = "线程[" + ThID + "]原始文件MD5值:【" + OldFileMD5 + "】"; _objForm.SetListBoxMsg = "线程[" + ThID + "][" + System.DateTime.Now.ToString() + "]:【" + fileName + "】接收完毕,服务端与客户端文件大小相同!"; } } _myFileStream.Dispose(); _myFileStream.Close(); System.IO.FileInfo f = new System.IO.FileInfo(SaveFile); if (EditEx == true) { //把文件改名为传输文件名 f.MoveTo(SaveFile.Substring(0, SaveFile.LastIndexOf(".")) + FileLastName); EditEx = false; } } socket.Close(); _objForm.SetListBoxMsg = "线程[" + ThID + "]客户端连接已经断开!"; _objForm.SetListBoxMsg = "***********************************************"; //Thread.CurrentThread.Abort(); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} }
/// <summary> /// Socket发送指标测试指令 /// </summary> /// <param name="strGetOrSet">字符串</param> private void RemoteSetting(object strGetOrSet)//GetConfig 或者 SetConfig { //初始化建立连接 try { setting_s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //缓冲区设置到2M setting_s.SendBufferSize = 1024 * 1024 * 2; setting_s.ReceiveBufferSize = 1024 * 1024 * 2; setting_s.NoDelay = true; IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(CurrentIP), CurrentPort); setting_s.Connect(ipep); //配置服务器IP与端口 this.Invoke(new ConnectStatus_Delegate(ConnectStatus), "连接成功"); } catch { this.Invoke(new ConnectStatus_Delegate(ConnectStatus), "连接【" + CurrentStationName + "】失败"); return; } try { TransferFiles.SendVarData(setting_s, Encoding.UTF8.GetBytes(strGetOrSet.ToString())); switch (strGetOrSet.ToString()) { case "GetConfig": try { //接受配置信息 byte[] res = TransferFiles.ReceiveVarData(setting_s); string jsonStr = Encoding.UTF8.GetString(res); if (jsonStr.Contains("Error")) { throw new Exception(jsonStr); } Dictionary <string, string> GetConfig = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonStr); this.Invoke(new LoadGridView_Delegate(LoadGridView), GetConfig); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; case "SetConfig": try { Dictionary <string, string> SetConfig = new Dictionary <string, string>(); for (int i = 0; i < gv_Setting.DataRowCount; i++) { DataRow tmp = gv_Setting.GetDataRow(i); SetConfig.Add(tmp["Key"].ToString(), tmp["Value"].ToString()); } //发送配置信息 TransferFiles.SendVarData(setting_s, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(SetConfig))); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { string fromDir = "C://Users//Student//Desktop//From"; string toDir = "C://Users//Student//Desktop//To"; string[] fileList; string[] xferFiles; GetFiles fl = new GetFiles(); fileList = fl.findFiles(fromDir); CheckDates cd = new CheckDates(); xferFiles = cd.checkDates(fileList); TransferFiles tf = new TransferFiles(); tf.transferFiles(xferFiles, fromDir, toDir); Console.WriteLine("Press Enter to terminate..."); Console.Read(); }