Archive

Archive for the ‘Deployment’ Category

Click-Once Deployment

July 18, 2011 Leave a comment

Deployment is the process by which you distribute a finished application or component to be installed on other computers. In Visual Studio 2010, you can deploy applications or components by using either ClickOnce deployment or Windows Installer deployment technology.

ClickOnce is a specially designed for smart client applications. It is very easy to develop and maintain. Once in place lot of time can be saved to distribute the application to the end users and turns out to be a very low cost solution.

There are two ways in which you can introduce it to your applications.

  1. Automatic Updates
  2. Using Click-Once API

Automatic Updates
In Visual Studio project properties you will see the Publish tab, where you will get various options to configure automatic updates. Following is the snapshot which depicts the same.

Automatic updates
Automatic updates
The automatic update has one problem in it. If you skip the update notification next time it won’t popup the notification for you. That means if the update is critical you may need to uninstall the application and the install form the server location. Also if you rollback the installation (can be done from Add/Remove Program) you won’t get the notification for latest update. But it can be solved by ClickOnce version number. That means you can tell your smart client application that user need to have minimum version at their machine to run.

ClickOnce API
For much more extensibility and to overcome the anomalies with Automatic Updates. We can use ClickOnce API.  Following sample shows a class implementation which will handle auto updates. Using API you can make updates on-demand or force them on to users. Following implementation can be used for the same using “UpdateCompleted” event using which you can either forcefully restart the application or notify the user to notify about updates.

public class ApplicationDeploymentManager
    {
        static ApplicationDeploymentManager _applicationDeploymentManager = null;
        Timer _updateCheckTimer = null;

        ApplicationDeployment _currentApplicationDeployment = null;

        public delegate void ApplicationUpdateHandler();
        public event ApplicationUpdateHandler UpdateAvailable;
        public event ApplicationUpdateHandler UpdateCompleted;

        private ApplicationDeploymentManager()
        {
            try
            {
                _currentApplicationDeployment = ApplicationDeployment.CurrentDeployment; _currentApplicationDeployment.CheckForUpdateCompleted += new CheckForUpdateCompletedEventHandler(_currentApplicationDeployment_CheckForUpdateCompleted); _currentApplicationDeployment.UpdateCompleted += new AsyncCompletedEventHandler(_currentApplicationDeployment_UpdateCompleted);InitializeUpdateCheckTimer();
            }
            catch (Exception ex)
            {
            }
        }

        public static ApplicationDeploymentManager Instance
        {
            get
            {
                if (_applicationDeploymentManager == null)
                    return _applicationDeploymentManager = new ApplicationDeploymentManager();

                return _applicationDeploymentManager;
            }
        }

        public void InitializeUpdateCheckTimer()
        {
            _updateCheckTimer = new Timer(new TimerCallback(CheckForTaskboardUpdate), null, 0, 60000);
        }

        public void CheckForTaskboardUpdate(object state)
        {
            if (_currentApplicationDeployment != null)
                _currentApplicationDeployment.CheckForUpdateAsync();
        }

        void _currentApplicationDeployment_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
        {
                if (e.UpdateAvailable)
                {
                    try
                    {
                        _availableApplicationVersion = e.AvailableVersion.ToString();
                        _currentApplicationDeployment.UpdateAsync();

                        if (UpdateAvailable != null)
                            UpdateAvailable();
                    }
                    catch (Exception ex)
                    {
                    }
                }
        }

        void _currentApplicationDeployment_UpdateCompleted(object sender, AsyncCompletedEventArgs e)
        {
               if (UpdateCompleted != null)
                    UpdateCompleted();
        }
    }
}

Here is the video which has the demonstration for the same. http://windowsclient.net/learn/video.aspx?v=6879

Follow

Get every new post delivered to your Inbox.