Exemplo n.º 1
0
        /*
         * 制作一个 InstanceDialog,可以允许管理多个实例。
         * 和 dp2kernel dp2library 不同,每个实例都有单独的 App 目录。
         * 
         * 
         * 
         * 
         * 
         * */
        private void MenuItem_dp2opac_install_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (Environment.OSVersion.Version.Major < 6)
            {
                strError = "dp2Installer 仅支持在 Windows Server 2008/2012 以及 Windows Vista/7/8 和以上版本的操作系统中安装 dp2OPAC";
                goto ERROR1;
            }

            this._floatingMessage.Text = "正在安装 dp2OPAC - 读者公共查询...";

            try
            {

                // 检查 IIS 是否已经启用
                List<OpacAppInfo> infos = null;
                nRet = OpacAppInfo.GetOpacInfo(out infos, out strError);
                if (nRet == -1)
                    goto ERROR1;

                AppendSectionTitle("安装 dp2OPAC 开始");

                AppendString("停止 AppPool 'dp2OPAC'\r\n");

                Application.DoEvents();

                // 启动或者停止 AppPool
                nRet = OpacAppInfo.StartAppPool("dp2OPAC",
                    false,
                    out strError);
                if (nRet == -1)
                    MessageBox.Show(this, strError);

                try
                {
                    DigitalPlatform.OPAC.InstanceDialog dlg = new DigitalPlatform.OPAC.InstanceDialog();
                    GuiUtil.AutoSetDefaultFont(dlg);

                    dlg.CopyFiles += dlg_dp2OPAC_CopyFiles;
                    dlg.StartPosition = FormStartPosition.CenterScreen;
                    dlg.ShowDialog(this);

                    if (dlg.DialogResult == DialogResult.Cancel)
                        return;

                    if (string.IsNullOrEmpty(dlg.DebugInfo) == false)
                        AppendString("创建实例时的调试信息:\r\n" + dlg.DebugInfo + "\r\n");

                    if (dlg.Changed == true)
                    {
                        // 兑现修改

                    }
                }
                finally
                {
                    AppendString("重新启动 AppPool 'dp2OPAC'\r\n");
                    // 启动或者停止 AppPool
                    nRet = OpacAppInfo.StartAppPool("dp2OPAC",
                        true,
                        out strError);
                    if (nRet == -1)
                        MessageBox.Show(this, strError);

                    Refresh_dp2OPAC_MenuItems();
                    AppendSectionTitle("安装 dp2OPAC 结束");
                }
            }
            finally
            {
                this._floatingMessage.Text = "";
            }
            return;
        ERROR1:
            AppendString("出错: " + strError + "\r\n");
            MessageBox.Show(this, strError);
        }
Exemplo n.º 2
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";
            int    nRet     = 0;

            // 检查

            if (String.IsNullOrEmpty(this.comboBox_site.Text) == true)
            {
                strError = "尚未指定站点名";
                goto ERROR1;
            }

            if (String.IsNullOrEmpty(this.textBox_instanceName.Text) == true)
            {
                strError = "尚未指定虚拟目录名";
                goto ERROR1;
            }

            if (this.textBox_instanceName.Text[0] != '/')
            {
                strError = "虚拟目录名第一字符必须为 '/'";
                goto ERROR1;
            }

            string strVirtualDirRight = this.textBox_instanceName.Text.Substring(1);

            if (strVirtualDirRight.IndexOfAny(new char[] { '/', ' ' }) != -1)
            {
                strError = "虚拟目录名第一字符以外的字符中,不允许包含 '/' 或空格字符";
                goto ERROR1;
            }

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

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

            if (this.LineInfo == null)
            {
                this.LineInfo = new DigitalPlatform.OPAC.LineInfo();
            }

            // 检查是否为旧式url地址
            string strUrl = this.LineInfo.LibraryUrl;

            if (strUrl.IndexOf(".asmx") != -1)
            {
                strError = "安装程序发现当前使用了旧版本 dp2LibraryWs 的地址 '" + strUrl + "',需要您将它修改为新版 dp2Library (图书馆应用服务器) 的 URL 地址。";
                goto ERROR1;
            }

            if (this.CreateMode == true &&
                this.m_bDataDirExist == false)
            {
                // opac 用户信息
                if (this.LineInfo.LibraryUserName == null ||
                    this.LineInfo.LibraryPassword == null)
                {
                    strError = "尚未设定 opac 账户的用户名、密码";
                    goto ERROR1;
                }
            }

            // 如果修改时,需要创建新的数据目录
            if (this.CreateMode == false)
            {
                // 探测数据目录,是否已经存在数据,是不是属于升级情形
                // return:
                //      -1  error
                //      0   数据目录不存在
                //      1   数据目录存在,但是xml文件不存在
                //      2   xml文件已经存在
                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)
                {
                    // opac 用户信息
                    if (this.LineInfo.LibraryUserName == null ||
                        this.LineInfo.LibraryPassword == null)
                    {
                        strError = "尚未设定 opac 账户的用户名、密码";
                        goto ERROR1;
                    }
                }
            }

            // 处理数据目录更名情况
            nRet = RenameDataDir(out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

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

            if (this.VerifyInstanceName != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.comboBox_site.Text + 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;
                }
            }

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

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