コード例 #1
0
ファイル: ISO2709StatisForm.cs プロジェクト: zgren/dp2
        // 准备脚本环境
        int PrepareScript(string strProjectName,
                          string strProjectLocate,
                          out Iso2709Statis objStatis,
                          out string strError)
        {
            this.AssemblyMain = null;

            objStatis = null;

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

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

            string[] saAddRef =
            {
                // 2011/4/20 增加
                "system.dll",
                "system.drawing.dll",
                "system.windows.forms.dll",
                "system.xml.dll",
                "System.Runtime.Serialization.dll",
                Environment.CurrentDirectory + "\\digitalplatform.core.dll",
                Environment.CurrentDirectory + "\\digitalplatform.dll",
                Environment.CurrentDirectory + "\\digitalplatform.Text.dll",
                Environment.CurrentDirectory + "\\digitalplatform.IO.dll",
                Environment.CurrentDirectory + "\\digitalplatform.Xml.dll",
                Environment.CurrentDirectory + "\\digitalplatform.marckernel.dll",
                Environment.CurrentDirectory + "\\digitalplatform.marcdom.dll",
                Environment.CurrentDirectory + "\\digitalplatform.marcquery.dll",
                Environment.CurrentDirectory + "\\digitalplatform.circulationclient.dll",
                Environment.CurrentDirectory + "\\digitalplatform.libraryclient.dll",
                Environment.CurrentDirectory + "\\digitalplatform.Script.dll",                                                          // 2011/8/25 新增
                Environment.CurrentDirectory + "\\digitalplatform.dp2.statis.dll",
                Environment.CurrentDirectory + "\\dp2circulation.exe",
            };


            // 创建Project中Script main.cs的Assembly
            // return:
            //		-2	出错,但是已经提示过错误信息了。
            //		-1	出错
            int nRet = ScriptManager.BuildAssembly(
                "Iso2709StatisForm",
                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, strWarning);
            }

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

            // 得到Assembly中Iso2709Statis派生类Type
            Type entryClassType = ScriptManager.GetDerivedClassType(
                this.AssemblyMain,
                "dp2Circulation.Iso2709Statis");

            if (entryClassType == null)
            {
                strError = strMainCsDllName + "中没有找到 dp2Circulation.Iso2709Statis 派生类。";
                goto ERROR1;
            }
            // new一个Iso2709Statis派生对象
            objStatis = (Iso2709Statis)entryClassType.InvokeMember(null,
                                                                   BindingFlags.DeclaredOnly |
                                                                   BindingFlags.Public | BindingFlags.NonPublic |
                                                                   BindingFlags.Instance | BindingFlags.CreateInstance, null, null,
                                                                   null);

            // 为Iso2709Statis派生类设置参数
            objStatis.Iso2709StatisForm = this;
            objStatis.ProjectDir        = strProjectLocate;
            objStatis.InstanceDir       = this.InstanceDir;

            return(0);

ERROR1:
            return(-1);
        }
コード例 #2
0
ファイル: ISO2709StatisForm.cs プロジェクト: paopaofeng/dp2
        // 准备脚本环境
        int PrepareScript(string strProjectName,
            string strProjectLocate,
            out Iso2709Statis objStatis,
            out string strError)
        {
            this.AssemblyMain = null;

            objStatis = null;

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

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

            string[] saAddRef = {
                                    // 2011/4/20 增加
                                    "system.dll",
                                    "system.drawing.dll",
                                    "system.windows.forms.dll",
                                    "system.xml.dll",
                                    "System.Runtime.Serialization.dll",

									Environment.CurrentDirectory + "\\digitalplatform.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Text.dll",
									Environment.CurrentDirectory + "\\digitalplatform.IO.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Xml.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marckernel.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marcdom.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marcquery.dll",
   									Environment.CurrentDirectory + "\\digitalplatform.circulationclient.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Script.dll",  // 2011/8/25 新增
									Environment.CurrentDirectory + "\\digitalplatform.dp2.statis.dll",
                Environment.CurrentDirectory + "\\dp2circulation.exe",
            };


            // 创建Project中Script main.cs的Assembly
            // return:
            //		-2	出错,但是已经提示过错误信息了。
            //		-1	出错
            int nRet = ScriptManager.BuildAssembly(
                "Iso2709StatisForm",
                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, strWarning);
            }


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

            // 得到Assembly中Iso2709Statis派生类Type
            Type entryClassType = ScriptManager.GetDerivedClassType(
                this.AssemblyMain,
                "dp2Circulation.Iso2709Statis");
            if (entryClassType == null)
            {
                strError = strMainCsDllName + "中没有找到 dp2Circulation.Iso2709Statis 派生类。";
                goto ERROR1;
            }
            // new一个Iso2709Statis派生对象
            objStatis = (Iso2709Statis)entryClassType.InvokeMember(null,
                BindingFlags.DeclaredOnly |
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.CreateInstance, null, null,
                null);

            // 为Iso2709Statis派生类设置参数
            objStatis.Iso2709StatisForm = this;
            objStatis.ProjectDir = strProjectLocate;
            objStatis.InstanceDir = this.InstanceDir;

            return 0;
        ERROR1:
            return -1;
        }
