A helper class that controls version updates by ClickOnce.
.NET Framework 4.5
-
Provides async/await asynchronous methods. ApplicationDeployment class provides an asynchronous method of the event callback method, but now I think that the async / await method is more familiar.
-
According to the registered assembly name and download group pairs, download the assembly when the assembly is referenced.
private ClickOnceController m_ClickOnce;
private void CheckForUpdate()
{
try
{
IClickOnceUpdateInfo info = m_ClickOnce.CheckForUpdate();
WriteLog(string.Format("AvailableVersion = {0}", info.AvailableVersion));
WriteLog(string.Format("IsUpdateRequired = {0}", info.IsUpdateRequired));
WriteLog(string.Format("MinimumRequiredVersion = {0}", info.MinimumRequiredVersion));
WriteLog(string.Format("UpdateAvailable = {0}", info.UpdateAvailable));
WriteLog(string.Format("UpdateSizeBytes = {0}", info.UpdateSizeBytes));
}
catch (Exception ex)
{
WriteExceptionLog(ex);
}
}
private async Task CheckForUpdateAsync()
{
try
{
IClickOnceUpdateInfo info = await m_ClickOnce.CheckForUpdateAsync().ConfigureAwait(false);
WriteLog(string.Format("AvailableVersion = {0}", info.AvailableVersion));
WriteLog(string.Format("IsUpdateRequired = {0}", info.IsUpdateRequired));
WriteLog(string.Format("MinimumRequiredVersion = {0}", info.MinimumRequiredVersion));
WriteLog(string.Format("UpdateAvailable = {0}", info.UpdateAvailable));
WriteLog(string.Format("UpdateSizeBytes = {0}", info.UpdateSizeBytes));
}
catch (Exception ex)
{
WriteExceptionLog(ex);
}
}private ClickOnceController m_ClickOnce;
private bool UpdateApplication()
{
try
{
bool result = m_ClickOnce.Update();
WriteLog(result ? "The version of this application has been updated." : "The version of this application was not updated.");
return result;
}
catch (Exception ex)
{
WriteExceptionLog(ex);
return false;
}
}
private async Task<bool> UpdateApplicationAsync()
{
try
{
bool result = await m_ClickOnce.UpdateAsync().ConfigureAwait(false);
WriteLog(result ? "The version of this application has been updated." : "The version of this application was not updated.");
return result;
}
catch (Exception ex)
{
WriteExceptionLog(ex);
return false;
}
}private ClickOnceController m_ClickOnce;
private bool DownloadFileGroup(string groupName)
{
try
{
bool result = m_ClickOnce.DownloadFileGroup(groupName);
WriteLog(string.Format(result ? "The version of '{0}' has been updated." : "The version of '{0}' was not updated.", groupName));
return result;
}
catch (Exception ex)
{
WriteExceptionLog(ex);
return false;
}
}
private async Task<bool> DownloadFileGroupAsync(string groupName)
{
try
{
bool result = await m_ClickOnce.DownloadFileGroupAsync(groupName).ConfigureAwait(false);
WriteLog(string.Format(result ? "The version of '{0}' has been updated." : "The version of '{0}' was not updated.", groupName));
return result;
}
catch (Exception ex)
{
WriteExceptionLog(ex);
return false;
}
}// Specify whether to enable automatic download with the second argument.
ClickOnceController clickOnce = new ClickOnceController(null, true);
// Registers assembly name and download-group name.
clickOnce.RegistAssemblyDownloadGroup("ClassLibrary1", "Group1");
clickOnce.RegistAssemblyDownloadGroup("ClassLibrary2", "Group2");
// Registers file name and download-group name.
clickOnce.RegistFileDownloadGroup("Group3.txt", "Group3");To receive progress, use IClickOnceProgressNotifier interface.
public interface IClickOnceProgressNotifier
{
void Start();
void Progress(IClickOnceProgressInfo progress);
void Complete();
}// Create a notifier instance.
IClickOnceProgressNotifier notifier = new SampleNotifier();
// Specify the notifier instance with the first argument.
ClickOnceController clickOnce = new ClickOnceController(notifier, false);This software is released under the MIT License, see LICENSE.
mxProject