/// <summary> /// 拖曳终止 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lstData_DragDrop(object sender, DragEventArgs e) { Array UploadfileList = (Array)e.Data.GetData(DataFormats.FileDrop); if (!MyMessageBox.ShowConfirm("UploadFile", "是否上传" + UploadfileList.Length + "个文件")) { return; } var opt = GetUploadFileOption(); var count = 0; foreach (string UploadFilename in UploadfileList) { if (File.Exists(UploadFilename)) { Gfs.UpLoadFile(UploadFilename, opt, RuntimeMongoDbContext.GetCurrentDataBase()); count++; } else { if (Directory.Exists(UploadFilename)) { var uploadDir = new DirectoryInfo(UploadFilename); UploadFolder(uploadDir, ref count, opt); } } } RefreshGui(); MyMessageBox.ShowMessage("Upload", "Upload Completed! Upload Files Count: " + count); }
/// <summary> /// Upload File /// </summary> private void UploadFileStripButton_Click(object sender, EventArgs e) { var upfile = new OpenFileDialog(); if (upfile.ShowDialog() == DialogResult.OK) { var opt = GetUploadFileOption(); Gfs.UpLoadFile(upfile.FileName, opt, RuntimeMongoDbContext.GetCurrentDataBase()); RefreshGui(); } }
/// <summary> /// Upload File /// </summary> private void UploadFileStripButton_Click(object sender, EventArgs e) { var upfile = new OpenFileDialog(); if (upfile.ShowDialog() == DialogResult.OK) { var opt = new Gfs.UpLoadFileOption(); var frm = new FrmGfsOption(); frm.ShowDialog(); opt.AlreadyOpt = frm.Option; opt.DirectorySeparatorChar = frm.DirectorySeparatorChar; opt.FileNameOpt = frm.Filename; opt.IgnoreSubFolder = frm.IgnoreSubFolder; Gfs.UpLoadFile(upfile.FileName, opt, RuntimeMongoDbContext.GetCurrentDataBase()); RefreshGui(); } }
/// <summary> /// </summary> /// <param name="uploadDir"></param> /// <param name="fileCount"></param> /// <param name="opt"></param> /// <returns>是否继续执行后续的所有操作</returns> private bool UploadFolder(DirectoryInfo uploadDir, ref int fileCount, Gfs.UpLoadFileOption opt) { foreach (var file in uploadDir.GetFiles()) { var rtn = Gfs.UpLoadFile(file.FullName, opt, RuntimeMongoDbContext.GetCurrentDataBase()); switch (rtn) { case Gfs.UploadResult.Complete: fileCount++; break; case Gfs.UploadResult.Skip: if (opt.AlreadyOpt == Gfs.EnumGfsAlready.Stop) { //这个操作返回为False,停止包括父亲过程在内的所有操作 return(false); } break; case Gfs.UploadResult.Exception: return(MyMessageBox.ShowConfirm("Upload Exception", "Is Continue?")); } } if (!opt.IgnoreSubFolder) { foreach (var dir in uploadDir.GetDirectories()) { //递归文件夹操作,如果下层有任何停止的意愿,则立刻停止,并且使上层也立刻停止 var isContinue = UploadFolder(dir, ref fileCount, opt); if (!isContinue) { return(false); } } } return(true); }