private void CheckForUpdateThread(object param) { Logger.Log("CheckForUpdate - thread started"); Stopwatch sw = new Stopwatch(); sw.Start(); bool succeed = false; double version = 0; bool updateRequired = false; string url = ""; string message = ""; try { string requrl = param.ToString(); using (HttpWebUtility http = new HttpWebUtility(5 * 1000, false, 0)) { Logger.Log("CheckForUpdate - open url: {0}", requrl); ExceptionTester.Instance.Throw("checkforupdatethread"); http.OpenUrl(requrl, null); string res = http.GetHtmlContent(); Logger.DLog("CheckForUpdate - http: {0}", res); // parse file string[] lines = res.Split('\n'); if (lines.Length == 4) { if (double.TryParse(lines[1], out version)) { succeed = true; url = lines[2]; message = lines[3]; // check version double curVersion = 0; if (double.TryParse(About.Version, out curVersion)) { if (version > curVersion) { updateRequired = true; } } else { Logger.Warn("cannot parse current version: {0}", version); } } else { Logger.Warn("cannot parse version number: {0}", lines[1]); } } } } catch (Exception) { Logger.Warn("CheckForUpdate - exception while http!"); } CheckForUpdateResultHandler(succeed, updateRequired, version, url, message); sw.Stop(); Logger.Log("CheckForUpdate - elapsed: {0}", sw.ElapsedMilliseconds); }
private void ReportThread(object param) { Logger.Log("UsageReporter - thread started"); // send info to server Stopwatch sw = new Stopwatch(); sw.Start(); // make post string Pair <Dictionary <string, string>, string> pairparam = param as Pair <Dictionary <string, string>, string>; Dictionary <string, string> post = null; string reportUrl = null; if (pairparam != null) { post = pairparam.First as Dictionary <string, string>; reportUrl = pairparam.Second as string; } if (post == null || reportUrl == null) { Logger.Warn("invalid report param"); return; } string postString = ""; int count = 0; foreach (KeyValuePair <string, string> kvp in post) { string key = kvp.Key; string value = kvp.Value; postString += string.Format("{0}={1}", key, HttpUtility.UrlEncode(value)); if (count != post.Count - 1) { postString += "&"; } count++; } //Logger.DLog("UsageReporter - url: {0}, poststring: {1}", reportUrl, postString); Logger.DLog("UsageReporter - url: {0}, post: {1}", reportUrl, postString); bool uploaded = false; // upload try { using (HttpWebUtility http = new HttpWebUtility(5 * 1000, false, 0)) { http.OpenUrl(reportUrl, null, postString); ExceptionTester.Instance.Throw("reportthread"); string res = http.GetHtmlContent(); Logger.DLog("UsageReporter - http: {0}", res); if (res.Contains("<OK>")) { uploaded = true; } } } catch (Exception) { Logger.Warn("UsageReporter - cannot upload usage report!"); } sw.Stop(); Logger.Log("UsageReporter - report result: {0}, elapsed: {1}", uploaded, sw.ElapsedMilliseconds); }
private void ReportThread(object param) { Logger.Log("UsageReporter - thread started"); // send info to server Stopwatch sw = new Stopwatch(); sw.Start(); // make post string Pair<Dictionary<string, string>, string> pairparam = param as Pair<Dictionary<string, string>, string>; Dictionary<string, string> post = null; string reportUrl = null; if(pairparam != null) { post = pairparam.First as Dictionary<string, string>; reportUrl = pairparam.Second as string; } if(post == null || reportUrl == null) { Logger.Warn("invalid report param"); return; } string postString = ""; int count = 0; foreach (KeyValuePair<string, string> kvp in post) { string key = kvp.Key; string value = kvp.Value; postString += string.Format("{0}={1}", key, HttpUtility.UrlEncode(value)); if (count != post.Count - 1) { postString += "&"; } count++; } //Logger.DLog("UsageReporter - url: {0}, poststring: {1}", reportUrl, postString); Logger.DLog("UsageReporter - url: {0}, post: {1}", reportUrl, postString); bool uploaded = false; // upload try { using(HttpWebUtility http = new HttpWebUtility(5 * 1000, false, 0)) { http.OpenUrl(reportUrl, null, postString); ExceptionTester.Instance.Throw("reportthread"); string res = http.GetHtmlContent(); Logger.DLog("UsageReporter - http: {0}", res); if (res.Contains("<OK>")) { uploaded = true; } } } catch (Exception) { Logger.Warn("UsageReporter - cannot upload usage report!"); } sw.Stop(); Logger.Log("UsageReporter - report result: {0}, elapsed: {1}", uploaded, sw.ElapsedMilliseconds); }