예제 #1
0
 /// <summary>
 /// 添加一个DownloadBar到主界面,为了避免线程问题写在这里
 /// 这段代码包含建立下载器的细节
 /// </summary>
 public async void AddDownloadBar(AbstractDownloader downloader)
 {
     GC.Collect();
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         DownloadBar db = new DownloadBar();
         DownloadBarCollection.Add(db);
         db.SetDownloader(downloader);
     });
 }
예제 #2
0
        private async void InitializeAsync()
        {
            //恢复上次关闭时保存的控件
            var list = await TXDataFileIO.GetMessagesAsync();

            if (list != null)
            {
                foreach (Models.DownloaderMessage ms in list)
                {
                    DownloadBar db = new DownloadBar();
                    DownloadBarCollection.Add(db);
                    AbstractDownloader dw = AbstractDownloader.GetDownloaderFromType(ms.DownloaderType);
                    db.SetDownloader(dw);
                    dw.SetDownloaderFromBreakpoint(ms);
                }
            }

            if (Settings.DownloadsFolderToken == null)
            {
                var contentDialog = new ContentDialog()
                {
                    Title               = Strings.AppResources.GetString("DownloadFolderPathIllegal"),
                    Content             = Strings.AppResources.GetString("SetDownloadFolder"),
                    PrimaryButtonText   = Strings.AppResources.GetString("Select"),
                    SecondaryButtonText = Strings.AppResources.GetString("Cancel"),
                    FullSizeDesired     = false,
                };

                contentDialog.PrimaryButtonClick += async(sender, e) =>
                {
                    var folderPicker = new FolderPicker();
                    folderPicker.FileTypeFilter.Add(".");
                    StorageFolder folder = null;
                    folder = await folderPicker.PickSingleFolderAsync();

                    if (folder == null)
                    {
                        App.Current.Exit();
                    }
                    else
                    {
                        Settings.DownloadsFolderToken = StorageApplicationPermissions
                                                        .MostRecentlyUsedList.Add(folder);
                    }
                };

                contentDialog.SecondaryButtonClick += (sender, e) =>
                                                      App.Current.Exit();

                await contentDialog.ShowAsync();
            }
        }
예제 #3
0
        private async void InitializeAsync()
        {
            DownloadBarCollection.CollectionChanged += DownloadBarCollection_CollectionChanged;//订阅内容变化事件
            //恢复上次关闭时保存的控件
            var list = await StorageManager.GetMessagesAsync();

            if (list != null)
            {
                foreach (Models.DownloaderMessage ms in list)
                {
                    DownloadBar db = new DownloadBar();
                    DownloadBarCollection.Add(db);
                    AbstractDownloader dw = AbstractDownloader.GetDownloaderFromType(ms.DownloaderType);
                    db.SetDownloader(dw);
                    dw.SetDownloaderFromBreakpoint(ms);
                }
            }
        }