Exemplo n.º 1
0
 private void AddCommand(IOpsCommand commandObj)
 {
     if (!CommandTable.Contains(commandObj.Name))
         CommandTable.Add(commandObj.Name, commandObj);
     else
         throw new OpsException("A command must not map to more than one IOpsCommand object.");
 }
Exemplo n.º 2
0
        public OpsStatement( OpsParsedStatement parsed, IOpsCommand command, object arguments)
        {
            Parsed = parsed;
            OpsParsedArgument arg = parsed.FindArgument("Src");
            ContentRegex = (arg == null) ? "(?# Default Expression ).*" : arg.Value;

            Command = command;
            Arguments = arguments;
        }
Exemplo n.º 3
0
        public OpsStatement(OpsParsedStatement parsed, IOpsCommand command, object arguments)
        {
            Parsed = parsed;
            OpsParsedArgument arg = parsed.FindArgument("Src");

            ContentRegex = (arg == null) ? "(?# Default Expression ).*" : arg.Value;

            Command   = command;
            Arguments = arguments;
        }
Exemplo n.º 4
0
        public IOpsCommand GetCommand(string name)
        {
            IOpsCommand result = CommandTable[name] as IOpsCommand;;

            if (result == null)
            {
                throw new OpsException("Could not find command: " + name);
            }

            return(result);
        }
Exemplo n.º 5
0
 private void AddCommand(IOpsCommand commandObj)
 {
     if (!CommandTable.Contains(commandObj.Name))
     {
         CommandTable.Add(commandObj.Name, commandObj);
     }
     else
     {
         throw new OpsException("A command must not map to more than one IOpsCommand object.");
     }
 }
Exemplo n.º 6
0
        public void FindCommands()
        {
            //This code will hit a broader set of assemblies
            //I left it here encase it is needed by the user or for future work.
            //AppDomain myDomain = AppDomain.CurrentDomain;
            //Assembly[] assemblies = myDomain.GetAssemblies();
            // foreach (Assembly assembly in assemblies)
            //{
            Assembly assembly = Assembly.GetExecutingAssembly();

            try
            {
                Type[] types = assembly.GetTypes();

                if (types != null)
                {
                    foreach (Type type in types)
                    {
                        if (type.Namespace == "Microsoft.DirectX.Solutions.DxOps.Commands")
                        {
                            if (type.IsClass &&
                                !type.IsAbstract &&
                                typeof(IOpsCommand).IsAssignableFrom(type))
                            {
                                //valid command;
                                try
                                {
                                    IOpsCommand commandObj = Activator.CreateInstance(type) as IOpsCommand;

                                    AddCommand(commandObj);
                                }
                                catch
                                {
                                    OpsConsole.WriteError(null, "Could not create instance of type: " + type.FullName);
                                    throw;
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Reflection.ReflectionTypeLoadException e)
            {
                OpsConsole.WriteError(e, "Could not get type from assembly: " + assembly.FullName);
                throw;
            }
            //}
        }
Exemplo n.º 7
0
        public OpsScript(OpsCommandLibrary library, string script)
        {
            OpsParsedStatement[] parsedStatements = OpsParser.ParseScript(script);
            if (parsedStatements != null)
            {
                if (OpsConsole.Verbose)
                {
                    OpsConsole.WriteLine("Prevalidating script starting.");
                }

                Statements = new OpsStatement[parsedStatements.Length];
                for (int i = 0; i < parsedStatements.Length; i++)
                {
                    OpsParsedStatement parsed    = parsedStatements[i] as OpsParsedStatement;
                    IOpsCommand        command   = null;
                    object             arguments = null;

                    if (OpsConsole.Verbose)
                    {
                        OpsConsole.WriteLine("Prevalidating statement #{0}: \"{1}\"", i, parsed);
                    }


                    try
                    {
                        command = library.GetCommand(parsed.Command);
                    }
                    catch (Exception e)
                    {
                        OpsConsole.WriteError(i + 1, e, "Unable to fetch command: " + parsed.Command);
                        throw;
                    }

                    if (command is IOpsRemappable)
                    {
                        try
                        {
                            command = (command as IOpsRemappable).RemapCommand(parsed);
                        }
                        catch (Exception e)
                        {
                            OpsConsole.WriteError(i + 1, e, "Unable to remap command: " + parsed.Command);
                            throw;
                        }
                    }

                    try
                    {
                        arguments = command.ParseArguments(parsed);
                    }
                    catch (Exception e)
                    {
                        OpsConsole.WriteError(i + 1, e, "Command failed to interpret the arguments.");
                        throw;
                    }

                    Statements[i] = new OpsStatement(parsed, command, arguments);
                }

                if (OpsConsole.Verbose)
                {
                    OpsConsole.WriteLine("Prevalidating script finished.");
                }
            }
        }