コード例 #1
0
ファイル: StackManager.cs プロジェクト: brentmerkle/ClixStack
 public bool CommandIsValid(string CommandName)
 {
     try
     {
         // NOTE: This should handle any kind of function/method.
         CommandManager ClixCommands = new CommandManager();
         Type t = ClixCommands.GetType();
         MethodInfo m = t.GetMethod(CommandName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase);
         if (m == null)
         {
             return false;
         }
         else
         {
             return true;
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
コード例 #2
0
ファイル: StackManager.cs プロジェクト: brentmerkle/ClixStack
        public object ExecuteCommand(string CommandName, object[] Parameters)
        {
            try
            {
                object[] ExeParams = new object[1];
                ExeParams[0] = this;
                CommandManager Cmds = new CommandManager();
                Type t = Cmds.GetType();
                // NOTE: This should handle any kind of function.
                MethodInfo m = t.GetMethod(CommandName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase);
                // NOTE: What if method still not found?
                if (m == null)
                {
                    throw new ErrorManager.NewException("ERROR: The Command: '" + CommandName + "' is not a valid command on line: '" + LineNumber.ToString() + "'.");
                }

                //Check to see if this command is a custom function definition
                if (!(CommandName.Trim().ToLower() == "function"))
                {
                    //Parameter Count Check
                    if ((Parameters != null))
                    {
                        if (!(m.GetParameters().Length == Parameters.Length + 2))
                        {
                            throw new ErrorManager.NewException("ERROR: The Command: '" + CommandName + "' expects a different number of parammeters then provided on line: '" + LineNumber.ToString() + "'.");
                        }
                    }
                    else
                    {
                        if (!(m.GetParameters().Length == 2))
                        {
                            throw new ErrorManager.NewException("ERROR: The Command: '" + CommandName + "' expects a parammeters on line: '" + LineNumber.ToString() + "'. None were provided.");
                        }
                    }
                    //' If the Command Has Parameters Then Dynamically Call The Function and Retreive Schema and Finalize the Parameters
                    if ((Parameters != null))
                    {
                        //Create a Parameter with an Instance of Current Script Engine
                        object[] cParameters = new object[1];
                        cParameters[0] = this;
                        //Create an Array of Null Parameters
                        foreach (object Obj in Parameters)
                        {
                            Array.Resize(ref cParameters, cParameters.Length + 1);
                            cParameters[cParameters.Length - 1] = null;
                        }
                        //Add SchemaReturn Flag and Set = True
                        Array.Resize(ref cParameters, cParameters.Length + 1);
                        cParameters[cParameters.Length - 1] = true;
                        string[] SchemaArray = m.Invoke(Cmds, cParameters).ToString().Split(';');
                        //Parameters = FinalizeParameters(Parameters, SchemaArray)
                        Parameters = FinalizeParameters(Parameters, SchemaArray);
                    }

                    if ((Parameters != null))
                    {
                        foreach (object Obj in Parameters)
                        {
                            Array.Resize(ref ExeParams, ExeParams.Length + 1);
                            ExeParams[ExeParams.Length - 1] = Obj;
                        }
                    }
                    Array.Resize(ref ExeParams, ExeParams.Length + 1);

                    ///// CONDITIONAL
                    ExeParams[ExeParams.Length - 1] = false;

                    return m.Invoke(Cmds, ExeParams);
                    // Dynamically Call The Command Function.
                }
                else
                {
                    if ((Parameters != null))
                    {
                        string[] SchemaArray = null;
                        foreach (object Parameter in Parameters)
                        {
                            if ((SchemaArray != null))
                            {
                                Array.Resize(ref SchemaArray, SchemaArray.Length + 1);
                            }
                            else
                            {
                                SchemaArray = new string[1];
                            }
                            SchemaArray[SchemaArray.Length - 1] = "string";
                        }

                        if (Parameters.Length > 1)
                        {
                            //FIX !!!!!!!!!!!!!!!!!!!!!!
                            Parameters = FinalizeParameters(Parameters, SchemaArray);
                            //Re-Insert Parameter 0
                        }
                        Parameters[0] = Parameters[0].ToString().Trim();
                        int cInst = 0;
                        foreach (object Obj in Parameters)
                        {
                            Array.Resize(ref ExeParams, ExeParams.Length + 1);
                            if (cInst > 0)
                            {
                                string[] ObjInst = new string[1];
                                ObjInst[0] = Obj.ToString();
                                ExeParams[ExeParams.Length - 1] = ObjInst;
                            }
                            else
                            {
                                ExeParams[ExeParams.Length - 1] = Obj;
                            }
                            cInst++;
                        }
                    }
                    return m.Invoke(Cmds, ExeParams);
                    // Dynamically Call The Command Function.
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }