示例#1
0
 public bool Run(ScriptProcedure procedure, bool noevent = false)
 {
     Clean();
     if (procedure == null)
     {
         return(true);
     }
     _procedure = procedure;
     try {
         procedure.Run();
     } catch (Exception ex) {
         if (_error == null && !ExitException.Is(ex))
         {
             throw;
         }
     }
     if (_error == null)
     {
         return(true);
     }
     if (OnError != null && !noevent)
     {
         OnError(_error);
     }
     return(false);
 }
示例#2
0
 private void Clean()
 {
     _error     = null;
     _err_line  = 0;
     _procedure = null;
     _result    = null;
 }
示例#3
0
 public ScriptError(Script script, ScriptProcedure procedure, string message) {
     _script = script;
     _proc_item = procedure;
     _message.Append(message.CleanEnd());
     if(script != null)
         _script.Succeed = false;
 }
示例#4
0
 public ScriptError(Script script, ScriptProcedure procedure, string message)
 {
     _script    = script;
     _proc_item = procedure;
     _message.Append(message.CleanEnd());
     if (script != null)
     {
         _script.Succeed = false;
     }
 }
示例#5
0
 private ScriptProcedures ListProcedures(Script script, Regex pattern) {
     ScriptProcedures procedures = new ScriptProcedures();
     foreach (IMSScriptModule msc_module in _scriptcontrol.Modules) {
         ScriptModule module = new ScriptModule(msc_module);
         foreach (IMSScriptProcedure msc_procedure in msc_module.Procedures) {
             var proc_name = msc_procedure.Name;
             ScriptProcedure procedure = new ScriptProcedure(module, proc_name);
             switch (proc_name.ToLower()) {
                 case "initialize": procedures.ProcInitialize = procedure; break;
                 case "terminate": procedures.ProcTerminate = procedure; break;
                 case "setup": procedures.ProcSetup = procedure; break;
                 case "teardown": procedures.ProcTearDown = procedure; break;
                 case "onerror": procedures.ProcOnError = procedure; break;
                 case "iif": break;
                 default:
                     if (msc_procedure.HasReturnValue)
                         continue;
                     if (!pattern.IsMatch(proc_name))
                         continue;
                     WithParams proc_params_str;
                     if (script.ScriptWithParams.TryGetValue(proc_name, out proc_params_str)) {
                         if (!_scriptcontrol.Eval("Array(" + proc_params_str.Params + ')')) {
                             var error = new ScriptError(script, procedure, "Invalide array: " + proc_params_str.Params);
                             error.AddTrace(script, proc_params_str.Line);
                             OnError(error);
                             continue;
                         }
                         var proc_params = (object[])_scriptcontrol.Result;
                         foreach (var proc_param in proc_params) {
                             object[] args = CastToArray(proc_param);
                             if (args.Length == 0) {
                                 var error = new ScriptError(script, procedure, string.Format(
                                     "Procedure {0} requires {1} argument(s). {2} provied.",
                                     proc_name, msc_procedure.NumArgs, args.Length));
                                 error.AddTrace(script, script.TextFormated.GetLineNumber("(Sub|Function).\b" + proc_name + "\b"));
                                 OnError(error);
                                 break;
                             }
                             procedure = new ScriptProcedure(module, proc_name, args);
                             procedures.Add(procedure);
                         }
                     } else if (msc_procedure.NumArgs == 0) {
                         procedures.Add(procedure);
                     }
                     break;
             }
         }
     }
     return procedures;
 }
示例#6
0
 public ScriptSuccess(Script script, ScriptProcedure procedure = null) {
     _script = script;
     _procedure = procedure;
 }
示例#7
0
 public ScriptSuccess(Script script, ScriptProcedure procedure = null)
 {
     _script    = script;
     _procedure = procedure;
 }
示例#8
0
        private ScriptProcedures ListProcedures(Script script, Regex pattern)
        {
            ScriptProcedures procedures = new ScriptProcedures();

            foreach (IMSScriptModule msc_module in _scriptcontrol.Modules)
            {
                ScriptModule module = new ScriptModule(msc_module);
                foreach (IMSScriptProcedure msc_procedure in msc_module.Procedures)
                {
                    var             proc_name = msc_procedure.Name;
                    ScriptProcedure procedure = new ScriptProcedure(module, proc_name);
                    switch (proc_name.ToLower())
                    {
                    case "initialize": procedures.ProcInitialize = procedure; break;

                    case "terminate": procedures.ProcTerminate = procedure; break;

                    case "setup": procedures.ProcSetup = procedure; break;

                    case "teardown": procedures.ProcTearDown = procedure; break;

                    case "onerror": procedures.ProcOnError = procedure; break;

                    case "iif": break;

                    default:
                        if (msc_procedure.HasReturnValue)
                        {
                            continue;
                        }
                        if (!pattern.IsMatch(proc_name))
                        {
                            continue;
                        }
                        WithParams proc_params_str;
                        if (script.ScriptWithParams.TryGetValue(proc_name, out proc_params_str))
                        {
                            if (!_scriptcontrol.Eval("Array(" + proc_params_str.Params + ')'))
                            {
                                var error = new ScriptError(script, procedure, "Invalide array: " + proc_params_str.Params);
                                error.AddTrace(script, proc_params_str.Line);
                                OnError(error);
                                continue;
                            }
                            var proc_params = (object[])_scriptcontrol.Result;
                            foreach (var proc_param in proc_params)
                            {
                                object[] args = CastToArray(proc_param);
                                if (args.Length == 0)
                                {
                                    var error = new ScriptError(script, procedure, string.Format(
                                                                    "Procedure {0} requires {1} argument(s). {2} provied.",
                                                                    proc_name, msc_procedure.NumArgs, args.Length));
                                    error.AddTrace(script, script.TextFormated.GetLineNumber("(Sub|Function).\b" + proc_name + "\b"));
                                    OnError(error);
                                    break;
                                }
                                procedure = new ScriptProcedure(module, proc_name, args);
                                procedures.Add(procedure);
                            }
                        }
                        else if (msc_procedure.NumArgs == 0)
                        {
                            procedures.Add(procedure);
                        }
                        break;
                    }
                }
            }
            return(procedures);
        }
示例#9
0
 private void Clean() {
     _error = null;
     _err_line = 0;
     _procedure = null;
     _result = null;
 }
示例#10
0
 public bool Run(ScriptProcedure procedure, bool noevent = false) {
     Clean();
     if (procedure == null)
         return true;
     _procedure = procedure;
     try {
         procedure.Run();
     } catch (Exception ex) {
         if (_error == null && !ExitException.Is(ex))
             throw;
     }
     if (_error == null)
         return true;
     if (OnError != null && !noevent)
         OnError(_error);
     return false;
 }