private void btnOk_Click(object sender, EventArgs e) { var file = txtTargetFile.Text.Trim(); txtTargetFile.Text = file; if (file == "") { MessageDisplayer.Tell("File to delete is mandatory.", Text); txtTargetFile.Focus(); return; } if (file.IndexOf("\"", StringComparison.Ordinal) >= 0) { MessageDisplayer.Tell("File to delete cannot contain quotes.", Text); txtTargetFile.Focus(); return; } if (file.StartsWith("-")) { MessageDisplayer.Tell("File to delete cannot start with \"-\".", Text); txtTargetFile.Focus(); return; } var helper = new InProcessJobIdentifyerHelper(); JobIdentiftyerString = helper.GetIdentifyerString(InProcessJobIdentifyer.DeleteFile); Arguments = DeleteFileArguments.CreateArgumentString(file, GetFileNotFoundBehaviour()); DialogResult = DialogResult.OK; }
public override void Begin(ArgumentList args) { var deleteFileArguments = new DeleteFileArguments(args); FileToDelete = deleteFileArguments.GetFilename(); switch (deleteFileArguments.GetFileNotFoundBehaviour()) { case FileNotFoundBehaviour.Skip: if (!File.Exists(FileToDelete)) { HasExited = true; ExitCode = 0; return; } break; case FileNotFoundBehaviour.Fail: if (!File.Exists(FileToDelete)) { HasExited = true; ExitCode = 1; throw new SystemException("File not found."); } break; } HasExited = false; Action = DeleteFile; Action.BeginInvoke(FileToDelete, CompletedCallback, null); }
private void DeleteFileDialog_Load(object sender, EventArgs e) { cboFileNotFoundBehaviour.Items.Add("Skip - do not delete anything"); cboFileNotFoundBehaviour.Items.Add("Fail"); cboFileNotFoundBehaviour.SelectedIndex = 0; var args = new ArgumentList(Arguments ?? ""); if (args.Count <= 0) { return; } var deleteFileArguments = new DeleteFileArguments(args); txtTargetFile.Text = deleteFileArguments.GetFilename(); cboFileNotFoundBehaviour.SelectedIndex = deleteFileArguments.TryGetFileNotFoundBehaviour() switch { FileNotFoundBehaviour.Fail => 1, _ => 0 }; }