Exemplo n.º 1
0
        private IEnumerable <string> GetSubFolders(CancellationToken token, string source)
        {
            var directories = new List <string>();

            try
            {
                directories.Add(source);
                var allSubFolders = QuickIODirectory.EnumerateDirectories(source);
                foreach (var subFolder in allSubFolders.TakeWhile(rawDir => !token.IsCancellationRequested))
                {
                    directories.AddRange(GetSubFolders(token, subFolder.FullName));
                }
            }
            catch (Exception e)
            {
                this.Log().ErrorException("EnumerateDirectories", e);
            }
            return(directories);
        }
Exemplo n.º 2
0
 private void DoFindFiles(CancellationToken token, string dir, ConcurrentQueue <IMediaFile> results)
 {
     try
     {
         var allFiles = QuickIODirectory.EnumerateFiles(dir, "*", SearchOption.TopDirectoryOnly)
                        .Where(f => this.IsAudioFile(f.Name));
         foreach (var file in allFiles.TakeWhile(rawDir => !token.IsCancellationRequested))
         {
             var mf = this.GetMediaFile(file.FullName);
             if (mf != null)
             {
                 results.Enqueue(mf);
             }
         }
     }
     catch (Exception exception)
     {
         this.Log().ErrorException("EnumerateFiles", exception);
     }
 }
Exemplo n.º 3
0
        private BitmapImage GetImageFromDirectory(string fileName)
        {
            try
            {
                var path2Image = Path.GetDirectoryName(fileName);
                if (string.IsNullOrEmpty(path2Image))
                {
                    return(null);
                }

                var extensions = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
                {
                    ".jpg", ".jpeg", ".png", ".bmp"
                };
                var regexCoverFiles       = new Regex(".*(folder|cover|front|back|band|artist).*", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                var allPossibleCoverFiles = QuickIODirectory.EnumerateFiles(path2Image).Where(f => extensions.Contains(Path.GetExtension(f.Name))).ToList();
                var cover = allPossibleCoverFiles.FirstOrDefault(f => regexCoverFiles.IsMatch(f.Name));
                cover = cover ?? allPossibleCoverFiles.FirstOrDefault();
                if (cover != null)
                {
                    var hashCode = cover.FullName.GetHashCode();
                    var image    = _storedImages.GetOrAdd(hashCode, i =>
                    {
                        var bi = new BitmapImage();
                        bi.BeginInit();
                        bi.CreateOptions = BitmapCreateOptions.DelayCreation;
                        bi.CacheOption   = BitmapCacheOption.OnDemand;
                        bi.UriSource     = new Uri(cover.FullName, UriKind.RelativeOrAbsolute);
                        bi.EndInit();
                        bi.Freeze();
                        return(bi);
                    });
                    return(image);
                }
            }
            catch (Exception e)
            {
                this.Log().ErrorException($"Could not load the cover for {fileName}!", e);
            }
            return(null);
        }
 private static void ProcessDirectory(string path)
 {
     Parallel.ForEach(QuickIODirectory.EnumerateDirectories(path), dir =>
     {
         try
         {
             Parallel.ForEach(QuickIODirectory.EnumerateFiles(dir), file =>
             {
                 if (file.AsFileInfo().Extension.Equals(".docx"))
                 {
                     fileInfos.Add(file);
                 }
             });
             ProcessDirectory(dir.FullName);
         }
         catch (Exception e)
         {
             Console.WriteLine("Unable to access directory {0}", dir.FullName);
         }
     });
 }
Exemplo n.º 5
0
        private static BitmapImage GetImageFromDirectory(string fileName)
        {
            try
            {
                var path2Image = Path.GetDirectoryName(fileName);
                if (string.IsNullOrEmpty(path2Image))
                {
                    return(null);
                }

                var extensions = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
                {
                    ".jpg", ".jpeg", ".png", ".bmp"
                };
                var regexCoverFiles       = new Regex(".*(folder|cover|front|back|band|artist).*", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                var allPossibleCoverFiles = QuickIODirectory.EnumerateFiles(path2Image).Where(f => extensions.Contains(Path.GetExtension(f.Name))).ToList();
                var cover = allPossibleCoverFiles.FirstOrDefault(f => regexCoverFiles.IsMatch(f.Name));
                cover = cover ?? allPossibleCoverFiles.FirstOrDefault();
                if (cover != null)
                {
                    var bi = new BitmapImage();
                    bi.BeginInit();
                    bi.CreateOptions = BitmapCreateOptions.DelayCreation;
                    bi.CacheOption   = BitmapCacheOption.OnDemand;
                    bi.UriSource     = new Uri(cover.FullName, UriKind.RelativeOrAbsolute);
                    bi.EndInit();
                    bi.Freeze();
                    return(bi);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Fail to load cover from directory: {0}, {1}", fileName, e);
            }
            return(null);
        }
Exemplo n.º 6
0
 private static bool IsDirectory(string dirName)
 {
     return(QuickIODirectory.Exists(dirName));
 }