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;
});
}
});
}