Beispiel #1
0
        internal static void RemoveScreenshot(FileInfoDto fileInfoDto)
        {
            string fullFileName = Path.Combine(fileInfoDto.Path, fileInfoDto.FileName);

            try
            {
                Win32Interop.File.Remove(fullFileName);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException(string.Format("Can't remove the file {0}: {1}", fullFileName, exception.Message));
            }
        }
Beispiel #2
0
        public static void TakeAndSaveScreenshot(FileInfoDto pathAndFileName)
        {
            try
            {
                Win32Interop.Directory.CreateDirectory(pathAndFileName.Path);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException(string.Format("Can't create path '{0}': {1}", pathAndFileName.Path, exception.Message));
            }
            Bitmap bitmap = TakeScreenshot();

            bitmap.Save(pathAndFileName);
        }
Beispiel #3
0
        public static void Save(this Bitmap bitmap, FileInfoDto fileInfo)
        {
            string destination = Path.Combine(fileInfo.Path, fileInfo.FileName);

            try
            {
                bitmap.Save(fileInfo.FileName, ImageFormat);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException(string.Format("Can't save the temporary file in {0}: {1}", Environment.CurrentDirectory, exception.Message));
            }
            try
            {
                Win32Interop.File.Move(
                    Path.Combine(Environment.CurrentDirectory, fileInfo.FileName),
                    destination);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException(string.Format("Can't copy the temporary file to {0}: {1}", destination, exception.Message));
            }
        }