private void btnSure_Click(object sender, RoutedEventArgs e) { FileInfoEntity info = new FileInfoEntity(); string path = tbLocalPath.Text; info.FilePath = path.Substring(0, path.LastIndexOf("\\")); info.FileName = path.Substring(info.FilePath.Length + 1, path.Length - info.FilePath.Length - 1); info.NewFilePath = ""; info.NewFileName = tbRomteFile.Text; info.FileType = FileType.File; if (FtpHelper.CheckExistOfRemoteFile("ftp://" + FtpHelper.IP + "/" + (string.IsNullOrEmpty(info.NewFilePath) ? "" : info.NewFilePath + "/") + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件已存在"); } else { this.Close(); FtpHelper.TaskInit(info); FtpTaskUserControl taskControl = new FtpTaskUserControl(info); taskControl.btnRun.Content = info.ResultCode == ResultCode.New ? "Wait" : "Run"; taskControl.mainWindow = mainWindow; mainWindow.lv.Items.Add(taskControl); mainWindow.TaskSum++; mainWindow.ReflashUI(); } }
private void btnSure_Click(object sender, RoutedEventArgs e) { string path = comBox.SelectedValue.ToString(); FileInfoEntity info = new FileInfoEntity(); info.Method = Method.Download; info.FileType = FileType.Directory; info.FilePath = path.Contains("/") ? path.Substring(0, path.LastIndexOf("/")) : ""; info.FileName = path.Contains("/") ? path.Substring(path.LastIndexOf("/") + 1, path.Length - path.LastIndexOf("/") - 1) : path; info.NewFilePath = tbLocalPath.Text; info.NewFileName = tbDirName.Text; if (Directory.Exists(info.NewFilePath + "\\" + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件夹已存在"); } else { this.Close(); List <FileInfoEntity> ls = FtpHelper.TaskInit(info).Where(x => x.FileType == FileType.File).Select(x => { return(x); }).ToList(); foreach (FileInfoEntity item in ls) { FtpTaskUserControl taskControl = new FtpTaskUserControl(item); taskControl.btnRun.Content = item.ResultCode == ResultCode.New ? "Wait" : "Run"; taskControl.mainWindow = mainWindow; mainWindow.DownloadTaskSum++; mainWindow.lvDownload.Items.Add(taskControl); } mainWindow.ReflashUI(); } }
private void btnSure_Click(object sender, RoutedEventArgs e) { FileInfoEntity info = new FileInfoEntity(); string path = tbLocalPath.Text; info.FilePath = path.Substring(0, path.LastIndexOf("\\")); info.FileName = path.Substring(info.FilePath.Length + 1, path.Length - info.FilePath.Length - 1); info.NewFilePath = ""; info.NewFileName = tbRomteFile.Text; info.FileType = FileType.Directory; if (FtpHelper.CheckExistOfRemoteDirectory("ftp://" + FtpHelper.IP + "/" + (string.IsNullOrEmpty(info.NewFilePath) ? "" : info.NewFilePath + "/") + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件夹已存在"); } else { this.Close(); List <FileInfoEntity> subDirList = new List <FileInfoEntity>(); List <FileInfoEntity> ls = FtpHelper.TaskInit(info).Where(x => x.FileType == FileType.File).Select(x => { return(x); }).ToList(); foreach (FileInfoEntity item in ls) { FtpTaskUserControl taskControl = new FtpTaskUserControl(item); taskControl.btnRun.Content = item.ResultCode == ResultCode.New ? "Wait" : "Run"; taskControl.mainWindow = mainWindow; mainWindow.TaskSum++; mainWindow.lv.Items.Add(taskControl); } mainWindow.ReflashUI(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { //初始化FTP FtpHelper.InitFtp("192.168.1.109:8003", "admin", "873709"); foreach (FileInfoEntity item in FtpHelper.FtpUploadFileInfoList) { FtpTaskUserControl taskControl = new FtpTaskUserControl(item); taskControl.mainWindow = this; lv.Items.Add(taskControl); TaskSum++; } foreach (FileInfoEntity item in FtpHelper.FtpDownloadFileInfoList) { FtpTaskUserControl taskControl = new FtpTaskUserControl(item); taskControl.mainWindow = this; lvDownload.Items.Add(taskControl); DownloadTaskSum++; } ReflashUI(); System.Timers.Timer timer = new System.Timers.Timer(); timer.AutoReset = true; timer.Interval = 1000; timer.Enabled = true; timer.Elapsed += (s, ex) => { this.Dispatcher.Invoke(delegate { if (lv.Items.OfType <FtpTaskUserControl>().Where(x => x.btnRun.Content.ToString() == "Pause" && x.btnRun.Visibility == Visibility.Visible).Select(x => { return(x); }).FirstOrDefault() == null) { FtpTaskUserControl taskControl = lv.Items.OfType <FtpTaskUserControl>().Where(x => x.btnRun.Content.ToString() == "Wait").Select(x => { return(x); }).FirstOrDefault(); if (taskControl != null) { taskControl.btnRun.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } } if (lvDownload.Items.OfType <FtpTaskUserControl>().Where(x => x.btnRun.Content.ToString() == "Pause" && x.btnRun.Visibility == Visibility.Visible).Select(x => { return(x); }).FirstOrDefault() == null) { FtpTaskUserControl taskControl = lvDownload.Items.OfType <FtpTaskUserControl>().Where(x => x.btnRun.Content.ToString() == "Wait").Select(x => { return(x); }).FirstOrDefault(); if (taskControl != null) { taskControl.btnRun.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } } }); }; }