Exemplo n.º 1
0
        // 准备可选的缺省绑定内容
        int PrepareDefaultBindings(string strTail,
                                   out string [] default_urls,
                                   out string strError)
        {
            default_urls = null;
            strError     = "";

            // 无法检查
            if (this.VerifyBindings == null)
            {
                default_urls = new string[] {
                    "net.tcp://localhost:8002/dp2kernel/" + strTail,
                    "net.pipe://localhost/dp2kernel/" + strTail,
                    "http://localhost:8001/dp2kernel/" + strTail
                };
                return(0);
            }

            string strTcpUrl = "";

            for (int nPort = 8002; ; nPort++)
            {
                strTcpUrl = "net.tcp://localhost:" + nPort.ToString() + "/dp2kernel/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strTcpUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strPipeUrl = "";

            for (int nNumber = 0; ; nNumber++)
            {
                strPipeUrl = "net.pipe://localhost/dp2kernel/" + strTail;
                if (nNumber > 0)
                {
                    strPipeUrl += nNumber.ToString() + "/";
                }

                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strPipeUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strHttpUrl = "";

            for (int nPort = 8001; ; nPort++)
            {
                strHttpUrl = "http://localhost:" + nPort.ToString() + "/dp2kernel/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strHttpUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            default_urls = new string[] {
                strTcpUrl,
                strPipeUrl,
                strHttpUrl
            };
            return(0);
        }
Exemplo n.º 2
0
        // 检测目录是否已经存在
        private void textBox_dataDir_Leave(object sender, EventArgs e)
        {
            // 已经准备Cancel,就不检查了
            if (IsMouseOnCancelButton() == true)
            {
                return;
            }

            // 新建时
            if (IsNew == true &&
                String.IsNullOrEmpty(this.textBox_dataDir.Text) == false &&
                this.LoadedDataDir != this.textBox_dataDir.Text)
            {
                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.textBox_dataDir.Text;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        MessageBox.Show(this, e1.ErrorInfo);
                        return;
                    }
                }

                string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "databases.xml");
                if (File.Exists(strXmlFilename) == true)
                {
                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
                                                          "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 database.xml 文件。\r\n\r\n是否要直接利用此其中(指xml文件和目录中有关帐户文件)的配置信息?",
                                                          "安装 dp2Kernel",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问
                        return;
                    }

                    if (this.LoadXmlFileInfo != null)
                    {
                        LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs();
                        e1.DataDir = this.textBox_dataDir.Text;
                        this.LoadXmlFileInfo(this, e1);
                        if (string.IsNullOrEmpty(e1.ErrorInfo) == false)
                        {
                            MessageBox.Show(this, e1.ErrorInfo);
                            return;
                        }

                        // refresh
                        this.LineInfo = e1.LineInfo;
                        RefreshSqlDef();
                        RefreshRootUserInfo();
                        this.LoadedDataDir   = this.textBox_dataDir.Text; // 防止重复装载
                        this.m_bDataDirExist = true;                      // 防止OK时不合适的检查警告
                    }
                }

                return;
            }

            // 修改时
            if (IsNew == false &&
                String.IsNullOrEmpty(this.textBox_dataDir.Text) == false &&
                this.LoadedDataDir != this.textBox_dataDir.Text)
            {
                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.textBox_dataDir.Text;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        MessageBox.Show(this, e1.ErrorInfo);
                        return;
                    }
                }

                string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "databases.xml");
                if (File.Exists(strXmlFilename) == true)
                {
                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
                                                          "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 database.xml 文件。\r\n\r\n是否要直接利用其中(指xml文件和目录中有关帐户文件)的配置信息?\r\n\r\n是:直接利用其中的信息,也即将其中的配置信息装入当前对话框\r\n否:利用这个数据目录,但其中xml文件和帐户文件的相关信息即将被当前对话框中的值覆盖\r\n\r\n(提示:无论您选“是”“否”,原有目录 '" + this.LoadedDataDir + "' 都会被闲置)",
                                                          "安装 dp2Kernel",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问
                        return;
                    }

                    if (this.LoadXmlFileInfo != null)
                    {
                        LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs();
                        e1.DataDir = this.textBox_dataDir.Text;
                        this.LoadXmlFileInfo(this, e1);
                        if (string.IsNullOrEmpty(e1.ErrorInfo) == false)
                        {
                            MessageBox.Show(this, e1.ErrorInfo);
                            return;
                        }

                        // refresh
                        this.LineInfo = e1.LineInfo;
                        RefreshSqlDef();
                        RefreshRootUserInfo();
                        this.LoadedDataDir   = this.textBox_dataDir.Text; // 防止重复装载
                        this.m_bDataDirExist = true;                      // 防止OK时不合适的检查警告
                    }
                }
                else if (String.IsNullOrEmpty(this.LoadedDataDir) == false)
                {
                    // 修改目录名

                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
                                                          "要将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '" + this.textBox_dataDir.Text + "' 么?\r\n\r\n(如果选择“否”,则安装程序在稍后将新创建一个数据目录,并复制进初始内容)",
                                                          "安装 dp2Kernel",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.m_bDataDirExist = false;
                        return;
                    }

                    try
                    {
                        // TODO: 需要测试当数据目录中内容尺寸太大,而目标盘无妨容纳时的报错情况
                        Directory.Move(this.LoadedDataDir, this.textBox_dataDir.Text);

                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, "将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '" + this.textBox_dataDir.Text + "' 时发生错误: " + ex.Message);
                    }
                }

                return;
            }
        }
