示例#1
0
        private void UpdatePreviewMacro()
        {
            textBoxMacroPreview.ForeColor = System.Drawing.Color.Black;
            textBoxMacroPreview.BackColor = System.Drawing.Color.LightYellow;

            textBoxMacroPreview.Text = _macroParser.ParseTags(config: false, textBoxFolder.Text, TagCollection, _log) +
                                       _macroParser.ParseTags(preview: true, config: false, textBoxScreenName.Text, textBoxMacro.Text, 1,
                                                              ImageFormatCollection.GetByName(comboBoxFormat.Text), Text, TagCollection, _log);
        }
示例#2
0
        /// <summary>
        /// Saves the screenshots.
        /// </summary>
        public static void Save()
        {
            try
            {
                if (_screenshotList != null && Directory.Exists(FileSystem.ApplicationFolder))
                {
                    XmlWriterSettings xSettings = new XmlWriterSettings
                    {
                        Indent           = true,
                        CloseOutput      = true,
                        CheckCharacters  = true,
                        Encoding         = Encoding.UTF8,
                        NewLineChars     = Environment.NewLine,
                        IndentChars      = XML_FILE_INDENT_CHARS,
                        NewLineHandling  = NewLineHandling.Entitize,
                        ConformanceLevel = ConformanceLevel.Document
                    };

                    using (XmlWriter xWriter =
                               XmlWriter.Create(FileSystem.ApplicationFolder + MacroParser.ParseTags(FileSystem.ScreenshotsFile), xSettings))
                    {
                        xWriter.WriteStartDocument();
                        xWriter.WriteStartElement(XML_FILE_ROOT_NODE);
                        xWriter.WriteAttributeString("app", "version", XML_FILE_ROOT_NODE, Settings.ApplicationVersion);
                        xWriter.WriteAttributeString("app", "codename", XML_FILE_ROOT_NODE, Settings.ApplicationCodename);
                        xWriter.WriteStartElement(XML_FILE_SCREENSHOTS_NODE);

                        foreach (object obj in _screenshotList)
                        {
                            Screenshot screenshot = (Screenshot)obj;

                            xWriter.WriteStartElement(XML_FILE_SCREENSHOT_NODE);
                            xWriter.WriteElementString(SCREENSHOT_VIEWID, screenshot.ViewId.ToString());
                            xWriter.WriteElementString(SCREENSHOT_DATE, screenshot.Date);
                            xWriter.WriteElementString(SCREENSHOT_TIME, screenshot.Time);
                            xWriter.WriteElementString(SCREENSHOT_PATH, screenshot.Path);
                            xWriter.WriteElementString(SCREENSHOT_FORMAT, screenshot.Format.Name);
                            xWriter.WriteElementString(SCREENSHOT_COMPONENT, screenshot.Component.ToString());
                            xWriter.WriteElementString(SCREENSHOT_SLIDENAME, screenshot.Slide.Name);
                            xWriter.WriteElementString(SCREENSHOT_SLIDEVALUE, screenshot.Slide.Value);
                            xWriter.WriteElementString(SCREENSHOT_WINDOW_TITLE, screenshot.WindowTitle);
                            xWriter.WriteElementString(SCREENSHOT_LABEL, screenshot.Label);

                            xWriter.WriteEndElement();
                        }

                        xWriter.WriteEndElement();
                        xWriter.WriteEndElement();
                        xWriter.WriteEndDocument();

                        xWriter.Flush();
                        xWriter.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write("ScreenshotCollection::Save", ex);
            }
        }
        private bool SaveScreenshot(Bitmap bitmap, Region region)
        {
            if (bitmap == null)
            {
                return(false);
            }

            Screenshot screenshot = new Screenshot(_screenCapture.ActiveWindowTitle, _screenCapture.DateTimeScreenshotsTaken)
            {
                ViewId      = region.ViewId,
                Path        = FileSystem.CorrectScreenshotsFolderPath(MacroParser.ParseTags(config: false, region.Folder, _formMacroTag.MacroTagCollection)) + MacroParser.ParseTags(preview: false, config: false, region.Name, region.Macro, -1, region.Format, _screenCapture.ActiveWindowTitle, _formMacroTag.MacroTagCollection),
                Bitmap      = bitmap,
                Format      = region.Format,
                ProcessName = _screenCapture.ActiveWindowProcessName + ".exe",
                Label       = checkBoxScreenshotLabel.Checked ? comboBoxScreenshotLabel.Text : string.Empty
            };

            if (_screenCapture.SaveScreenshot(region.JpegQuality, screenshot, _screenshotCollection))
            {
                ScreenshotTakenWithSuccess();

                return(true);
            }
            else
            {
                ScreenshotTakenWithFailure();

                return(false);
            }
        }
示例#4
0
        private void UpdatePreviewMacro()
        {
            textBoxMacroPreview.ForeColor = System.Drawing.Color.Black;
            textBoxMacroPreview.BackColor = System.Drawing.Color.LightYellow;

            textBoxMacroPreview.Text = MacroParser.ParseTags(textBoxFolder.Text, TagCollection) +
                                       MacroParser.ParseTags(preview: true, textBoxName.Text, textBoxMacro.Text, 1,
                                                             ImageFormatCollection.GetByName(comboBoxFormat.Text), Text, TagCollection);
        }
示例#5
0
        private void UpdatePreviewMacro()
        {
            textBoxMacroPreview.ForeColor = System.Drawing.Color.Black;
            textBoxMacroPreview.BackColor = System.Drawing.Color.LightYellow;

            Screen screen = new Screen
            {
                Name   = textBoxScreenName.Text,
                X      = (int)numericUpDownX.Value,
                Y      = (int)numericUpDownY.Value,
                Width  = (int)numericUpDownWidth.Value,
                Height = (int)numericUpDownHeight.Value,
                Format = ImageFormatCollection.GetByName(comboBoxFormat.Text)
            };

            string label = _config.Settings.User.GetByKey("ScreenshotLabel", string.Empty).Value.ToString();

            textBoxMacroPreview.Text = _macroParser.ParseTags(preview: true, textBoxFolder.Text, screen, Text, Assembly.GetExecutingAssembly().GetName().Name, label, TagCollection, _log) +
                                       _macroParser.ParseTags(preview: true, textBoxMacro.Text, screen, Text, Assembly.GetExecutingAssembly().GetName().Name, label, TagCollection, _log);
        }
示例#6
0
        /// <summary>
        /// The event method used by "Region Select / Auto Save".
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _formRegionSelectWithMouse_RegionSelectAutoSaveMouseSelectionCompleted(object sender, EventArgs e)
        {
            int x      = _formRegionSelectWithMouse.outputX + 1;
            int y      = _formRegionSelectWithMouse.outputY + 1;
            int width  = _formRegionSelectWithMouse.outputWidth - 2;
            int height = _formRegionSelectWithMouse.outputHeight - 2;

            string autoSaveFolder = textBoxAutoSaveFolder.Text;
            string autoSaveMacro  = textBoxAutoSaveMacro.Text;

            ImageFormat imageFormat = new ImageFormat(ImageFormatSpec.NAME_JPEG, ImageFormatSpec.EXTENSION_JPEG);

            if (_screenCapture.GetScreenImages(-1, x, y, width, height, mouse: false, resolutionRatio: 100, out Bitmap bitmap))
            {
                DateTime dtNow = DateTime.Now;

                _screenCapture.DateTimeScreenshotsTaken = dtNow;
                _screenCapture.ActiveWindowTitle        = "*** Auto Screen Capture - Region Select / Auto Save ***";

                if (_screenCapture.SaveScreenshot(
                        path: FileSystem.CorrectScreenshotsFolderPath(MacroParser.ParseTags(config: false, autoSaveFolder, _formTag.TagCollection)) + MacroParser.ParseTags(preview: false, config: false, DateTime.Now.ToString(MacroParser.DateFormat), autoSaveMacro, -1, imageFormat, _screenCapture.ActiveWindowTitle, _formTag.TagCollection),
                        format: imageFormat,
                        component: -1,
                        screenshotType: ScreenshotType.Region,
                        jpegQuality: 100,
                        viewId: new Guid(),
                        bitmap: bitmap,
                        label: checkBoxScreenshotLabel.Checked ? comboBoxScreenshotLabel.Text : string.Empty,
                        windowTitle: _screenCapture.ActiveWindowTitle,
                        processName: _screenCapture.ActiveWindowProcessName,
                        screenshotCollection: _screenshotCollection
                        ))
                {
                    ScreenshotTakenWithSuccess();
                }
                else
                {
                    ScreenshotTakenWithFailure();
                }
            }
        }
示例#7
0
        /// <summary>
        /// Gets the path from the configuration file based on what line is being processed and a regex pattern.
        /// </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 static bool GetPath(string line, string regex, out string path)
        {
            if (line.StartsWith("#") || !Regex.IsMatch(line, regex))
            {
                path = null;
                return(false);
            }

            path = Regex.Match(line, regex).Groups["Path"].Value;

            TagCollection tagCollection = new TagCollection();

            tagCollection.Add(new Tag("user", "The user using this computer (%user%)", TagType.User, active: true));
            tagCollection.Add(new Tag("machine", "The name of the computer (%machine%)", TagType.Machine, active: true));

            path = MacroParser.ParseTags(path, tagCollection);

            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 listBoxMacroTags_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            Tag tag = _tagCollection.GetByName((string)listBoxMacroTags.SelectedItem);

            labelHelp.Text = MacroParser.ParseTags(tag.Description, _tagCollection);
        }
        private void RunRegionCaptures()
        {
            try
            {
                Log.WriteDebugMessage(":: RunRegionCaptures Start ::");

                foreach (Region region in formRegion.RegionCollection)
                {
                    if (region.Active)
                    {
                        MacroParser.screenCapture = _screenCapture;

                        if (!string.IsNullOrEmpty(_screenCapture.ActiveWindowTitle))
                        {
                            // Do not contiune if the active window title needs to be checked and the active window title
                            // does not contain the text defined in "Active Window Title Capture Text".
                            if (region.ActiveWindowTitleCaptureCheck && !string.IsNullOrEmpty(region.ActiveWindowTitleCaptureText) &&
                                !_screenCapture.ActiveWindowTitle.ToLower().Contains(region.ActiveWindowTitleCaptureText.ToLower()))
                            {
                                return;
                            }

                            if (_screenCapture.GetScreenImages(-1, region.X, region.Y, region.Width, region.Height, region.Mouse, region.ResolutionRatio, out Bitmap bitmap))
                            {
                                if (_screenCapture.SaveScreenshot(
                                        path: FileSystem.CorrectScreenshotsFolderPath(MacroParser.ParseTags(region.Folder, formTag.TagCollection)) + MacroParser.ParseTags(preview: false, region.Name, region.Macro, -1, region.Format, _screenCapture.ActiveWindowTitle, formTag.TagCollection),
                                        format: region.Format,
                                        component: -1,
                                        screenshotType: ScreenshotType.Region,
                                        jpegQuality: region.JpegQuality,
                                        viewId: region.ViewId,
                                        bitmap: bitmap,
                                        label: checkBoxScreenshotLabel.Checked ? comboBoxScreenshotLabel.Text : string.Empty,
                                        windowTitle: _screenCapture.ActiveWindowTitle,
                                        processName: _screenCapture.ActiveWindowProcessName,
                                        screenshotCollection: _screenshotCollection
                                        ))
                                {
                                    ScreenshotTakenWithSuccess();
                                }
                                else
                                {
                                    ScreenshotTakenWithFailure();
                                }
                            }
                        }
                    }
                }

                Log.WriteDebugMessage(":: RunRegionCaptures End ::");
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("FormMain-Regions::RunRegionCaptures", ex);
            }
        }
示例#10
0
        private void RunRegionCaptures()
        {
            try
            {
                foreach (Region region in _formRegion.RegionCollection)
                {
                    if (region.Active)
                    {
                        MacroParser.screenCapture = _screenCapture;

                        if (!string.IsNullOrEmpty(_screenCapture.ActiveWindowTitle))
                        {
                            // Do not contiune if the active window title needs to be checked and the active window title
                            // does not contain the text defined in "Active Window Title Capture Text" and CaptureNow is false.
                            // CaptureNow could be set to "true" during a "Capture Now / Archive" or "Capture Now / Edit" option
                            // so, in that case, we want to capture the screen and save the screenshot regardless of the title text.
                            if (checkBoxActiveWindowTitle.Checked && !string.IsNullOrEmpty(textBoxActiveWindowTitle.Text) &&
                                !_screenCapture.ActiveWindowTitle.ToLower().Contains(textBoxActiveWindowTitle.Text.ToLower()) &&
                                !_screenCapture.CaptureNow)
                            {
                                return;
                            }

                            _screenCapture.CaptureNow = false;

                            if (_screenCapture.GetScreenImages(-1, region.X, region.Y, region.Width, region.Height, region.Mouse, region.ResolutionRatio, out Bitmap bitmap))
                            {
                                if (_screenCapture.SaveScreenshot(
                                        path: FileSystem.CorrectScreenshotsFolderPath(MacroParser.ParseTags(config: false, region.Folder, _formTag.TagCollection)) + MacroParser.ParseTags(preview: false, config: false, region.Name, region.Macro, -1, region.Format, _screenCapture.ActiveWindowTitle, _formTag.TagCollection),
                                        format: region.Format,
                                        component: -1,
                                        screenshotType: ScreenshotType.Region,
                                        jpegQuality: region.JpegQuality,
                                        viewId: region.ViewId,
                                        bitmap: bitmap,
                                        label: checkBoxScreenshotLabel.Checked ? comboBoxScreenshotLabel.Text : string.Empty,
                                        windowTitle: _screenCapture.ActiveWindowTitle,
                                        processName: _screenCapture.ActiveWindowProcessName,
                                        screenshotCollection: _screenshotCollection
                                        ))
                                {
                                    ScreenshotTakenWithSuccess();
                                }
                                else
                                {
                                    ScreenshotTakenWithFailure();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _screenCapture.ApplicationError = true;
                Log.WriteExceptionMessage("FormMain-Regions::RunRegionCaptures", ex);
            }
        }