Esempio n. 1
0
        /// <summary>
        /// Returns true if deleted file was imported otherwise false
        /// </summary>
        /// <returns></returns>
        public bool delete_WLock()
        {
            bool isImported = false;

            if (ItemState == MediaItemState.DELETED)
            {
                return(isImported);
            }

            FileUtils fileUtils = new FileUtils();

            if (ItemState != MediaItemState.FILE_NOT_FOUND)
            {
                fileUtils.deleteFile(Location);
            }

            if (Metadata != null && Metadata.IsImported)
            {
                using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
                {
                    metadataCommands.delete(Metadata);
                }

                Metadata = null;

                isImported = true;
            }

            ItemState = MediaItemState.DELETED;
            //Factory.deleteFromDictionary(location);
            Logger.Log.Info("Deleted: " + Location);

            return(isImported);
        }
Esempio n. 2
0
        public bool export_WLock(CancellationToken token)
        {
            if (ItemState == MediaItemState.DELETED || Metadata == null || Metadata.IsImported == false)
            {
                return(false);
            }

            using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
            {
                metadataCommands.delete(Metadata);
            }

            QueueOnPropertyChangedEvent("Metadata");
            return(true);
        }
Esempio n. 3
0
        public bool export_WLock(CancellationToken token)
        {           
            if (ItemState == MediaItemState.DELETED || Metadata == null || Metadata.IsImported == false)
            {
                return (false);
            }

            using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
            {
                metadataCommands.delete(Metadata);
                   
            }               
           
            QueueOnPropertyChangedEvent("Metadata");
            return (true);
        }
Esempio n. 4
0
        /// <summary>
        /// Returns true if deleted file was imported otherwise false
        /// </summary>
        /// <returns></returns>
        public bool delete_WLock()
        {           
            bool isImported = false;

            if (ItemState == MediaItemState.DELETED)
            {
                return (isImported);
            }

            FileUtils fileUtils = new FileUtils();

            if (ItemState != MediaItemState.FILE_NOT_FOUND)
            {
                fileUtils.deleteFile(Location);
            }

            if (Metadata != null && Metadata.IsImported)
            {
                using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
                {
                    metadataCommands.delete(Metadata);
                }

                Metadata = null;

                isImported = true;
            }

            ItemState = MediaItemState.DELETED;
            //Factory.deleteFromDictionary(location);
            Logger.Log.Info("Deleted: " + Location);

            return (isImported);            
           
        }
