public void Activate(CachedFileUpdaterActivatedEventArgs args) { // cache CachedFileUpdaterUI cachedFileUpdaterUI = args.CachedFileUpdaterUI; // Currently, the Desktop device family activates the app in the background. Other device families // use a background task activation. We need to handle both cases. // // We can check to see if there is UI on activation to determine which case we are in, because // we receive the FileUpdateRequest differently. // // If activated in the foreground (visible), then the FileUpdateRequest is passed explicitly as // part of the activation. // // If activated in the background (not visible), then we subscribe to the FileUpdateRequested // and UIRequest events. The FileUpdateRequest is received as part of the FileUpdatedRequested event, // and UIRequested is raised when user input is needed to resolve a conflict. bool isForegroundActivated = (cachedFileUpdaterUI.UIStatus == UIStatus.Visible); if (isForegroundActivated) { fileUpdateRequest = cachedFileUpdaterUI.UpdateRequest; fileUpdateRequestDeferral = cachedFileUpdaterUI.GetDeferral(); } else { cachedFileUpdaterUI.FileUpdateRequested += CachedFileUpdaterUI_FileUpdateRequested; cachedFileUpdaterUI.UIRequested += CachedFileUpdaterUI_UIRequested; } switch (cachedFileUpdaterUI.UpdateTarget) { case CachedFileTarget.Local: scenarios = new List<Scenario> { new Scenario() { Title = "Get latest version", ClassType = typeof(FilePickerContracts.CachedFileUpdater_Local) } }; break; case CachedFileTarget.Remote: scenarios = new List<Scenario> { new Scenario() { Title = "Remote file update", ClassType = typeof(FilePickerContracts.CachedFileUpdater_Remote) } }; break; } if (isForegroundActivated) { Window.Current.Content = this; this.OnNavigatedTo(null); Window.Current.Activate(); } }
void CachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args) { fileUpdateRequest = args.Request; fileUpdateRequestDeferral = fileUpdateRequest.GetDeferral(); switch (cachedFileUpdaterUI.UIStatus) { case UIStatus.Hidden: fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded; fileUpdateRequestDeferral.Complete(); break; case UIStatus.Visible: break; case UIStatus.Unavailable: fileUpdateRequest.Status = FileUpdateStatus.Failed; fileUpdateRequestDeferral.Complete(); break; } }
void CachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args) { fileUpdateRequest = args.Request; fileUpdateRequestDeferral = fileUpdateRequest.GetDeferral(); switch (cachedFileUpdaterUI.UIStatus) { case UIStatus.Hidden: if (fileUpdateRequest.File.Name.Contains("ConflictingFile")) { fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded; } else { fileUpdateRequest.Status = FileUpdateStatus.Complete; } fileUpdateRequestDeferral.Complete(); break; case UIStatus.Visible: break; case UIStatus.Unavailable: fileUpdateRequest.Status = FileUpdateStatus.Failed; fileUpdateRequestDeferral.Complete(); break; } }