Ejemplo n.º 1
0
        private async Task<int> GetSongs(string tempPath, double percent, int total)
        {
            StorageFolder tempFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(tempPath);
            IReadOnlyList<IStorageFile> AllList = await SearchAllinFolder(tempFolder);
            int count = AllList.Count;
            int index = albumList.Count;
            int progress = 0;
            if (count == 0)
            {
                OnProgressChanged(1 / total, percent);
                return 0;
            }
            foreach (StorageFile tempFile in AllList)
            {
                if (tempTypeStrings.Contains(tempFile.FileType))
                {
                    Song song = new Song(tempFile, tempPath);
                    await song.initial();
                    await AddtoAlbum_first(song);
                }
                progress++;
                OnProgressChanged((double)progress / ((double)count * total), percent);
            }
            foreach (AlbumItem item in albumList)
            {
                await item.Refresh();
            }
            List<AlbumItem> afterList = albumList.ToList();
            afterList.RemoveRange(0, index);
#pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
            Task.Run(() =>
             {
                 saveAlbumstoStorage(afterList, tempPath);
             });
#pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
            return count;
        }
Ejemplo n.º 2
0
 public async Task RefreshtoList(KeyValuePair<string, List<IStorageFile>> item)
 {
     if (Refreshing == true && NowRefreshKeys.Contains(item.Key))
         return;
     Refreshing = true;
     NowRefreshKeys.Add(item.Key);
     int index = albums.Count;
     string tempPath = item.Key;
     foreach (IStorageFile tempFile in item.Value)
     {
         if (tempTypeStrings.Contains(tempFile.FileType))
         {
             Song song = new Song((StorageFile)tempFile, tempPath);
             await song.initial();
             await AddtoAlbum_first(song);
         }
     }
     foreach (AlbumItem album in albumList)
     {
         await album.Refresh();
     }
     List<AlbumItem> afterList = albumList.ToList();
     afterList.RemoveRange(0, index);
     albums.AddRange(afterList);
     this.OnNotifyRefresh("finish");
     ThreadPool.RunAsync((work) =>
     {
         RefreshAlbumstoStorage(afterList, tempPath);
     });
     NowRefreshKeys.Remove(item.Key);
 }