예제 #1
0
        private void button_editBindings_Click(object sender, EventArgs e)
        {
            string strError = "";
            // 检查绑定内容是否适合利用对话框进行编辑
            // return:
            //      -1  出错
            //      0   适合编辑
            //      1   不适合编辑
            int nRet = CheckBindingsEditable(out strError);

            if (nRet == -1)
            {
                goto ERROR1;
            }
            if (nRet == 1)
            {
                strError = "当前绑定内容因为 " + strError + " 而无法被专用对话框进行编辑,但可以直接在文本框中进行修改";
                goto ERROR1;
            }

            // TODO: 要找到一个没有被使用过的tcp端口号
            string strTail = this.InstanceName + (String.IsNullOrEmpty(this.InstanceName) == false ? "/" : "");

            string[] default_urls = null;
            nRet = PrepareDefaultBindings(strTail,
                                          out default_urls,
                                          out strError);
            if (nRet == -1)
            {
                strError = "准备缺省班定值时发生错误: " + strError;
                goto ERROR1;
            }

            /*
             * string[] default_urls = new string[] {
             *      "net.tcp://localhost:8002/dp2kernel/" + strTail,
             *      "net.pipe://localhost/dp2kernel/" + strTail,
             *      "http://localhost:8001/dp2kernel/" + strTail
             *  };
             * */

            WcfBindingDlg dlg = new WcfBindingDlg();

            GuiUtil.AutoSetDefaultFont(dlg);
            if (this.IsNew && String.IsNullOrEmpty(this.textBox_bindings.Text) == true)
            {
                dlg.Urls = default_urls;
            }
            else
            {
                dlg.Urls = this.textBox_bindings.Text.Replace("\r\n", ";").Split(new char[] { ';' });
            }
            dlg.DefaultUrls   = default_urls;
            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);
            if (dlg.DialogResult != DialogResult.OK)
            {
                return;
            }

            this.textBox_bindings.Text = string.Join("\r\n", dlg.Urls);
            return;

ERROR1:
            MessageBox.Show(this, strError);
            return;
        }
예제 #2
0
        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
        }