public Boolean run() { if (this.currentScript.Parent != null && this.currentScript.Parent.CurrentExecuter != null) { this.watcherMethod = this.currentScript.Parent.CurrentExecuter.watcherMethod; this.parentWatcher = this.currentScript.Parent.CurrentExecuter.parentWatcher; this.debugMode = this.currentScript.Parent.CurrentExecuter.debugMode; this.runlevel += this.currentScript.Parent.CurrentExecuter.runlevel + 1; this.startLine += this.currentScript.Parent.CurrentExecuter.startLine; } if (!ProcSync.isRegistered(RefScriptExecute.PROC_NAME + this.ProcID)) { ProcSync.registerProc(RefScriptExecute.PROC_NAME + this.ProcID); } this.internalError = false; if (this.currentScript.getNotRuntimeErrorCount() == 0) { this.runState = RefScriptExecute.STATE_RUN; Boolean runSucceed = this.exec(); return(runSucceed == true && this.internalError == false); } else { this.internalError = true; if (this.currentScript.Parent != null) { this.currentScript.updateErrorsToParent(); } } return(false); }
private void clearing() { ProcSync.removeMainProc(RefScriptExecute.PROC_NAME + this.ProcID); /* * foreach (DictionaryEntry existingObjects in this.objectReferences) * { * Object obj = (object)existingObjects.Value; * * } */ }
private Boolean execLine(ReflectionScriptDefines scrLine) { // what ever happens ..tis line is executed this.currentExecLine++; if (this.forceAbort) { return(true); } if (this.currentScript.Parent != null && this.currentScript.Parent.CurrentExecuter != null) { if (this.currentScript.Parent.CurrentExecuter.aborting()) { return(true); } } string cmd = scrLine.code.ToUpper(); //this.currentScript.updateParam(scrLine); if (cmd == "MESSAGEBOX") { string message = ""; foreach (string parStr in scrLine.scriptParameters) { message += this.currentScript.fillUpAll(parStr); } MessageBox.Show(message); } if (cmd == "REG") { string procIdent = ""; foreach (string parStr in scrLine.scriptParameters) { procIdent += this.currentScript.fillUpAll(parStr); } ProcSync.addSubProc(RefScriptExecute.PROC_NAME + this.ProcID, procIdent); } if (cmd == "UNREG") { string procIdent = ""; foreach (string parStr in scrLine.scriptParameters) { procIdent += this.currentScript.fillUpAll(parStr); } if (ProcSync.getProcCount(RefScriptExecute.PROC_NAME + this.ProcID, procIdent) > 0) { ProcSync.removeSubProc(RefScriptExecute.PROC_NAME + this.ProcID, procIdent); } } if (cmd == "EXEC") { List <string> execPars = new List <string>(); string externalScript = ""; foreach (string parStr in scrLine.scriptParameters) { if (externalScript == "") { externalScript = this.currentScript.fillUpAll(parStr); } else { execPars.Add(this.currentScript.fillUpAll(parStr)); } } PConfig seting = new PConfig(); string scrPath = seting.getSettingWidthDefault("client.scriptpath", System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)); string scrFileName = scrPath + System.IO.Path.DirectorySeparatorChar.ToString() + externalScript; if (System.IO.File.Exists(scrFileName)) { string code = System.IO.File.ReadAllText(scrFileName); ReflectionScript exScrpt = new ReflectionScript(); exScrpt.setCode(code); exScrpt.addSetupIfNotExists(ReflectionScript.SETUP_PREVIEW, true); RefScriptExecute subExec = new RefScriptExecute(exScrpt, this.parentObject); int ppp = 0; foreach (string parToExec in execPars) { ppp++; exScrpt.createOrUpdateStringVar("&PARAM." + ppp, parToExec); } subExec.run(); } else { ScriptErrors error = new ScriptErrors(); error.errorMessage = "script not found:" + scrFileName; error.lineNumber = scrLine.lineNumber; error.runtimeError = true; error.errorCode = Projector.RefSrcStates.ERROR_TYPE_WARNING; this.currentScript.addError(error); } } if (cmd == "WAITFOR") { Application.DoEvents(); string procIdent = ""; foreach (string parStr in scrLine.scriptParameters) { procIdent += this.currentScript.fillUpAll(parStr); } if (ProcSync.getProcCount(RefScriptExecute.PROC_NAME + this.ProcID, procIdent) > 0) { // max time reached ? if (this.checkWaitingTimer(procIdent)) { // get back to my self currentExecLine--; Application.DoEvents(); return(true); } else { ScriptErrors error = new ScriptErrors(); error.errorMessage = "Max Waiting Time reached. Check code or increase max waiting Time"; error.lineNumber = scrLine.lineNumber; error.runtimeError = true; error.errorCode = Projector.RefSrcStates.ERROR_TYPE_WARNING; this.currentScript.addError(error); this.removeWaitTimerIfExists(procIdent); } } else { this.removeWaitTimerIfExists(procIdent); } } if (scrLine.setState != 0) { if (scrLine.isParentAssigned) { if (this.currentScript.Parent != null && this.currentScript.Parent.CurrentExecuter != null) { //this.currentScript.Parent. this.currentScript.Parent.CurrentExecuter.runState = scrLine.setState; this.currentScript.Parent.CurrentExecuter.changedState(); } else { ScriptErrors error = new ScriptErrors(); error.errorMessage = "Parent can be used in subscripts only "; error.lineNumber = scrLine.lineNumber; error.runtimeError = true; error.errorCode = Projector.RefSrcStates.EXEC_ERROR_INVALIDOBJECT; this.currentScript.addError(error); } } else { this.runState = scrLine.setState; } } // execute object assignements that NOT are methods. so just code assignements if (scrLine.isAssignement && scrLine.name != null && scrLine.isMethod == false) { // for any assignement a variable must be exists and allready defined this.currentScript.recalcBrackets(scrLine); } if (scrLine.isVariable && !scrLine.isSetup) { this.currentScript.updateParam(scrLine, true); } if (scrLine.isObject && this.objectDefines.ContainsKey(cmd)) { scrLine.Referenz = objectDefines[cmd]; this.execReflectObject(scrLine); if (scrLine.ReflectObject == null) { ScriptErrors error = new ScriptErrors(); error.errorMessage = "object " + scrLine.typeOfObject + " not createable"; error.lineNumber = scrLine.lineNumber; error.errorCode = Projector.RefSrcStates.EXEC_ERROR_NONOBJECT; error.runtimeError = true; this.currentScript.addError(error); lastErrorCode = Projector.RefSrcStates.EXEC_ERROR_INVALIDOBJECT; return(false); } if (!this.scrVars.objectIsStored(scrLine.name)) { this.scrVars.createObject(scrLine.name, scrLine.ReflectObject, scrLine.typeOfObject); } else { ScriptErrors error = new ScriptErrors(); error.errorMessage = "object " + scrLine.typeOfObject + " allready added. Check Script"; error.lineNumber = scrLine.lineNumber; error.errorCode = Projector.RefSrcStates.EXEC_ERROR_NONOBJECT; error.runtimeError = true; this.currentScript.addError(error); lastErrorCode = Projector.RefSrcStates.EXEC_ERROR_INVALIDOBJECT; return(false); } } if (scrLine.isMethod && scrLine.namedReference != null) { Object useObject = this.getRegisteredObject(scrLine.namedReference); //Object useObject = scrLine.ReflectObject; //Object useObject = this.currentScript.getRegisteredObject(scrLine.namedReference); if (useObject != null) { this.lastErrorCode = 0; this.currentScript.updateParam(scrLine, true); Object execResult = this.execMethod(useObject, scrLine); scrLine.ReflectObject = useObject; this.currentScript.scrVars.updateExistingObject(scrLine.namedReference, useObject); if (this.lastErrorCode > 0) { ScriptErrors error = new ScriptErrors(); error.errorMessage = "object " + scrLine.typeOfObject + " reports an error on execution " + this.lastErrorCode + this.lastErrorMessage; error.lineNumber = scrLine.lineNumber; error.runtimeError = true; error.errorCode = this.lastErrorCode; this.currentScript.addError(error); } else { this.currentScript.updateMeByObject(scrLine); if (scrLine.isAssignement && execResult != null) { if (scrLine.isParentAssigned) { if (this.currentScript.Parent != null) { this.currentScript.Parent.scrVars.updateVarByObject(scrLine.name, execResult); } } else { this.currentScript.scrVars.updateVarByObject(scrLine.name, execResult); } } } } else { ScriptErrors error = new ScriptErrors(); error.errorMessage = "execution Fail: " + scrLine.namedReference + " is not registered as an executable Object "; error.lineNumber = scrLine.lineNumber; error.errorCode = this.lastErrorCode; error.runtimeError = true; this.currentScript.addError(error); } } // last trigger call if (this.debugMode) { this.currentDebugLine = scrLine; this.updateMessage(scrLine); } return(true); }