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;
        }
예제 #2
0
        public static async Task <Boolean> DownloadPackageUpdatesAsync(IEnumerable <StorePackageUpdate> updates)
        {
            InitStoreContext();

            bool success = false;

            IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = shared._storeContext.RequestDownloadStorePackageUpdatesAsync(updates);

            downloadOperation.Progress = (asyncInfo, progress) =>
            {
                LogProgress(progress);
                UpdateManager.OnDownloadProgress(progress);
            };

            StorePackageUpdateResult result = await downloadOperation.AsTask();

            switch (result.OverallState)
            {
            case StorePackageUpdateState.Completed:
                success = true;
                break;

            case StorePackageUpdateState.OtherError:
                System.Diagnostics.Debug.WriteLine("Error code: " + downloadOperation.ErrorCode);
                break;

            default:
                break;
            }

            return(success);
        }
예제 #3
0
        public static async Task TrySilentDownloadAndInstallAync(IEnumerable <StorePackageUpdate> updates)
        {
            App.LogService.Write("Trying to silently download and install updates...");

            // Check if silent API supported (RS4+)
            if (Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.Services.Store.StoreContext", "TrySilentDownloadAndInstallStorePackageUpdatesAsync"))
            {
                StoreContext             context = GetStoreContext();
                StorePackageUpdateResult result  = await context.TrySilentDownloadAndInstallStorePackageUpdatesAsync(updates).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:
                    App.TelemetryService.WriteEvent("AppUpdateError", new
                    {
                        StorePackageUpdateState = result.OverallState
                    });
                    break;
                }
            }
        }
        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();
            }
        }
예제 #5
0
        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();
            }
        }
예제 #6
0
        public static async Task <StorePackageUpdateState> InstallPackageUpdatesAsync(IEnumerable <StorePackageUpdate> updates)
        {
            IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> installOperation = shared._storeContext.RequestDownloadAndInstallStorePackageUpdatesAsync(updates);

            StorePackageUpdateResult result = await installOperation.AsTask();

            return(result.OverallState);
        }
예제 #7
0
        /// <summary>
        /// Handle the result of the update process and update the UI accordingly.
        /// </summary>
        private async Task HandleUpdateResultAsync(
            IReadOnlyList <StorePackageUpdate> updates, StorePackageUpdateResult result)
        {
            if (result == null)
            {
                VisualStateManager.GoToState(this, this.UpdateFailedState.Name, false);
                Debug.WriteLine($"{this.GetType()}: HandleUpdateResultAsync: result was null");
                return;
            }

            switch (result.OverallState)
            {
            // When the app has updated successfully, attempt to restart it,
            // or show a notification to user and exit.
            case StorePackageUpdateState.Completed: {
                Debug.WriteLine($"{this.GetType()}: HandleUpdateResultAsync: Update successful");
                if (!await this.RestartAppAsync())
                {
                    // We expect the Microsoft Store to show a notification that
                    // the app was updated.
                    CoreApplication.Exit();
                }
                break;
            }

            // If the update was cancelled by the user, allow them to try again.
            case StorePackageUpdateState.Canceled: {
                Debug.WriteLine($"{this.GetType()}: HandleUpdateResultAsync: Update cancelled");
                VisualStateManager.GoToState(this, this.UpdateAvailableState.Name, false);
                break;
            }

            // When the update failed for whatever reason, indicate this to
            // the user and what to do next.
            default: {
                Debug.WriteLine($"{this.GetType()}: HandleUpdateResultAsync: " +
                                $"Update failed {result.OverallState}");
                VisualStateManager.GoToState(this, this.UpdateFailedState.Name, false);

                IEnumerable <StorePackageUpdateStatus> failedUpdates =
                    result.StorePackageUpdateStatuses.Where(
                        status => status.PackageUpdateState != StorePackageUpdateState.Completed);

                foreach (StorePackageUpdateStatus failedUpdate in failedUpdates)
                {
                    Debug.WriteLine($"{this.GetType()}: HandleUpdateResultAsync: " +
                                    $"{failedUpdate.PackageFamilyName} state is {failedUpdate.PackageUpdateState}");
                }
                if (updates.Any(u => u.Mandatory && failedUpdates.Any(
                                    failed => failed.PackageFamilyName == u.Package.Id.FamilyName)))
                {
                    Debug.WriteLine($"{this.GetType()}: HandleUpdateResultAsync: " +
                                    $"Mandatory updates remaining");
                }
                break;
            }
            }
        }
        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 <bool> DownloadPackageUpdatesAsync(IEnumerable <StorePackageUpdate> updates)
        {
            bool downloadedSuccessfully = false;

            // If automatic updates are on, the download will begin, otherwise it may prompt
            IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation =
                updateManager.RequestDownloadStorePackageUpdatesAsync(updates);

            downloadOperation.Progress = async(asyncInfo, progress) =>
            {
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    // Progress gets called once for each progress step of each package.
                    // If you are downloading 10 packages, and each gets 10 notifications...
                    // You will receive 100 progress updates.
                    ShowProgress(
                        updates.SingleOrDefault(update => update.Package.Id.FamilyName == progress.PackageFamilyName),
                        progress);
                });
            };

            // Wait for the download operation to complete
            StorePackageUpdateResult result = await downloadOperation.AsTask();

            switch (result.OverallState)
            {
            case StorePackageUpdateState.Completed:
                // Everything worked, now ready to install the updates.
                downloadedSuccessfully = true;
                break;

            default:
                // The overall progress didn't complete
                // Find failed updates
                var failedUpdates = result.StorePackageUpdateStatuses.Where(status => status.PackageUpdateState != StorePackageUpdateState.Completed);

                // See if any failed updates were mandatory
                if (updates.Any(u => u.Mandatory && failedUpdates.Any(failed => failed.PackageFamilyName == u.Package.Id.FamilyName)))
                {
                    // At least one of the updates is mandatory, so tell the user.
                    ShowMandatoryMessage();
                }
                break;
            }

            return(downloadedSuccessfully);
        }
