Esempio n. 1
0
        static void Main(string[] input)
        {
            IContainer     container = ModuleLoader.LoadModule();
            ILifetimeScope scope     = container.BeginLifetimeScope();
            IEnumerable <ICommandModule <ICanvas> >         commands   = scope.Resolve <IEnumerable <ICommandModule <ICanvas> > >();
            IDictionary <string, ICommandModule <ICanvas> > commandMap = new Dictionary <string, ICommandModule <ICanvas> >();

            foreach (ICommandModule <ICanvas> command in commands)
            {
                commandMap.Add(command.Command.ToUpper(), command);
            }

            while (true)
            {
                Console.Write("Enter Command: ");
                string[] args = Console.ReadLine().Split(' ');

                if (args == null || args.Length == 0)
                {
                    Console.WriteLine("Parameter format is needed");
                }

                if (!commandMap.ContainsKey(args[0]))
                {
                    Console.WriteLine("ERROR: Unrecognized command " + args[0]);
                    foreach (ICommandModule <ICanvas> command in commands)
                    {
                        Console.WriteLine(command.Command + " " + string.Join(" ", command.Parameters));
                        Console.WriteLine("\t" + command.Description);
                    }
                }
                else
                {
                    try {
                        ICommandModule <ICanvas> command = commandMap[args[0].ToUpper()];
                        string[] param = args.Skip(1).Take(args.Length - 1).ToArray();

                        if (param.Length != command.Parameters.Length)
                        {
                            Console.WriteLine("ERROR: Invalid command syntax");
                            Console.WriteLine($"Command syntax: {command.Command} {string.Join(" ", command.Parameters)}");
                        }
                        else
                        {
                            ICanvas canvas = command.Execute(param);
                            canvas.Render();
                        }
                    }
                    catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        private void AddModule(ICommandModule module, string prefix = null)
        {
            if (prefix != null)
            {
                prefix = $"{prefix}.{module.Name}";
            }
            else
            {
                prefix = module.Name;
            }

            module.PushNotification += Module_PushNotification;

            var exceptions = new List <Exception>();

            foreach (var command in module.Commands)
            {
                try
                {
                    AddCommand(command, prefix);
                }
                catch (AggregateException e)
                {
                    exceptions.Add(e);
                }
            }

            if (module.SubModules != null)
            {
                foreach (var subModule in module.SubModules)
                {
                    subModule.PushNotification += Module_PushNotification;
                    try
                    {
                        AddModule(subModule, prefix);
                    }
                    catch (AggregateException ae)
                    {
                        exceptions.AddRange(ae.InnerExceptions);
                    }
                }
            }

            if (exceptions.Count > 0)
            {
                throw new AggregateException("Failed to load module", exceptions);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new command builder.
        /// </summary>
        /// <param name="module">Module on which this command is to be defined.</param>
        public CommandBuilder(ICommandModule module)
        {
            this.AliasList = new List <string>();
            this.Aliases   = new ReadOnlyCollection <string>(this.AliasList);

            this.ExecutionCheckList = new List <CheckBaseAttribute>();
            this.ExecutionChecks    = new ReadOnlyCollection <CheckBaseAttribute>(this.ExecutionCheckList);

            this.OverloadArgumentSets = new HashSet <string>();
            this.OverloadList         = new List <CommandOverloadBuilder>();
            this.Overloads            = new ReadOnlyCollection <CommandOverloadBuilder>(this.OverloadList);

            this.Module = module;

            this.CustomAttributeList = new List <Attribute>();
            this.CustomAttributes    = new ReadOnlyCollection <Attribute>(this.CustomAttributeList);
        }
Esempio n. 4
0
        public static async Task ExecuteSubcommand(ICommandModule parentCommandModule, string subcommandName, CommandRequest request)
        {
            MethodInfo method = parentCommandModule.GetType()
                                .GetMethod(
                subcommandName,
                // We want public methods that aren't static - and we don't know what casing the method has
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase
                );

            if (method == null)
            {
                await request.WriteLine($"Error: No subcommand with the name '{subcommandName}' exists (type 'help' instead for a list).");

                return;
            }

            await(Task) method.Invoke(parentCommandModule, new object[] { request });
        }
Esempio n. 5
0
 /// <summary>
 /// Creates a new command group builder.
 /// </summary>
 /// <param name="module">Module on which this group is to be defined.</param>
 public CommandGroupBuilder(ICommandModule module)
     : base(module)
 {
     this.ChildrenList = new List <CommandBuilder>();
     this.Children     = new ReadOnlyCollection <CommandBuilder>(this.ChildrenList);
 }
        private void InitRoutedCommands()
        {
            RoutedCommands = new RoutedCommands();

            //todo get module from container
            var modules = new ICommandModule[]
                          {
                              new ProfessorHandlers(_professorRepository),
                              new ProfessorNavigation(this),
                              new PublicationHandlers(_publicationRepository),
                              new PublicationNavigation(this),
                              new ConferenceHandlers(_conferenceRepository),
                              new ConferenceNavigation(this),
                              new ExhibitionHandlers(_exhibitionRepository),
                              new ExhibitionNavigation(this),
                              new BookHandlers(_bookRepository),
                              new BookNavigation(this),
                              new DissertationHandlers(_dissertationRepository),
                              new DissertationNavigation(this),
                              new InventiveApplicationHandlers(_inventiveApplicationRepository),
                              new InventiveApplicationNavigation(this),
                              new EfficiencyProposalHandlers(_efficiencyProposalRepository),
                              new EfficiencyProposalNavigation(this),
                              new CouncilParticipationHandlers(_councilParticipationRepository),
                              new CouncilParticipationNavigation(this),
                              new ScienceRankHandlers(_scienceRankRepository, _scienceRankMetricRepository),
                              new ScienceRankNavigation(this, _scienceRankMetricDefinitionRepository),
                              new ResearchHandlers(_researchRepository),
                              new ResearchNavigation(this),
                              new NavigationHistory(this),
                              new ReportingHandlers(_cathedraRepository,
                                                    _professorRepository,
                                                    _excelReportingService,
                                                    _reportGenerator)
                          };

            modules.ForEach(m => m.LoadModule(RoutedCommands));
        }
Esempio n. 7
0
 private void registerModule(ICommandModule newCommandModule)
 {
     commandModules.Add(newCommandModule);
     Log.WriteLine($"[CommandConsole] Registered module {newCommandModule.Description.Name}");
 }