//根据盘符获得磁盘信息 private bool getDiskInfo(string diskName /*盘符*/, MDUsb usbDisk /*Out 返回一个对象*/) { DriveInfo[] s = DriveInfo.GetDrives(); bool findDisk = false; foreach (DriveInfo myDrive in s) { if (myDrive.Name.Equals(diskName.ToUpper())) { findDisk = true; usbDisk.driverName = myDrive.Name; usbDisk.driverLable = myDrive.VolumeLabel; usbDisk.driverType = myDrive.DriveType.ToString(); usbDisk.driverFormat = myDrive.DriveFormat; usbDisk.TotalSize = myDrive.TotalSize.ToString(); usbDisk.TotalFreeSpace = myDrive.TotalFreeSpace.ToString(); usbDisk.AvailableFreeSpace = myDrive.AvailableFreeSpace.ToString(); usbDisk.freePercent = (int)(myDrive.AvailableFreeSpace * 100 / myDrive.TotalSize); break; } } return(findDisk); }
private void setUsbInfoToScreen(string diskName, bool isShow) { string currentDriverName = diskName; int pos = -1; //根据盘符获得磁盘信息,并且将此对象放入队列待用 MDUsb usbDiskObject = new MDUsb(); if (isShow)//插入U盘 { if (getDiskInfo(currentDriverName, usbDiskObject)) { usbDiskDic.Add(currentDriverName, usbDiskObject);//将插入U盘对象放入容器 writeMsg(usbDiskObject.getDiskInfoStrirng()); writeMsg(diskName + " 盘 成功载入"); } else { writeMsg(diskName + " 盘 内容读取失败!"); return; } // 获得当前U盘对应的屏幕位置 pos = MDUsbPos.getUsbPos(currentDriverName); } else//U盘拔出 { if (usbDiskDic.ContainsKey(currentDriverName)) { usbDiskObject = usbDiskDic[currentDriverName];//取出对应的元素 // 获得当前U盘对应的屏幕位置 pos = MDUsbPos.getUsbPos(currentDriverName); MDUsbPos.setDisconnect(currentDriverName);//拔出时清空数据 usbDiskDic.Remove(currentDriverName); } if (pos < 0) { return; } writeMsg(diskName + " 盘已经拔出"); } //修改屏幕上的lable信息------------------------------------------------------- //根据Name获得对应的控件对象 string sID = "label_id_" + pos.ToString();; string sCount = "label_count_" + pos.ToString(); string sPic = "pictureBox" + pos.ToString(); System.Reflection.FieldInfo label1 = this.GetType().GetField(sID); //反射 System.Reflection.FieldInfo label2 = this.GetType().GetField(sCount); //反射 System.Reflection.FieldInfo pic1 = this.GetType().GetField(sPic); //反射 Label lableID = (Label)label1.GetValue(this); Label lableCount = (Label)label2.GetValue(this); PictureBox pic = (PictureBox)pic1.GetValue(this); if (isShow) { //计算当前U盘的文件个数,并且将文件列表放入当前usb对象的队列 int count = usbDiskObject.calcFileCountAndAdd(m_FilePrefixString, m_FileExtString); lableCount.Text = "0 / " + count.ToString();// 0 / 999 lableCount.Visible = true; lableCount.Refresh(); // 获得当前U盘的设备ID //lableID.Text = usbDiskObject.getDeviceID();// 设备ID: 99999 //lableID.Text = "编号: " + usbDiskObject.getPoliceID();// 警员编号ID: 99999 lableID.Text = "编号 " + usbDiskObject.getDeviceID();// 设备编号ID: A000022 string id1 = usbDiskObject.getPoliceID(); string id2 = usbDiskObject.getDataTime(); lableID.Visible = true; lableID.Refresh(); //设置设备颜色为蓝色 pic.BackgroundImage = MDWorkStation.Properties.Resources.b3; if (usbDiskObject.getFileCount() <= 0)//如果usb中没有文件,则设置成绿色 { pic.BackgroundImage = MDWorkStation.Properties.Resources.b1; } pic.Refresh(); } else { lableCount.Visible = lableID.Visible = false; pic.BackgroundImage = MDWorkStation.Properties.Resources.b2;//灰色 pic.Refresh(); } //修改屏幕上的lable信息 end------------------------------------------------------- return; /* * * if (bFirstRun)//只运行一次 * StartIdle(); * * return; * * * if (bFirstRun) * { * * * worker.DoWork += new DoWorkEventHandler(worker_DoWork); * worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); * worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); * * bFirstRun = false; * * return; * * } * * return; * */ }
private void setUsbInfoToScreen(string diskName, bool isShow) { string currentDriverName = diskName; int pos = -1; //根据盘符获得磁盘信息,并且将此对象放入队列待用 MDUsb usbDiskObject = new MDUsb(); if (isShow)//插入U盘 { if (getDiskInfo(currentDriverName, usbDiskObject)) { usbDiskDic.Add(currentDriverName, usbDiskObject);//将插入U盘对象放入容器 writeMsg(usbDiskObject.getDiskInfoStrirng()); writeMsg(diskName + " 盘 成功载入"); } else { writeMsg(diskName + " 盘 内容读取失败!"); return; } // 获得当前U盘对应的屏幕位置 pos = MDUsbPos.getUsbPos(currentDriverName); } else//U盘拔出 { if( usbDiskDic.ContainsKey(currentDriverName) ) { usbDiskObject = usbDiskDic[currentDriverName];//取出对应的元素 // 获得当前U盘对应的屏幕位置 pos = MDUsbPos.getUsbPos(currentDriverName); MDUsbPos.setDisconnect(currentDriverName);//拔出时清空数据 usbDiskDic.Remove(currentDriverName); } if (pos < 0) return; writeMsg(diskName + " 盘已经拔出"); } //修改屏幕上的lable信息------------------------------------------------------- //根据Name获得对应的控件对象 string sID = "label_id_" + pos.ToString(); ; string sCount = "label_count_" + pos.ToString(); string sPic = "pictureBox" + pos.ToString(); System.Reflection.FieldInfo label1 = this.GetType().GetField(sID);//反射 System.Reflection.FieldInfo label2 = this.GetType().GetField(sCount);//反射 System.Reflection.FieldInfo pic1 = this.GetType().GetField(sPic);//反射 Label lableID = (Label)label1.GetValue(this); Label lableCount = (Label)label2.GetValue(this); PictureBox pic = (PictureBox)pic1.GetValue(this); if (isShow) { //计算当前U盘的文件个数,并且将文件列表放入当前usb对象的队列 int count = usbDiskObject.calcFileCountAndAdd(m_FilePrefixString, m_FileExtString); lableCount.Text = "0 / " + count.ToString();// 0 / 999 lableCount.Visible = true; lableCount.Refresh(); // 获得当前U盘的设备ID //lableID.Text = usbDiskObject.getDeviceID();// 设备ID: 99999 //lableID.Text = "编号: " + usbDiskObject.getPoliceID();// 警员编号ID: 99999 lableID.Text = "编号 " + usbDiskObject.getDeviceID();// 设备编号ID: A000022 string id1 = usbDiskObject.getPoliceID(); string id2 = usbDiskObject.getDataTime(); lableID.Visible = true; lableID.Refresh(); //设置设备颜色为蓝色 pic.BackgroundImage = MDWorkStation.Properties.Resources.b3; if (usbDiskObject.getFileCount() <= 0)//如果usb中没有文件,则设置成绿色 { pic.BackgroundImage = MDWorkStation.Properties.Resources.b1; } pic.Refresh(); } else { lableCount.Visible = lableID.Visible = false; pic.BackgroundImage = MDWorkStation.Properties.Resources.b2;//灰色 pic.Refresh(); } //修改屏幕上的lable信息 end------------------------------------------------------- return; /* if (bFirstRun)//只运行一次 StartIdle(); return; if (bFirstRun) { worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); bFirstRun = false; return; } return; * */ }
private void UploadWork() { //LogManager.showNotifaction("ereqrew"); //string str1 = LogManager.getTimeString(); //string str = LogManager.getTimeString() + Path.GetExtension("c:\\123\\345\\222\\12346.jpg"); //str.Equals(""); //启动时先查看当前目录下是否有未上传完成的文件 if (Directory.Exists(System.Environment.CurrentDirectory + "\\Data\\")) { List <string> listUnUploadFiles = new List <string>(); calcFileCountAndAdd(System.Environment.CurrentDirectory + "\\Data\\", listUnUploadFiles); FtpList.AddRange(listUnUploadFiles); } FtpClient ftpClient = new FtpClient(m_ftpSever, m_ftpUser, m_ftpPwd, 120, int.Parse(m_ftpPort), m_ftpBuffer); //for test //ftpClient.Upload(FtpList[0], true);//true,断点续传 使用工作站中的文件上传,防止U盘被拔掉 //string remoteRanameFile1 = LogManager.getTimeStringFileExtension(FtpList[0]); //ftpClient.RenameFile(Path.GetFileName(FtpList[0]), remoteRanameFile1, true);//上传后立刻重命名 格式20120312100624_001 while (threadRunFlag) { Thread.Sleep(1); for (int i = 0; i < FtpList.Count; i++) { if (FtpList.Count <= 0 || !threadRunFlag) { Thread.Sleep(1000); continue; } Thread.Sleep(1); string localFileName = FtpList[i]; try { ftpClient.Login(); //ftpClient.Download("0218620121203103434.mp4", "123.mp4", true);//断点下载 //LogManager.WriteLog("正在上传文件: " + ); //ftpClient.Upload(@"E:\company\MD\自动上传软件\执法记录仪资料\mp4\0218620121203103434.mp4",true);//断点续传 //从接口获取文件FTP的上传路径 string interface_Ftp = m_interfaceStr + "?method=getFtpPath"; string interface_Upload = m_interfaceStr + "?method=uploadFile"; string responseText = ""; string removeDir = ""; //服务器返回的FTP文件存放路径 string removeDir1 = ""; string removeFileName = ""; //上传到FTP上的文件绝对路径 1/101/103/11.mp4 try { if (HttpWebResponseUtility.getFtpDirRequestStatusCode(interface_Ftp, m_WorkStationID, MDUsb.getPoliceIDFromFile(localFileName), m_AppCode, out removeDir1) != System.Net.HttpStatusCode.OK) { //接口调用失败,停止下面的工作,直接退出 writeMsg("错误,路径接口调用失败,请检查系统设备配置、网络及服务器!"); continue; } } catch (Exception ex) { writeMsg("错误,接口调用失败,请检查系统设备配置、网络及服务器!"); LogManager.WriteErrorLog(ex.Message); continue; } string[] list1 = removeDir1.Substring(removeDir1.LastIndexOf('\n') + 1).Split(';'); if (!list1[0].Equals("0")) { LogManager.showErrorMsg("错误," + list1[1]); continue; } removeDir = list1[1]; //切换到服务器接口返回的工作目录 ftpClient.MakeDirs(removeDir); //ftpClient.ChangeDir(removeDir); //上传文件 writeMsg("正在上传文件: " + localFileName); ftpClient.Upload(localFileName, true); //true,断点续传 使用工作站中的文件上传,防止U盘被拔掉 string remoteRanameFile = LogManager.getTimeStringFileExtension(localFileName); ftpClient.RenameFile(Path.GetFileName(localFileName), remoteRanameFile, true); //上传后立刻重命名 格式20120312100624_001 //获得文件的播放时间 string fileDuration = FFMpegUtility.getMediaPlayTime(localFileName); removeFileName = removeDir + remoteRanameFile;// 包含全ftp路径,例:1/2/201202201223210044.jpg FileInfo fileInfo = new FileInfo(localFileName); try { //调用平台上传接口 if (HttpWebResponseUtility.getUrlRequestStatusCode(interface_Upload, m_WorkStationID, MDUsb.getPoliceIDFromFile(localFileName), Path.GetFileName(localFileName), removeFileName, MDUsb.getDataTimeFromFile(localFileName), fileInfo.Length.ToString(), fileDuration, m_AppCode, out responseText) != System.Net.HttpStatusCode.OK) { //接口调用失败,停止下面的工作,直接退出 writeMsg("错误,上传接口调用失败,请检查系统设备配置、网络及服务器!"); continue; } } catch (Exception ex) { writeMsg("错误,接口调用失败,请检查系统设备配置、网络及服务器!"); LogManager.WriteErrorLog(ex.Message); continue; } string[] list2 = responseText.Substring(responseText.LastIndexOf('\n') + 1).Split(';'); if (!list2[0].Equals("0")) { LogManager.showErrorMsg("错误," + list2[1]); continue; } //上传成功删除队列及本地文件 FtpList.Remove(localFileName); writeMsg("文件上传服务器成功" + localFileName); File.Delete(localFileName); writeMsg("删除已上传文件" + localFileName); } catch (Exception ex) { LogManager.WriteLog(ex.Message); Thread.Sleep(1000); continue; } } } }
//根据盘符获得磁盘信息 private bool getDiskInfo(string diskName/*盘符*/ ,MDUsb usbDisk/*Out 返回一个对象*/) { DriveInfo[] s = DriveInfo.GetDrives(); bool findDisk = false; foreach (DriveInfo myDrive in s) { if (myDrive.Name.Equals(diskName.ToUpper())) { findDisk = true; usbDisk.driverName = myDrive.Name; usbDisk.driverLable = myDrive.VolumeLabel; usbDisk.driverType = myDrive.DriveType.ToString(); usbDisk.driverFormat = myDrive.DriveFormat; usbDisk.TotalSize = myDrive.TotalSize.ToString(); usbDisk.TotalFreeSpace = myDrive.TotalFreeSpace.ToString(); usbDisk.AvailableFreeSpace = myDrive.AvailableFreeSpace.ToString(); usbDisk.freePercent = (int)(myDrive.AvailableFreeSpace * 100 / myDrive.TotalSize); break; } } return findDisk; }