예제 #10
0
        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);
            });
        }
예제 #11
0
        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));
        }
예제 #12
0
        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);
        }
예제 #13
0
        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();
                }
            }
        }
        private async Task InstallPackageUpdatesAsync(IEnumerable <StorePackageUpdate> updates)
        {
            // This will prompt the user with a dialog depending on the state:
            //      Download and Install these updates? (size, etc)
            //      Install these updates?
            IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> installOperation =
                updateManager.RequestDownloadAndInstallStorePackageUpdatesAsync(updates);

            // Note: This has "progress" as it can download if necessary
            // Since we separated our download and install into two steps, we won't have anything to download
            // and the download part will complete immediately.  If we hadn't done that, then we would get progress
            // notifications as the package was downloaded.
            StorePackageUpdateResult result = await installOperation.AsTask();

            await new MessageDialog("Installing...").ShowAsync();

            switch (result.OverallState)
            {
            case StorePackageUpdateState.Completed:
                // Should never hit for this sample. The install kills the app.
                break;

            default:

                // The install failed for some reason
                // Find failed updates
                var failedUpdates = result.StorePackageUpdateStatuses.Where(status => status.PackageUpdateState != StorePackageUpdateState.Completed);

                // See if any failed updates were mandatory
                if (updates.Any(u => u.Mandatory && failedUpdates.Any(failed => failed.PackageFamilyName == u.Package.Id.FamilyName)))
                {
                    // At least one of the updates is mandatory, so tell the user.
                    ShowMandatoryMessage();
                }
                break;

                //await new MessageDialog("Here 3").ShowAsync();
            }
        }
예제 #15
0
        /// <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);
            }
        }
예제 #16
0
        private static async Task CheckForUpdatesAsync()
        {
            //https://docs.microsoft.com/en-us/windows/uwp/packaging/self-install-package-updates
            if (NepApp.Network.IsConnected && NepApp.Network.NetworkUtilizationBehavior == NepAppNetworkManager.NetworkDeterminedAppBehaviorStyle.Normal)
            {
                var storeContext = Windows.Services.Store.StoreContext.GetDefault();

                if (storeContext != null)
                {
                    var updates = await storeContext.GetAppAndOptionalStorePackageUpdatesAsync();

                    if (updates.Count > 0)
                    {
                        if (await NepApp.UI.ShowYesNoDialogAsync("Updates available!", "There is an update to this application available. Would you like to install it?") == true)
                        {
                            var dialogController = await NepApp.UI.Overlay.ShowProgressDialogAsync("Update in progress", "Downloading updates....");

                            //download the updates

                            IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = storeContext.RequestDownloadStorePackageUpdatesAsync(updates);
                            downloadOperation.Progress = async(asyncInfo, progress) =>
                            {
                                await App.Dispatcher.RunWhenIdleAsync(() =>
                                {
                                    dialogController.SetDeterminateProgress(progress.PackageDownloadProgress);
                                });
                            };

                            var downloadResults = await downloadOperation.AsTask();

                            await dialogController.CloseAsync();

                            if (downloadResults.OverallState == StorePackageUpdateState.Completed)
                            {
                                //continue to installing updates
                                dialogController = await NepApp.UI.Overlay.ShowProgressDialogAsync("Update in progress", "Installing updates....");

                                dialogController.SetIndeterminate();
                                IAsyncOperationWithProgress <StorePackageUpdateResult, StorePackageUpdateStatus> installOperation = storeContext.RequestDownloadAndInstallStorePackageUpdatesAsync(updates);

                                StorePackageUpdateResult result = await installOperation.AsTask();

                                switch (result.OverallState)
                                {
                                case StorePackageUpdateState.Completed:
                                    await NepApp.UI.ShowInfoDialogAsync("Update successfull", "Please restart this application. This application will now close.");

                                    Application.Current.Exit();
                                    break;

                                default:
                                    // Get the failed updates.
                                    var failedUpdates = result.StorePackageUpdateStatuses.Where(
                                        status => status.PackageUpdateState != StorePackageUpdateState.Completed);

                                    await NepApp.UI.Overlay.ShowSnackBarMessageAsync("Updates failed to install.");

                                    break;
                                }
                            }
                            else
                            {
                                await NepApp.UI.Overlay.ShowSnackBarMessageAsync("Updates failed to download.");
                            }
                        }
                    }
                }
            }
        }