コード例 #1
0
        private void AddDapProperties()
        {
            if (AudioFolders.Length > 0 && !String.IsNullOrEmpty(AudioFolders[0]))
            {
                AddDapProperty(String.Format(
                                   Catalog.GetPluralString("Audio Folder", "Audio Folders", AudioFolders.Length), AudioFolders.Length),
                               System.String.Join("\n", AudioFolders)
                               );
            }

            if (VideoFolders.Length > 0 && !String.IsNullOrEmpty(VideoFolders[0]))
            {
                AddDapProperty(String.Format(
                                   Catalog.GetPluralString("Video Folder", "Video Folders", VideoFolders.Length), VideoFolders.Length),
                               System.String.Join("\n", VideoFolders)
                               );
            }

            if (FolderDepth != -1)
            {
                AddDapProperty(Catalog.GetString("Required Folder Depth"), FolderDepth.ToString());
            }

            AddYesNoDapProperty(Catalog.GetString("Supports Playlists"), PlaylistTypes.Count > 0);

            /*if (AcceptableMimeTypes.Length > 0) {
             *  AddDapProperty (String.Format (
             *      Catalog.GetPluralString ("Audio Format", "Audio Formats", PlaybackFormats.Length), PlaybackFormats.Length),
             *      System.String.Join (", ", PlaybackFormats)
             *  );
             * }*/
        }
コード例 #2
0
        private static IReadOnlyList <string> GetFilesCore(string directory, FolderDepth folderDepth, string userSearchFilter, string applicationSearchFilter,
                                                           CancellationToken cancellationToken)
        {
            // This method is run in an task (not in the UI thread) => static ensures some thread-safety.
            var folder       = StorageFolder.GetFolderFromPathAsync(directory).GetResult(cancellationToken);
            var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, SupportedFileTypes.MusicFileExtensions)
            {
                UserSearchFilter        = userSearchFilter ?? "",
                ApplicationSearchFilter = applicationSearchFilter ?? "",
                FolderDepth             = folderDepth
            };
            var result = folder.CreateFileQueryWithOptions(queryOptions);

            // It seems that GetFilesAsync does not check the cancellationToken; so get only parts of the file results in a loop.
            Logger.Verbose("ManagerController.UpdateMusicFiles:GetFilesAsync Start");
            List <string> files       = new List <string>();
            uint          index       = 0;
            int           resultCount = 0;
            const uint    maxFiles    = 100;

            do
            {
                var filesResult = result.GetFilesAsync(index, maxFiles).GetResult(cancellationToken);
                resultCount = filesResult.Count;
                files.AddRange(filesResult.Select(x => x.Path));
                index += maxFiles;
            }while (resultCount == maxFiles);
            Logger.Verbose("ManagerController.UpdateMusicFiles:GetFilesAsync End");
            return(files);
        }
コード例 #3
0
        private async void UpdateMusicFiles(FolderDepth folderDepth)
        {
            if (updateMusicFilesCancellation != null)
            {
                updateMusicFilesCancellation.Cancel();
            }
            var cancellation = new CancellationTokenSource();

            updateMusicFilesCancellation = cancellation;
            Logger.Verbose("ManagerController.UpdateMusicFiles:Start");
            managerStatusService.StartUpdatingFilesList();

            musicFiles.Clear();
            var path = ManagerViewModel.FolderBrowser.CurrentPath;

            try
            {
                var filesCount = 0;
                if (Directory.Exists(path))
                {
                    var userSearchFilter        = ManagerViewModel.SearchFilter.UserSearchFilter;
                    var applicationSearchFilter = ManagerViewModel.SearchFilter.ApplicationSearchFilter;
                    var files = await GetFilesAsync(path, folderDepth, userSearchFilter, applicationSearchFilter, cancellation.Token);

                    filesCount = files.Count();

                    var newFiles = files.Select(x => musicFileContext.Create(x)).ToArray();
                    foreach (var newFile in newFiles)
                    {
                        musicFiles.Add(newFile);
                    }

                    if (selectionService.MusicFiles.Any())
                    {
                        selectionService.SelectedMusicFiles.Clear();
                        selectionService.SelectedMusicFiles.Add(selectionService.MusicFiles.First());
                    }
                }
                managerStatusService.FinishUpdatingFilesList(filesCount);
            }
            catch (OperationCanceledException)
            {
                Logger.Verbose("ManagerController.UpdateMusicFiles:Canceled");
            }

            if (cancellation == updateMusicFilesCancellation)
            {
                updateMusicFilesCancellation = null;
            }

            Logger.Verbose("ManagerController.UpdateMusicFiles:End");
        }
コード例 #4
0
        private Task <IReadOnlyList <string> > GetFilesAsync(string directory, FolderDepth folderDepth, string userSearchFilter, string applicationSearchFilter, CancellationToken cancellationToken)
        {
            if (folderDepth == FolderDepth.Shallow)
            {
                fileSystemWatcherService.Path = directory;
                fileSystemWatcherService.EnableRaisingEvents = true;
            }
            else
            {
                fileSystemWatcherService.EnableRaisingEvents = false;
            }

            // It is necessary to run this in an own task => otherwise, reentrance would block the UI thread although this should not happen.
            return(Task.Run(() => GetFilesCore(directory, folderDepth, userSearchFilter, applicationSearchFilter, cancellationToken)));
        }
