public static AppInfo GetAppInfo() { ISysInfoHelper sih = new SysInfoHelper(); var result = new AppInfo(); try { result.AppVersion = sih.GetAppVersion(); result.ComputerName = sih.GetComputerName(); result.MAC = sih.GetMAC(); result.RuntimeVersion = sih.GetRuntimeVersion(); var ini = new IniFileOperator(IniFileOperator.IniFileName); result.AppId = ini.ReadValue("Application", "AppId", ""); //Serial Number result.SN = ini.ReadValue("Application", "SN", ""); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(result); }
public static CultureInfo SetCultureInfo(CultureInfo culture) { try { _cultureName = culture.Name; var iniPath = IniFileOperator.IniFileName; var ini = new IniFileOperator(iniPath); ini.WriteValue("Languages", "Name", _cultureName); } catch { #if DEBUG Debug.WriteLine("failed to get UI-CULTURE"); #endif } return(null); }
public StartUpInfo(AppInfo appInfo) { this.AppId = appInfo.AppId; this.MAC = appInfo.MAC; this.ComputerName = appInfo.ComputerName; this.AppVersion = appInfo.AppVersion; this.RuntimeVersion = appInfo.RuntimeVersion; SysInfoHelper sih = new SysInfoHelper(); this.CDriveSerialNumber = sih.GetDiskVolumeSerialNumber(null); this.CPUNumber = sih.GetCpu(); var ini = new IniFileOperator(IniFileOperator.IniFileName); //Serial Number string sn = ini.ReadValue("Application", "SN", ""); var encdec = new EncDec(); this.PublicKeyHash = encdec.GetMd5Hash(AppHelper.STR_PUBLIC_KEY); this.SN = sn; }
public static CultureInfo GetCultureInfo() { try { if (_cultureName != null) { return(CultureInfo.CreateSpecificCulture(_cultureName)); } var iniPath = IniFileOperator.IniFileName; var ini = new IniFileOperator(iniPath); _cultureName = ini.ReadValue("Languages", "Name", Thread.CurrentThread.CurrentUICulture.Name); return(CultureInfo.CreateSpecificCulture(_cultureName)); } catch { #if DEBUG Debug.WriteLine("failed to get UI-CULTURE"); #endif } return(null); }
private static void StartUp(int count, AppStartRequest asReq) { const int tryCount = 2; if (count > tryCount) { return; } bool failed = false; var info = GetAppInfo(); var ini = new IniFileOperator(IniFileOperator.IniFileName); if (info != null && string.IsNullOrWhiteSpace(info.AppId)) { var guid = Guid.NewGuid(); info.AppId = guid.ToString(); ini.WriteValue("Application", "AppId", info.AppId); } var data = new StartUpInfo(info); //asReq.StartUpData = data; try { #if DEBUG string abc = data.ToQueryString(); //var abc2 = System.Web.HttpUtility.UrlEncode(abc); //Debug.WriteLine(abc); //Debug.WriteLine(abc2); #endif byte[] bytes = Encoding.UTF8.GetBytes("data=" + System.Web.HttpUtility.UrlEncode(data.ToQueryString())); //byte[] bytes = Encoding.UTF8.GetBytes("data=testdata"); //TODO remove .aspx HttpWebRequest request = (HttpWebRequest)WebRequest.Create(RegexToolHelper.ULR_APP_STARTUP); request.Method = "POST"; request.UserAgent = STR_USEA_AGENT_DEFAULT; AppendLanguageInfoToHeader(request); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = bytes.Length; System.IO.Stream newStream = request.GetRequestStream(); // Send the data. newStream.Write(bytes, 0, bytes.Length); newStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Stream strmResp = response.GetResponseStream(); if (response.Headers["AuthResult"] == "Success") { if (response.ContentLength > 0 && false == data.SNExists()) { string sn = response.Headers["SN"]; if (false == string.IsNullOrEmpty(sn)) { ini.WriteValue("Application", "SN", sn); } } } if (response.ContentLength > 0) { string content = string.Empty; using (StreamReader reader = new StreamReader(strmResp)) { content = reader.ReadToEnd(); } if (!string.IsNullOrEmpty(content)) { var asr = JsonConvert.DeserializeObject <AppStartResponse>(content); if (asr != null) { if (asr.UpdateInfo != null) { asReq.UpdateInfo = asr.UpdateInfo; // ProcessUpdateInfo(asr.UpdateInfo); } } } } } } catch (WebException wex) { failed = true; Debug.WriteLine(wex.Message); } catch (Exception ex) { //TODO ....Important failed = true; Debug.WriteLine(ex.Message); } finally { if ((!failed) || count == tryCount) { //var x = data.SNVerifyLocally(); } } if (failed) { Thread.Sleep(1000 * (count + 1)); StartUp(count + 1, asReq); } }