public ProgressForm(UploadFile[] files, string url, string user, string password) { InitializeComponent(); this.files = files; this.url = url; this.user = user; this.password = password; total = 0; currentBytes = 0; ques = new Queue<UploadFile>(files); uploader = UploaderFactory.CreateInstance(); currentPercent = 0; }
void UploadFile(UploadFile file) { Invoke(new Action(() => { lblUploadFile.Text = "上傳檔案 : " + file.File.Name; int count = this.files.Length; lblFileCount.Text = "檔案數 : " + (count - ques.Count) + "/" + this.files.Length; })); //string ftp = Path.Combine(this.url, file.ServerPath); string ftp = PathHelper.CombineURL(this.url, file.ServerPath); ftp = ftp.Replace(@"\", "/"); uploader.Upload(ftp, file.File.FullName, this.user, this.password); }
public void Upload() { string msg = "確定要「上傳」差異檔案到主機?這會覆蓋主機的檔案。"; if (MessageBox.Show(msg, "檔案同步", MessageBoxButtons.YesNo) == DialogResult.No) return; if (!ModuleHandler.LocalPathExists) return; string moduleName = ModuleHandler.Name; ModifierCollection list = ModuleHandler.CheckUploadModifier(); List<UploadFile> files = new List<UploadFile>(); XmlHelper req = new XmlHelper(); req.AddElement(".", "ModuleName", moduleName); foreach (Modifier m in list) { if (m.ActionMode == ActionType.SendDelete) ModuleHandler.DeletePath(m.Path); else if (m.ActionMode == ActionType.UpdateFile && m.FileMode == FileType.Directory) { req.AddElement(".", "Path", m.Path); } else if (m.ActionMode == ActionType.UpdateFile && m.FileMode == FileType.File) { UploadFile f = new UploadFile(); FileInfo file = new FileInfo(m.Path); f.File = file; f.ServerPath = PathHelper.GetServerPath(ModuleHandler.LocalPath, m.Path); files.Add(f); } } if (req.GetElement("Path") != null) MainForm.LoginArgs.SendModuleRequest("PrepareDirectory", new Envelope(req)); if (files.Count > 0) { string ftp = PathHelper.GetFtpPath(MainForm.LoginArgs.FtpURL, MainForm.LoginArgs.GreeningID, moduleName); ProgressForm pf = new ProgressForm(files.ToArray(), ftp, MainForm.LoginArgs.FtpUser, MainForm.LoginArgs.FtpPassword); pf.ShowDialog(); } ModuleHandler.Reload(); //if (NeedUploadChanged != null) // NeedUploadChanged.Invoke(this, new NeedStatusEventArgs(false)); FileEditable fe = CurrentEditor as FileEditable; FileUIEditor ui = fe.Editor as FileUIEditor; ui.Reload(); }
private void treeDir_DragDrop(object sender, DragEventArgs e) { Point p = treeDir.PointToClient(new Point(e.X, e.Y)); TreeViewHitTestInfo info = treeDir.HitTest(p); if (info == null) return; bool fd = false; foreach (string each in e.Data.GetFormats()) { if (each != DataFormats.FileDrop) continue; fd = true; } if (!fd) return; TreeNode target = info.Node; XmlElement nodeElement = target.Tag as XmlElement; string targetPath = PathHelper.GetNodeDirectory(target); object dropObjectArray = e.Data.GetData(DataFormats.FileDrop); string[] dropFiles = dropObjectArray as string[]; StringBuilder sb = new StringBuilder(); XmlHelper content = new XmlHelper(); content.AddElement(".", "ModuleName", _moduleHandler.Name); List<UploadFile> files = new List<UploadFile>(); bool prefed = !string.IsNullOrWhiteSpace(_moduleHandler.LocalPath); foreach (string filename in dropFiles) { if (Directory.Exists(filename)) { DirectoryInfo dir = new DirectoryInfo(filename); string dirName = targetPath + "/" + dir.Name; content.AddElement(".", "Path", dirName); if (prefed) { string copyTo = Path.Combine(_moduleHandler.LocalPath, targetPath, dir.Name); Directory.CreateDirectory(copyTo); } foreach (DirectoryInfo sub in dir.GetDirectories("*", SearchOption.AllDirectories)) { string subDirName = dirName + sub.FullName.Replace(dir.FullName, "").Replace(@"\", "/"); content.AddElement(".", "Path", subDirName); if (prefed) { string copyTo = PathHelper.GetLocalFileFullName(_moduleHandler.LocalPath, targetPath, dir, sub); Directory.CreateDirectory(copyTo); } } foreach (FileInfo sub in dir.GetFiles("*", SearchOption.AllDirectories)) { string subFileName = dirName + sub.FullName.Replace(dir.FullName, "").Replace(@"\", "/"); UploadFile uf = new UploadFile(); uf.File = sub; uf.ServerPath = subFileName; files.Add(uf); if (prefed) { string copyTo = PathHelper.GetLocalFileFullName(_moduleHandler.LocalPath, targetPath, dir, sub); sub.CopyTo(copyTo, true); } } } else { UploadFile uf = new UploadFile(); FileInfo file = new FileInfo(filename); uf.File = file; uf.ServerPath = PathHelper.CombineTargetPath(targetPath, uf.File.Name); files.Add(uf); if (prefed) { string copyTo = Path.Combine(_moduleHandler.LocalPath, targetPath, file.Name); file.CopyTo(copyTo, true); } } sb.Append(filename).Append("\n"); } if (content.GetElement("Path") != null) MainForm.LoginArgs.SendModuleRequest("PrepareDirectory", new Envelope(content)); if (files.Count > 0) { string ftp = PathHelper.GetFtpPath(MainForm.LoginArgs.FtpURL, MainForm.LoginArgs.GreeningID, _moduleHandler.Name); ProgressForm pf = new ProgressForm(files.ToArray(), ftp, MainForm.LoginArgs.FtpUser, MainForm.LoginArgs.FtpPassword); pf.ShowDialog(); } _moduleHandler.Reload(); this.Reload(); }
private void treeDir_DragDrop(object sender, DragEventArgs e) { Point p = treeDir.PointToClient(new Point(e.X, e.Y)); TreeViewHitTestInfo info = treeDir.HitTest(p); if (info == null) { return; } bool fd = false; foreach (string each in e.Data.GetFormats()) { if (each != DataFormats.FileDrop) { continue; } fd = true; } if (!fd) { return; } TreeNode target = info.Node; XmlElement nodeElement = target.Tag as XmlElement; string targetPath = PathHelper.GetNodeDirectory(target); object dropObjectArray = e.Data.GetData(DataFormats.FileDrop); string[] dropFiles = dropObjectArray as string[]; StringBuilder sb = new StringBuilder(); XmlHelper content = new XmlHelper(); content.AddElement(".", "ModuleName", _moduleHandler.Name); List <UploadFile> files = new List <UploadFile>(); bool prefed = !string.IsNullOrWhiteSpace(_moduleHandler.LocalPath); foreach (string filename in dropFiles) { if (Directory.Exists(filename)) { DirectoryInfo dir = new DirectoryInfo(filename); string dirName = targetPath + "/" + dir.Name; content.AddElement(".", "Path", dirName); if (prefed) { string copyTo = Path.Combine(_moduleHandler.LocalPath, targetPath, dir.Name); Directory.CreateDirectory(copyTo); } foreach (DirectoryInfo sub in dir.GetDirectories("*", SearchOption.AllDirectories)) { string subDirName = dirName + sub.FullName.Replace(dir.FullName, "").Replace(@"\", "/"); content.AddElement(".", "Path", subDirName); if (prefed) { string copyTo = PathHelper.GetLocalFileFullName(_moduleHandler.LocalPath, targetPath, dir, sub); Directory.CreateDirectory(copyTo); } } foreach (FileInfo sub in dir.GetFiles("*", SearchOption.AllDirectories)) { string subFileName = dirName + sub.FullName.Replace(dir.FullName, "").Replace(@"\", "/"); UploadFile uf = new UploadFile(); uf.File = sub; uf.ServerPath = subFileName; files.Add(uf); if (prefed) { string copyTo = PathHelper.GetLocalFileFullName(_moduleHandler.LocalPath, targetPath, dir, sub); sub.CopyTo(copyTo, true); } } } else { UploadFile uf = new UploadFile(); FileInfo file = new FileInfo(filename); uf.File = file; uf.ServerPath = PathHelper.CombineTargetPath(targetPath, uf.File.Name); files.Add(uf); if (prefed) { string copyTo = Path.Combine(_moduleHandler.LocalPath, targetPath, file.Name); file.CopyTo(copyTo, true); } } sb.Append(filename).Append("\n"); } if (content.GetElement("Path") != null) { MainForm.LoginArgs.SendModuleRequest("PrepareDirectory", new Envelope(content)); } if (files.Count > 0) { string ftp = PathHelper.GetFtpPath(MainForm.LoginArgs.FtpURL, MainForm.LoginArgs.GreeningID, _moduleHandler.Name); ProgressForm pf = new ProgressForm(files.ToArray(), ftp, MainForm.LoginArgs.FtpUser, MainForm.LoginArgs.FtpPassword); pf.ShowDialog(); } _moduleHandler.Reload(); this.Reload(); }