Esempio n. 1
0
        static void Main(string[] args)
        {
            var arguments       = ConsoleApplication.ParseCommandLineArguments(args);
            var applicationName = arguments.ContainsKey("SettingsFolderName") ? arguments["SettingsFolderName"] : "Unknown Console Context";

            //okay need to create app
            var dependencyResolver = new DependencyContainer();
            var controller         = new ConsoleApplicationController(applicationName, dependencyResolver);

            try
            {
                var settingsManager    = new DesktopSettingsManager(controller);
                var applicationOptions = new ApplicationOptionsViewModel(controller);
                var app = new ConsoleApplication(controller, applicationOptions, settingsManager);
                //load modules in folder path
                app.LoadModulesInExecutionFolder();
                //run app
                app.Run(args);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.DisplayString());
                System.Console.WriteLine("Fatal Error");
                var logFile = new LogFileUserInterface(controller.LogPath, controller.ApplicationName, true, 50);
                logFile.LogMessage($"Fatal Error During Console Execution: {ex.XrmDisplayString()}");
                throw;
            }
        }
Esempio n. 2
0
        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 LoadModulesInExecutionFolder()
        {
            ConsoleApplicationController.WriteToConsole("Loading Modules");
            var    codeBase = Assembly.GetExecutingAssembly().Location;
            var    uri      = new UriBuilder(codeBase);
            string path     = Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path));

            var ignoreThese = new[]
            {
                "Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter",
                "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices",
                "Microsoft.VisualStudio.GraphModel",
                "Microsoft.VisualStudio.Shell.Framework",
                "Microsoft.VisualStudio.Utilities",
                "Microsoft.VisualStudio.Telemetry",
                "StreamJsonRpc"
            };

            foreach (string dll in Directory.GetFiles(path, "*.dll"))
            {
                var loadIt = Assembly.LoadFile(dll);
                if (!ignoreThese.Any(s => loadIt.FullName.Contains(s)))
                {
                    try
                    {
                        foreach (var type in loadIt.GetTypes())
                        {
                            if (type.IsTypeOf(typeof(ModuleBase)) && !type.IsGenericType && !type.IsAbstract)
                            {
                                AddModule(type);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"Error Loading Modules In Assembly {loadIt.FullName}", ex);
                    }
                }
            }

            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 ConsoleApplication(ConsoleApplicationController applicationController, IApplicationOptions applicationOptions, ISettingsManager settingsManager)
     : base(applicationController, applicationOptions, settingsManager)
 {
     ConsoleApplicationController = applicationController;
     Controller.RegisterType <IDialogController, ConsoleDialogController>();
 }