//************************************************************** // CheckForUpdates() // - Checks for an update // - This is a sync call... normally called by the poller object // on the poller thread. //************************************************************** public bool CheckForUpdates() { Debug.WriteLine("APPMANAGER: Checking for updates."); bool retValue = false; //If the OnCheckForUpdate event the caller is doing the check if (OnCheckForUpdate != null) { retValue = OnCheckForUpdate(this, new EventArgs()); } //otherwise do the check ourselves else //If versioning is enabled check to see if the version file has changed. if (ChangeDetectionMode == ChangeDetectionModes.ServerManifestCheck) { ServerManifest vm = new ServerManifest(); vm.Load(UpdateUrl); retValue = vm.IsServerVersionNewer(GetLatestInstalledVersion()); } //If versioning is not enabled, check the files themselves else { Resource currentResource; foreach (Object r in Manifest.Resources.ResourceList) { currentResource = (Resource)(((DictionaryEntry)r).Value); string url = UpdateUrl + currentResource.Name; string FilePath = currentResource.FilePath; if (WebFileLoader.CheckForFileUpdate(url, FilePath)) { retValue = true; } } } //Fire the OnUpdateDetected Event on the UI thread if (retValue == true) { if (OnUpdateDetected != null) { foreach (UpdateDetectedEventHandler UC in OnUpdateDetected.GetInvocationList()) { EventControl.BeginInvoke(UC, new object[] { this, new EventArgs() }); } } } return(retValue); }
public void MonitorForUpdates(string currentVersion, OnUpdateDetected updateCallback = null, int timerIntervalMs = 24 * 60 * 60 * 1000) { if (timerIntervalMs != Timeout.Infinite && timerIntervalMs < _MIN_UPDATE_CHECK_INTERVAL) { throw new ArgumentException($"{nameof(timerIntervalMs)} ({timerIntervalMs}) must be less than {_MIN_UPDATE_CHECK_INTERVAL}ms in order to avoid throttling limits"); } if (_updateTimer != null) { _updateTimer.Dispose(); } var args = new CheckForUpdateParams() { CurrentVersion = currentVersion, Callback = updateCallback }; _updateTimer = new Timer(CheckForUpdateAsync, args, 0, timerIntervalMs); }