Exemplo n.º 1
0
        int RunVerifyCsScript(
    object sender,
    GenerateDataEventArgs e,
    string strCode,
    string strRef,
            out VerifyHost hostObj,
    out string strError)
        {
            strError = "";
            string[] saRef = null;
            int nRet;
            hostObj = null;

            nRet = ScriptManager.GetRefsFromXml(strRef,
                out saRef,
                out strError);
            if (nRet == -1)
                return -1;

            // 2007/12/4
            ScriptManager.RemoveRefsBinDirMacro(ref saRef);

            string[] saAddRef = {
                                    "system.dll",
                                    "system.xml.dll",
                                    "system.windows.forms.dll",
                                    "system.drawing.dll",
                                    "System.Runtime.Serialization.dll",

									Environment.CurrentDirectory + "\\digitalplatform.dll",
									Environment.CurrentDirectory + "\\digitalplatform.IO.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Text.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Xml.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marceditor.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marckernel.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marcfixedfieldcontrol.dll",
									Environment.CurrentDirectory + "\\digitalplatform.gcatclient.dll",
									Environment.CurrentDirectory + "\\digitalplatform.script.dll",
									Environment.CurrentDirectory + "\\digitalplatform.commoncontrol.dll",
									Environment.CurrentDirectory + "\\digitalplatform.circulationclient.dll",
									Environment.CurrentDirectory + "\\dp2catalog.exe"
								};

            if (saAddRef != null)
            {
                string[] saTemp = new string[saRef.Length + saAddRef.Length];
                Array.Copy(saRef, 0, saTemp, 0, saRef.Length);
                Array.Copy(saAddRef, 0, saTemp, saRef.Length, saAddRef.Length);
                saRef = saTemp;
            }

            Assembly assembly = null;
            string strErrorInfo = "";
            string strWarningInfo = "";
            nRet = ScriptManager.CreateAssembly_1(strCode,
                saRef,
                null,   // strLibPaths,
                out assembly,
                out strErrorInfo,
                out strWarningInfo);
            if (nRet == -1)
            {
                strError = "脚本编译发现错误或警告:\r\n" + strErrorInfo;
                return -1;
            }

            // 得到Assembly中VerifyHost派生类Type
            Type entryClassType = ScriptManager.GetDerivedClassType(
                assembly,
                "dp2Catalog.VerifyHost");
            if (entryClassType == null)
            {

                strError = "dp2Catalog.VerifyHost派生类没有找到";
                return -1;
            }

            {
                // new一个VerifyHost派生对象
                hostObj = (VerifyHost)entryClassType.InvokeMember(null,
                    BindingFlags.DeclaredOnly |
                    BindingFlags.Public | BindingFlags.NonPublic |
                    BindingFlags.Instance | BindingFlags.CreateInstance, null, null,
                    null);

                if (hostObj == null)
                {
                    strError = "new VerifyHost派生类对象失败";
                    return -1;
                }

                // 为Host派生类设置参数
                hostObj.DetailForm = this;
                hostObj.Assembly = assembly;

                HostEventArgs e1 = new HostEventArgs();
                e1.e = e;   // 2009/2/24

                hostObj.Main(sender, e1);
            }

            return 0;
        }
