public void Dispose() { if (_client.IsBusy) { _client.CancelAsync(); } _client.Dispose(); _client = null; }
public VersionChecker(string url, int timeOutSeconds = 15) { _url = url; _client = new TimeOutWebClient() { TimeOutSecs = timeOutSeconds }; _client.Proxy = null; _client.Encoding = System.Text.Encoding.UTF8; _client.DownloadStringCompleted += (sender, args) => { if (args.Cancelled) { OnCanceled(); return; } if (args.Error != null) { OnErrorHappened(args.Error); return; } VersionInfo versionInfo = null; //{"Version":"1.5.2.0","WhatsNew":"Abcd\"efg"} try { versionInfo = JsonConvert.DeserializeObject <VersionInfo>(args.Result); /*const string versionPattern = "\"Version\"\\s*:\\s*\"\\d.\\d.\\d.\\d\""; * const string whatsNewPattern = "\"WhatsNew\"\\s*:\\s*((?<![\\\\])['\"])((?:.(?!(?<![\\\\])\\1))*.?)\\1"; * * var versionMatch = Regex.Match(args.Result, versionPattern);//"^\\{\"Version\":\"\\d.\\d.\\d.\\d\",\"WhatsNew\":\"[^\"]*\"\\}$"); * var whatsNewMatch = Regex.Match(args.Result, whatsNewPattern); * if (versionMatch.Success && whatsNewMatch.Success) * { * var versionStr = Regex.Match(versionMatch.Value,"\\d.\\d.\\d.\\d").Value; * var whatsNewStr = whatsNewMatch.Value.Split(':')[1]; * whatsNewStr = whatsNewStr.Substring(1,whatsNewStr.Length -2).Replace("\\r\\n","\r\n").Replace("\\\"","\""); * * versionInfo = new VersionInfo(){Version = versionStr, WhatsNew = whatsNewStr}; * } * else throw new Exception();*/ } catch (Exception e) { OnErrorHappened(e); return; } OnFinished(versionInfo); }; }
public VersionChecker(string url, int timeOutSeconds = 15) { _url = url; _client = new TimeOutWebClient(){TimeOutSecs = timeOutSeconds}; _client.Encoding = System.Text.Encoding.UTF8; _client.DownloadStringCompleted += (sender, args) => { if (args.Cancelled) { OnCanceled(); return; } if (args.Error != null) { OnErrorHappened(args.Error); return; } VersionInfo versionInfo = null; //{"Version":"1.5.2.0","WhatsNew":"Abcd\"efg"} try { versionInfo = JsonConvert.DeserializeObject<VersionInfo>(args.Result); /*const string versionPattern = "\"Version\"\\s*:\\s*\"\\d.\\d.\\d.\\d\""; const string whatsNewPattern = "\"WhatsNew\"\\s*:\\s*((?<![\\\\])['\"])((?:.(?!(?<![\\\\])\\1))*.?)\\1"; var versionMatch = Regex.Match(args.Result, versionPattern);//"^\\{\"Version\":\"\\d.\\d.\\d.\\d\",\"WhatsNew\":\"[^\"]*\"\\}$"); var whatsNewMatch = Regex.Match(args.Result, whatsNewPattern); if (versionMatch.Success && whatsNewMatch.Success) { var versionStr = Regex.Match(versionMatch.Value,"\\d.\\d.\\d.\\d").Value; var whatsNewStr = whatsNewMatch.Value.Split(':')[1]; whatsNewStr = whatsNewStr.Substring(1,whatsNewStr.Length -2).Replace("\\r\\n","\r\n").Replace("\\\"","\""); versionInfo = new VersionInfo(){Version = versionStr, WhatsNew = whatsNewStr}; } else throw new Exception();*/ } catch (Exception e) { OnErrorHappened(e); return; } OnFinished(versionInfo); }; }
public VersionChecker(string url, int timeOutSeconds = 15) { _url = url; _client = new TimeOutWebClient() { TimeOutSecs = timeOutSeconds }; _client.Encoding = System.Text.Encoding.UTF8; _client.DownloadStringCompleted += (sender, args) => { if (args.Cancelled) { OnCanceled(); return; } if (args.Error != null) { OnErrorHappened(args.Error); return; } VersionInfo versionInfo = null; try { versionInfo = JsonConvert.DeserializeObject <VersionInfo>(args.Result); } catch (Exception e) { OnErrorHappened(e); return; } OnFinished(versionInfo); }; }
public void Dispose() { if(_client.IsBusy) _client.CancelAsync(); _client.Dispose(); _client = null; }