public async Task ChangeOfficeChannel() { await Task.Run(async () => { var installOffice = new InstallOffice(); try { installOffice = new InstallOffice(); installOffice.UpdatingOfficeStatus += installOffice_UpdatingOfficeStatus; var newChannel = ""; Dispatcher.Invoke(() => { UpdateStatus.Content = "Updating..."; newChannel = ((OfficeBranch) ProductBranch.SelectedItem).NewName; ChangeChannel.IsEnabled = false; NewVersion.IsEnabled = false; }); SetItemState(LocalViewItem.Update, LocalViewState.Wait); var ppDownloader = new ProPlusDownloader(); var baseUrl = await ppDownloader.GetChannelBaseUrlAsync(newChannel, OfficeEdition.Office32Bit); if (string.IsNullOrEmpty(baseUrl)) throw (new Exception(string.Format("Cannot find BaseUrl for Channel: {0}", newChannel))); var channelToChangeTo = ""; if (NewVersionRow.Visibility != Visibility.Visible) { channelToChangeTo = await ppDownloader.GetLatestVersionAsync(newChannel, OfficeEdition.Office32Bit); } else { Dispatcher.Invoke(() => { var manualVersion = NewVersion.Text; if (string.IsNullOrEmpty(manualVersion) && NewVersion.SelectedItem != null) { manualVersion = ((Build)NewVersion.SelectedItem).Version; } if (!string.IsNullOrEmpty(manualVersion)) { channelToChangeTo = manualVersion; } }); } if (string.IsNullOrEmpty(channelToChangeTo)) { throw (new Exception("Version required")); } else { if (!channelToChangeTo.IsValidVersion()) { throw (new Exception(string.Format("Invalid Version: {0}", channelToChangeTo))); } } await installOffice.ChangeOfficeChannel(channelToChangeTo, baseUrl); Dispatcher.Invoke(() => { UpdateStatus.Content = ""; }); var installGenerator = new OfficeInstallManager(); LocalInstall = await installGenerator.CheckForOfficeInstallAsync(); if (LocalInstall.Installed) { Dispatcher.Invoke(() => { VersionLabel.Content = LocalInstall.Version; ChannelLabel.Content = LocalInstall.Channel; ProductBranch.SelectedItem = LocalInstall.Channel; }); if (LocalInstall.LatestVersionInstalled) { SetItemState(LocalViewItem.Update, LocalViewState.Success); } else { SetItemState(LocalViewItem.Update, LocalViewState.Action); Dispatcher.Invoke(() => { UpdateStatus.Content = "New version available (" + LocalInstall.LatestVersion + ")"; }); } } } catch (Exception ex) { SetItemState(LocalViewItem.Update, LocalViewState.Fail); Dispatcher.Invoke(() => { UpdateStatus.Content = "The update failed"; ErrorText.Text = ex.Message; RetryButtonColumn.Width = new GridLength(0, GridUnitType.Pixel); }); LogErrorMessage(ex); } finally { Dispatcher.Invoke(() => { ChangeChannel.IsEnabled = true; NewVersion.IsEnabled = true; }); } }); }
public async Task RunUpdateOffice() { await Task.Run(async () => { InstallOffice installOffice = null; try { installOffice = new InstallOffice(); installOffice.UpdatingOfficeStatus += installOffice_UpdatingOfficeStatus; Dispatcher.Invoke(() => { UpdateStatus.Content = "Updating..."; ShowVersion.IsEnabled = false; ChangeChannel.IsEnabled = false; }); GlobalObjects.ViewModel.BlockNavigation = true; SetItemState(LocalViewItem.Update, LocalViewState.Wait); var currentChannel = LocalInstall.Channel; if (!installOffice.IsUpdateRunning()) { var ppDownloader = new ProPlusDownloader(); var baseUrl = await ppDownloader.GetChannelBaseUrlAsync(currentChannel, OfficeEdition.Office32Bit); if (string.IsNullOrEmpty(baseUrl)) throw (new Exception(string.Format("Cannot find BaseUrl for Channel: {0}", currentChannel))); installOffice.ChangeUpdateSource(baseUrl); } SetSelectedVersion(); await installOffice.RunOfficeUpdateAsync(LocalInstall.LatestVersion); Dispatcher.Invoke(() => { UpdateStatus.Content = ""; }); var installGenerator = new OfficeInstallManager(); LocalInstall = await installGenerator.CheckForOfficeInstallAsync(); if (LocalInstall.Installed) { Dispatcher.Invoke(() => { VersionLabel.Content = LocalInstall.Version; ChannelLabel.Content = LocalInstall.Channel; ProductBranch.SelectedItem = LocalInstall.Channel; }); if (LocalInstall.LatestVersionInstalled) { SetItemState(LocalViewItem.Update, LocalViewState.Success); } else { SetItemState(LocalViewItem.Update, LocalViewState.Action); Dispatcher.Invoke(() => { UpdateStatus.Content = "New version available (" + LocalInstall.LatestVersion + ")"; }); } } } catch (Exception ex) { SetItemState(LocalViewItem.Update, LocalViewState.Fail); Dispatcher.Invoke(() => { UpdateStatus.Content = "The update failed"; ErrorText.Text = ex.Message; }); LogErrorMessage(ex); } finally { installOffice.ResetUpdateSource(); Dispatcher.Invoke(() => { ShowVersion.IsEnabled = true; ChangeChannel.IsEnabled = true; }); GlobalObjects.ViewModel.BlockNavigation = false; } }); }