예제 #1
0
        public virtual void writeMetadata(BaseMetadata media, CancellableOperationProgressBase progress = null)
        {
            Progress = progress;       

            XMPLib.MetaData.ErrorCallbackDelegate errorCallbackDelegate = new XMPLib.MetaData.ErrorCallbackDelegate(errorCallback);
            // bug in xmplib, crashes on write when video is mpg and a progresscallback is active
            XMPLib.MetaData.ProgressCallbackDelegate progressCallbackDelegate = media.MimeType.Equals("video/mpeg") ? null : new XMPLib.MetaData.ProgressCallbackDelegate(progressCallback);

            XMPLib.MetaData xmpMetaDataWriter = new XMPLib.MetaData(errorCallbackDelegate, progressCallbackDelegate);

            try
            {
               if (media.SupportsXMPMetadata)
               {
                   xmpMetaDataWriter.open(media.Location, Consts.OpenOptions.XMPFiles_OpenForUpdate);

                   write(xmpMetaDataWriter, media);
               }
               else
               {
                  throw new Exception("Format does not support XMP metadata");
               }

            }
            finally
            {
                xmpMetaDataWriter.Dispose();
                xmpMetaDataWriter = null;
            }
        }
예제 #2
0
        /// <summary>
        /// returns true if the moved item was a imported item otherwise false
        /// </summary>
        /// <param name="newLocation"></param>
        /// <param name="progress"></param>        
        /// <returns></returns>
        public bool move_URLock(String newLocation, CancellableOperationProgressBase progress)
        {                    
            bool isImported = false;

            if (ItemState == MediaItemState.DELETED)
            {
                return (isImported);
            }
               
            FileUtils fileUtils = new FileUtils();
            
            fileUtils.moveFile(Location, newLocation, progress);
                           
            // A delete event will be fired by the mediafilewatcher for the current item with it's old location.
            // If location is changed to it's new location it will not be be found in the current mediastate. 
            // So only update the location when mediafilewatcher is not active.               
            EnterWriteLock();
            try
            {
                Location = newLocation;
            }
            finally
            {
                ExitWriteLock(false);
            }
                                             
            return (isImported = Metadata.IsImported);
                       
        }
예제 #3
0
        public void writeMetadata_URLock(MetadataFactory.WriteOptions options, CancellableOperationProgressBase progress = null)
        {                  
            if (Metadata != null)
            {
                MetadataFactory.write(Metadata, options, progress);
                QueueOnPropertyChangedEvent("Metadata");

                EnterWriteLock();
                try
                {
                    checkVariables(Metadata);
                }
                finally
                {
                    ExitWriteLock(false);
                }
            }           
        }
예제 #4
0
        public static void writeImage(String outputPath, BitmapSource image, Dictionary<String, Object> options = null, ImageMetadata metaData = null, CancellableOperationProgressBase progress = null)
        {            
            int width = image.PixelWidth;
            int height = image.PixelHeight;

            float scale = ImageUtils.resizeRectangle(width, height, Constants.MAX_THUMBNAIL_WIDTH, Constants.MAX_THUMBNAIL_HEIGHT);

            TransformedBitmap thumbnail = new TransformedBitmap(image, new System.Windows.Media.ScaleTransform(scale, scale));
          
            if (options != null)
            {                
                if (options.ContainsKey("Width"))
                {
                    width = (int)options["Width"];

                    if (!options.ContainsKey("Height"))
                    {
                        height = (int)(((float)width / image.PixelWidth) * image.PixelHeight);
                    }

                } 
                
                if (options.ContainsKey("Height")) {

                    height = (int)options["Height"];

                    if (!options.ContainsKey("Width"))
                    {
                        width = (int)(((float)height / image.PixelHeight) * image.PixelWidth);
                    }
                }
            }

            BitmapSource outImage = image;

            if (width != image.PixelWidth || height != image.PixelHeight)
            {      
                outImage = new TransformedBitmap(image, new System.Windows.Media.ScaleTransform((double)width / image.PixelWidth, (double)height / image.PixelHeight));
            }
          
            ImageFormat format = MediaFormatConvert.fileNameToImageFormat(outputPath);

            BitmapEncoder encoder = null;

            if (format == ImageFormat.Jpeg)
            {
                encoder = configureJpeg(options, ref thumbnail);
            }
            else if (format == ImageFormat.Png)
            {
                encoder = configurePng(options);                
            }
            else if (format == ImageFormat.Gif)
            {
                encoder = new GifBitmapEncoder();               
            }
            else if (format == ImageFormat.Bmp)
            {
                encoder = new BmpBitmapEncoder();
            }
            else if (format == ImageFormat.Tiff)
            {
                encoder = configureTiff(options);                
            }

            encoder.Frames.Add(BitmapFrame.Create(outImage, thumbnail, null, null));

            FileStream outputFile = new FileStream(outputPath, FileMode.Create);

            encoder.Save(outputFile);

            outputFile.Close();

            if (metaData != null)
            {
                metaData.Location = outputPath;
                ImageFileMetadataWriter metadataWriter = new ImageFileMetadataWriter();
                metadataWriter.writeMetadata(metaData, progress);
            }
        }
