Exemplo n.º 1
0
        public int PrepareMarcFilter(
    FilterHost host,
    string strFilterFileName,
    out LoanFilterDocument filter,
    out string strError)
        {
            strError = "";

            // 看看是否有现成可用的对象
            filter = (LoanFilterDocument)this.Filters.GetFilter(strFilterFileName);

            if (filter != null)
            {
                filter.FilterHost = host;
                return 1;
            }

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

            filter = new LoanFilterDocument();

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

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

            // filter.Load(strFilterFileName);

            try
            {
                filter.Load(strFilterFileName);
            }
            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 = {
										 this.BinDir + "\\digitalplatform.marcdom.dll",
										 this.BinDir + "\\digitalplatform.marckernel.dll",
										 this.BinDir + "\\digitalplatform.OPAC.Server.dll",
										 this.BinDir + "\\digitalplatform.dll",
										 this.BinDir + "\\digitalplatform.Text.dll",
										 this.BinDir + "\\digitalplatform.IO.dll",
										 this.BinDir + "\\digitalplatform.Xml.dll",
										 this.BinDir + "\\digitalplatform.script.dll",
										 this.BinDir + "\\digitalplatform.marcquery.dll",
										 /*strMainCsDllName*/ };

            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.º 2
0
        public int PrepareMarcFilter(
    FilterHost host,
    string strFilterFileName,
    out LoanFilterDocument filter,
    out string strError)
        {
            strError = "";

            // 看看是否有现成可用的对象
            filter = (LoanFilterDocument)this.Filters.GetFilter(strFilterFileName);
            if (filter != null)
            {
                filter.FilterHost = host;
                return 1;
            }

            // 新创建
            filter = new LoanFilterDocument();

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

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

            try
            {
                filter.Load(strFilterFileName);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                return -1;
            }

            string strCode = "";    // c#代码
            int nRet = filter.BuildScriptFile(out strCode,
                out strError);
            if (nRet == -1)
                return -1;

            try
            {
                string[] saRef2 = filter.GetRefs();

                filter.Assembly = this.AssemblyCache.GetObject(strFilterFileName,
                    () =>
                    {
                        string[] saAddRef1 = {
                                         this.BinDir + "\\digitalplatform.marcdom.dll",
                                         this.BinDir + "\\digitalplatform.marckernel.dll",
                                         this.BinDir + "\\digitalplatform.OPAC.Server.dll",
                                         this.BinDir + "\\digitalplatform.dll",
                                         this.BinDir + "\\digitalplatform.Text.dll",
                                         this.BinDir + "\\digitalplatform.IO.dll",
                                         this.BinDir + "\\digitalplatform.Xml.dll",
                                         this.BinDir + "\\digitalplatform.script.dll",
                                         this.BinDir + "\\digitalplatform.marcquery.dll",
										 };

                        string strError1 = "";
                        string strWarning = "";
                        // string strLibPaths = "";

                        string[] saRef = StringUtil.Append(saRef2, saAddRef1);
#if NO
                        string[] saRef = new string[saRef2.Length + saAddRef1.Length];
                        Array.Copy(saRef2, saRef, saRef2.Length);
                        Array.Copy(saAddRef1, 0, saRef, saRef2.Length, saAddRef1.Length);
#endif

                        Assembly assembly1 = null;
                        // 创建Script的Assembly
                        // 本函数内对saRef不再进行宏替换
                        nRet = ScriptManager.CreateAssembly_1(strCode,
                            saRef,
                            "", // strLibPaths,
                            out assembly1,
                            out strError1,
                            out strWarning);
                        if (nRet == -2)
                            throw new Exception(strError1);
                        if (nRet == -1)
                        {
                            if (string.IsNullOrEmpty(strWarning) == true)
                                throw new Exception(strError1);
                        }

                        return assembly1;
                    });
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                return -1;
            }

            return 0;
        }