public void Start() { lock (_lock) { if (IsDownloading) { return; } if (_downloadQueue == null) { _downloadQueue = new OfflineDownloadQueue(); _downloadQueue.DownloadCompleted += OfflineDownload_Completed; _downloadQueue.ContentDownloadCompleted += OfflineContentDownload_Completed; } if (App.Settings.OfflineContentManager.DownloadQueue.Count > 0) { DisableIdleDetection(); IsDownloading = true; _downloadQueue.SetDownloadContents(App.Settings.OfflineContentManager.DownloadQueue); _downloadQueue.StartDownload(App.WebSession.CreateWebClient(), null); } } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { PageHelper.InitAdControl(AdGrid); var parameters = NavigationContext.QueryString; String _url = null; String _type = null; String _name = null; if (parameters.ContainsKey("Type")) { _type = parameters["Type"].ToLower(); } if (parameters.ContainsKey("Url")) { _url = parameters["Url"].ToLower(); } if (parameters.ContainsKey("Name")) { _name = parameters["Name"].ToLower(); } else { _name = "离线内容"; } if (State.ContainsKey("DownloadCompleted")) { _downloadCompleted = (bool)State["DownloadCompleted"]; } MitbbsOfflineContentType contentType = MitbbsOfflineContentType.Unknown; if (_downloader == null) { if (_type == "home") { contentType = MitbbsOfflineContentType.Home; } else if (_type == "userhome") { contentType = MitbbsOfflineContentType.UserHome; } else if (_type == "board") { contentType = MitbbsOfflineContentType.Board; } else if (_type == "clubboard") { contentType = MitbbsOfflineContentType.ClubBoard; } else if (_type == "topic") { contentType = MitbbsOfflineContentType.Topic; } else if (_type == "clubtopic") { contentType = MitbbsOfflineContentType.ClubTopic; } if (_url != null && !App.Settings.OfflineContentManager.AddContentToQueue(_url, _name, contentType)) { MessageBox.Show("无法识别离线内容的类型", "无法添加离线内容到下载队列", MessageBoxButton.OK); NavigationService.GoBack(); return; } else { if (_url != null) { App.Settings.SaveToStorage(); MessageBoxResult result = MessageBox.Show("现在开始下载下载队列中的所有内容吗?如果选择关闭,你可以之后在离线内容页面里选择继续下载队列中的项目。", "离线内容已成功添加至队列", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { _downloadCompleted = true; NavigationService.GoBack(); } } _downloader = new OfflineDownloadQueue(); } } else if (_downloader.IsDownloading) { DisableIdleDetection(); } if (_downloader != null && !_downloadCompleted && !_downloader.IsDownloading) { StartDownload(); } UpdateButtonStates(); }
private void OfflineContentDownload_Completed(object sender, OfflineDownloadQueue.DownloadQueueContentCompletedEventArgs e) { if (e.Success) { App.Settings.OfflineContentManager.MoveQueuedContentToIndex(e.Content); App.Settings.SaveToStorage(); } }
private void OfflineContentDownload_Completed(object sender, OfflineDownloadQueue.DownloadQueueContentCompletedEventArgs e) { if (e.Success) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke( () => { App.Settings.OfflineContentManager.MoveQueuedContentToIndex(e.Content); App.Settings.SaveToStorage(); } ); } else { if (AppUtil.AppInfo.IsNetworkConnected()) { e.Content.Failed = true; System.Windows.Deployment.Current.Dispatcher.BeginInvoke( () => { App.Settings.OfflineContentManager.MoveQueuedContentToIndex(e.Content); App.Settings.SaveToStorage(); } ); } else { e.Content.Failed = false; } } }