Skip to content

mxProject/ClickOnceHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ClickOnceHelper

A helper class that controls version updates by ClickOnce.

Dependency

.NET Framework 4.5

Features

  • 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.

Usage

CheckForUpdate / CheckForUpdateAsync

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

UpdateApplication / UpdateApplicationAsync

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

DownloadFileGroup / DownloadFileGroupAsync

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

Auto download assenmly

// 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");

IClickOnceProgressNotifier

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

Licence

This software is released under the MIT License, see LICENSE.

Authors

mxProject

About

A helper class that controls version updates by ClickOnce.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages