Beispiel #1
0
        public bool Capture(Rectangle captureBounds, EngineSnapshot snapshot)
        {
            Logger.Information(MethodBase.GetCurrentMethod().DeclaringType.Name, ".", MethodBase.GetCurrentMethod().Name);

            try
            {
                snapshot.HasScreenshot = false;

                Bitmap bitmap = new Bitmap(captureBounds.Width, captureBounds.Height);
                using (Graphics graphics = Graphics.FromImage(bitmap))
                {
                    graphics.CopyFromScreen(captureBounds.Location, Point.Empty, captureBounds.Size);
                }

                string      screenShotExtension;
                ImageFormat screenShotFormat;
                switch (ScreenshotFormat)
                {
                case ScreenshotQuality.Gif:
                    screenShotExtension = ".gif";
                    screenShotFormat    = ImageFormat.Gif;
                    break;

                case ScreenshotQuality.Jpg:
                    screenShotExtension = ".jpg";
                    screenShotFormat    = ImageFormat.Jpeg;
                    break;

                default:
                    screenShotExtension = ".png";
                    screenShotFormat    = ImageFormat.Png;
                    break;
                }

                string path = Path.Combine(_engine.SnapshotsFolder, snapshot.RelativePath, "screenshot" + screenShotExtension);

                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                bitmap.Save(path, screenShotFormat);

                snapshot.ScreenshotFilename = "screenshot" + screenShotExtension;
                snapshot.HasScreenshot      = true;
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message);
                Utilities.Logger.LogException(exception);
                return(false);
            }

            return(snapshot.HasScreenshot);
        }
Beispiel #2
0
        public bool ActionSnapshotRestore(ActionSource actionSource, EngineSnapshot snapshot, params object[] args)
        {
            Logger.Information(MethodBase.GetCurrentMethod().DeclaringType.Name, ".", MethodBase.GetCurrentMethod().Name);

            args = new object[] { actionSource, snapshot }.Concat(args).ToArray();
            if (OnActionSnapshotRestore.Call(args).First() is bool b)
            {
                return(b);
            }

            return(false);
        }