//构造函数 public MonitorUnitCtrl(UsbInfo info) { InitializeComponent(); InitializeColor(); //创建处理类 process = new MonitorUnitCtrlProcess(this); policeNo = ""; nameT = info.TerminalNo; usbNo = process.GetBorderNo(nameT); this.Name = "Unit" + nameT; this.lblTerInfo.Content = nameT; this.lblCpStatus.Content = "拷贝"; this.pgbCopy.Minimum = 0; this.pgbCopy.Maximum = 100; lblCpPerc.Content = "0% (-- / --)"; this.lblChStatus.Content = "充电"; this.pgbCharge.Minimum = 0; this.pgbCharge.Maximum = 100; lblChPerc.Content = "40% (06 : 00)"; SetFocus(false); SetFree(); }
//创建Grid行列并追加一个控件 public void CreateUsbInfoControl(WrapPanel panelPage, UsbInfo info) { this.info = info; MonitorUnitCtrl mUnit = new MonitorUnitCtrl(info); win.Grid_Container.RegisterName(mUnit.Name, mUnit); panelPage.Children.Add(mUnit); }
//获取记录仪的API,根据记录仪的编号获取信息 public UsbInfo readUsbInfo(String name) { UsbInfo info = new UsbInfo(); string infos = ini.ReadValue(MainConst.ROOE_VALUE_1, name); String[] inf = infos.Split(','); info.GrapherNo = name; info.TerminalNo = inf[0]; info.PoliceNo = inf[1]; return info; }
public Dictionary<String, UsbInfo> read() { Dictionary<String, UsbInfo> dic = new Dictionary<String, UsbInfo>(); UsbInfo usbInfo; for (int i = 1; i <= MainConst.USB_INFO_NUMBER_TOTAL; i++) { usbInfo = new UsbInfo(); // 获取当前警察所用的端口号 string infos = ini.ReadValue(MainConst.ROOE_VALUE, MainConst.USB_KEY + i); String[] info = infos.Split(','); String terminaNo = info[0]; int acquisitionState = int.Parse(info[1]); usbInfo.TerminalNo = terminaNo; usbInfo.AcquisitionState = acquisitionState; dic.Add(MainConst.USB_KEY + i, usbInfo); } return dic; }
//遍历记录仪,如果有新媒体文件存在,则弹出上传画面 public void UploadWindowShow(string drive_name) { string path = drive_name + "sn.txt"; try { pathList = new List<string>(); policeNo = OpenTxt(path); String folderPath = ""; String filePath = GetFiles(new DirectoryInfo(drive_name), "*.MP4", folderPath); //if (filePath == string.Empty || filePath.Length == 0) //if (pathList.Count==0) { filePath = GetFiles(new DirectoryInfo(drive_name), "*.WAV", folderPath); } //if (filePath == string.Empty || filePath.Length == 0) //if (pathList.Count == 0) { filePath = GetFiles(new DirectoryInfo(drive_name), "*.JPG", folderPath); } //if (filePath == String.Empty || filePath.Length == 0) if (pathList.Count == 0) { //采集进度表示 UsbInfo info = new UsbInfo(); info.NumFileCopied = 0; info.NumFileAll = 0; this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(AcquisitionStateOfChange), info); MessageBox.Show("该执法记录仪中没有有效的媒体文件!", MainControl.MainConst.MESSAGE_BOX_TITLE); LogConfig.info("Administrator", drive_name+":该执法记录仪中没有有效的媒体文件"); return; } } catch (Exception ioe) { LogConfig.error("Administrator", ioe.Message); LogConfig.error("Administrator", ioe.StackTrace); UsbInfo info = new UsbInfo(); this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(SetControlFree), info); return; } //分类模式 if (categoFlag.Equals("1")) { LogConfig.info("Administrator", "启动分类上传画面"); LogConfig.info(policeNo, "启动分类上传画面"); LogConfig.info(policeNo, "媒体文件存放路径个数:" + pathList.Count); //弹出文件上传画面 MonitorWindow winMonitor = (MonitorWindow)Window.GetWindow(this.lordCtrl); Double iTop = winMonitor.Top; //Move the monitor window out of the screen winMonitor.Top = -3000; CategoUploadWindow swp = new CategoUploadWindow(this.lordCtrl.TerminalNo, policeNo, pathList); MainWindow mainwin = (MainWindow)Application.Current.MainWindow; mainwin.PpUpload = swp; swp.Owner = winMonitor; Boolean isclose = true; try { isclose = (Boolean)swp.ShowDialog(); }catch(Exception e){ LogConfig.error("Administrator", e.Message); LogConfig.error("Administrator", e.StackTrace); swp.Close(); UsbInfo info = new UsbInfo(); this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(SetControlFree), info); } //Restore the monitor window to it's original position winMonitor.Top = iTop; killProcess(); if (!isclose) { if (swp.buttonType.Equals("ButtonUpload")) { if (!Directory.Exists(localCachePath)) { Directory.CreateDirectory(localCachePath); } xmlFile = swp.xmlFileName; ThreadStart threadDelegate = delegate { CopyFile(drive_name, xmlFile); }; Thread newThread = new Thread(threadDelegate); newThread.Start(); } else if (swp.buttonType.Equals("ButtonQuit")) { //采集进度表示 UsbInfo info = new UsbInfo(); info.NumFileCopied = 0; info.NumFileAll = 0; this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(AcquisitionStateOfChange), info); } else { //Upload画面中异常断开时,设置USB状态为空闲 UsbInfo info = new UsbInfo(); this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(SetControlFree), info); } } } //直接上传模式 else { //this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(SetReady), new UsbInfo()); //开始上传 ThreadStart threadDelegate = delegate { CopyFile(drive_name, xmlFile); }; Thread newThread = new Thread(threadDelegate); newThread.Start(); } }
//追加已有的设备 public void Create_Canvas() { WrapPanel panel = null; if (panels != null || panels.Count != 0) { int j = 0; for (int i = 0; i < dic.Count; i++) { if (i % MainConst.USB_INFO_NUMBER_BY_PAGE == 0) { panel = panels[j]; j++; } UsbInfo info = new UsbInfo(); dic.TryGetValue(MainConst.USB_KEY + (i + 1), out info); control.CreateUsbInfoControl(panel, info); if (i % MainConst.USB_INFO_NUMBER_BY_PAGE == 0) { this.win.Grid_Container.Children.Add(panel); } } } }
public void SetInfoForFirst(UsbInfo info) { this.lordCtrl.SetInfoForFirst(info.NumFileCopied,info.NumFileAll); }
//采集进度改变为空闲 public void SetControlFree(UsbInfo info) { this.lordCtrl.SetFree(); }
//采集进度改变 public void SetReady(UsbInfo info) { this.lordCtrl.SetReady(0.4, 6, 0); }
//采集进度改变 public void AcquisitionStateOfChange(UsbInfo info) { this.lordCtrl.SetInfoCopyOnly(info.NumFileCopied, info.NumFileAll); //this.lordCtrl.SetInfoChargeOnly(0.4, 6, 0); }
// 复制文件 private void CopyFile(String drive_name, String xmlFile) { if (!categoFlag.Equals("1")) { LogConfig.info("Administrator", "自动上传"); LogConfig.info(policeNo, "自动上传"); LogConfig.info(policeNo, "媒体文件存放路径个数:" + pathList.Count); //遍历文件,自动生成XML try { AutoXML(); xmlFile = this.xmlFile; } catch (Exception e) { LogConfig.error(policeNo, e.Message); LogConfig.error(policeNo, e.StackTrace); LogConfig.error("Administrator", e.Message); LogConfig.error("Administrator", e.StackTrace); if (File.Exists(xmlFile)) { //如果存在则删除 File.Delete(xmlFile); } MessageBox.Show("执法记录仪中可能存在被病毒感染的文件!", MainControl.MainConst.MESSAGE_BOX_TITLE); return; } } try { // 获取采集文件信息 List<string> upload_file_list = new List<string>(); List<string> new_file_list = new List<string>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@".\\" + xmlFile); String[] inf = xmlFile.Split('_'); string policeNo = inf[0]; XmlNodeList list = xmlDoc.GetElementsByTagName("Name"); XmlNodeList newList = xmlDoc.SelectNodes("//@ChangedName"); foreach (XmlNode item2 in list) { upload_file_list.Add(item2.InnerText); } foreach (XmlNode newItem in newList) { new_file_list.Add(newItem.Value); } LogConfig.info(policeNo, "媒体文件个数:" + new_file_list.Count); // 情报 DateTime dt = DateTime.Now; String uploadTime = dt.ToString("yyyyMMddHHmmss"); //移走根目录下xml文件 String xmlPath = localCachePath + "\\" + policeNo + "\\" + policeNo + "\\" + uploadTime + "\\"; if (!Directory.Exists(xmlPath)) { Directory.CreateDirectory(xmlPath); } File.Copy(@".\\" + xmlFile, xmlPath + System.IO.Path.GetFileName(xmlFile), true); LogConfig.info(policeNo, xmlFile + "被移到" + xmlPath); //删除xml文件 DeleteAfterCopy(@".\\" + xmlFile, ""); LogConfig.info(policeNo, xmlFile + "被删除"); UsbInfo info = new UsbInfo(); info.NumFileCopied = 1; info.NumFileAll = upload_file_list.Count; //初始采集进度表示 //this.SetInfoCopyOnly(0, upload_file_list.Count); this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(SetInfoForFirst), info); int i; for (i = 0; i < upload_file_list.Count; i++) { try { // 拷贝文件并且重新命名 CopyAndRename(drive_name, localCachePath + "\\" + policeNo + "\\" + policeNo + "\\" + uploadTime + "\\", upload_file_list[i], new_file_list[i]); LogConfig.info(policeNo, upload_file_list[i] + "被重新命名为" + new_file_list[i]); LogConfig.info(policeNo, new_file_list[i] + "被复制或压缩"); setDeleteFlagForPC(xmlPath + System.IO.Path.GetFileName(xmlFile), new_file_list[i]); String filePath = GetFileName(new DirectoryInfo(drive_name), "*" + upload_file_list[i] + "*", ""); File.Delete(filePath); LogConfig.info(policeNo, upload_file_list[i] + "从执法记录仪中删除"); //设定参数 info.NumFileCopied = i + 1; //采集进度表示 this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(AcquisitionStateOfChange), info); }catch(Exception copye){ LogConfig.error(policeNo, copye.Message); LogConfig.error(policeNo, copye.StackTrace); LogConfig.error("Administrator", copye.Message); LogConfig.error("Administrator", copye.StackTrace); MessageBox.Show("上传失败,上传过程中请不要随意拔掉执法记录仪!", MainControl.MainConst.MESSAGE_BOX_TITLE); return; } } //设定参数 info.NumFileCopied = upload_file_list.Count; //采集进度表示 this.lordCtrl.Dispatcher.Invoke(new DelegateHandle(AcquisitionStateOfChange), info); //拷贝完了 Ini mainIni = new Ini(AppDomain.CurrentDomain.BaseDirectory + "Main.ini"); //服务器路径 string sRemoteDir = mainIni.ReadValue("Server", "sRemoteDir"); string sIP = mainIni.ReadValue("Server", "sIP"); string sRemoteUser = mainIni.ReadValue("Server", "sRemoteUser"); string sRemotePin = mainIni.ReadValue("Server", "sRemotePin"); string iDays = mainIni.ReadValue("Local", "iDays"); if (i == upload_file_list.Count) { //删除执法记录仪里文件(保留sn.txt) //DeleteFolder(drive_name); //sRemoteDir = @"\\" + sIP + "\\" + sRemoteDir; String localPath = localCachePath + "\\" + policeNo + "\\" + policeNo + "\\" + uploadTime + "\\"; String policePath = localCachePath + "\\" + policeNo + "\\" + policeNo + "\\"; String serverPath = @"\\" + sIP + "\\" + sRemoteDir + "\\" + policeNo + "\\" + uploadTime + "\\";//+ policeNo + "\\" //非分布式模式 if (serverFlag.Equals("server")) { LogConfig.info(policeNo, "服务器模式,准备上传。"); // 拷贝文件到服务器 if (Connect(sIP + "\\" + sRemoteDir, sRemoteUser, sRemotePin) || ExistConnect(sIP + "\\" + sRemoteDir, sRemoteUser, sRemotePin)) { for (i = 0; i < new_file_list.Count; i++) { LogConfig.info(policeNo, "服务器连接成功,开始上传。"); // 拷贝文件到服务器 //CopyFolder(localCachePath + "\\", sRemoteDir, new_file_list[i]); CopyFolder(localPath, serverPath, new_file_list[i]); //CopyFolder(localCachePath + "\\" + policeNo + "\\" + policeNo + "\\" + uploadTime + "\\", sRemoteDir + "\\" + policeNo + "\\" + policeNo + "\\" + uploadTime + "\\", new_file_list[i]); LogConfig.info(policeNo, new_file_list[i]+"上传成功。"); setDeleteFlagForXML(xmlPath + System.IO.Path.GetFileName(xmlFile), new_file_list[i]); File.Copy(xmlPath + System.IO.Path.GetFileName(xmlFile), serverPath + System.IO.Path.GetFileName(xmlFile), true); LogConfig.info(policeNo, iDays + "天后删除。"); if (iDays.Equals("0")) { deleteFileFromFolder(new DirectoryInfo(localPath), new_file_list[i]); LogConfig.info(policeNo, new_file_list[i] + "删除成功。"); } } //查找未上传的文件 Dictionary<String, String> unUploadList = findUnUploadFile(new DirectoryInfo(policePath)); Dictionary<String, String>.KeyCollection fileNamekeys = unUploadList.Keys; LogConfig.info(policeNo, "查找到"+unUploadList.Count + "件未上传成功的文件。"); foreach (string name in fileNamekeys) { string value = unUploadList[name].ToString(); CopyFolder(policePath, @"\\" + sIP + "\\" + sRemoteDir + "\\" + policeNo + "\\", name);// + policeNo + "\\" LogConfig.info(policeNo, name + "再次上传成功。"); setDeleteFlagForXML(value, name); String[] fileInfomation = name.Split('_'); String oldUploadTime = fileInfomation[3]; FileInfo oldXmlFile = new FileInfo(value); File.Copy(value, @"\\" + sIP + "\\" + sRemoteDir + "\\" + policeNo + "\\" + oldXmlFile.Directory.Name + "\\" + oldXmlFile.Name, true);//+ policeNo + "\\" LogConfig.info(policeNo, iDays + "天后删除。"); if (iDays.Equals("0")) { deleteFileFromFolder(new DirectoryInfo(policePath), name); LogConfig.info(policeNo, name + "删除成功。"); } } this.unUploadList = new Dictionary<String, String>(); } else { LogConfig.error(policeNo, "上传失败,与服务器连接存在问题,请稍后再试!"); LogConfig.error("Administrator", "上传失败,与服务器连接存在问题,请稍后再试!"); MessageBox.Show("上传失败,与服务器连接存在问题,请稍后再试!", MainControl.MainConst.MESSAGE_BOX_TITLE); } } else { LogConfig.info(policeNo, "采集站模式,操作结束。"); } } }catch(Exception e){ //MessageBox.Show(e.StackTrace); LogConfig.error(policeNo,e.Message); LogConfig.error(policeNo, e.StackTrace); LogConfig.error("Administrator", e.Message); LogConfig.error("Administrator", e.StackTrace); //MessageBox.Show("上传失败,与服务器连接出现问题!", MainControl.MainConst.MESSAGE_BOX_TITLE); } }