Exemplo n.º 3
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";

            // 检查

            // 数据目录
            if (String.IsNullOrEmpty(this.textBox_dataDir.Text) == true)
            {
                strError = "尚未指定数据目录";
                goto ERROR1;
            }

            if (String.IsNullOrEmpty(this.comboBox_sqlServerType.Text) == true)
            {
                strError = "尚未指定 SQL 服务器类型";
                goto ERROR1;
            }

            // sql服务器信息
            if (String.IsNullOrEmpty(this.textBox_sqlDef.Text) == true)
            {
                strError = "尚未指定 SQL 服务器信息";
                goto ERROR1;
            }

            // 协议绑定
            if (String.IsNullOrEmpty(this.textBox_bindings.Text) == true)
            {
                strError = "尚未指定协议绑定信息";
                goto ERROR1;
            }


            if (this.IsNew == true &&
                this.m_bDataDirExist == false)
            {
                // root用户信息
                if (this.LineInfo.RootUserName == null ||
                    this.LineInfo.RootPassword == null ||
                    this.LineInfo.RootUserRights == null)
                {
                    strError = "尚未设定root账户的用户名、密码、权限";
                    goto ERROR1;
                }
            }

            // 如果修改时,需要创建新的数据目录
            if (this.IsNew == false)
            {
                // 探测数据目录,是否已经存在数据,是不是属于升级情形
                // return:
                //      -1  error
                //      0   数据目录不存在
                //      1   数据目录存在,但是xml文件不存在
                //      2   xml文件已经存在
                int nRet = InstanceDialog.DetectDataDir(this.textBox_dataDir.Text,
                                                        out strError);
                if (nRet == -1)
                {
                    strError = "探测数据目录 '" + this.textBox_dataDir.Text + "' 是否存在时,出现错误: " + strError;
                    goto ERROR1;
                }

                if (nRet == 0 || nRet == 1)
                {
                    // root用户信息
                    if (this.LineInfo.RootUserName == null ||
                        this.LineInfo.RootPassword == null ||
                        this.LineInfo.RootUserRights == null)
                    {
                        strError = "尚未设定root账户的用户名、密码、权限";
                        goto ERROR1;
                    }
                }
            }

            // TODO: 如果在编辑状态,需要排除和listview中自己重的情况

            if (this.VerifyInstanceName != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_instanceName.Text;
                this.VerifyInstanceName(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyDataDir != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_dataDir.Text;
                this.VerifyDataDir(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyBindings != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_bindings.Text;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }