void CheckForUpdates() { if (task == null || task.Status != TaskStatus.Running) { var container = TinyIoCContainer.Current; IResourceProvider resource = container.Resolve <IResourceProvider>(ContainerNSR.RESOURCE_PROVIDER); IConfigProvider config = container.Resolve <IConfigProvider>(ContainerNSR.APP_SETTINGS); ServiceUpdater updater = new ServiceUpdater(); IWebProxy proxy = null; if (config.EnableProxy) { proxy = new System.Net.WebProxy(config.Host, config.Port); if (config.EnableCredentials) { proxy.Credentials = new System.Net.NetworkCredential(config.User, config.Password, config.Domain); } } System.Version currentVersion = Utility.GetVersionInfo(this.GetType().Assembly); task = Task.Factory.StartNew(() => { ServiceUpdater.VersionInfo version = updater.GetMetaInfoVersion(resource.VersionCheckUri.ToString()); return(version); }).ContinueWith((o) => { if (o.Status != TaskStatus.Faulted) { System.Version latestVersion = o.Result.LatestVersion; bool isVersionUpToDate = latestVersion <= currentVersion; VersionCheckEventArgs eventArgs = new VersionCheckEventArgs { Version = latestVersion }; if (isVersionUpToDate == false) { OnNewVersionFoundEvent(this, eventArgs); } else { OnVersionUpToDateEvent(this, eventArgs); } } else { VersionCheckEventArgs eventArgs = new VersionCheckEventArgs { ErrorMessage = o.Exception.Message }; OnNetworkErrorEvent(this, eventArgs); } }); } }
public static void CheckForUpdates(bool showMessageAnyway, WebProxy webProxy) { Task.Factory.StartNew(() => ServiceUpdater.CheckForUpdates(Globals.URI_UPDATER, webProxy)).ContinueWith(task => { if (task.Result != null) { ServiceUpdater.VersionInfo lastVersionInfo = task.Result; Version productVersion = Shared.GetProductVersion(); if (lastVersionInfo.LatestVersion > productVersion) { DialogResult result = MessageBox.Show(String.Format("A new version ({0}) is avaible, do you want to go to the homepage?", lastVersionInfo.LatestVersion), "NEW VERSION", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { Process.Start(lastVersionInfo.LatestVersionUrl); } } else if (showMessageAnyway) { MessageBox.Show(String.Format("This version is up to date", lastVersionInfo.LatestVersion), "No updates avaible", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (showMessageAnyway) { MessageBox.Show("Network error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }); }
public void CheckForUpdates(Version version, Assembly assembly) { ServiceUpdater updater = new ServiceUpdater(Proxy); try { ServiceUpdater.VersionInfo latestVersionInfo = updater.GetMetaInfoVersion(Uri.AbsoluteUri); if (latestVersionInfo != null) { Version productVersion = new Version(FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion); //Version productVersion = Utils.Utility.GetProductVersion(); bool isVersionUpToDate = latestVersionInfo.LatestVersion <= productVersion; VersionCheckEventArgs eventArgs = new VersionCheckEventArgs { Version = latestVersionInfo.LatestVersion }; if (isVersionUpToDate == false) { System.Diagnostics.Debug.WriteLine("New version found: " + eventArgs.Version.ToString()); if (NewVersionFoundEvent != null) { NewVersionFoundEvent(this, eventArgs); } } else { System.Diagnostics.Debug.WriteLine("Version is up to date: " + eventArgs.Version.ToString()); if (VersionUpToDateEvent != null) { VersionUpToDateEvent(this, eventArgs); } } } } catch (Exception e) { VersionCheckEventArgs eventArgs = new VersionCheckEventArgs { ErrorMessage = e.Message }; if (NetworkErrorEvent != null) { NetworkErrorEvent(this, eventArgs); } } }
void CheckForUpdates() { var container = TinyIoCContainer.Current; IResourceProvider resource = container.Resolve <IResourceProvider>(ContainerNSR.RESOURCE_PROVIDER); IConfigProvider config = container.Resolve <IConfigProvider>(ContainerNSR.APP_SETTINGS); ServiceUpdater updater = new ServiceUpdater(); IWebProxy proxy = null; if (config.EnableProxy) { proxy = new System.Net.WebProxy(config.Host, config.Port); if (config.EnableCredentials) { proxy.Credentials = new System.Net.NetworkCredential(config.User, config.Password, config.Domain); } } System.Version currentVersion = Utility.GetVersionInfo(this.GetType().Assembly); Task.Factory.StartNew(() => { ServiceUpdater.VersionInfo version = updater.GetMetaInfoVersion(resource.VersionCheckUri.ToString()); return(version); }).ContinueWith((o) => { if (o.Status != TaskStatus.Faulted) { System.Version latestVersion = o.Result.LatestVersion; bool isVersionUpToDate = latestVersion <= currentVersion; VersionCheckEventArgs eventArgs = new VersionCheckEventArgs { Version = latestVersion }; if (isVersionUpToDate == false) { System.Diagnostics.Debug.WriteLine("New version found: " + eventArgs.Version.ToString()); IDialogMessage service = container.Resolve <IDialogMessage>(ContainerNSR.DLG_OPEN_MESSAGE); MSG_RESPONSE response = MSG_RESPONSE.CANCEL; RootDispatcher.Dispatcher.Invoke((System.Action) delegate { response = service.ShowMessage(String.Format("A new version ( {0} ) is available. Do you want to download it?", eventArgs.Version), "Version information", true); if (response == MSG_RESPONSE.OK) { if (RequestHomepageEvent != null) { RequestHomepageEvent(this, eventArgs); } } }); } } }); }
public virtual Version GetLatestVersion() { updater = new ServiceUpdater(this.Proxy); ServiceUpdater.VersionInfo version = updater.GetMetaInfoVersion(MetaInfoUrl); return(version.LatestVersion); }