Example #1
0
        private ReflectionScriptDefines execReflectObject(ReflectionScriptDefines refObj)
        {
            Type       queryWinType = refObj.Referenz.GetType();
            MethodInfo myMethodInfo = queryWinType.GetMethod("getObject");

            object[] mParam = new object[] { refObj, this.parentObject };
            refObj.ReflectObject = myMethodInfo.Invoke(refObj.Referenz, mParam);
            return(refObj);
        }
Example #2
0
        private void updateMessage(ReflectionScriptDefines refObj)
        {
            if (this.parentWatcher != null && watcherMethod != null)
            {
                int startLn = 0;

                if (this.currentScript.Parent != null)
                {
                    startLn = this.currentScript.parentLineNumber;
                }

                Type       queryWinType = this.parentWatcher.GetType();
                MethodInfo myMethodInfo = queryWinType.GetMethod(this.watcherMethod);
                object[]   mParam       = new object[] { refObj, refObj.lineNumber + startLn, this.runState, this.runlevel };
                refObj.ReflectObject = myMethodInfo.Invoke(this.parentWatcher, mParam);
            }
            Application.DoEvents();
        }
Example #3
0
        private Object execMethod(Object obj, ReflectionScriptDefines refObj)
        {
            if (obj == null)
            {
                lastErrorCode      = Projector.RefSrcStates.EXEC_ERROR_NONOBJECT;
                lastErrorMessage   = "Object is NULL";
                this.internalError = true;
                return(null);
            }

            Type       executeableObj = obj.GetType();
            MethodInfo myMethodInfo   = executeableObj.GetMethod(refObj.originCode);

            if (myMethodInfo == null)
            {
                lastErrorCode      = Projector.RefSrcStates.EXEC_ERROR_NONMETHOD;
                lastErrorMessage   = "invalid Method (null)";
                this.internalError = true;
                return(null);
            }

            int countOfparams = refObj.parameters.Count();

            if (countOfparams > 0)
            {
                object[] mParam = new object[countOfparams];
                for (int i = 0; i < countOfparams; i++)
                {
                    mParam[i] = refObj.parameters[i];
                }

                try
                {
                    return(myMethodInfo.Invoke(obj, mParam));
                }
                catch (TargetParameterCountException te)
                {
                    lastErrorCode      = Projector.RefSrcStates.EXEC_ERROR_INVALID_PARAMETER_COUNT;
                    lastErrorMessage   = te.Message;
                    this.internalError = true;
                    return(null);
                }
                catch (TargetInvocationException te)
                {
                    lastErrorCode      = Projector.RefSrcStates.EXEC_ERROR_UNKNOWNREASON;
                    lastErrorMessage   = te.Message;
                    this.internalError = true;
                    return(null);
                }
                catch (ArgumentException te)
                {
                    lastErrorCode      = Projector.RefSrcStates.EXEC_ERROR_UNKNOWNREASON;
                    lastErrorMessage   = te.Message;
                    this.internalError = true;
                    return(null);
                }
            }
            else
            {
                try
                {
                    return(myMethodInfo.Invoke(obj, null));
                }
                catch (TargetParameterCountException te)
                {
                    lastErrorCode      = Projector.RefSrcStates.EXEC_ERROR_INVALID_PARAMETER_COUNT;
                    lastErrorMessage   = te.Message;
                    this.internalError = true;
                    return(null);
                }
            }
        }
Example #4
0
        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);
        }