Exemple #1
0
        /// <summary>
        /// Parse command line and load all the extensions.
        /// </summary>
        /// <param name="args">Command line arguments to be parsed.</param>
        private string[] ParseCommandLineAndLoadExtensions(string[] args)
        {
            this.commandLine = new LightCommandLine();
            string[] unprocessed = this.commandLine.Parse(args);
            if (Messaging.Instance.EncounteredError)
            {
                return(unprocessed);
            }

            // Load extensions.
            ExtensionManager extensionManager = new ExtensionManager();

            foreach (string extension in this.commandLine.Extensions)
            {
                extensionManager.Load(extension);
            }

            // Extension data command line processing.
            this.extensionData = extensionManager.Create <IExtensionData>();
            foreach (IExtensionCommandLine dce in this.extensionData.Where(e => e is IExtensionCommandLine).Cast <IExtensionCommandLine>())
            {
                dce.MessageHandler = Messaging.Instance;
                unprocessed        = dce.ParseCommandLine(unprocessed);
            }

            // Binder extensions command line processing.
            this.binderExtensions = extensionManager.Create <IBinderExtension>();
            foreach (IExtensionCommandLine bce in this.binderExtensions.Where(e => e is IExtensionCommandLine).Cast <IExtensionCommandLine>())
            {
                bce.MessageHandler = Messaging.Instance;
                unprocessed        = bce.ParseCommandLine(unprocessed);
            }

            // File resolution command line processing.
            this.fileManagers = extensionManager.Create <IBinderFileManager>();
            if (this.fileManagers.Any())
            {
                foreach (IExtensionCommandLine fme in this.fileManagers.Where(e => e is IExtensionCommandLine).Cast <IExtensionCommandLine>())
                {
                    fme.MessageHandler = Messaging.Instance;
                    unprocessed        = fme.ParseCommandLine(unprocessed);
                }
            }
            else // there are no extension file managers so add the default one.
            {
                List <IBinderFileManager> defaultBinderFileManager = new List <IBinderFileManager>();
                defaultBinderFileManager.Add(new BinderFileManager());

                this.fileManagers = defaultBinderFileManager;
            }

            return(commandLine.ParsePostExtensions(unprocessed));
        }
Exemple #2
0
        /// <summary>
        /// Parse command line and load all the extensions.
        /// </summary>
        /// <param name="args">Command line arguments to be parsed.</param>
        private IEnumerable <string> ParseCommandLineAndLoadExtensions(IServiceProvider serviceProvider, IMessaging messaging, string[] args)
        {
            this.commandLine = new LightCommandLine(messaging);

            string[] unprocessed = this.commandLine.Parse(args);
            if (messaging.EncounteredError)
            {
                return(unprocessed);
            }

            // Load extensions.
            var extensionManager = CreateExtensionManagerWithStandardBackends(serviceProvider);

            foreach (string extension in this.commandLine.Extensions)
            {
                extensionManager.Load(extension);
            }

            // Extension data command line processing.
            var context = serviceProvider.GetService <ICommandLineContext>();

            context.Arguments        = null;
            context.ExtensionManager = extensionManager;
            context.Messaging        = messaging;
            context.ParsedArguments  = args;

            var commandLineExtensions = extensionManager.Create <IExtensionCommandLine>();

            foreach (var extension in commandLineExtensions)
            {
                extension.PreParse(context);
            }

            // Process unproccessed arguments.
            List <string> actuallyUnprocessed = new List <string>();

            foreach (var arg in unprocessed)
            {
                if (!this.TryParseCommandLineArgumentWithExtension(arg, commandLineExtensions))
                {
                    actuallyUnprocessed.Add(arg);
                }
            }

            return(this.commandLine.ParsePostExtensions(actuallyUnprocessed.ToArray()));
        }
Exemple #3
0
        /// <summary>
        /// Parse command line and load all the extensions.
        /// </summary>
        /// <param name="args">Command line arguments to be parsed.</param>
        private IEnumerable <string> ParseCommandLineAndLoadExtensions(IServiceProvider serviceProvider, IMessaging messaging, string[] args)
        {
            var arguments = serviceProvider.GetService <ICommandLineArguments>();

            arguments.Populate(args);

            var extensionManager = CreateExtensionManagerWithStandardBackends(serviceProvider, arguments.Extensions);

            var context = serviceProvider.GetService <ICommandLineContext>();

            context.ExtensionManager = extensionManager;
            context.Arguments        = arguments;

            this.commandLine = new LightCommandLine(messaging);
            var unprocessed = this.commandLine.Parse(context);

            return(unprocessed);
        }