public ArgumentParserForm() { Icon = Properties.Resources.Icon; textBoxClicks = 0; textBoxClicksTimer = new Timer(); argumentParser = new ArgumentParser(); InitializeComponent(); Text = Program.GetTitle() + Constants.NDashWithSpaces + Text; statusBarPanel = new StatusBarPanel() { BorderStyle = StatusBarPanelBorderStyle.Sunken, AutoSize = StatusBarPanelAutoSize.Spring, Alignment = HorizontalAlignment.Left }; statusBar.Panels.Add(statusBarPanel); statusBarPanelCapsLock = new StatusBarPanel() { BorderStyle = StatusBarPanelBorderStyle.Sunken, Alignment = HorizontalAlignment.Center, Width = 42 }; statusBar.Panels.Add(statusBarPanelCapsLock); statusBarPanelNumLock = new StatusBarPanel() { BorderStyle = StatusBarPanelBorderStyle.Sunken, Alignment = HorizontalAlignment.Center, Width = 42 }; statusBar.Panels.Add(statusBarPanelNumLock); statusBarPanelInsert = new StatusBarPanel() { BorderStyle = StatusBarPanelBorderStyle.Sunken, Alignment = HorizontalAlignment.Center, Width = 42 }; statusBar.Panels.Add(statusBarPanelInsert); statusBarPanelScrollLock = new StatusBarPanel() { BorderStyle = StatusBarPanelBorderStyle.Sunken, Alignment = HorizontalAlignment.Center, Width = 42 }; statusBar.Panels.Add(statusBarPanelScrollLock); statusBar.ContextMenu = new ContextMenu(); statusBar.ContextMenu.MenuItems.Add(new MenuItem(Properties.Resources.MenuItemCopy, new EventHandler((sender, e) => { if (!string.IsNullOrEmpty(statusBarPanel.Text)) { try { Clipboard.SetText(statusBarPanel.Text); } catch (Exception exception) { Debug.WriteLine(exception); ErrorLog.WriteLine(exception); } } }))); statusBar.ContextMenu.Popup += new EventHandler((sender, e) => { ((ContextMenu)sender).MenuItems[0].Visible = !string.IsNullOrEmpty(statusBarPanel.Text); }); SubscribeEvents(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("/i "); stringBuilder.Append(ArgumentParser.EscapeArgument(Constants.ExampleApplicationFilePath)); stringBuilder.Append(" /d 2019-01-01 /a "); stringBuilder.Append(ArgumentParser.EscapeArgument(Constants.ExampleApplicationArguments)); stringBuilder.Append(" /w "); stringBuilder.Append(ArgumentParser.EscapeArgument(Constants.ExampleWorkingFolderPath)); stringBuilder.Append(" /o /s 5"); textBox1.Text = stringBuilder.ToString(); textBoxInput.Text = Constants.ExampleApplicationArguments; }
private List <string> BuildArguments() { bool setTestArgument = false; List <string> arguments = new List <string>(); string applicationFilePath = textBox1.Text; if (!string.IsNullOrWhiteSpace(applicationFilePath) && !File.Exists(applicationFilePath)) { throw new ApplicationException(Properties.Resources.MessageApplicationNotFound); } if (!string.IsNullOrWhiteSpace(applicationFilePath)) { arguments.Add("/i"); arguments.Add(ArgumentParser.EscapeArgument(applicationFilePath)); } else if (Program.IsDebugging) { arguments.Add("/i"); arguments.Add(ArgumentParser.EscapeArgument(Application.ExecutablePath)); setTestArgument = true; } else { throw new ApplicationException(Properties.Resources.MessageApplicationNotSet); } if (comboBox1.SelectedIndex > 0) { string[] spanUnit = new string[] { "day", "month", "year" }; if (numericUpDown1.Value > 0) { arguments.Add("/r"); arguments.Add("+" + Math.Abs(numericUpDown1.Value).ToString("#") + spanUnit[comboBox2.SelectedIndex]); } else if (numericUpDown1.Value < 0) { arguments.Add("/r"); arguments.Add("-" + Math.Abs(numericUpDown1.Value).ToString("#") + spanUnit[comboBox2.SelectedIndex]); } else { throw new ApplicationException(Properties.Resources.ExceptionMessageZ); } } else { arguments.Add("/d"); arguments.Add(dateTimePicker.Value.ToString("yyyy-MM-dd")); } if (!string.IsNullOrWhiteSpace(textBox2.Text)) { arguments.Add("/a"); arguments.Add(ArgumentParser.EscapeArgument(textBox2.Text)); } else if (setTestArgument) { arguments.Add("/a"); arguments.Add("\"/t\""); } if (Directory.Exists(textBox3.Text)) { arguments.Add("/w"); arguments.Add(ArgumentParser.EscapeArgument(textBox3.Text)); } if (checkBox.Checked) { arguments.Add("/o"); } arguments.Add("/s"); arguments.Add(numericUpDown2.Value.ToString()); return(arguments); }
private void EscapeArgument() { textBoxOutput.Text = ArgumentParser.EscapeArgument(textBoxInput.Text); }