private static bool EnterFacName(ref string facName) { // 检查 Factory Name 是否已经输入 facName = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "FacName"); if (string.IsNullOrEmpty(facName)) { InputFacName inputForm = new InputFacName(); inputForm.ShowDialog(); if (inputForm.enterKeyFlag == false) { MessageBox.Show("未正常输入,请重新启动程序并输入厂商名字"); return false; } facName = inputForm.FacName; if (string.IsNullOrEmpty(facName)) { MessageBox.Show("输入为空,请重新启动程序并输入厂商名字"); return false; } // FacName 合法,写注册表 if (RegUtil.CreateKeyValue(@"SOFTWARE\Wow6432Node\CamAligner", "FacName", facName) == false) { MessageBox.Show("由于系统问题无法注册软件"); return false; } } return true; }
private void UploadMachineInfoOnNetConn() { //this.EventLog.WriteEntry(String.Format("CDKey:{0}, MachineCode:{1}", cdKey, mc), EventLogEntryType.Information); //string mc = myWcfService.GetMachineCode(); //this.EventLog.WriteEntry(String.Format("GetMachineCode success, value is {0}", mc), EventLogEntryType.Information); try { // checked if all infomration are available if (string.IsNullOrEmpty(RegConfig.Cdkey) || string.IsNullOrEmpty(RegConfig.MachineCode) || string.IsNullOrEmpty(RegConfig.FacName) || string.IsNullOrEmpty(RegConfig.HostLink) ) { InitReadReg(); return; } var customerData = GetNewCustomer(String.Format("{0}/GetCustomerInfo?MachineCode={1}", RegConfig.HostLink, RegConfig.MachineCode)); if (customerData == null) { return; } if (RegConfig.ValidKeyInfo == null) { //this.EventLog.WriteEntry(String.Format("Calling UpdateValidKeyInfoByCDKey"), EventLogEntryType.Information); try { UpdateValidKeyInfoByCDKey(); } catch (Exception ex) { this.EventLog.WriteEntry(String.Format("After Calling UpdateValidKeyInfoByCDKey, Excpetoin: {0}", ex.Message), EventLogEntryType.Information); } } if (RegConfig.ValidKeyInfo == null) { RegConfig.KeyStatus = "密钥格式错误"; } else if (RegConfig.ValidKeyInfo.Features[0]) { RegConfig.KeyStatus = "永久密钥"; } else if (!RegConfig.ValidKeyInfo.IsValid || !RegConfig.ValidKeyInfo.IsOnRightMachine || RegConfig.ValidKeyInfo.IsExpired) { //this.EventLog.WriteEntry(String.Format("Fail to get info from cdkey {0}, IsValid: {1}, IsOnRightMachine: {2}", RegConfig.Cdkey, // RegConfig.ValidKeyInfo.IsValid, // RegConfig.ValidKeyInfo.IsOnRightMachine), // EventLogEntryType.Error // ); RegConfig.KeyStatus = "密钥失效"; } else { RegConfig.KeyStatus = "密钥正常"; } //this.EventLog.WriteEntry(String.Format("After judage ValidKeyInfo"), EventLogEntryType.Information); string CreationDate = null; string ValidDate = null; // Update RegConfig.ValidKeyInfo by read new cdkey from Reg try { if (RegConfig.ValidKeyInfo != null) { // This coversion may cause issue CreationDate = RegConfig.ValidKeyInfo.CreationDate.ToShortDateString(); ValidDate = RegConfig.ValidKeyInfo.CreationDate.AddDays(RegConfig.ValidKeyInfo.SetTime).ToShortDateString(); } } catch (Exception ex) { this.EventLog.WriteEntry(String.Format("Convert Date string excption: {0}", ex.Message), EventLogEntryType.Information); } //this.EventLog.WriteEntry(String.Format("CreationDate: {0}", CreationDate), EventLogEntryType.Information); //this.EventLog.WriteEntry(String.Format("ValidDate: {0}", ValidDate), EventLogEntryType.Information); //this.EventLog.WriteEntry(String.Format("Check web table"), EventLogEntryType.Information); //DateTime now = DateTime.Now; //string nowToNodeJs = now.ToString("s") + "Z"; //this.EventLog.WriteEntry(String.Format("After judge CreationDate"), EventLogEntryType.Information); if (customerData.result.Count == 0) { //this.EventLog.WriteEntry(String.Format("Check web table finished"), EventLogEntryType.Information); // No customer rocord found from db table "Customers", need to upload //GetUrltoHtml("http://*****:*****@"SOFTWARE\Wow6432Node\CamAligner", "CDKey", newCDKey) == false) { this.EventLog.WriteEntry(String.Format("CDKey write to reg Fail"), EventLogEntryType.Error); } // Reload Config and Reg InitReadReg(); //this.EventLog.WriteEntry(String.Format("After Re-generate CDKey, cdkey {0}, machinecode {1}", RegConfig.Cdkey, int.Parse(RegConfig.MachineCode)), EventLogEntryType.Information); UpdateValidKeyInfoByCDKey(); //this.EventLog.WriteEntry(String.Format("After Rereload cdkey and get key info"), EventLogEntryType.Information); // update cdkey to web database // Run http://nirovm2-pc:3000/UpdateCDKey?MachineCode=92040&CDKey=KTZEY-UBGPZ-REXIG-INWXB to update string updateCDKeyInfo = string.Format("{0}/UpdateCDKey?MachineCode={1}&CDKey={2}&MachineStatus={3}", RegConfig.HostLink, RegConfig.MachineCode, newCDKey, RegConfig.KeyStatus); // Update cdkey on web mongo db updateResult = GetNewUpdateResult(updateCDKeyInfo); if (updateResult.result.ok != 1) { this.EventLog.WriteEntry(String.Format("Update CDKey failed"), EventLogEntryType.Information); } } } } catch (Exception ex) { this.EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Information); } }
/// <summary> /// /// </summary> /// <param name="cdKey"></param> /// <param name="myWcf"></param> /// <param name="validKeyInfo"></param> /// <param name="reEnterCDKey"></param> private void EnterNewCDKey(ref string cdKey, MyWcfService myWcf, ref KeyInfo validKeyInfo, bool reEnterCDKey = false) { // KXXNR-OCMGT-SOFQO-WBJRY // ICFXR - YDZOG - LDPLB - NMODN // MachineCode // ProcessorId // "178BFBFF00600F12" // Win32_BIOS // "To be filled by O.E.M." // Win32_BaseBoard // "MB-1234567890" // join 3 part togeter and cal 8byte hash // result like 83628 string machineCode = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "MachineCode"); if (string.IsNullOrEmpty(machineCode)) { try { machineCode = myWcf.GetMachineCode(); } catch { MessageBox.Show("计算机器码错误"); this.Close(); return; } } // CDKey 不存在 或者 需要重新输入(因为过期),重新输入 if (string.IsNullOrEmpty(cdKey) || reEnterCDKey) { InputCDKey inputForm = new InputCDKey(); inputForm.MachineCode = machineCode; inputForm.ShowDialog(); if (inputForm.enterKeyFlag == false) { return; } cdKey = inputForm.CDKey; if (string.IsNullOrEmpty(cdKey)) { MessageBox.Show("请输入CDKey"); return; } } try { validKeyInfo = myWcf.GetKeyInfo(cdKey, "hello"); if (validKeyInfo.IsValid == true && validKeyInfo.IsOnRightMachine == true) { JudgeCDKeyStillWorks(); LoadValidKeyOnPanel(); } else { MessageBox.Show("CDKey内容非法"); } } catch { MessageBox.Show("CDKey格式非法"); } if (validKeyInfo == null) { button1.Enabled = false; timer1.Enabled = false; } // CDKey 合法,写注册表 if (RegUtil.CreateKeyValue(@"SOFTWARE\Wow6432Node\CamAligner", "CDKey", cdKey) == false) { MessageBox.Show("由于系统问题无法注册软件"); return; } // Machine Code 合法,写注册表 if (RegUtil.CreateKeyValue(@"SOFTWARE\Wow6432Node\CamAligner", "MachineCode", machineCode) == false) { MessageBox.Show("机器码写入注册表失败"); return; } }