private void Form1_Load(object sender, EventArgs e) { try { string commstring = GetConnSting(); if (string.IsNullOrEmpty(commstring)) { MessageBox.Show("配置错误!"); this.Close(); } else { CreatConfig(commstring); } reg = SeatManage.Bll.Registry.GetRegistryKey(); textBox1.Text = reg.RegistryList["JuneberryReadingRoomInterfaceKey"]; textBox2.Text = reg.RegistryList["JuneberryAccessInterfaceKey"]; textBox3.Text = reg.RegistryList["JuneberryMediaReleaseKey"]; } catch (Exception ex) { MessageBox.Show("配置错误!"); this.Close(); } }
/// <summary> /// 保存注册表 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool SaveRegistryKey(SeatManage.ClassModel.RegistryKey model) { IWCFService.ISeatManageService service = SeatManage.WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService(); bool error = false; try { return(service.SaveRegistryKey(model)); } catch (Exception ex) { error = true; WriteLog.Write(string.Format("获取保存注册表出错:{0}", ex.Message)); throw ex; } finally { ICommunicationObject ICommObjectService = service as ICommunicationObject; try { if (ICommObjectService.State == CommunicationState.Faulted) { ICommObjectService.Abort(); } else { ICommObjectService.Close(); } } catch { ICommObjectService.Abort(); } } }
/// <summary> /// 验证查询接口授权 /// </summary> /// <returns></returns> public bool ReadingRoomInterfaceIsAuthorize() { string schoolNum = GetSchoolNum(); if (string.IsNullOrEmpty(schoolNum)) { return(false); } SeatManage.ClassModel.RegistryKey reg = GetRegistryKey(); if (string.IsNullOrEmpty(reg.RegistryList["JuneberryReadingRoomInterfaceKey"])) { return(false); } else { string pass = SeatManage.SeatManageComm.MD5Algorithm.GetMD5Str32WithListKey(new List <string>() { schoolNum, "JuneberryReadingRoomInterfaceKey" }); if (reg.RegistryList["JuneberryReadingRoomInterfaceKey"] == pass.Substring(0, 8) + "-" + pass.Substring(8, 8) + "-" + pass.Substring(16, 8) + "-" + pass.Substring(24, 8)) { return(true); } else { return(false); } } }
/// <summary> /// 获取注册表值 /// </summary> /// <returns></returns> public SeatManage.ClassModel.RegistryKey GetRegistryKey() { SeatManage.ClassModel.RegistryKey model = new SeatManage.ClassModel.RegistryKey(); RegistryKey lm = Registry.CurrentUser; //对应HKEY_LOCAL_MACHINE基项分支 RegistryKey software = lm.OpenSubKey("SOFTWARE", false); RegistryKey juneberry = software.OpenSubKey("Juneberry", false); if (juneberry != null) { RegistryKey interfaceKey = juneberry.OpenSubKey("InterfaceKey", false); if (interfaceKey != null) { if (interfaceKey.GetValue("JuneberryReadingRoomInterfaceKey") != null) { model.RegistryList["JuneberryReadingRoomInterfaceKey"] = interfaceKey.GetValue("JuneberryReadingRoomInterfaceKey").ToString(); } if (interfaceKey.GetValue("JuneberryAccessInterfaceKey") != null) { model.RegistryList["JuneberryAccessInterfaceKey"] = interfaceKey.GetValue("JuneberryAccessInterfaceKey").ToString(); } if (interfaceKey.GetValue("JuneberryMediaReleaseKey") != null) { model.RegistryList["JuneberryMediaReleaseKey"] = interfaceKey.GetValue("JuneberryMediaReleaseKey").ToString(); } } } lm.Close(); return(model); }
/// <summary> /// 保存注册表 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool SaveRegistryKey(SeatManage.ClassModel.RegistryKey model) { IWCFService.ISeatManageService service = new WcfServiceForSeatManage.SeatManageDateService(); bool error = false; try { return(service.SaveRegistryKey(model)); } catch (Exception ex) { error = true; WriteLog.Write(string.Format("获取保存注册表出错:{0}", ex.Message)); throw ex; } }
/// <summary> /// 保存注册表 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool SaveRegistryKey(SeatManage.ClassModel.RegistryKey model) { RegistryKey lm = Registry.CurrentUser; //对应HKEY_LOCAL_MACHINE基项分支 RegistryKey software = lm.OpenSubKey("SOFTWARE", true); RegistryKey juneberry = software.OpenSubKey("Juneberry", true); if (juneberry == null) { juneberry = software.CreateSubKey("Juneberry"); } RegistryKey interfaceKey = juneberry.OpenSubKey("InterfaceKey", true); if (interfaceKey == null) { interfaceKey = juneberry.CreateSubKey("InterfaceKey"); } interfaceKey.SetValue("JuneberryReadingRoomInterfaceKey", model.RegistryList["JuneberryReadingRoomInterfaceKey"]); interfaceKey.SetValue("JuneberryAccessInterfaceKey", model.RegistryList["JuneberryAccessInterfaceKey"]); interfaceKey.SetValue("JuneberryMediaReleaseKey", model.RegistryList["JuneberryMediaReleaseKey"]); lm.Close(); return(true); }
/// <summary> /// 发布器注册激活码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { if (reg == null) { reg = new SeatManage.ClassModel.RegistryKey(); } reg.RegistryList["JuneberryReadingRoomInterfaceKey"] = textBox1.Text; reg.RegistryList["JuneberryAccessInterfaceKey"] = textBox2.Text; reg.RegistryList["JuneberryMediaReleaseKey"] = textBox3.Text; try { string schoolNum = SeatManage.Bll.Registry.GetSchoolNum(); if (string.IsNullOrEmpty(schoolNum)) { lb_Error.Text = "注册失败!"; return; } if (!string.IsNullOrEmpty(reg.RegistryList["JuneberryReadingRoomInterfaceKey"])) { string pass = SeatManage.SeatManageComm.MD5Algorithm.GetMD5Str32WithListKey(new List <string>() { schoolNum, "JuneberryReadingRoomInterfaceKey" }); if (reg.RegistryList["JuneberryReadingRoomInterfaceKey"] != pass.Substring(0, 8) + "-" + pass.Substring(8, 8) + "-" + pass.Substring(16, 8) + "-" + pass.Substring(24, 8)) { lb_Error.Text = "注册码错误!"; return; } } if (!string.IsNullOrEmpty(reg.RegistryList["JuneberryAccessInterfaceKey"])) { string pass = SeatManage.SeatManageComm.MD5Algorithm.GetMD5Str32WithListKey(new List <string>() { schoolNum, "JuneberryAccessInterfaceKey" }); if (reg.RegistryList["JuneberryAccessInterfaceKey"] != pass.Substring(0, 8) + "-" + pass.Substring(8, 8) + "-" + pass.Substring(16, 8) + "-" + pass.Substring(24, 8)) { lb_Error.Text = "注册码错误!"; return; } } if (!string.IsNullOrEmpty(reg.RegistryList["JuneberryMediaReleaseKey"])) { string pass = SeatManage.SeatManageComm.MD5Algorithm.GetMD5Str32WithListKey(new List <string>() { schoolNum, "JuneberryMediaReleaseKey" }); if (reg.RegistryList["JuneberryMediaReleaseKey"] != pass.Substring(0, 8) + "-" + pass.Substring(8, 8) + "-" + pass.Substring(16, 8) + "-" + pass.Substring(24, 8)) { lb_Error.Text = "注册码错误!"; return; } } if (SeatManage.Bll.Registry.SaveRegistryKey(reg)) { MessageBox.Show("保存成功!"); this.Close(); } else { lb_Error.Text = "保存失败!"; } } catch (Exception ex) { lb_Error.Text = ex.Message; } }