コード例 #3
0
ファイル: ISO2709StatisForm.cs プロジェクト: zgren/dp2
        public override int RunScript(string strProjectName,
                                      string strProjectLocate,
                                      string strInitialParamString,
                                      out string strError,
                                      out string strWarning)
        {
            strWarning = "";

            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在执行脚本 ...");
            stop.BeginLoop();

            this.Update();
            Program.MainForm.Update();

            _dllPaths.Clear();
            _dllPaths.Add(strProjectLocate);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            try
            {
                int nRet = 0;
                strError = "";

                this.objStatis    = null;
                this.AssemblyMain = null;

                // 2009/11/5
                // 防止以前残留的打开的文件依然没有关闭
                Global.ForceGarbageCollection();

                nRet = PrepareScript(strProjectName,
                                     strProjectLocate,
                                     out objStatis,
                                     out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                if (strInitialParamString == "test_compile")
                {
                    return(0);
                }

                objStatis.ProjectDir    = strProjectLocate;
                objStatis.Console       = this.Console;
                objStatis.InputFilename = this._openMarcFileDialog.FileName;

                // 执行脚本的OnInitial()

                // 触发Script中OnInitial()代码
                // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                    {
                        goto END1;
                    }
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                // 触发Script中OnBegin()代码
                // OnBegin()中仍然有修改MainForm面板的自由
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                    {
                        goto END1;
                    }
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                // 循环
                nRet = DoLoop(out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                if (nRet == 1)
                {
                    goto END1;  // TODO: SkipAll如何执行? 是否连OnEnd也不执行了?
                }
END1:
                // 触发Script的OnEnd()代码
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnEnd(this, args);
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                return(0);

ERROR1:
                return(-1);
            }
            catch (Exception ex)
            {
                strError = "脚本执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                if (objStatis != null)
                {
                    objStatis.FreeResources();
                }

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                this.AssemblyMain = null;

                EnableControls(true);
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }
コード例 #4
0
ファイル: ISO2709StatisForm.cs プロジェクト: paopaofeng/dp2
        int RunScript(string strProjectName,
            string strProjectLocate,
            out string strError)
        {
            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在执行脚本 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            _dllPaths.Clear();
            _dllPaths.Add(strProjectLocate);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            try
            {

                int nRet = 0;
                strError = "";

                this.objStatis = null;
                this.AssemblyMain = null;

                // 2009/11/5
                // 防止以前残留的打开的文件依然没有关闭
                Global.ForceGarbageCollection();

                nRet = PrepareScript(strProjectName,
                    strProjectLocate,
                    out objStatis,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                objStatis.ProjectDir = strProjectLocate;
                objStatis.Console = this.Console;
                objStatis.InputFilename = this._openMarcFileDialog.FileName;

                // 执行脚本的OnInitial()

                // 触发Script中OnInitial()代码
                // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        goto END1;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                // 触发Script中OnBegin()代码
                // OnBegin()中仍然有修改MainForm面板的自由
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        goto END1;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                // 循环
                nRet = DoLoop(out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (nRet == 1)
                    goto END1;  // TODO: SkipAll如何执行? 是否连OnEnd也不执行了?

            END1:
                // 触发Script的OnEnd()代码
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnEnd(this, args);
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                return 0;

            ERROR1:
                return -1;
            }
            catch (Exception ex)
            {
                strError = "脚本执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                return -1;
            }
            finally
            {
                if (objStatis != null)
                    objStatis.FreeResources();

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                this.AssemblyMain = null;

                EnableControls(true);
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }