コード例 #1
0
        public static void WriteBitmapMetadata(string outputFile, BitmapMetadata bitmapMetadata, int retryCount)
        {
            // Check file exists and is a valid jpg\jpeg file
            WpfFileManager.ValidateFileIsJpeg(outputFile);

            // Validate Threading Model
            WpfFileManager.ValidateThreadingModel();

            // Source file is is used as source of the the image & thumbnail for the new file
            string sourceFile = outputFile.ToLower().Replace(".jpg", ".fotoflytmp");

            // Try saving the file as needed
            bool fileSaved = false;

            while (true)
            {
                if (fileSaved || retryCount == 0)
                {
                    break;
                }

                // Copy file so we have a source file
                try
                {
                    if (File.Exists(sourceFile))
                    {
                        File.Delete(sourceFile);
                    }

                    File.Move(outputFile, sourceFile);
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to create the backup file.", e);
                }

                try
                {
                    WpfFileManager.WriteBitmapMetadata(outputFile, bitmapMetadata, sourceFile);

                    File.Delete(sourceFile);

                    fileSaved = true;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());

                    fileSaved = false;

                    retryCount--;
                }

                // Save file failed so restore files to original location
                if (!fileSaved)
                {
                    try
                    {
                        File.Delete(outputFile);
                        File.Move(sourceFile, outputFile);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Unable to recover from failed save\n" + e);
                    }
                }
            }

            if (!fileSaved)
            {
                throw new Exception("Unable to save the file:\n\n" + outputFile);
            }
        }
コード例 #2
0
 public static void WriteBitmapMetadata(string outputFile, BitmapMetadata bitmapMetadata)
 {
     WpfFileManager.WriteBitmapMetadata(outputFile, bitmapMetadata, 3);
 }