Click here to Skip to main content
15,893,622 members
Articles / Web Development / IIS

WSE 3 Deployment: MSI and ClickOnce

Rate me:
Please Sign up or sign in to vote.
4.90/5 (61 votes)
4 Oct 2009CPOL29 min read 221.9K   776   217  
Overview of deployment techniques using example WSE 3 enabled solutions
using System;
using System.Collections.Generic;
using System.Text;
using System.Deployment.Application;
using WSEDeployment.Properties;
using System.ComponentModel;
using System.Security.Cryptography.X509Certificates;
using System.Windows.Forms;
using Util;

namespace WSEDeployment
{
class ClickOnceFunctions
{
    public static void CheckForCertificate()
    {
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            if (ApplicationDeployment.CurrentDeployment.IsFirstRun)
            {
                X509Certificate2 cert = new X509Certificate2(Resources.TestCertificateClient);

                CertificateInstall.PlaceInStore(
                    cert, StoreName.AddressBook, StoreLocation.CurrentUser, null);
            }
        }
    }

    private static System.Timers.Timer _updateTimer = null;
    public static void StartListeningForUpdates()
    {
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            _updateTimer = new System.Timers.Timer();
            _updateTimer.Interval = 10000;
            _updateTimer.Elapsed += new System.Timers.ElapsedEventHandler(_updateTimer_Elapsed);
            _updateTimer.Start();
        }
    }

    public static void StopListeningForUpdates()
    {
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            _updateTimer.Stop();
            _updateTimer.Dispose();
        }
    }

    private static bool _updating;
    static void _updateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            ApplicationDeployment current = ApplicationDeployment.CurrentDeployment;

            if (!_updating)
            {
                try
                {
                    if (current.CheckForUpdate())
                    {
                        //MessageBox.Show("Test");
                        _updating = true;
                        current.Update();

                        DialogResult dr = MessageBox.Show(
                        "Update downloaded, restart application?",
                        "Application Update", MessageBoxButtons.YesNo);

                        if (dr == DialogResult.Yes)
                            Application.Restart();
                    }
                }
                catch (Exception ex)
                {
                    _updating = false;
                    Console.WriteLine("Clickonce connection failed: " + ex.ToString());
                }
            }
        }
    }
}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
United States United States
If you liked this article, consider reading other articles by me. For republishing article on other websites, please contact me by leaving a comment.

Comments and Discussions