private void CheckForUpdateAsync(object state) { try { if (!_manualCheck & (_updateCheckedAt.AddMilliseconds(_updateCheckInterval) > DateTime.UtcNow)) { return; } using (WebClientEx wC = new WebClientEx()) { wC.Proxy = _proxy; wC.Timeout = 30000; byte[] response = wC.DownloadData(_updateCheckUri); using (BinaryReader bR = new BinaryReader(new MemoryStream(response, false))) { if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "MU") //format { throw new InvalidDataException("Mesh update info format is invalid."); } switch (bR.ReadByte()) //version { case 1: _updateVersion = bR.ReadShortString(); _displayText = bR.ReadShortString(); _downloadLink = bR.ReadShortString(); break; default: throw new InvalidDataException("Mesh update info version not supported."); } if (IsUpdateAvailable(_currentVersion, _updateVersion)) { _syncCxt.Send(delegate(object state2) { UpdateAvailable?.Invoke(this, EventArgs.Empty); }, null); } else if (_manualCheck) { _syncCxt.Send(delegate(object state2) { NoUpdateAvailable?.Invoke(this, EventArgs.Empty); }, null); } } } } catch (Exception ex) { if (_manualCheck) { _syncCxt.Send(delegate(object state2) { UpdateCheckFailed?.Invoke(this, ex); }, null); } } finally { _manualCheck = false; _updateCheckedAt = DateTime.UtcNow; } }
protected virtual void OnNoUpdateAvailable() { NoUpdateAvailable?.Invoke(this, EventArgs.Empty); }
protected virtual void OnRaiseNoUpdateAvailable(NoUpdateAvailableEventArgs e) { NoUpdateAvailable?.Invoke(this, e); }