예제 #5
0
        public void move(StringCollection sourcePaths, StringCollection destPaths, CancellableOperationProgressBase progress)
        {

            if (progress.CancellationToken.IsCancellationRequested) return;

            if (sourcePaths.Count != destPaths.Count)
            {
                throw new System.ArgumentException();
            }

            try
            {

                StringCollection allSourcePaths;
                StringCollection allDestPaths;
                StringCollection createDirs;
                StringCollection removeDirs;

                getPaths(sourcePaths, destPaths, out allSourcePaths, out allDestPaths, out createDirs, out removeDirs);

                progress.TotalProgressMax = allSourcePaths.Count - 1;

                foreach (String directory in createDirs)
                {
                    Directory.CreateDirectory(directory);
                }

                for (int i = 0; i < allSourcePaths.Count; i++)
                {
                    if (progress.CancellationToken.IsCancellationRequested) return;

                    progress.TotalProgress = i;

                    moveFile(allSourcePaths[i], allDestPaths[i], progress);
                }

                foreach (String directory in removeDirs)
                {
                    Directory.Delete(directory);
                }

            }
            catch (Exception e)
            {

                Logger.Log.Error("Move Exception", e);
                progress.ItemInfo = "Move Exception: " + e.Message;
            }
         

        }
예제 #6
0
        public void moveFile(string source, string destination, CancellableOperationProgressBase progress)
        {
            if (progress.CancellationToken.IsCancellationRequested) return;
            
            if (source.Equals(destination))
            {
                return;

            } else if (Path.GetPathRoot(source).Equals(Path.GetPathRoot(destination)))
            {
                progress.ItemProgress = 0;
                progress.ItemInfo = "Moving: " + source + "->" + destination;
                             
                if(source.ToLowerInvariant().Equals(destination.ToLowerInvariant())) 
                {
                    // use temporary filename to change case of filename characters
                    string temp = getUniqueFileName(source);
                    System.IO.Directory.Move(source, temp);
                    System.IO.Directory.Move(temp, destination);

                } else {

                    System.IO.Directory.Move(source, destination);
                }

                string info = "Moved: " + source + " -> " + destination;

                progress.InfoMessages.Add(info);
                Logger.Log.Info(info);
                progress.ItemProgress = progress.ItemProgressMax;
            }
            else
            {
                FileInfo sourceFile = new FileInfo(source);
                if (sourceFile.Attributes.HasFlag(FileAttributes.ReadOnly))
                {
                    throw new System.IO.IOException("Cannot move readonly file");
                }

                copyFile(source, destination, progress);

                System.IO.File.Delete(source);

                string info = "Deleted: " + source;

                progress.InfoMessages.Add(info);
                Logger.Log.Info(info);
            }

        }
예제 #7
0
        public void copy(StringCollection sourcePaths, StringCollection destPaths, CancellableOperationProgressBase progress)
        {
            if (sourcePaths.Count != destPaths.Count)
            {

                throw new System.ArgumentException();
            }

            try
            {

                StringCollection allSourcePaths;
                StringCollection allDestPaths;
                StringCollection createDirs;
                StringCollection removeDirs;

                getPaths(sourcePaths, destPaths, out allSourcePaths, out allDestPaths, out createDirs, out removeDirs);

                progress.TotalProgressMax = allSourcePaths.Count - 1;              
         
                foreach (String directory in createDirs)
                {
                    Directory.CreateDirectory(directory);
                }

                for (int i = 0; i < allSourcePaths.Count; i++)
                {

                    progress.TotalProgress = i;

                    bool success = copyFile(allSourcePaths[i], allDestPaths[i], progress);               

                    if (success == false) break;
                                     
                }            

            }
            catch (Exception e)
            {
                Logger.Log.Error("Copy Exception", e);
                progress.ItemInfo = "Copy Exception: " + e.Message;
            }            

        }
