public void LoadModulesInExecutionFolder() { ConsoleApplicationController.WriteToConsole("Loading Modules"); var codeBase = Assembly.GetExecutingAssembly().Location; var uri = new UriBuilder(codeBase); string path = Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)); foreach (string dll in Directory.GetFiles(path, "*.dll")) { var loadIt = Assembly.LoadFile(dll); foreach (var type in loadIt.GetTypes()) { if (type.IsTypeOf(typeof(ModuleBase)) && !type.IsGenericType && !type.IsAbstract) { AddModule(type); } } } var commands = GetCommandOptions(); if (!commands.Any()) { throw new NullReferenceException(string.Format("No {0} Implementing {1} Was Found In The Execution Folder '{2}'", nameof(ModuleBase), nameof(ICommandLineExecutable), codeBase)); } }
public void Run(string[] args) { //need to run as per the arguments or display the console options if (args == null || !args.Any()) { ConsoleApplicationController.WriteToConsole("The Valid Commands For This Application Are\n"); ConsoleApplicationController.UserMessage(GetCommandLineSwitchString()); } else { var command = args.First(); if (command == "?" || command.ToLower() == "help") { ConsoleApplicationController.WriteToConsole("The Valid Commands For This Application Are\n"); ConsoleApplicationController.UserMessage(GetCommandLineSwitchString()); } else { var matchingOptions = GetCommandOptions().Where(o => o.CommandName.ToLower() == command.ToLower()); if (!matchingOptions.Any()) { ConsoleApplicationController.WriteToConsole(string.Format("No Matching Command Found For '{0}'\n", command)); ConsoleApplicationController.UserMessage(GetCommandLineSwitchString()); } else { var matchingOption = matchingOptions.First(); var arguments = ParseCommandLineArguments(args); if (!arguments.Any() || arguments.First().Key == "?" || arguments.First().Key == "help") { ConsoleApplicationController.WriteToConsole("The Commands Arguments Are"); ConsoleApplicationController.WriteToConsole(GetCommandLineArgumentsString(command)); } else { ConsoleApplicationController.WriteToConsole(string.Format("Loading {0} Command", command)); var commandArgs = matchingOption.GetArgs(); foreach (var arg in arguments.Where(a => !StandardCommandArguments.Any(sca => sca.CommandName == a.Key))) { var matchingCommand = commandArgs.Where(c => c.CommandName == arg.Key); if (!matchingCommand.Any()) { throw new ArgumentOutOfRangeException(arg.Key, string.Format("'{0}' is not a valid argument name for the command. The valid arguments are\n{1}", arg.Key, GetCommandLineArgumentsString(command))); } matchingCommand.First().LoadAction(arg.Value); } ConsoleApplicationController.WriteToConsole(string.Format("Starting {0} Process", command)); matchingOption.Command(); } } } } }
public void LoadModulesInExcecutionFolder() { ConsoleApplicationController.WriteToConsole("Loading Modules"); var codeBase = Assembly.GetExecutingAssembly().Location; var uri = new UriBuilder(codeBase); string path = Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)); foreach (string dll in Directory.GetFiles(path, "*.dll")) { var loadIt = Assembly.LoadFile(dll); foreach (var type in loadIt.GetTypes()) { if (type.IsTypeOf(typeof(ModuleBase)) && !type.IsGenericType && !type.IsAbstract) { AddModule(type); } } } }