/// <summary> /// Empty constructor for the Macro Tags tool window. /// </summary> public FormMacroTagsToolWindow(MacroTagCollection tagCollection, MacroParser macroParser, Log log) { InitializeComponent(); _log = log; _macroParser = macroParser; _macroTagCollection = tagCollection; }
private void ChangeMacroTag() { if (InputValid()) { if (NameChanged() || InputChanged()) { TrimInput(); if (MacroTagCollection.GetByName(textBoxName.Text) != null && NameChanged()) { MessageBox.Show("A macro tag with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MacroTagCollection.Get(MacroTagObject).Name = textBoxName.Text; MacroTagCollection.Get(MacroTagObject).Description = textBoxDescription.Text; MacroTagCollection.Get(MacroTagObject).Type = (MacroTagType)comboBoxType.SelectedIndex; MacroTagCollection.Get(MacroTagObject).DateTimeFormatValue = textBoxDateTimeFormatValue.Text; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro1Start = dateTimePickerMacro1Start.Value; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro1End = dateTimePickerMacro1End.Value; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro1Macro = textBoxMacro1Macro.Text; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro2Start = dateTimePickerMacro2Start.Value; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro2End = dateTimePickerMacro2End.Value; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro2Macro = textBoxMacro2Macro.Text; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro3Start = dateTimePickerMacro3Start.Value; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro3End = dateTimePickerMacro3End.Value; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro3Macro = textBoxMacro3Macro.Text; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro4Start = dateTimePickerMacro4Start.Value; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro4End = dateTimePickerMacro4End.Value; MacroTagCollection.Get(MacroTagObject).TimeRangeMacro4Macro = textBoxMacro4Macro.Text; MacroTagCollection.Get(MacroTagObject).Active = checkBoxActive.Checked; MacroTagCollection.Get(MacroTagObject).Notes = textBoxNotes.Text; Okay(); } } else { Close(); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Gets the path from the configuration file based on what line is being processed and a regex pattern. /// If the path cannot be found then the directory or file will be created. /// </summary> /// <param name="line">The line to read from the file.</param> /// <param name="regex">The regex pattern to use against the line.</param> /// <param name="path">The output of the path being returned.</param> /// <returns>A boolean to indicate if getting a path was successful or not.</returns> private bool GetPathAndCreateIfNotFound(string line, string regex, out string path) { if (!Regex.IsMatch(line, regex)) { path = null; return(false); } path = Regex.Match(line, regex).Groups["Path"].Value; MacroTagCollection tagCollection = new MacroTagCollection(); tagCollection.Add(new MacroTag(MacroParser, "user", "The user using this computer (%user%)", MacroTagType.User, active: true)); tagCollection.Add(new MacroTag(MacroParser, "machine", "The name of the computer (%machine%)", MacroTagType.Machine, active: true)); path = MacroParser.ParseTags(config: true, path, tagCollection, Log); if (FileSystem.HasExtension(path)) { string dir = FileSystem.GetDirectoryName(path); if (!string.IsNullOrEmpty(dir) && !FileSystem.DirectoryExists(dir)) { FileSystem.CreateDirectory(dir); } } else { if (!path.EndsWith(FileSystem.DirectorySeparatorChar().ToString())) { path += FileSystem.DirectorySeparatorChar(); } if (!string.IsNullOrEmpty(path) && !FileSystem.DirectoryExists(path)) { FileSystem.CreateDirectory(path); } } return(true); }
private void AddMacroTag() { if (InputValid()) { TrimInput(); if (MacroTagCollection.GetByName(textBoxName.Text) == null) { MacroTagCollection.Add(new MacroTag(textBoxName.Text, textBoxDescription.Text, (MacroTagType)comboBoxType.SelectedIndex, textBoxDateTimeFormatValue.Text, dateTimePickerMacro1Start.Value, dateTimePickerMacro1End.Value, textBoxMacro1Macro.Text, dateTimePickerMacro2Start.Value, dateTimePickerMacro2End.Value, textBoxMacro2Macro.Text, dateTimePickerMacro3Start.Value, dateTimePickerMacro3End.Value, textBoxMacro3Macro.Text, dateTimePickerMacro4Start.Value, dateTimePickerMacro4End.Value, textBoxMacro4Macro.Text, checkBoxActive.Checked, textBoxNotes.Text )); Okay(); } else { MessageBox.Show("A macro tag with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void FormRegion_Load(object sender, EventArgs e) { ScreenDictionary.Clear(); comboBoxScreenTemplate.Items.Clear(); comboBoxTags.DataSource = null; int component = 1; foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens) { ScreenDictionary.Add(component, screen); component++; } // *** Screen Template *** comboBoxScreenTemplate.Items.Add(string.Empty); for (int i = 1; i <= ScreenDictionary.Count; i++) { System.Windows.Forms.Screen screen = ScreenDictionary[i]; comboBoxScreenTemplate.Items.Add("Screen " + i + " (" + screen.Bounds.Width + " x " + screen.Bounds.Height + ")"); } comboBoxScreenTemplate.SelectedIndex = 0; // *********************** // *** Macro Tags *** comboBoxTags.DisplayMember = "Description"; comboBoxTags.ValueMember = "Name"; comboBoxTags.DataSource = MacroTagCollection.GetList(); // ****************** comboBoxFormat.Items.Clear(); foreach (ImageFormat imageFormat in ImageFormatCollection) { comboBoxFormat.Items.Add(imageFormat.Name); } if (RegionObject != null) { Text = "Change Region"; textBoxName.Text = RegionObject.Name; textBoxFolder.Text = FileSystem.CorrectDirectoryPath(RegionObject.Folder); textBoxMacro.Text = RegionObject.Macro; comboBoxFormat.SelectedItem = RegionObject.Format.Name; numericUpDownJpegQuality.Value = RegionObject.JpegQuality; numericUpDownResolutionRatio.Value = RegionObject.ResolutionRatio; checkBoxMouse.Checked = RegionObject.Mouse; numericUpDownX.Value = RegionObject.X; numericUpDownY.Value = RegionObject.Y; numericUpDownWidth.Value = RegionObject.Width; numericUpDownHeight.Value = RegionObject.Height; } else { Text = "Add New Region"; textBoxName.Text = "Region " + (RegionCollection.Count + 1); textBoxFolder.Text = FileSystem.ScreenshotsFolder; textBoxMacro.Text = MacroParser.DefaultMacro; comboBoxFormat.SelectedItem = ScreenCapture.DefaultImageFormat; numericUpDownJpegQuality.Value = 100; numericUpDownResolutionRatio.Value = 100; checkBoxMouse.Checked = true; numericUpDownX.Value = 0; numericUpDownY.Value = 0; numericUpDownWidth.Value = 800; numericUpDownHeight.Value = 600; } timerPreview.Enabled = true; }
private void FormScreen_Load(object sender, EventArgs e) { comboBoxFormat.Items.Clear(); comboBoxScreenComponent.Items.Clear(); comboBoxTags.DataSource = null; pictureBoxPreview.Image = null; // *** Macro Tags *** comboBoxTags.DisplayMember = "Description"; comboBoxTags.ValueMember = "Name"; comboBoxTags.DataSource = MacroTagCollection.GetList(); // ****************** foreach (ImageFormat imageFormat in ImageFormatCollection) { comboBoxFormat.Items.Add(imageFormat.Name); } comboBoxScreenComponent.Items.Add("Active Window"); for (int i = 1; i <= ScreenDictionary.Count; i++) { System.Windows.Forms.Screen screen = ScreenDictionary[i]; comboBoxScreenComponent.Items.Add("Screen " + i + " (" + screen.Bounds.Width + " x " + screen.Bounds.Height + ")"); } if (ScreenObject != null) { Text = "Change Screen"; textBoxName.Text = ScreenObject.Name; textBoxFolder.Text = FileSystem.CorrectDirectoryPath(ScreenObject.Folder); textBoxMacro.Text = ScreenObject.Macro; if (ScreenObject.Component < comboBoxScreenComponent.Items.Count) { SetControls(enabled: true); comboBoxScreenComponent.SelectedIndex = ScreenObject.Component; } else { SetControls(enabled: false); } comboBoxFormat.SelectedItem = ScreenObject.Format.Name; numericUpDownJpegQuality.Value = ScreenObject.JpegQuality; numericUpDownResolutionRatio.Value = ScreenObject.ResolutionRatio; checkBoxMouse.Checked = ScreenObject.Mouse; } else { Text = "Add New Screen"; textBoxName.Text = "Screen " + (ScreenCollection.Count + 1); textBoxFolder.Text = FileSystem.ScreenshotsFolder; textBoxMacro.Text = MacroParser.DefaultMacro; comboBoxScreenComponent.SelectedIndex = 0; comboBoxFormat.SelectedItem = ScreenCapture.DefaultImageFormat; numericUpDownJpegQuality.Value = 100; numericUpDownResolutionRatio.Value = 100; checkBoxMouse.Checked = true; } timerScreenPreview.Enabled = true; }
private void CheckAndCreateFiles(Security security, ScreenCapture screenCapture, Log log) { if (string.IsNullOrEmpty(FileSystem.CommandFile)) { FileSystem.CommandFile = FileSystem.DefaultCommandFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nCommandFile=" + FileSystem.DefaultCommandFile); if (!FileSystem.FileExists(FileSystem.DefaultCommandFile)) { FileSystem.CreateFile(FileSystem.DefaultCommandFile); } } if (string.IsNullOrEmpty(FileSystem.ApplicationSettingsFile)) { FileSystem.ApplicationSettingsFile = FileSystem.DefaultApplicationSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nApplicationSettingsFile=" + FileSystem.DefaultApplicationSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.SmtpSettingsFile)) { FileSystem.SmtpSettingsFile = FileSystem.DefaultSmtpSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nSMTPSettingsFile=" + FileSystem.DefaultSmtpSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.SftpSettingsFile)) { FileSystem.SftpSettingsFile = FileSystem.DefaultSftpSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nSFTPSettingsFile=" + FileSystem.DefaultSftpSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.UserSettingsFile)) { FileSystem.UserSettingsFile = FileSystem.DefaultUserSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nUserSettingsFile=" + FileSystem.DefaultUserSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } Settings.User.Load(Settings, FileSystem); Settings.SMTP.Load(Settings, FileSystem); Settings.SFTP.Load(Settings, FileSystem); Settings.VersionManager.OldApplicationSettings = Settings.Application.Clone(); Settings.VersionManager.OldUserSettings = Settings.User.Clone(); Settings.UpgradeApplicationSettings(Settings.Application, FileSystem); Settings.UpgradeUserSettings(Settings.User, screenCapture, security, FileSystem); Settings.UpgradeSmtpSettings(Settings.SMTP, FileSystem); Settings.UpgradeSftpSettings(Settings.SFTP, FileSystem); if (string.IsNullOrEmpty(FileSystem.ScreenshotsFile)) { ImageFormatCollection imageFormatCollection = new ImageFormatCollection(); ScreenCollection screenCollection = new ScreenCollection(); ScreenshotCollection screenshotCollection = new ScreenshotCollection(imageFormatCollection, screenCollection, screenCapture, this, FileSystem, log); screenshotCollection.SaveToXmlFile(this); } if (string.IsNullOrEmpty(FileSystem.EditorsFile)) { // Loading the editor collection will automatically create the default editors and add them to the collection. EditorCollection editorCollection = new EditorCollection(); editorCollection.LoadXmlFileAndAddEditors(this, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.RegionsFile)) { RegionCollection regionCollection = new RegionCollection(); regionCollection.SaveToXmlFile(Settings, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.ScreensFile)) { // Loading the screen collection will automatically create the available screens and add them to the collection. ScreenCollection screenCollection = new ScreenCollection(); screenCollection.LoadXmlFileAndAddScreens(new ImageFormatCollection(), this, MacroParser, screenCapture, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.TriggersFile)) { // Loading triggers will automatically create the default triggers and add them to the collection. TriggerCollection triggerCollection = new TriggerCollection(); triggerCollection.LoadXmlFileAndAddTriggers(this, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.TagsFile)) { // Loading tags will automatically create the default tags and add them to the collection. MacroTagCollection tagCollection = new MacroTagCollection(); tagCollection.LoadXmlFileAndAddTags(this, MacroParser, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.SchedulesFile)) { // Loading schedules will automatically create the default schedules and add them to the collection. ScheduleCollection scheduleCollection = new ScheduleCollection(); scheduleCollection.LoadXmlFileAndAddSchedules(this, FileSystem, log); } }
/// <summary> /// Replaces series of tags with appropriate values. /// </summary> /// <param name="preview">Determines if this is a preview of a macro. We either use screen capture date/time or DateTime.Now depending on this boolean.</param> /// <param name="config">Determines if we are parsing tags from the config file or not.</param> /// <param name="name">The name of a region or screen when parsing the %name% tag.</param> /// <param name="macro">The macro to parse. A macro usually includes tags such as %count% and %date%.</param> /// <param name="screenNumber">The screen number. For example, if this is the second display then the screen number is 2.</param> /// <param name="format">The image format to use as an image file extension when parsing the %format% tag.</param> /// <param name="activeWindowTitle">The title of the active window.</param> /// <param name="tagCollection">A collection of macro tags to parse.</param> /// <param name="log"></param> /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns> public string ParseTags(bool preview, bool config, string name, string macro, int screenNumber, ImageFormat format, string activeWindowTitle, MacroTagCollection tagCollection, Log log) { if (!config) { int activeWindowTitleLengthLimit = Convert.ToInt32(_settings.Application.GetByKey("ActiveWindowTitleLengthLimit", _settings.DefaultSettings.ActiveWindowTitleLengthLimit).Value); if (!string.IsNullOrEmpty(activeWindowTitle) && activeWindowTitle.Length > activeWindowTitleLengthLimit) { log.WriteMessage($"Active Window title length exceeds the configured length of {activeWindowTitleLengthLimit} characters so value was truncated. Correct the value for the ActiveWindowTitleLengthLimit application setting to prevent truncation"); activeWindowTitle = activeWindowTitle.Substring(0, activeWindowTitleLengthLimit); } } foreach (MacroTag tag in tagCollection) { if (tag.Type == MacroTagType.TimeRange) { DateTime dt; if (preview || screenCapture == null) { dt = DateTime.Now; } else { dt = screenCapture.DateTimeScreenshotsTaken; } string macro1Macro = tag.TimeRangeMacro1Macro; string macro2Macro = tag.TimeRangeMacro2Macro; string macro3Macro = tag.TimeRangeMacro3Macro; string macro4Macro = tag.TimeRangeMacro4Macro; // Temporarily make this tag a DateTimeFormat type because we're going to recursively call ParseTagsForFilePath // for each macro tag in the macro 1, macro 2, macro 3, and macro 4 fields. tag.Type = MacroTagType.DateTimeFormat; // Recursively call the same method we're in to parse each TimeRange macro as if it was a date/time macro tag. macro1Macro = ParseTags(preview, config, name, macro1Macro, screenNumber, format, activeWindowTitle, tagCollection, log); macro2Macro = ParseTags(preview, config, name, macro2Macro, screenNumber, format, activeWindowTitle, tagCollection, log); macro3Macro = ParseTags(preview, config, name, macro3Macro, screenNumber, format, activeWindowTitle, tagCollection, log); macro4Macro = ParseTags(preview, config, name, macro4Macro, screenNumber, format, activeWindowTitle, tagCollection, log); // Now that we have the new parsed values based on date/time macro tags we can set this tag back to its TimeRange type. tag.Type = MacroTagType.TimeRange; if (dt.TimeOfDay >= tag.TimeRangeMacro1Start.TimeOfDay && dt.TimeOfDay <= tag.TimeRangeMacro1End.TimeOfDay) { macro = macro.Replace(tag.Name, macro1Macro); } if (dt.TimeOfDay >= tag.TimeRangeMacro2Start.TimeOfDay && dt.TimeOfDay <= tag.TimeRangeMacro2End.TimeOfDay) { macro = macro.Replace(tag.Name, macro2Macro); } if (dt.TimeOfDay >= tag.TimeRangeMacro3Start.TimeOfDay && dt.TimeOfDay <= tag.TimeRangeMacro3End.TimeOfDay) { macro = macro.Replace(tag.Name, macro3Macro); } if (dt.TimeOfDay >= tag.TimeRangeMacro4Start.TimeOfDay && dt.TimeOfDay <= tag.TimeRangeMacro4End.TimeOfDay) { macro = macro.Replace(tag.Name, macro4Macro); } } else { macro = ParseTag(preview, name, macro, screenNumber, format, activeWindowTitle, tag); } } return(StripInvalidWindowsCharacters(macro)); }
/// <summary> /// Replaces a series of tags with appropriate values. Assumes you are either parsing a folder path or just need a preview of the returned values. /// </summary> /// <param name="config">Determines if we are parsing tags from the config file or not.</param> /// <param name="macro">The macro to parse. A macro usually includes tags such as %count% and %date%.</param> /// <param name="tagCollection">A collection of macro tags to parse.</param> /// <param name="log"></param> /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns> public string ParseTags(bool config, string macro, MacroTagCollection tagCollection, Log log) { return(ParseTags(preview: true, config, string.Empty, macro, 0, new ImageFormat("JPEG", ".jpeg"), string.Empty, tagCollection, log)); }
/// <summary> /// Empty constructor for the Macro Tags tool window. /// </summary> public FormMacroTagsToolWindow(MacroTagCollection tagCollection) { InitializeComponent(); _tagCollection = tagCollection; }
private static void CheckAndCreateFiles() { if (string.IsNullOrEmpty(FileSystem.CommandFile)) { FileSystem.CommandFile = FileSystem.DefaultCommandFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nCommandFile=" + FileSystem.DefaultCommandFile); if (!FileSystem.FileExists(FileSystem.DefaultCommandFile)) { FileSystem.CreateFile(FileSystem.DefaultCommandFile); } } if (string.IsNullOrEmpty(FileSystem.ApplicationSettingsFile)) { FileSystem.ApplicationSettingsFile = FileSystem.DefaultApplicationSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nApplicationSettingsFile=" + FileSystem.DefaultApplicationSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.SmtpSettingsFile)) { FileSystem.SmtpSettingsFile = FileSystem.DefaultSmtpSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nSMTPSettingsFile=" + FileSystem.DefaultSmtpSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.SftpSettingsFile)) { FileSystem.SftpSettingsFile = FileSystem.DefaultSftpSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nSFTPSettingsFile=" + FileSystem.DefaultSftpSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.UserSettingsFile)) { FileSystem.UserSettingsFile = FileSystem.DefaultUserSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nUserSettingsFile=" + FileSystem.DefaultUserSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } Settings.Initialize(); Log.WriteMessage("Loading user settings"); Settings.User.Load(); Log.WriteDebugMessage("User settings loaded"); Log.WriteMessage("Loading SMTP settings"); Settings.SMTP.Load(); Log.WriteDebugMessage("SMTP settings loaded"); Log.WriteMessage("Loading SFTP settings"); Settings.SFTP.Load(); Log.WriteDebugMessage("SFTP settings loaded"); Log.WriteDebugMessage("Attempting upgrade of application settings from old version of application (if needed)"); Settings.UpgradeApplicationSettings(Settings.Application); Log.WriteDebugMessage("Attempting upgrade of SMTP settings from old version of application (if needed)"); Settings.UpgradeSmtpSettings(Settings.SMTP); Log.WriteDebugMessage("Attempting upgrade of SFTP settings from old version of application (if needed)"); Settings.UpgradeSftpSettings(Settings.SFTP); Log.WriteDebugMessage("Attempting upgrade of user settings from old version of application (if needed)"); Settings.UpgradeUserSettings(Settings.User); if (string.IsNullOrEmpty(FileSystem.ScreenshotsFile)) { ImageFormatCollection imageFormatCollection = new ImageFormatCollection(); ScreenCollection screenCollection = new ScreenCollection(); ScreenshotCollection screenshotCollection = new ScreenshotCollection(imageFormatCollection, screenCollection); screenshotCollection.SaveToXmlFile(); } if (string.IsNullOrEmpty(FileSystem.EditorsFile)) { // Loading the editor collection will automatically create the default editors and add them to the collection. EditorCollection editorCollection = new EditorCollection(); editorCollection.LoadXmlFileAndAddEditors(); } if (string.IsNullOrEmpty(FileSystem.RegionsFile)) { RegionCollection regionCollection = new RegionCollection(); regionCollection.SaveToXmlFile(); } if (string.IsNullOrEmpty(FileSystem.ScreensFile)) { // Loading the screen collection will automatically create the available screens and add them to the collection. ScreenCollection screenCollection = new ScreenCollection(); screenCollection.LoadXmlFileAndAddScreens(new ImageFormatCollection()); } if (string.IsNullOrEmpty(FileSystem.TriggersFile)) { // Loading triggers will automatically create the default triggers and add them to the collection. TriggerCollection triggerCollection = new TriggerCollection(); triggerCollection.LoadXmlFileAndAddTriggers(); } if (string.IsNullOrEmpty(FileSystem.TagsFile)) { // Loading tags will automatically create the default tags and add them to the collection. MacroTagCollection tagCollection = new MacroTagCollection(); tagCollection.LoadXmlFileAndAddTags(); } if (string.IsNullOrEmpty(FileSystem.SchedulesFile)) { // Loading schedules will automatically create the default schedules and add them to the collection. ScheduleCollection scheduleCollection = new ScheduleCollection(); scheduleCollection.LoadXmlFileAndAddSchedules(); } }
/// <summary> /// Replaces series of tags with appropriate values. /// </summary> /// <param name="preview">Determines if this is a preview of a macro. We either use screen capture date/time or DateTime.Now depending on this boolean.</param> /// <param name="macro">The macro to parse. A macro usually includes tags such as %count% and %date%.</param> /// <param name="screenOrRegion">The screen or region to use when parsing macro tags.</param> /// <param name="activeWindowTitle">The title of the active window.</param> /// <param name="processName">The name of the current process.</param> /// <param name="label">The label that is applied to the saved screenshot.</param> /// <param name="macroTagCollection">A collection of macro tags to parse.</param> /// <param name="log">The log to use.</param> /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns> public string ParseTags(bool preview, string macro, object screenOrRegion, string activeWindowTitle, string processName, string label, MacroTagCollection macroTagCollection, Log log) { string name = string.Empty; // The name of a region or screen when parsing the %name% tag. int screenNumber = 0; // The screen number. For example, if this is the second display then the screen number is 2. int x = 0; int y = 0; int width = 0; int height = 0; ImageFormat format = new ImageFormat("JPEG", ".jpeg"); // The image format to use as an image file extension when parsing the %format% tag. if (screenOrRegion != null && screenOrRegion is Screen screen) { name = screen.Name; screenNumber = (screen.Source == 0 && screen.Component == 0) ? 0 : (screen.Component + 1); x = screen.X; y = screen.Y; width = screen.Width; height = screen.Height; format = screen.Format; } if (screenOrRegion != null && screenOrRegion is Region region) { name = region.Name; screenNumber = -1; x = region.X; y = region.Y; width = region.Width; height = region.Height; format = region.Format; } if (_settings != null && _settings.DefaultSettings != null) { int activeWindowTitleLengthLimit = Convert.ToInt32(_settings.Application.GetByKey("ActiveWindowTitleLengthLimit", _settings.DefaultSettings.ActiveWindowTitleLengthLimit).Value); if (!string.IsNullOrEmpty(activeWindowTitle) && activeWindowTitle.Length > activeWindowTitleLengthLimit) { log.WriteMessage($"Active Window title length exceeds the configured length of {activeWindowTitleLengthLimit} characters so value was truncated. Correct the value for the ActiveWindowTitleLengthLimit application setting to prevent truncation"); activeWindowTitle = activeWindowTitle.Substring(0, activeWindowTitleLengthLimit); } } foreach (MacroTag tag in macroTagCollection) { if (tag.Type == MacroTagType.TimeRange) { DateTime dt; if (preview || screenCapture == null) { dt = DateTime.Now; } else { dt = screenCapture.DateTimeScreenshotsTaken; } string macro1Macro = tag.TimeRangeMacro1Macro; string macro2Macro = tag.TimeRangeMacro2Macro; string macro3Macro = tag.TimeRangeMacro3Macro; string macro4Macro = tag.TimeRangeMacro4Macro; // Temporarily make this tag a DateTimeFormat type because we're going to recursively call ParseTagsForFilePath // for each macro tag in the macro 1, macro 2, macro 3, and macro 4 fields. tag.Type = MacroTagType.DateTimeFormat; // Recursively call the same method we're in to parse each TimeRange macro as if it was a date/time macro tag. macro1Macro = ParseTags(preview, macro1Macro, screenOrRegion, activeWindowTitle, processName, label, macroTagCollection, log); macro2Macro = ParseTags(preview, macro2Macro, screenOrRegion, activeWindowTitle, processName, label, macroTagCollection, log); macro3Macro = ParseTags(preview, macro3Macro, screenOrRegion, activeWindowTitle, processName, label, macroTagCollection, log); macro4Macro = ParseTags(preview, macro4Macro, screenOrRegion, activeWindowTitle, processName, label, macroTagCollection, log); // Now that we have the new parsed values based on date/time macro tags we can set this tag back to its TimeRange type. tag.Type = MacroTagType.TimeRange; if (dt.TimeOfDay >= tag.TimeRangeMacro1Start.TimeOfDay && dt.TimeOfDay <= tag.TimeRangeMacro1End.TimeOfDay) { macro = macro.Replace(tag.Name, macro1Macro); } if (dt.TimeOfDay >= tag.TimeRangeMacro2Start.TimeOfDay && dt.TimeOfDay <= tag.TimeRangeMacro2End.TimeOfDay) { macro = macro.Replace(tag.Name, macro2Macro); } if (dt.TimeOfDay >= tag.TimeRangeMacro3Start.TimeOfDay && dt.TimeOfDay <= tag.TimeRangeMacro3End.TimeOfDay) { macro = macro.Replace(tag.Name, macro3Macro); } if (dt.TimeOfDay >= tag.TimeRangeMacro4Start.TimeOfDay && dt.TimeOfDay <= tag.TimeRangeMacro4End.TimeOfDay) { macro = macro.Replace(tag.Name, macro4Macro); } } else { macro = ParseTag(preview, name, macro, screenNumber, x, y, width, height, format, activeWindowTitle, processName, label, tag); } } return(StripInvalidWindowsCharacters(macro)); }
/// <summary> /// Replaces series of tags with appropriate values. This is a simpler method that does a simple parsing of the macro without considering the screen and the active window title. /// </summary> /// <param name="macro">The macro to parse. A macro usually includes tags such as %count% and %date%.</param> /// <param name="macroTagCollection">A collection of macro tags to parse.</param> /// <param name="log">The log to use.</param> /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns> public string ParseTags(string macro, MacroTagCollection macroTagCollection, Log log) { return(ParseTags(preview: false, macro, null, null, null, string.Empty, macroTagCollection, log)); }
/// <summary> /// Replaces a series of tags with appropriate values. Assumes you are either parsing a folder path or just need a preview of the returned values. /// </summary> /// <param name="config">Determines if we are parsing tags from the config file or not.</param> /// <param name="macro">The macro to parse. A macro usually includes tags such as %count% and %date%.</param> /// <param name="tagCollection">A collection of macro tags to parse.</param> /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns> public static string ParseTags(bool config, string macro, MacroTagCollection tagCollection) { return(ParseTags(preview: true, config, string.Empty, macro, 0, new ImageFormat(ImageFormatSpec.NAME_JPEG, ImageFormatSpec.EXTENSION_JPEG), string.Empty, tagCollection)); }