private void UnLockFile(string net_id, bool isBatch = false) { this.Dispatcher.Invoke(() => { int retval = -1; this.WaitEvent(() => { unsafe { void *r_data = null; int r_len = 0; int arg = 0;// 解锁 retval = NetInterface.NetPostSyncPackage(Convert.ToInt32(net_id), (int)NetInterface.PKTTYPE.kAgvShellProto_ModifyMutex, &arg, 4, &r_data, &r_len); if (null == r_data) { return; } NetInterface.FreeDetail(r_data); } }, true, true); if (retval < 0) { if (!isBatch) { this.ShowNotify("解锁失败", "提示"); } return; } if (!isBatch) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "解锁完成", "提示"); } }); }
//删除车载文件 private void OnClickDeleteFile(object sender, RoutedEventArgs e) { List <TransFilesInfo> tmpList = new List <TransFilesInfo>(); CheckSelFileList(ref tmpList); MessageBoxResult Result = NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "是否删除此文件?", "提示", MessageBoxButton.YesNo); if (Result == MessageBoxResult.No) { return; } int retval = -1; this.Dispatcher.Invoke(() => { this.WaitEvent(() => { unsafe { retval = Tool.FileHandle.FTS.DeleteFile(EP, tmpList); } }, true, true); }); if (retval < 0) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "删除文件失败", "错误"); RefreshList(); dcRemote.Collection.ToList().ForEach(p => p.IsSelectedRemote = false); return; } RefreshList(); dcRemote.Collection.ToList().ForEach(p => p.IsSelectedRemote = false); TipsMessageEx.ShowTips(Tool.MainWindow.This, "删除文件成功", 18, 5, Colors.Green); }
//文件Local to Remote private void OnClickedPushFiles(object sender, RoutedEventArgs e) { if (0 == SelectLocalList.Count) { return; } String dir = null; Tool.Setting.ConfigRead.ReadLocalDir(ref dir); if (dir == null) { return; } int retval = Tool.FileHandle.FTS.PushFile(EP, SelectLocalList, DirRelative); if (retval < 0 && -2 == retval) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "发送文件失败,目标IP已有其他任务正在运行!", "错误"); return; } if (retval < 0 && -1 == retval) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "发送文件失败!", "错误"); return; } TipsMessageEx.ShowTips(Tool.MainWindow.This, "已经加入传输列表", 18, 5, Colors.Green); AllLocalFilesCheckBox.IsChecked = false; SelectLocalList.Clear(); dcLocal.Collection.ToList().ForEach(p => p.IsSelectedLocal = false); }
//双击列表文件夹 private void OnDoubleClickFileList(object sender, MouseButtonEventArgs e) { ListView list = sender as ListView; if (null == list) { return; } if (null == PointItem) { return; } FileDetailInfo item = ((FileDetailInfo)PointItem); if (item.IsDir) { string strRelativeDir = ""; if ("RemoteListView" == list.Name) { string splitstr = IP; if (null == item.RemoteDir) { return; } int pos = item.RemoteDir.IndexOf(IP); strRelativeDir = item.RemoteDir; } else if ("LocalListView" == list.Name) { if (null == item.LocalDir) { return; } strRelativeDir = item.LocalDir; } NodeOperationInitList(strRelativeDir); } else { if ("" == item.FileName) { return; } string pathRemote = ""; if (item.RemoteDir != null) { pathRemote = item.RemoteDir.Substring(1, item.RemoteDir.Length - 1); } String dir = null; Tool.Setting.ConfigRead.ReadLocalDir(ref dir); string pathLocal = ""; if (item.LocalDir != null) { pathLocal = dir + item.LocalDir.Substring(1, item.LocalDir.Length - 1); } if ("RemoteListView" == list.Name) { if (item.FileSize > 1024 * 1024) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "文件大于1M,无法显示", "提示"); return; } TransFilesInfo info = new TransFilesInfo(); info.Path = ((FileDetailInfo)PointItem).RemoteDir; info.Type = ((FileDetailInfo)PointItem).IsDir ? 0 : 1; List <TransFilesInfo> tmpList = new List <TransFilesInfo>(); tmpList.Add(info); int retval = -1; this.Dispatcher.Invoke(() => { this.WaitEvent(() => { unsafe { retval = Tool.FileHandle.FTS.DownLoadFile(EP, tmpList, BaseDir); } }, true, true); }); if (retval < 0) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "下载文件失败!", "错误"); return; } } else if ("LocalListView" == list.Name) { if (!CheckFileSize(pathLocal)) { return; } if (item.FileSize > 1024 * 1024) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "文件大于1M,无法显示", "提示"); return; } TransFilesInfo info = new TransFilesInfo(); info.Path = ((FileDetailInfo)PointItem).RemoteDir; info.Type = ((FileDetailInfo)PointItem).IsDir ? 0 : 1; List <TransFilesInfo> tmpList = new List <TransFilesInfo>(); tmpList.Add(info); int retval = -1; this.Dispatcher.Invoke(() => { this.WaitEvent(() => { unsafe { retval = Tool.FileHandle.FTS.DownLoadFile(EP, tmpList, BaseDir); } }, true, true); }); if (retval < 0) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "下载文件失败!", "错误"); return; } } WidCompareListEx.Show(Tool.MainWindow.This, EP, pathLocal, pathRemote, DirRelative); } }
//初始化Remote文件列表信息 private void InitRemoteList() { Int32 retval = -1; Proto.ProtoFileList fileList = new Proto.ProtoFileList(); this.Dispatcher.Invoke(() => { unsafe { void *r_data = null; int r_len = 0; retval = NetInterface.NetQueryCurrentCatalog(EP, DirRelative, &r_data, &r_len); if (r_len == 0) { return; } byte[] ack_msg = null; ack_msg = new byte[r_len]; using (UnmanagedMemoryStream ms = new UnmanagedMemoryStream((byte *)r_data, r_len)) { ms.Read(ack_msg, 0, ack_msg.Length); } Tool.Proto.Unpackage <Proto.ProtoFileList> list = new Proto.Unpackage <Proto.ProtoFileList>(ack_msg); if (list.build()) { fileList = list.ob; } NetInterface.FreeDetail(r_data); } }); if (retval < -1) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "获取车载文件列表失败", "错误"); return; } DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1601, 1, 1)); foreach (var obj in fileList.FileListList) { FileDetailInfo Info = new FileDetailInfo(); Info.FileName = obj.FileName.value_; Info.IsEnable = true; if (".\\" == DirRelative) { Info.RemoteDir = DirRelative + Info.FileName; } else { Info.RemoteDir = DirRelative + "\\" + Info.FileName; } if (0 == obj.FileType.value_) { Info.IsDir = true; } Info.RemoteCRC = obj.FileCRC32.value_.ToString(); DateTime targetDt = dtStart.AddTicks((long)obj.FileModifyTime.value_); Info.MotifyRemoteTime = targetDt.ToString(); Info.FileSize = obj.FileSize.value_; RemoteList.Add(Info); } }
private void SaveFile() { if (null == DirRemote) { return; } if (Directory.Exists(DirRemote)) { return; } string text = TBRemote.Text.ToString(); FileStream fs = new FileStream(DirRemote, FileMode.Create); byte[] data = System.Text.Encoding.Default.GetBytes(text); fs.Write(data, 0, data.Length); fs.Flush(); fs.Close(); List <TransFilesInfo> tmpList = new List <TransFilesInfo>(); TransFilesInfo info = new TransFilesInfo(); info.Path = SendFilePath; info.Type = 1; tmpList.Add(info); int retval = 0; string dir_path = ToDir + DirRemote.Substring(DirRemote.LastIndexOf("\\")); Tool.Proto.ProtoMSG protomsg = new Proto.ProtoMSG(); protomsg.MSG.value_ = dir_path; byte[] b_msg = new byte[protomsg.length()]; Int32 offset = 0; protomsg.serialize(b_msg, ref offset); this.WaitEvent(() => { unsafe { void *r_data = null; int r_len = 0; int net_id = Tool.RobotsHome.RobotInfoCollect.GetInstance().FindNetIdByfts(EP); unsafe { fixed(byte *l_msg = b_msg) { retval = NetInterface.NetPostSyncPackage(net_id, (int)NetInterface.PKTTYPE.kAgvShellProto_ProtoBackFiles, l_msg, protomsg.length(), &r_data, &r_len); } } } }, true, true); if (retval < 0) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "备份失败!", "错误"); return; } retval = Tool.FileHandle.FTS.SaveFile(EP, tmpList, ToDir); if (retval < 0 && -2 == retval) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "保存文件失败,目标IP已有其他任务正在运行!", "错误"); return; } if (retval < 0 && -1 == retval) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "保存文件失败!", "错误"); return; } }
private bool CheckBatchArgs() { string strId = TBBatchAddID.Text.ToString(); int id; if (!isNumberic(strId, out id)) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "编号必须为纯数字", "错误"); return(false); } string strIp = TBBatchIP.Text.ToString(); var array_ip = strIp.Split('.'); if (array_ip.Length != 4) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "请正确的IP格式,例如192.168.1.1", "错误"); return(false); } uint ipv4_1 = 0; uint ipv4_2 = 0; uint ipv4_3 = 0; uint ipv4_4 = 0; try { ipv4_1 = UInt32.Parse(array_ip[0]); ipv4_2 = UInt32.Parse(array_ip[1]); ipv4_3 = UInt32.Parse(array_ip[2]); ipv4_4 = UInt32.Parse(array_ip[3]); } catch (Exception) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "输入正确的ip格式", "错误"); return(false); } if (ipv4_1 > 255 || ipv4_2 > 255 || ipv4_3 > 255 || ipv4_4 > 255) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "请正确的IP范围", "错误"); return(false); } string strPort = TBBatchPort.Text.ToString(); int port; if (!isNumberic(strPort, out port)) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "编号必须为纯数字", "错误"); return(false); } if (port > 65536 || port < 0) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "端口范围:0-65536", "错误"); return(false); } string strNum = TBBatchNum.Text.ToString(); if (strNum.Length > 4) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "输入的数量太大(<999)。", "错误"); return(false); } int num; if (!isNumberic(strNum, out num)) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "批量生成必须为纯数字", "错误"); return(false); } return(true); }
private void OnChangeMode(object sender, RoutedEventArgs e) { if (This == null) { return; } if (null == dcRobotInfo) { dcRobotInfo = RobotInfoCollect.GetInstance(); } List <int> list = dcRobotInfo.Collection.ToList().Select(l => l.NetId).ToList(); foreach (int netid in list) { if (netid < 0) { continue; } Tool.Net.NetInterface.Disconnect(netid); } if (true == RDYes.IsChecked) { Tool.Net.NetInterface.OpenDhcp(false); Tool.RobotsHome.RobotInfoCollect.GetInstance().CleanRobotObj(); Tool.RobotsHome.RobotInfoCollect.GetInstance().ReadXML(); Tool.RobotsHome.RobotsHome.This.Refresh(); BtnAdd.IsEnabled = true; BtnDel.IsEnabled = true; MenuEdit.IsEnabled = true; MenuDel.IsEnabled = true; Refresh(); } else if (true == RDNo.IsChecked) { int ret = Tool.Net.NetInterface.OpenDhcp(true); if (ret < 0) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "打开DHCP失败", "提示"); return; } Tool.RobotsHome.RobotInfoCollect.GetInstance().CleanRobotObj(); Refresh(); this.Dispatcher.Invoke(() => { this.WaitEvent(() => { Tool.RobotsHome.RobotInfoCollect.GetInstance().FromDHCP(); }, true, true); }); Tool.RobotsHome.RobotsHome.This.Refresh(); //int ret = Tool.Net.NetInterface.OpenDhcp(true); //if (ret < 0) //{ // NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "打开DHCP失败", "提示"); // return; //} BtnAdd.IsEnabled = false; BtnDel.IsEnabled = false; MenuEdit.IsEnabled = false; MenuDel.IsEnabled = false; Refresh(); } }