Esempio n. 5
0
        private bool iterateFiles(System.IO.DirectoryInfo location, object state)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            Tuple <ScanLocation, ObservableCollection <ScanLocation> > locationArgs = state as Tuple <ScanLocation, ObservableCollection <ScanLocation> >;

            ScanLocation scanLocation = locationArgs.Item1;
            ObservableCollection <ScanLocation> excludeLocations = locationArgs.Item2;

            FileInfo[] files = null;

            try
            {
                files = location.GetFiles("*.*");
            }
            catch (UnauthorizedAccessException e)
            {
                Logger.Log.Warn(e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                Logger.Log.Warn(e.Message);
            }

            List <BaseMetadata> staleItems = new List <BaseMetadata>();

            using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
            {
                staleItems = metadataCommands.getAllMetadataInDirectory(location.FullName);
            }

            foreach (FileInfo info in files)
            {
                if (CancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                {
                    staleItems.RemoveAll(x => x.Name.Equals(info.Name));
                }

                String addItem = null;

                switch (scanLocation.MediaType)
                {
                case Search.MediaType.All:
                {
                    if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Images:
                {
                    if (MediaFormatConvert.isImageFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Video:
                {
                    if (MediaFormatConvert.isVideoFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Audio:
                {
                    if (MediaFormatConvert.isAudioFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }
                }

                if (addItem != null)
                {
                    String path = FileUtils.getPathWithoutFileName(addItem);

                    bool excluded = false;

                    foreach (ScanLocation excludeLocation in excludeLocations)
                    {
                        if (excludeLocation.IsRecursive)
                        {
                            if (path.StartsWith(excludeLocation.Location))
                            {
                                if (excludeLocation.MediaType == Search.MediaType.All ||
                                    (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                    (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                                {
                                    excluded = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (path.Equals(excludeLocation.Location))
                            {
                                if (excludeLocation.MediaType == Search.MediaType.All ||
                                    (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                    (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                                {
                                    excluded = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!excluded)
                    {
                        importItem(info);
                    }
                }
            }

            if (staleItems.Count > 0)
            {
                using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
                {
                    foreach (BaseMetadata staleItem in staleItems)
                    {
                        metadataCommands.delete(staleItem);
                    }
                }

                Logger.Log.Info("Removed " + staleItems.Count + " stale media items from " + location.FullName);
                InfoMessages.Add("Removed " + staleItems.Count + " stale media items from " + location.FullName);
            }

            return(true);
        }
        private bool iterateFiles(System.IO.DirectoryInfo location, object state)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return (false);
            }

            Tuple<ScanLocation, ObservableCollection<ScanLocation>> locationArgs = state as Tuple<ScanLocation, ObservableCollection<ScanLocation>>;

            ScanLocation scanLocation = locationArgs.Item1;
            ObservableCollection<ScanLocation> excludeLocations = locationArgs.Item2;
                    
            FileInfo[] files = null;
                    
            try
            {
                files = location.GetFiles("*.*");
            }       
            catch (UnauthorizedAccessException e)
            {           
                Logger.Log.Warn(e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                Logger.Log.Warn(e.Message);
            }

            List<BaseMetadata> staleItems = new List<BaseMetadata>();

            using(MetadataDbCommands metadataCommands = new MetadataDbCommands()) 
            {
                staleItems = metadataCommands.getAllMetadataInDirectory(location.FullName);            
            }

            foreach (FileInfo info in files)
            {
                if (CancellationToken.IsCancellationRequested) return false;

                if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                {
                    staleItems.RemoveAll(x => x.Name.Equals(info.Name));
                }

                String addItem = null;

                switch (scanLocation.MediaType)
                {
                    case Search.MediaType.All:
                        {
                            if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                            {
                                addItem = info.FullName;
                            }
                            break;
                        }
                    case Search.MediaType.Images:
                        {
                            if (MediaFormatConvert.isImageFile(info.Name))
                            {
                                addItem = info.FullName;
                            }
                            break;
                        }
                    case Search.MediaType.Video:
                        {
                            if (MediaFormatConvert.isVideoFile(info.Name))
                            {
                                addItem = info.FullName;
                            }
                            break;
                        }
                    case Search.MediaType.Audio:
                        {
                            if (MediaFormatConvert.isAudioFile(info.Name))
                            {
                                addItem = info.FullName;
                            }
                            break;
                        }
                }

                if (addItem != null)
                {
                    String path = FileUtils.getPathWithoutFileName(addItem);

                    bool excluded = false;

                    foreach (ScanLocation excludeLocation in excludeLocations)
                    {
                        if (excludeLocation.IsRecursive)
                        {
                            if (path.StartsWith(excludeLocation.Location))
                            {
                                if (excludeLocation.MediaType == Search.MediaType.All ||
                                    (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                     (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                                {
                                    excluded = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (path.Equals(excludeLocation.Location))
                            {
                                if (excludeLocation.MediaType == Search.MediaType.All ||
                                    (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                     (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                                {
                                    excluded = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!excluded)
                    {
                        importItem(info);
                    }
                }
            }

            if(staleItems.Count > 0) {

                using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
                {
                    foreach (BaseMetadata staleItem in staleItems)
                    {
                        metadataCommands.delete(staleItem);
                    }
                }

                Logger.Log.Info("Removed " + staleItems.Count + " stale media items from " + location.FullName);
                InfoMessages.Add("Removed " + staleItems.Count + " stale media items from " + location.FullName);
            }

            return (true);
        }