Пример #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.marcfixedfieldcontrol.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marckernel.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marcquery.dll",
									Environment.CurrentDirectory + "\\digitalplatform.gcatclient.dll",
									Environment.CurrentDirectory + "\\digitalplatform.script.dll",
									Environment.CurrentDirectory + "\\digitalplatform.commoncontrol.dll",
									Environment.CurrentDirectory + "\\digitalplatform.circulationclient.dll",
									Environment.CurrentDirectory + "\\digitalplatform.libraryclient.dll",

                                    Environment.CurrentDirectory + "\\dp2circulation.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,
                "dp2Circulation.VerifyHost");
            if (entryClassType == null)
            {

                strError = "dp2Circulation.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;
        }
Пример #2
0
        /*public*/
        int PrepareMarcFilter(
            VerifyHost host,
            string strFilterFileName,
            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.Load(strFilterFileName);
            }
            catch (Exception ex)
            {
                strError = "EntityForm filter.Load() exception: " + ExceptionUtil.GetAutoText(ex);
                return -1;
            }

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

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

#if NO
            string[] saAddRef1 = {
										 this.BinDir + "\\digitalplatform.marcdom.dll",
										 this.BinDir + "\\digitalplatform.marckernel.dll",
										 this.BinDir + "\\digitalplatform.libraryserver.dll",
										 this.BinDir + "\\digitalplatform.dll",
										 this.BinDir + "\\digitalplatform.Text.dll",
										 this.BinDir + "\\digitalplatform.IO.dll",
										 this.BinDir + "\\digitalplatform.Xml.dll",
										 };
#endif
            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.marcquery.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 + "\\digitalplatform.libraryclient.dll",

                                    Environment.CurrentDirectory + "\\dp2circulation.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;
        }
Пример #3
0
        // MARC格式校验
        // parameters:
        //      sender    从何处启动? MarcEditor EntityEditForm BindingForm
        /// <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,
            bool bAutoVerify)
        {
            string strError = "";
            this._processing++;
            try
            {
                if (this.IsDisposed == true)
                {
                    strError = "VerifyData() 失败。因 EntityForm 窗口已经释放";
                    goto ERROR1;
                }

                // test
                //Thread.Sleep(10 * 1000);

                // 库名部分路径
                string strBiblioDbName = Global.GetDbName(this.BiblioRecPath);

                string strCode = "";
                string strRef = "";
                string strOutputFilename = "";

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

                    // 2011/8/17
                    if (this.MainForm.PanelFixedVisible == true)
                        MainForm.ActivateVerifyResultPage();
                }

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

                string strCfgFileName = "dp2circulation_marc_verify.fltx";

                byte[] baCfgOutputTimestamp = null;
                // return:
                //      -1  error
                //      0   not found
                //      1   found
                int nRet = GetCfgFile(strBiblioDbName,
                    strCfgFileName,
                    out strOutputFilename,
                    out baCfgOutputTimestamp,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                // test
                //Thread.Sleep(10 * 1000);

                if (nRet == 0)
                {
                    // .cs 和 .cs.ref
                    strCfgFileName = "dp2circulation_marc_verify.cs";
                    nRet = GetCfgFileContent(strBiblioDbName,
        strCfgFileName,
        out strCode,
        out baCfgOutputTimestamp,
        out strError);
                    if (nRet == 0)
                    {
                        strError = "服务器上没有定义路径为 '" + strBiblioDbName + "/" + strCfgFileName + "' 的配置文件(或.fltx配置文件),数据校验无法进行";
                        goto ERROR1;
                    }
                    if (nRet == -1 || nRet == 0)
                        goto ERROR1;
                    strCfgFileName = "dp2circulation_marc_verify.cs.ref";
                    nRet = GetCfgFileContent(strBiblioDbName,
                        strCfgFileName,
                        out strRef,
                        out baCfgOutputTimestamp,
                        out strError);
                    if (nRet == 0)
                    {
                        strError = "服务器上没有定义路径为 '" + strBiblioDbName + "/" + strCfgFileName + "' 的配置文件,虽然定义了.cs配置文件。数据校验无法进行";
                        goto ERROR1;
                    }
                    if (nRet == -1 || nRet == 0)
                        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.PrepareMarcFilter(
                        host,
                        strOutputFilename,
                        out filter,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "编译文件 '" + strCfgFileName + "' 的过程中出错:\r\n" + strError;
                        goto ERROR1;
                    }

                    try
                    {
                        nRet = filter.DoRecord(null,
                            this.GetMarc(),    //  this.m_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/3
                    bVerifyFail = true;
                }

                this.SetSaveAllButtonState(true);   // 2009/3/29 
                return bVerifyFail == true ? 2 : 0;
            }
            finally
            {
                this._processing--;
            }
        ERROR1:
            MessageBox.Show(this, strError);
            if (this.m_verifyViewer != null)
                this.m_verifyViewer.ResultString = strError;
            return 0;
        }