/// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="environment">The <see cref="CommandEnvironment"/> to use in executing the command.</param>
        /// <param name="parameters">The <see cref="Dictionary{string, object}"/> containing the command parameters.</param>
        /// <returns>The JSON serialized string representing the command response.</returns>
        public override Response Execute(CommandEnvironment environment, Dictionary <string, object> parameters, System.Threading.CancellationToken cancellationToken)
        {
            var windows = environment.GetWindows(cancellationToken);

            object[] handles = windows.Select(w => w.Current.AutomationId).ToArray();
            return(Response.CreateSuccessResponse(handles));
        }
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="environment">The <see cref="CommandEnvironment"/> to use in executing the command.</param>
        /// <param name="parameters">The <see cref="Dictionary{string, object}"/> containing the command parameters.</param>
        /// <returns>The JSON serialized string representing the command response.</returns>
        public override Response Execute(CommandEnvironment environment, Dictionary <string, object> parameters, System.Threading.CancellationToken cancellationToken)
        {
            var capture = new Cyotek.Demo.SimpleScreenshotCapture.ScreenshotCapture();

            var region = capture.GetRectangle(environment.ApplicationWindowHandle);

            // expand the screeshot region to include all application windows
            var windows = environment.GetWindows(cancellationToken);

            foreach (var window in windows)
            {
                var windowRegion = capture.GetRectangle(new IntPtr(window.Current.NativeWindowHandle));
                if (windowRegion.Left < region.Left)
                {
                    region = Rectangle.FromLTRB(windowRegion.Left, region.Top, region.Right, region.Bottom);
                }

                if (windowRegion.Right > region.Right)
                {
                    region = Rectangle.FromLTRB(region.Left, region.Top, windowRegion.Right, region.Bottom);
                }

                if (windowRegion.Top < region.Top)
                {
                    region = Rectangle.FromLTRB(region.Left, windowRegion.Top, region.Right, region.Bottom);
                }

                if (windowRegion.Bottom > region.Bottom)
                {
                    region = Rectangle.FromLTRB(region.Left, region.Top, region.Right, windowRegion.Bottom);
                }
            }

            var bitmap = capture.CaptureRegion(region);

            string screenshot = string.Empty;

            using (MemoryStream stream = new MemoryStream())
            {
                bitmap.Save(stream, ImageFormat.Png);
                byte[] imageBytes = stream.ToArray();

                screenshot = Convert.ToBase64String(imageBytes);
            }

            return(Response.CreateSuccessResponse(screenshot));
        }