예제 #1
0
        public async System.Threading.Tasks.Task<uint> BrowseFolder(StorageFolder folder)
        {
            //     LogMessage("Discover folder Name: " + folder.Name + " Path: " + folder.Path + " files: [" + fileDiscovered + "] folders: [" + folderDiscovered + "]");
            folderDiscovered++;
            if (ProgressEvent != null)
                ProgressEvent(folderDiscovered);

            await System.Threading.Tasks.Task.Delay(100);
            try
            {

                if (discoverCancelToken != null)
                    if (discoverCancelToken.Token.IsCancellationRequested)
                        discoverCancelToken.Token.ThrowIfCancellationRequested();
                IReadOnlyList<StorageFolder> folders = await folder.GetFoldersAsync(CommonFolderQuery.DefaultQuery);
                foreach (var f in folders)
                {
                    if (discoverCancelToken != null)
                        if (discoverCancelToken.Token.IsCancellationRequested)
                            discoverCancelToken.Token.ThrowIfCancellationRequested();
                    uint value = await BrowseFolder(f);
                }
            }
            catch (Exception e)
            {
                LogMessage("Discover folder exception: " + folder.Path + " Exception:" + e.Message);
            }
            uint currentFilesDiscovered = fileDiscovered;
            try
            {
                if (discoverCancelToken != null)
                    if (discoverCancelToken.Token.IsCancellationRequested)
                        discoverCancelToken.Token.ThrowIfCancellationRequested();
                //                IReadOnlyList<StorageFile> files = await folder.GetFilesAsync(CommonFileQuery.OrderByName);
                IReadOnlyList<StorageFile> files = await folder.GetFilesAsync(CommonFileQuery.DefaultQuery);
                foreach (var f in files)
                {
                    if (discoverCancelToken != null)
                        if (discoverCancelToken.Token.IsCancellationRequested)
                            discoverCancelToken.Token.ThrowIfCancellationRequested();
                    string path = await GetPath(f);
                    string extension = f.FileType;
                    foreach (string e in extensionArray)
                    {
                        if (extension.EndsWith(e, StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (!defaultMediaDictionary.ContainsKey(path))
                            {
                                MediaLibraryItem mli = new MediaLibraryItem(path);
                                defaultMediaDictionary.Add(path, mli);
                                fileDiscovered = (uint)defaultMediaDictionary.Count;
                            }
                            UpdateUI();
                            //statusValue.Text = fileDiscovered.ToString() + " files discovered";
                          //  LogMessage("Discover file name: " + f.Name + " path: " + path);
                            break;
                        }

                    }
                }
            }
            catch (Exception e)
            {
                LogMessage("Discover files exception: " + folder.Path + " Exception:" + e.Message);
            }
            if (currentFilesDiscovered != fileDiscovered)
            {
                UpdateCounter();
            }
            return fileDiscovered;
        }
예제 #2
0
 public static MediaLibraryItem GetMediaIteamFromPath(string path)
 {
     MediaLibraryItem mi = new MediaLibraryItem(path);
     return mi;
 }