public static async Task <bool> DownloadUpdatesAsync(IEnumerable <StorePackageUpdate> updates) { App.LogService.Write("Downloading app updates..."); bool success = false; StoreContext context = GetStoreContext(); IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = context.RequestDownloadStorePackageUpdatesAsync(updates); downloadOperation.Progress = (asyncInfo, progress) => { LogProgress(progress); OnUpdateDownloadProgress?.Invoke(null, new StorePackageUpdateStatusEventArgs() { Status = progress }); }; StorePackageUpdateResult result = await downloadOperation.AsTask(); switch (result.OverallState) { case StorePackageUpdateState.Completed: success = true; break; case StorePackageUpdateState.Canceled: case StorePackageUpdateState.Deploying: case StorePackageUpdateState.Downloading: case StorePackageUpdateState.Pending: break; default: OnUpdateOperationError?.Invoke(null, new StorePackageUpdateStateEventArgs() { State = result.OverallState }); break; } OnUpdatesRefresh?.Invoke(null, new UpdateRefreshEventArgs(UpdateStage.Download, success)); return(success); }
public static async Task InstallUpdatesAsync(IEnumerable <StorePackageUpdate> updates) { App.LogService.Write("Installing updates..."); IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> installOperation = null; StoreContext context = GetStoreContext(); installOperation = context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); installOperation.Progress = (asyncInfo, progress) => { LogProgress(progress); OnUpdateInstallProgress?.Invoke(null, new StorePackageUpdateStatusEventArgs() { Status = progress }); }; StorePackageUpdateResult result = await installOperation.AsTask(); switch (result.OverallState) { case StorePackageUpdateState.Completed: // Should never hit this state as the install process will terminate the app App.LogService.Write("App should have terminated in order to begin app install..."); break; case StorePackageUpdateState.Canceled: case StorePackageUpdateState.Deploying: case StorePackageUpdateState.Downloading: case StorePackageUpdateState.Pending: break; default: OnUpdateOperationError?.Invoke(null, new StorePackageUpdateStateEventArgs() { State = result.OverallState }); break; } OnUpdatesRefresh?.Invoke(null, new UpdateRefreshEventArgs(UpdateStage.Install, false)); }
public static async Task <IEnumerable <StorePackageUpdate> > FetchUpdatesAsync() { App.LogService.Write("Fetching app updates..."); var context = GetStoreContext(); IEnumerable <StorePackageUpdate> updates; try { updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); PendingUpdatesCount = updates.Count(); App.LogService.Write("Pending app updates: " + PendingUpdatesCount); } catch (Exception ex) { App.LogService.WriteException(ex); return(null); } OnUpdatesRefresh?.Invoke(null, new UpdateRefreshEventArgs(UpdateStage.Fetch, true, updates)); return(updates); }