public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver); #if NO string strRootDir = UnQuote(this.Context.Parameters["rootdir"]); string strDataDir = ""; bool bWriteInstanceInfo = false; bool bUpgrade = false; // 是否为升级安装? 所谓升级安装就是发现数据目录已经存在了 int nRet = 0; string strError = ""; // ebug.Assert(false, ""); bool bDialogOpened = false; InstallParamDlg param_dlg = new InstallParamDlg(); GuiUtil.AutoSetDefaultFont(param_dlg); // 从XML文件中装载已有的信息到对话框 // return: // -1 error // 0 not load // 1 loaded LoadExistingInfoFromDp2zserverXmlFile( param_dlg, strRootDir, out strError); string strInstanceName = ""; string[] existing_urls = null; string strCertSN = ""; // 获得instance信息 // parameters: // urls 获得绑定的Urls // return: // false instance没有找到 // true 找到 bool bRet = InstallHelper.GetInstanceInfo("dp2ZServer", 0, out strInstanceName, out strDataDir, out existing_urls, out strCertSN); strDataDir = strRootDir; string strExistingXmlFile = PathUtil.MergePath(strRootDir, "unioncatalog.xml"); if (File.Exists(strExistingXmlFile) == false) { param_dlg.ShowDialog(ForegroundWindow.Instance); if (param_dlg.DialogResult == DialogResult.Cancel) { throw new Exception("安装被放弃"); } bDialogOpened = true; // 创建unioncatalog.xml文件 // return: // -1 error, install faild // 0 succeed // 1 suceed, but some config ignored nRet = WriteUnionCatalogXmlFile( param_dlg, strRootDir, out strError); if (nRet == -1) { throw new Exception(strError); } } else { bUpgrade = true; } END1: // if (existing_urls == null || existing_urls.Length == 0) { string[] default_urls = new string[] { //"net.tcp://localhost:7001/gcatserver/", //"net.pipe://localhost/gcatserver/", "http://localhost/unioncatalog/" }; List <string> urls = new List <string>(existing_urls == null ? new string[0] : existing_urls); if (urls.Count == 0) { urls.AddRange(default_urls); } WcfBindingDlg binding_dlg = new WcfBindingDlg(); GuiUtil.AutoSetDefaultFont(binding_dlg); binding_dlg.Text = "请指定 UnionCatalogServer 服务器的通讯协议"; binding_dlg.Urls = StringUtil.FromListString(urls); binding_dlg.DefaultUrls = default_urls; binding_dlg.NetPipeEnabled = false; binding_dlg.NetTcpEnabled = false; binding_dlg.HttpComment = "适用于Intranet和Internet"; binding_dlg.StartPosition = FormStartPosition.CenterScreen; REDO_BINDING: if (binding_dlg.ShowDialog(ForegroundWindow.Instance) != DialogResult.OK) { throw new Exception("用户取消安装。"); } existing_urls = binding_dlg.Urls; // 检查和其他产品的bindings是否冲突 // return: // -1 出错 // 0 不重 // 1 重复 nRet = InstallHelper.IsGlobalBindingDup(string.Join(";", existing_urls), "dp2ZServer", out strError); if (nRet != 0) { MessageBox.Show(ForegroundWindow.Instance, "协议绑定有问题: " + strError + "\r\n\r\n请重新指定协议绑定"); goto REDO_BINDING; } bWriteInstanceInfo = true; } if (bWriteInstanceInfo == true) { // 设置instance信息 InstallHelper.SetInstanceInfo( "dp2ZServer", 0, "", strDataDir, existing_urls, strCertSN); } strExistingXmlFile = PathUtil.MergePath(strRootDir, "dp2zserver.xml"); if (File.Exists(strExistingXmlFile) == false) { if (bDialogOpened == false) { param_dlg.ShowDialog(ForegroundWindow.Instance); if (param_dlg.DialogResult == DialogResult.Cancel) { throw new Exception("安装被放弃"); } bDialogOpened = true; } // 写入dp2zserver.xml文件 // return: // -1 error, install faild // 0 succeed nRet = WriteDp2zserverXmlFile( param_dlg, strRootDir, out strError); if (nRet == -1) { throw new Exception(strError); } } #endif }
// 从注册表和 library.xml 文件中获得实例信息 // parameters: // // return: // -1 出错 // 0 实例没有找到 // 1 成功 public static int GetLibraryInstanceInfo( string strInstanceNameParam, out LibraryInstanceInfo info, out string strError) { strError = ""; info = new LibraryInstanceInfo(); string strInstanceName = ""; string strDataDir = ""; string strCertificatSN = ""; string[] existing_urls = null; for (int i = 0; ; i++) { bool bRet = InstallHelper.GetInstanceInfo("dp2Library", i, out strInstanceName, out strDataDir, out existing_urls, out strCertificatSN); if (bRet == false) { strError = "实例 '" + strInstanceNameParam + "' 不存在"; return(0); } if (strInstanceName == strInstanceNameParam) { info.InstanceName = strInstanceName; info.Urls = existing_urls; info.DataDir = strDataDir; break; } } string strFileName = Path.Combine(strDataDir, "library.xml"); if (File.Exists(strFileName) == false) { strError = "实例 '" + strInstanceNameParam + "' 的 library.xml 文件不存在"; return(0); } XmlDocument dom = new XmlDocument(); try { dom.Load(strFileName); } catch (Exception ex) { strError = "文件 '" + strFileName + "' 装载到 XMLDOM 时出错: " + ex.Message; return(-1); } if (dom.DocumentElement == null) { strError = "文件 '" + strFileName + "' 格式不正确,缺乏根元素"; return(-1); } info.Version = LibraryServerUtil.GetLibraryXmlVersion(dom); // supervisor // XmlElement nodeSupervisor = dom.DocumentElement.SelectSingleNode("accounts/account[@type='']") as XmlElement; XmlElement nodeSupervisor = null; // 找到第一个具备 managedatabase 权限用户 XmlNodeList nodes = dom.DocumentElement.SelectNodes("accounts/account[@type='']"); if (nodes.Count > 0) { foreach (XmlElement account in nodes) { string strRights = account.GetAttribute("rights"); if (StringUtil.IsInList("managedatabase", strRights) == true) { nodeSupervisor = account; break; } } } if (nodeSupervisor != null) { info.SupervisorUserName = nodeSupervisor.GetAttribute("name"); info.SupervisorPassword = nodeSupervisor.GetAttribute("password"); if (info.Version <= 2.0) { // library.xml 2.00 及以前的做法 try { info.SupervisorPassword = Cryptography.Decrypt(info.SupervisorPassword, "dp2circulationpassword"); } catch { strError = "<account password='******' /> 中的密码不正确"; return(-1); } // 得到 supervisor 密码的明文 } } string strValue = dom.DocumentElement.GetAttribute("_initialDatabase"); if (DomUtil.IsBooleanTrue(strValue, false) == true) { info.InitialDatabase = true; } else { info.InitialDatabase = false; } return(1); }