コード例 #5
0
 private static IReadOnlyList<string> GetFilesCore(string directory, FolderDepth folderDepth, string userSearchFilter, string applicationSearchFilter, 
     CancellationToken cancellationToken)
 {
     // This method is run in an task (not in the UI thread) => static ensures some thread-safety.
     var folder = StorageFolder.GetFolderFromPathAsync(directory).GetResult(cancellationToken);
     var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, SupportedFileTypes.MusicFileExtensions) 
     { 
         UserSearchFilter = userSearchFilter ?? "", 
         ApplicationSearchFilter = applicationSearchFilter ?? "", 
         FolderDepth = folderDepth 
     };
     var result = folder.CreateFileQueryWithOptions(queryOptions);
     
     // It seems that GetFilesAsync does not check the cancellationToken; so get only parts of the file results in a loop.
     Logger.Verbose("ManagerController.UpdateMusicFiles:GetFilesAsync Start");
     List<string> files = new List<string>();
     uint index = 0;
     int resultCount = 0;
     const uint maxFiles = 100;
     do
     {
         var filesResult = result.GetFilesAsync(index, maxFiles).GetResult(cancellationToken);
         resultCount = filesResult.Count;
         files.AddRange(filesResult.Select(x => x.Path));
         index += maxFiles;
     }
     while (resultCount == maxFiles);
     Logger.Verbose("ManagerController.UpdateMusicFiles:GetFilesAsync End");
     return files;
 }
コード例 #6
0
 private Task<IReadOnlyList<string>> GetFilesAsync(string directory, FolderDepth folderDepth, string userSearchFilter, string applicationSearchFilter, CancellationToken cancellationToken)
 {
     if (folderDepth == FolderDepth.Shallow)
     {
         fileSystemWatcherService.Path = directory;
         fileSystemWatcherService.EnableRaisingEvents = true;
     }
     else
     {
         fileSystemWatcherService.EnableRaisingEvents = false;
     }
     
     // It is necessary to run this in an own task => otherwise, reentrance would block the UI thread although this should not happen.
     return Task<IReadOnlyList<string>>.Factory.StartNew(() =>
     {    
         return GetFilesCore(directory, folderDepth, userSearchFilter, applicationSearchFilter, cancellationToken);   
     },
     TaskCreationOptions.LongRunning);
 }
コード例 #7
0
        private async void UpdateMusicFiles(FolderDepth folderDepth)
        {
            if (updateMusicFilesCancellation != null)
            {
                updateMusicFilesCancellation.Cancel();
            }
            var cancellation = new CancellationTokenSource();
            updateMusicFilesCancellation = cancellation;
            Logger.Verbose("ManagerController.UpdateMusicFiles:Start");
            managerStatusService.StartUpdatingFilesList();
            
            musicFiles.Clear();
            var path = ManagerViewModel.FolderBrowser.CurrentPath;
            try
            {
                var filesCount = 0;
                if (Directory.Exists(path))
                {
                    var userSearchFilter = ManagerViewModel.SearchFilter.UserSearchFilter;
                    var applicationSearchFilter = ManagerViewModel.SearchFilter.ApplicationSearchFilter;
                    var files = await GetFilesAsync(path, folderDepth, userSearchFilter, applicationSearchFilter, cancellation.Token);

                    filesCount = files.Count();

                    var newFiles = files.Select(x => musicFileContext.Create(x)).ToArray();
                    foreach (var newFile in newFiles)
                    {
                        musicFiles.Add(newFile);
                    }

                    if (selectionService.MusicFiles.Any())
                    {
                        selectionService.SelectedMusicFiles.Clear();
                        selectionService.SelectedMusicFiles.Add(selectionService.MusicFiles.First());
                    }
                }
                managerStatusService.FinishUpdatingFilesList(filesCount);
            }
            catch (OperationCanceledException)
            {
                Logger.Verbose("ManagerController.UpdateMusicFiles:Canceled");
            }
            
            if (cancellation == updateMusicFilesCancellation)
            {
                updateMusicFilesCancellation = null;
            }

            Logger.Verbose("ManagerController.UpdateMusicFiles:End");
        }
コード例 #8
0
        public static QueryOptions GetQueryOptions(string aqsQuery = null, bool useIndexer = true, FolderDepth folderDepth = FolderDepth.Deep)
        {
            QueryOptions options = new QueryOptions(CommonFileQuery.OrderByName,
                                                    new[] { ".mp3", ".wav", ".ogg", ".flac", ".m4a", ".aif", ".wma", ".aac", ".mp4" });

            options.FolderDepth   = folderDepth;
            options.IndexerOption = useIndexer ? IndexerOption.UseIndexerWhenAvailable : IndexerOption.DoNotUseIndexer;
            options.SetThumbnailPrefetch(ThumbnailMode.MusicView, 512, ThumbnailOptions.ReturnOnlyIfCached);
            options.SetPropertyPrefetch(PropertyPrefetchOptions.MusicProperties, TagReaderHelper.GetExtraPropertiesNames());
            //options.ApplicationSearchFilter += "System.Kind:=System.Kind#Music" + aqsQuery;

            return(options);
        }