private async void Button_Click_Update_Blocking(object sender, RoutedEventArgs e) { try { // Block trying to get all updates updates = await updateManager.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count > 0) { TotalProgressBar.Visibility = Visibility.Visible; // Trigger download and monitor progress IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = updateManager.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); downloadOperation.Progress = async(asyncInfo, progress) => { await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { TotalProgressBar.Value = progress.TotalDownloadProgress * 100; }); }; // Wait for download and install to complete StorePackageUpdateResult result = await downloadOperation.AsTask(); } } catch (Exception ex) { await new MessageDialog("Unable to perform simple blocking update. {" + err(ex) + "}").ShowAsync(); } }
public async void CheckForUpdatesAsync(bool mandatoryOnly = true) { try { if (context == null) { context = await Task.Run(() => StoreContext.GetDefault()); } var updateList = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (mandatoryOnly) { updateList = updateList.Where(e => e.Mandatory).ToList(); } if (updateList.Count > 0) { if (await DownloadUpdatesConsent()) { await DownloadUpdates(updateList); } } } #if !DEBUG catch (Exception ex) { App.Logger.Warn(ex, "Could not fetch updates."); } #else catch (Exception) { } #endif }
public async void CheckForUpdatesAsync(bool mandantoryOnly = true) { try { if (context == null) { context = StoreContext.GetDefault(); } UpdateList = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (mandantoryOnly) { UpdateList = (IReadOnlyList <StorePackageUpdate>)UpdateList.Where(e => e.Mandatory); } if (UpdateList.Count > 0) { if (await DownloadUpdatesConsent()) { DownloadUpdates(); } } } catch (Exception) { } }
private async Task StartAppSelfUpdate() { Debug.WriteLine("Check for updates..."); StoreContext context = StoreContext.GetDefault(); // Check for updates... string lastCheck = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ"); ReportSelfUpdateStatus(lastCheck, "checkStarting"); IReadOnlyList <StorePackageUpdate> updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count == 0) { ReportSelfUpdateStatus(lastCheck, "noUpdates"); return; } // Download and install the updates... IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); ReportSelfUpdateStatus(lastCheck, "updatesDownloadingAndInstalling"); // Wait for completion... StorePackageUpdateResult result = await downloadOperation.AsTask(); ReportSelfUpdateStatus(lastCheck, result.OverallState == StorePackageUpdateState.Completed ? "installed" : "failed"); return; }
/// <summary> /// check for update as an asynchronous operation. /// </summary> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public async Task <bool> CheckForUpdateAsync() { var result = false; try { updates = null; if (context is null) { context = StoreContext.GetDefault(); } updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count > 0) { result = true; } } catch (Exception) { result = false; } return(result); }
public async Task CheckForUpdatesAsync() { if (context == null) { context = StoreContext.GetDefault(); } IReadOnlyList <StorePackageUpdate> updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count > 0) { MessageDialog dialog = new MessageDialog("There is a new update available.", "Download and Install?"); dialog.Commands.Add(new UICommand("Open Store")); dialog.Commands.Add(new UICommand("Cancel")); IUICommand command = await dialog.ShowAsync(); if (command.Label.Equals("Open Store", StringComparison.CurrentCultureIgnoreCase)) { bool result = await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store://pdp/?productid=9PCFMSX2G386")); } } else { MessageDialog dialog = new MessageDialog("No new updates found.", "You're Good"); dialog.Commands.Add(new UICommand("Close")); IUICommand command = await dialog.ShowAsync(); } }
public async Task DownloadAndInstallAllUpdatesAsync() { UpdateRing.IsActive = true; CheckUpdate.IsEnabled = false; if (context == null) { context = StoreContext.GetDefault(); } // Get the updates that are available. IReadOnlyList <StorePackageUpdate> updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count > 0) { // Alert the user that updates are available and ask for their consent // to start the updates. MessageDialog dialog = new MessageDialog( "立即下载并安装更新吗? 此过程应用可能会关闭。", "发现新版本的夏日!"); dialog.Commands.Add(new UICommand("更新")); dialog.Commands.Add(new UICommand("取消")); IUICommand command = await dialog.ShowAsync(); if (command.Label.Equals("更新", StringComparison.CurrentCultureIgnoreCase)) { //downloadProgressBar.Visibility = Visibility.Visible; // Download and install the updates. IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); // The Progress async method is called one time for each step in the download // and installation process for each package in this request. downloadOperation.Progress = async(asyncInfo, progress) => { await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { }); }; //downloadProgressBar.Visibility = Visibility.Collapsed; StorePackageUpdateResult result = await downloadOperation.AsTask(); UpdateRing.IsActive = false; CheckUpdate.IsEnabled = true; } else { UpdateRing.IsActive = false; CheckUpdate.IsEnabled = true; } } else { UpdateRing.IsActive = false; CheckUpdate.IsEnabled = true; PopupNotice popupNotice = new PopupNotice("已是最新版本!"); popupNotice.ShowAPopup(); } }
async Task <bool> PlatformCheckForMandatoryUpdates() { context = context ?? StoreContext.GetDefault(); var updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); return(updates.FirstOrDefault(u => u.Mandatory) != null); }
async Task <bool> PlatformCheckForUpdates() { context = context ?? StoreContext.GetDefault(); var updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); return(updates.Count > 0); }
async Task PlatformDownloadAndInstallUpdates() { context = context ?? StoreContext.GetDefault(); var updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count > 0) { await context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); } }
private async void GetEasyUpdates() { StoreContext updateManager = StoreContext.GetDefault(); IReadOnlyList <StorePackageUpdate> updates = await updateManager.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count > 0) { IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = updateManager.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); StorePackageUpdateResult result = await downloadOperation.AsTask(); } }
private async Task InternalStartDmAppStoreUpdateAsync(string jsonParamString) { Logger.Log("InternalStartDmAppStoreUpdateAsync() invoked.", LoggingLevel.Verbose); await Helpers.EnsureErrorsLogged(_deviceManagementClient, PropertySectionName, async() => { // Report to the device twin StatusSection status = new StatusSection(StatusSection.StateType.Pending); await _deviceManagementClient.ReportStatusAsync(PropertySectionName, status); StoreContext context = StoreContext.GetDefault(); // Check for updates... string lastCheck = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ"); await ReportResponse(DmAppStoreUpdateDataContract.JSonChecking, lastCheck); IReadOnlyList <StorePackageUpdate> updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count == 0) { await ReportResponse(DmAppStoreUpdateDataContract.JSonNoUpdates, lastCheck); return; } // Download and install the updates... IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); await ReportResponse(DmAppStoreUpdateDataContract.JsonDownloadingAndInstalling, lastCheck); // Wait for completion... StorePackageUpdateResult result = await downloadOperation.AsTask(); string resultString = result.OverallState == StorePackageUpdateState.Completed ? DmAppStoreUpdateDataContract.JsonInstalled : DmAppStoreUpdateDataContract.JsonFailed; await ReportResponse(resultString, lastCheck); // Report to the device twin status.State = StatusSection.StateType.Completed; await _deviceManagementClient.ReportStatusAsync(PropertySectionName, status); }); }
public void PreLoadStoreData() { PreLoadTask = Task.Factory.StartNew(() => { try { Store = StoreContext.GetDefault(); Store.OfflineLicensesChanged += Store_OfflineLicensesChanged; License = Store.GetAppLicenseAsync().AsTask().Result; ProductResult = Store.GetStoreProductForCurrentAppAsync().AsTask().Result; Updates = Store.GetAppAndOptionalStorePackageUpdatesAsync().AsTask().Result; } catch (Exception ex) { LogTracer.Log(ex, "Could not load MSStore data"); } }, TaskCreationOptions.LongRunning); }
public async Task <StorePackageUpdateState> DownloadAndInstallMostRecentVersionAsync() { if (_storeContext == null) { return(StorePackageUpdateState.OtherError); } // Get available updates. var updates = await _storeContext.GetAppAndOptionalStorePackageUpdatesAsync(); if ((updates?.Count ?? 0) < 1) { return(StorePackageUpdateState.OtherError); // No updates were found } // Content verification. foreach (var update in updates) { if (!await update.Package.VerifyContentIntegrityAsync()) { return(StorePackageUpdateState.OtherError); } } // Download and install. // This method will automatically show a consent dialog. var downloadOperation = _storeContext.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); // Show the message dialog. var result = await downloadOperation.AsTask(); switch (result.OverallState) { case StorePackageUpdateState.OtherError: MessageDialog mdialog = new MessageDialog("An app update was detected, but may still be unavailable to download. Please try updating again at a later time."); mdialog.Commands.Add(new UICommand("Close this dialog")); IUICommand command = await mdialog.ShowAsync(); break; } return(result.OverallState); }
private async Task CheckForUpdates() { if (context == null) { context = StoreContext.GetDefault(); } // Get the updates that are available. IReadOnlyList <StorePackageUpdate> updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); if (updates.Count > 0) { // Alert the user that updates are available and ask for their consent // to start the updates. MessageDialog dialog = new MessageDialog( "Download and install updates now? This may cause the application to exit.", "There's an update available!"); dialog.Commands.Add(new UICommand("Yes")); dialog.Commands.Add(new UICommand("No")); IUICommand command = await dialog.ShowAsync(); if (command.Label.Equals("Yes", StringComparison.CurrentCultureIgnoreCase)) { // Download and install the updates. IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); // The Progress async method is called one time for each step in the download // and installation process for each package in this request. //downloadOperation.Progress = async (asyncInfo, progress) => //{ // await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, // () => // { // downloadProgressBar.Value = progress.PackageDownloadProgress; // }); //}; StorePackageUpdateResult result = await downloadOperation.AsTask(); } } }
/// <summary> /// Start the update process and change the UI accordingly. /// </summary> private async Task DoUpdateAsync() { VisualStateManager.GoToState(this, this.UpdateInstallingState.Name, false); try { StoreContext context = StoreContext.GetDefault(); await this.CancelQueuedUpdatesAsync(context); IReadOnlyList <StorePackageUpdate> updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); StorePackageUpdateResult download = await this.DownloadAllUpdatesAsync(context, updates); Debug.WriteLine($"{this.GetType()}: DoUpdateAsync: " + $"Download result {download.OverallState}"); // Only abort the process if the user explicitly cancelled. If there were // failures, the next step *should* handle it. if (download.OverallState == StorePackageUpdateState.Canceled) { VisualStateManager.GoToState(this, this.UpdateAvailableState.Name, false); return; } StorePackageUpdateResult result = await this.InstallAllUpdatesAsync(context, updates); await this.HandleUpdateResultAsync(updates, result); // If anything fails, go straight to the Failed state. } catch (Exception e) { Debug.WriteLine($"{this.GetType()}: DoUpdateAsync: Caught {e}"); VisualStateManager.GoToState(this, this.UpdateFailedState.Name, false); } }