예제 #8
0
        public bool copyFile(string source, string destination, CancellableOperationProgressBase progress)
        {

            GCHandle handle = GCHandle.Alloc(progress);
            IntPtr progressPtr = GCHandle.ToIntPtr(handle);

            try
            {

                progress.ItemInfo = "Copying: " + source + " -> " + destination;

                FileIOPermission sourcePermission = new FileIOPermission(FileIOPermissionAccess.Read, source);
                sourcePermission.Demand();

                FileIOPermission destinationPermission = new FileIOPermission(
                    FileIOPermissionAccess.Write, destination);
                destinationPermission.Demand();

                string destinationDir = System.IO.Path.GetDirectoryName(destination);

                if (!Directory.Exists(destinationDir))
                {

                    Directory.CreateDirectory(destinationDir);                  
                }

                CopyProgressDelegate progressCallback = new CopyProgressDelegate(copyProgress);

                int cancel = 0;

                if (!CopyFileEx(source, destination, progressCallback,
                    progressPtr, ref cancel, (int)CopyFileOptions.ALL))
                {

                    Win32Exception win32exception = new Win32Exception();

                    if (win32exception.NativeErrorCode == 1235)
                    {

                        // copy was cancelled
                        return (false);
                    }

                    throw new IOException(win32exception.Message);
                }

                string info = "Copied: " + source + " -> " + destination;
                progress.InfoMessages.Add(info);
                Logger.Log.Info(info);

                return (true);

            }
            finally
            {

                handle.Free();
            }
        }
예제 #9
0
        public void move(IEnumerable<MediaFileItem> items, IEnumerable<String> locations,
            CancellableOperationProgressBase progress)
        {

            List<String> deletedImportedLocations = new List<String>();
            List<MediaFileItem> addedImportedItems = new List<MediaFileItem>();

            try
            {
                var itemsEnum = items.GetEnumerator();
                var locationsEnum = locations.GetEnumerator();

                while (itemsEnum.MoveNext() && locationsEnum.MoveNext())
                {
                    if (progress.CancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    MediaFileItem item = itemsEnum.Current;
                    String location = locationsEnum.Current;

                    if (!item.Location.Equals(location))
                    {
                        String oldLocation = item.Location;

                        bool isImported = false;

                        item.EnterUpgradeableReadLock();
                        try
                        {
                            isImported = item.move_URLock(location, progress);
                        }
                        finally
                        {
                            item.ExitUpgradeableReadLock();
                        }

                        if (MediaFileWatcher.Instance.IsWatcherEnabled &&
                            !FileUtils.getPathWithoutFileName(location).Equals(MediaFileWatcher.Instance.Path))
                        {
                            List<MediaFileItem> removeList = new List<MediaFileItem>();
                            removeList.Add(item);

                            removeUIState(removeList);
                        }

                        if (isImported)
                        {
                            deletedImportedLocations.Add(oldLocation);
                            addedImportedItems.Add(item);
                        }
                    }

                }

            }
            finally
            {
                if (deletedImportedLocations.Count > 0)
                {
                    OnNrImportedItemsChanged(new MediaStateChangedEventArgs(
                        MediaStateChangedAction.Replace, addedImportedItems, deletedImportedLocations));
                }

            }

        }
예제 #10
0
 public void move(MediaFileItem item, String location, CancellableOperationProgressBase progress)
 {
     
     move(new List<MediaFileItem>{item}, new List<String>{location}, progress);
 }
예제 #11
0
        public static void write(BaseMetadata metadata, CancellableOperationProgressBase progress = null)
        {
            if (metadata is ImageMetadata)
            {
                ImageFileMetadataWriter imageMetadataWriter = new ImageFileMetadataWriter();
                imageMetadataWriter.writeMetadata(metadata, progress);

            }
            else if (metadata is VideoMetadata)
            {
                VideoFileMetadataWriter videoMetadataWriter = new VideoFileMetadataWriter();
                videoMetadataWriter.writeMetadata(metadata, progress);

            }
            else if (metadata is AudioMetadata)
            {
                AudioFileMetadataWriter audioMetadataWriter = new AudioFileMetadataWriter();
                audioMetadataWriter.writeMetadata(metadata, progress);
            }
            else 
            {
                MetadataFileWriter metadataFileWriter = new MetadataFileWriter();
                metadataFileWriter.writeMetadata(metadata, progress);
            } 

        }
예제 #12
0
        public static void write(BaseMetadata metadata, WriteOptions options, CancellableOperationProgressBase progress = null)
        {
           
            if (options.HasFlag(WriteOptions.AUTO) || options.HasFlag(WriteOptions.WRITE_TO_DISK))
            {
                MetadataFileFactory.write(metadata, progress);                
            }

            if (metadata.IsImported && (options.HasFlag(WriteOptions.AUTO) || options.HasFlag(WriteOptions.WRITE_TO_DATABASE)))
            {
                using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
                {
                    metadata = metadataCommands.update(metadata);
                }
            }

            metadata.IsModified = false;
            
        }