public IActionResult Upload(IList <IFormFile> files) { string apiKey = HttpContext.Session.GetString("apiKey"); string serverKey = HttpContext.Session.GetString("serverKey"); if (apiKey != null && serverKey != null) { List <CopyFileTask> copyFileTasks = new List <CopyFileTask>(); foreach (IFormFile file in files) { if (file.FileName.Contains("zip")) { string fileName = file.FileName.Replace(".zip", ""); if (file.Length > 0) { Random random = new Random(); string path = @"D:\Data\temp\" + random.Next(1000); Directory.CreateDirectory(path); string filePath = path + "\\" + file.FileName; using (var fileStream = new FileStream(filePath, FileMode.Create)) { Task task = file.CopyToAsync(fileStream); copyFileTasks.Add(new CopyFileTask(task, fileName, filePath)); } } } } while (copyFileTasks.Count > 0) { for (int i = copyFileTasks.Count - 1; i >= 0; i--) { CopyFileTask copyFileTask = copyFileTasks[i]; if (copyFileTask.task.IsCompleted) { copyFileTasks.RemoveAt(i); if (copyFileTask.task.IsCompletedSuccessfully) { string fileName = copyFileTask.fileName; string filePath = copyFileTask.filePath; int taskId = copyFileTask.task.Id; string boPath = "From Illustrator/" + taskId; Task <ChiliService.DocumentCreateFromChiliPackageResponse> createFromPdfResponse = _chiliConnector.soapClient.DocumentCreateFromChiliPackageAsync(serverKey, fileName, boPath, filePath, boPath, boPath); } } } } } return(Json(new { complete = "true" })); }
private void btn_Copy_Start_Click(object sender, EventArgs e) { Copy_SetSubmitButtonStatus(false); string destinationFilePath = GetDestinationFilePath(); var task = new CopyFileTask(new FileInfo(txt_Copy_SrcFile.Text), new FileInfo(destinationFilePath)) { OverwriteDestinationFile = chk_Copy_OverwriteDest.Checked, DeleteSourceFileAfterCopy = chk_Copy_DeletSrcAfterCopy.Checked }; task.ExecutionCompleted += (result) => { if (result.Exception != null) { MessageBox.Show(result.Exception.Message, "Error copying file", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (chk_Copy_CloseOnSuccess.Checked) { Application.Exit(); } Copy_SetSubmitButtonStatus(true); MessageBox.Show("Success"); }; task.ExecuteAsync(); }
public override void RegisterRealTasks(PhysicalServer site) { string to = site.MapPath(_to); var o = new CopyFileTask(_from, to, _newFileName, new DotNetPath()); site.AddTask(o); }
public void CopyFile(IFileObject file) { var targetDirectory = GetTargetDirectory(file.FullName); var copyFileTask = new CopyFileTask(file, targetDirectory); QueueTask(copyFileTask); }
public void Verify_CopyFileTask_PathDoesNotExist() { var source = Path.GetTempFileName(); var destination = @"C:\DoesNotExist\CopyFileTest\testing.txt"; var task = new CopyFileTask(source, destination); task.Run(); }
public TRunner CopyFile( string sourceFileName, string destinationFileName, bool overwrite) { CopyFileTask.Execute(scriptExecutionEnvironment, sourceFileName, destinationFileName, overwrite); return(ReturnThisTRunner()); }
public void CopyFileToFileWithSameName() { var t = new CopyFileTask(_sourceFilePath, _destinationFolderPath, "test.txt", new DotNetPath()); t.Execute(); string s = File.ReadAllText(_path.Combine(_destinationFolderPath, "test.txt")); Assert.AreEqual("the test\r\n", s); }
protected override void ExecuteInternal(Dictionary<string, string> args) { string srcFile = GetArg(args, CommonArgs.SRC_FILE); string destFile = GetArg(args, CommonArgs.DEST_FILE); CopyFileTask task = new CopyFileTask(new FileInfo(srcFile), new FileInfo(destFile)) { OverwriteDestinationFile = ContainsArg(args, CommonArgs.REPLACE_EXISTING) }; task.Execute(); }
public void Verify_CopyFileTask_FileIsCopied() { var source = Path.GetTempFileName(); var destinationFolder = Path.Combine(BaseTestFolder, "CopyFileTest"); Directory.CreateDirectory(destinationFolder); var destinationFile = Path.Combine(destinationFolder, "testing.tmp"); ; var task = new CopyFileTask(source, destinationFile); task.Run(); Assert.IsTrue(File.Exists(destinationFile)); }
public void ThrowsWhenFileIsLocked() { var file = new MemoryFileObject("name", "contents"); var targetDirectory = new MemoryDirectoryObject("target"); file.IsReady = false; file.Exists = true; var copyFile = new CopyFileTask(file, targetDirectory, new TimeSpan(0, 0, 1)); copyFile.Execute(); }
public void CopyFileToUncPath() { var sourceUncPath = PathConverter.Convert(Environment.MachineName, _path.GetFullPath(_sourceFilePath)); var destinationUncPath = PathConverter.Convert(Environment.MachineName, _path.GetFullPath(_destinationFolderPath)); var t = new CopyFileTask(sourceUncPath, destinationUncPath, null, new DotNetPath()); t.Execute(); string s = File.ReadAllText(_path.Combine(destinationUncPath, "test.txt")); Assert.AreEqual("the test\r\n", s); }
public void CopyFileToFileWithSameNameAndOverwriteReadOnly() { var dest = _path.Combine(_destinationFolderPath, "test.txt"); File.WriteAllLines(dest, new[] { "bad file" }); var destFile = new FileInfo(dest); //destFile.Attributes = (destFile.Attributes & FileAttributes.ReadOnly); destFile.IsReadOnly = true; Assert.IsTrue(destFile.IsReadOnly, "Expected the destination file to be readonly"); var t = new CopyFileTask(_sourceFilePath, _destinationFolderPath, "test.txt", new DotNetPath()); t.Execute(); string s = File.ReadAllText(_path.Combine(_destinationFolderPath, "test.txt")); Assert.AreEqual("the test\r\n", s); }