Exemplo n.º 2
0
        public int PrepareVerifyMarcFilter(
    VerifyHost host,
    string strContent,
    out VerifyFilterDocument filter,
    out string strError)
        {
            strError = "";

            // 新创建
            // string strFilterFileContent = "";

            filter = new VerifyFilterDocument();

            filter.FilterHost = host;
            filter.strOtherDef = "VerifyHost Host = null;";

            filter.strPreInitial = " VerifyFilterDocument doc = (VerifyFilterDocument)this.Document;\r\n";
            filter.strPreInitial += " Host = ("
                + "VerifyHost" + ")doc.FilterHost;\r\n";

            try
            {
                filter.LoadContent(strContent);
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                return -1;
            }

            string strCode = "";    // c#代码

            int nRet = filter.BuildScriptFile(out strCode,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            string[] saAddRef1 = {
                                    "system.dll",
                                    "system.xml.dll",
                                    "system.windows.forms.dll",
                                    "system.drawing.dll",
                                    "System.Runtime.Serialization.dll",

									Environment.CurrentDirectory + "\\digitalplatform.dll",
									Environment.CurrentDirectory + "\\digitalplatform.IO.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Text.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Xml.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marceditor.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marckernel.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marcdom.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marcfixedfieldcontrol.dll",
									Environment.CurrentDirectory + "\\digitalplatform.gcatclient.dll",
									Environment.CurrentDirectory + "\\digitalplatform.script.dll",
									Environment.CurrentDirectory + "\\digitalplatform.commoncontrol.dll",
									Environment.CurrentDirectory + "\\digitalplatform.circulationclient.dll",
									Environment.CurrentDirectory + "\\dp2catalog.exe"
								};

            Assembly assembly = null;
            string strWarning = "";
            string strLibPaths = "";

            string[] saRef2 = filter.GetRefs();

            string[] saRef = new string[saRef2.Length + saAddRef1.Length];
            Array.Copy(saRef2, saRef, saRef2.Length);
            Array.Copy(saAddRef1, 0, saRef, saRef2.Length, saAddRef1.Length);

            // 创建Script的Assembly
            // 本函数内对saRef不再进行宏替换
            nRet = ScriptManager.CreateAssembly_1(strCode,
                saRef,
                strLibPaths,
                out assembly,
                out strError,
                out strWarning);

            if (nRet == -2)
                goto ERROR1;
            if (nRet == -1)
            {
                if (strWarning == "")
                {
                    goto ERROR1;
                }
                // MessageBox.Show(this, strWarning);
            }

            filter.Assembly = assembly;

            return 0;
        ERROR1:
            return -1;
        }
Exemplo n.º 3
0
        // MARC格式校验
        // parameters:
        //      sender    从何处启动? MarcEditor EntityEditForm
        /// <summary>
        /// MARC格式校验
        /// </summary>
        /// <param name="sender">从何处启动?</param>
        /// <param name="e">GenerateDataEventArgs对象,表示动作参数</param>
        /// <param name="bAutoVerify">是否自动校验。自动校验的时候,如果没有发现错误,则不出现最后的对话框</param>
        /// <returns>0: 没有发现校验错误; 1: 发现校验警告; 2: 发现校验错误</returns>
        public int VerifyData(object sender,
            GenerateDataEventArgs e,
            string strSavePath,
            bool bAutoVerify)
        {
            string strError = "";
            string strCode = "";
            string strRef = "";


            if (string.IsNullOrEmpty(strSavePath) == true)
                strSavePath = this.SavePath;

            if (String.IsNullOrEmpty(strSavePath) == true)
            {
                strError = "缺乏保存路径";
                goto ERROR1;
            }

            string strProtocol = "";
            string strPath = "";
            int nRet = Global.ParsePath(strSavePath,
                out strProtocol,
                out strPath,
                out strError);
            if (nRet == -1)
                goto ERROR1;


            // dtlp协议的自动创建数据
            if (strProtocol.ToLower() == "dtlp")
            {
                strError = "暂不支持来自DTLP协议的数据自动创建功能";
                goto ERROR1;
            }

            // Debug.Assert(false, "");
            this.m_strVerifyResult = "正在校验...";
            // 自动校验的时候,如果没有发现错误,则不出现最后的对话框
            if (bAutoVerify == false)
            {
                // 如果固定面板隐藏,就打开窗口
                DoViewVerifyResult(this.MainForm.PanelFixedVisible == false ? true : false);
            }

            VerifyHost host = new VerifyHost();
            host.DetailForm = this;

            // dp2library协议的自动创建数据
            if (strProtocol.ToLower() == "dp2library")
            {
                dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

                if (dp2_searchform == null)
                {
                    strError = "没有连接的或者打开的dp2检索窗,无法进行数据创建";
                    goto ERROR1;
                }

                string strServerName = "";
                string strLocalPath = "";
                // 解析记录路径。
                // 记录路径为如下形态 "中文图书/1 @服务器"
                dp2SearchForm.ParseRecPath(strPath,
                    out strServerName,
                    out strLocalPath);

                string strBiblioDbName = dp2SearchForm.GetDbName(strLocalPath);

                string strCfgFileName = "dp2catalog_marc_verify.fltx";

                string strCfgPath = strBiblioDbName + "/cfgs/" + strCfgFileName + "@" + strServerName;

                byte[] baCfgOutputTimestamp = null;
                // return:
                //      -1  error
                //      0   not found
                //      1   found
                nRet = dp2_searchform.GetCfgFile(strCfgPath,
                    out strCode,
                    out baCfgOutputTimestamp,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
                if (nRet == 0)
                {
                    strCfgFileName = "dp2catalog_marc_verify.cs";

                    strCfgPath = strBiblioDbName + "/cfgs/" + strCfgFileName + "@" + strServerName;

                    baCfgOutputTimestamp = null;
                    nRet = dp2_searchform.GetCfgFile(strCfgPath,
                        out strCode,
                        out baCfgOutputTimestamp,
                        out strError);
                    if (nRet == 0)
                    {
                        strError = "服务器上没有定义路径为 '" + strCfgPath + "' 的配置文件(或.fltx配置文件),数据校验无法进行";
                        goto ERROR1;
                    } 
                    if (nRet == -1)
                        goto ERROR1;

                    strCfgFileName = "dp2catalog_marc_verify.cs.ref";

                    strCfgPath = strBiblioDbName + "/cfgs/" + strCfgFileName + "@" + strServerName;

                    nRet = dp2_searchform.GetCfgFile(strCfgPath,
                        out strRef,
                        out baCfgOutputTimestamp,
                        out strError);
                    if (nRet == 0)
                    {
                        strError = "服务器上没有定义路径为 '" + strCfgPath + "' 的配置文件,虽然定义了.cs配置文件。数据校验无法进行";
                        goto ERROR1;
                    }
                    if (nRet == -1)
                        goto ERROR1;

                    try
                    {
                        // 执行代码
                        nRet = RunVerifyCsScript(
                            sender,
                            e,
                            strCode,
                            strRef,
                            out host,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;
                    }
                    catch (Exception ex)
                    {
                        strError = "执行脚本代码过程中发生异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                        goto ERROR1;
                    }
                }
                else
                {
                    VerifyFilterDocument filter = null;

                    nRet = this.PrepareVerifyMarcFilter(
                        host,
                        strCode,
                        out filter,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "编译文件 '" + strCfgFileName + "' 的过程中出错:\r\n" + strError;
                        goto ERROR1;
                    }

                    try
                    {

                        nRet = filter.DoRecord(null,
                            this.MarcEditor.Marc,
                            0,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;

                    }
                    catch (Exception ex)
                    {
                        strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex);
                        goto ERROR1;
                    }
                }
            }

            bool bVerifyFail = false;
            if (string.IsNullOrEmpty(host.ResultString) == true)
            {
                if (this.m_verifyViewer != null)
                    this.m_verifyViewer.ResultString = "经过校验没有发现任何错误。";
            }
            else
            {
                if (bAutoVerify == true)
                {
                    // 延迟打开窗口
                    DoViewVerifyResult(this.MainForm.PanelFixedVisible == false ? true : false);
                }
                this.m_verifyViewer.ResultString = host.ResultString;
                this.MainForm.ActivateVerifyResultPage();   // 2014/7/13
                bVerifyFail = true;
            }

            return bVerifyFail == true ? 2 : 0;
        ERROR1:
            MessageBox.Show(this, strError);
            if (this.m_verifyViewer != null)
                this.m_verifyViewer.ResultString = strError;
            return 0;
        }