|
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.
If you liked this article, consider reading
other articles by me. For republishing article on other websites, please contact me by leaving a comment.