Exemplo n.º 1
0
        // 准备脚本环境
        int PrepareScript(string strProjectName,
            string strProjectLocate,
            out string strError)
        {
            strError = "";
            this.PrintAssembly = null;

            PrintHostObj = null;

            string strWarning = "";


            string strMainCsDllName = PathUtil.MergePath(this.InstanceDir, "\\~charging_print_main_" + Convert.ToString(AssemblyVersion++) + ".dll");    // ++

            string strLibPaths = "\"" + this.MainForm.DataDir + "\""
                + ","
                + "\"" + strProjectLocate + "\"";

            string[] saAddRef = {
									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.libraryclient.dll",   // 2016/10/24
									Environment.CurrentDirectory + "\\dp2circulation.exe"
            };


            // 创建Project中Script main.cs的Assembly
            // return:
            //		-2	出错,但是已经提示过错误信息了。
            //		-1	出错
            int nRet = ScriptManager.BuildAssembly(
                "OperHistory",
                strProjectName,
                "main.cs",
                saAddRef,
                strLibPaths,
                strMainCsDllName,
                out strError,
                out strWarning);
            if (nRet == -2)
                goto ERROR1;
            if (nRet == -1)
            {
                if (strWarning == "")
                    goto ERROR1;
                MessageBox.Show(this.MainForm, strWarning);
            }


            this.PrintAssembly = Assembly.LoadFrom(strMainCsDllName);
            if (this.PrintAssembly == null)
            {
                strError = "LoadFrom " + strMainCsDllName + " fail";
                goto ERROR1;
            }

            // 得到Assembly中PrintHost派生类Type
            Type entryClassType = ScriptManager.GetDerivedClassType(
                PrintAssembly,
                "dp2Circulation.PrintHost");
            if (entryClassType == null)
            {
                strError = "dp2Circulation.PrintHost派生类没有找到";
                return -1;
            }

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

            if (this.PrintHostObj == null)
            {
                strError = "new PrintHost派生类对象失败";
                return -1;
            }

            this.PrintHostObj.ProjectDir = strProjectLocate;
            this.PrintHostObj.InstanceDir = this.InstanceDir;
            return 0;
        ERROR1:
            return -1;
        }
Exemplo n.º 2
0
        int PrepareScript(string strCode,
            string strRef,
            out string strError)
        {
            strError = "";
            string[] saRef = null;
            int nRet;

            nRet = ScriptManager.GetRefsFromXml(strRef,
                out saRef,
                out strError);
            if (nRet == -1)
            {
                strError = "strRef代码\r\n\r\n" + strRef + "\r\n\r\n格式错误: " + strError;
                return -1;
            }

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

            string[] saAddRef = {
									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 + "\\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;
            }

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

            // 得到Assembly中PrintHost派生类Type
            Type entryClassType = ScriptManager.GetDerivedClassType(
                PrintAssembly,
                "dp2Circulation.PrintHost");
            if (entryClassType == null)
            {
                strError = "dp2Circulation.PrintHost派生类没有找到";
                return -1;
            }

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

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



            return 0;
        }