コード例 #1
0
        public ICommandLineCommand ParseStandardCommandLine(ICommandLineArguments arguments)
        {
            ICommandLineCommand command = null;
            var parser = arguments.Parse();

            while (command?.StopParsing != true &&
                   String.IsNullOrEmpty(parser.ErrorArgument) &&
                   parser.TryGetNextSwitchOrArgument(out var arg))
            {
                if (String.IsNullOrWhiteSpace(arg)) // skip blank arguments.
                {
                    continue;
                }

                // First argument must be the command or global switch (that creates a command).
                if (command == null)
                {
                    if (!this.TryParseUnknownCommandArg(arg, parser, out command))
                    {
                        parser.ReportErrorArgument(arg, ErrorMessages.HarvestTypeNotFound(arg));
                    }
                }
                else if (!command.TryParseArgument(parser, arg))
                {
                    parser.ReportErrorArgument(arg);
                }
            }

            return(command ?? new HelpCommand(this.extensions));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IsValidCompilationLevelArgument"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        /// <param name="compilationLevelHelper">
        /// The CompilationLevel helper
        /// </param>
        public IsValidCompilationLevelArgument(ICommandLineArguments commandLineArguments, ICompilationLevelHelper compilationLevelHelper)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);
            Guard.ArgumentNotNull(() => compilationLevelHelper, compilationLevelHelper);

            this.commandLineArguments = commandLineArguments;
            this.compilationLevelHelper = compilationLevelHelper;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsValidCompilationLevelArgument"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        /// <param name="compilationLevelHelper">
        /// The CompilationLevel helper
        /// </param>
        public IsValidCompilationLevelArgument(ICommandLineArguments commandLineArguments, ICompilationLevelHelper compilationLevelHelper)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);
            Guard.ArgumentNotNull(() => compilationLevelHelper, compilationLevelHelper);

            this.commandLineArguments   = commandLineArguments;
            this.compilationLevelHelper = compilationLevelHelper;
        }
コード例 #4
0
        public CliControllerInstance CreateController(Type controller, ICommandLineArguments commandLineArgs)
        {
            object instance           = Activator.CreateInstance(controller);
            var    controllerInstance = new CliControllerInstance(controller, instance);

            SatisfyProperties(controllerInstance, commandLineArgs);

            return(controllerInstance);
        }
コード例 #5
0
        // -------------------------------------------------------------------
        // Constructor
        // -------------------------------------------------------------------
        public ColladaMinecraft(IFactory factory)
            : base(factory)
        {
            this.arguments = factory.Resolve<ICommandLineArguments>();

            this.modelBoundingBox = new BoundingBox(new Vector3(0), new Vector3(0));

            this.blocks = new Dictionary<Block, Block>();

            this.mode = ProcessingMode.ColladaToSchematic;
        }
        public async Task <IDesktopContext> Build(ICommandLineArguments commandLineArguments, CancellationToken cancellation)
        {
            IDesktopContext desktopContext;

            using (var fileStream = await _fileService.OpenReadStreamAsync(commandLineArguments.FilePath, commandLineArguments.Container, cancellation))
            {
                desktopContext = _jsonSerializationService.Deserialize <DesktopContext>(fileStream);
            }

            return(desktopContext);
        }
コード例 #7
0
 public IDesktopContext Build(ICommandLineArguments commandLineArguments)
 {
     _desktopSettingsDefaultsService.CheckDefaults(commandLineArguments);
     return(new DesktopContext(
                _dateTimeProvider.GetNowUtc(),
                OverrideConfig(commandLineArguments.OutputDirectory, _desktopServiceSettings.OutputDirectory),
                commandLineArguments.FilePath,
                _assemblyService.GetExecutingAssemblyPath(),
                string.Concat(ReferenceDataConstants.FilePath, _desktopServiceSettings.ReferenceDataVersion, ReferenceDataConstants.FileExtension),
                OverrideConfig(commandLineArguments.ConnectionString, _desktopServiceSettings.IlrDatabaseConnectionString),
                _releaseVersionInformationService.VersionNumber,
                Enumerable.Empty <IDesktopContextReportFilterQuery>()));
 }
        public async Task ExecuteAsync(ICommandLineArguments commandLineArguments, CancellationToken cancellationToken)
        {
            if (_featureSwitchService.VersionUpdate)
            {
                _logger.LogInfo("Checking for Reference data updates.");
                await CheckForReferenceDataUpdates(commandLineArguments.CheckAndUpdateReferenceData);
            }

            _logger.LogInfo("Creating Context.");
            var context = _desktopContextFactory.Build(commandLineArguments);

            await _ilrDesktopService.ProcessAsync(context, cancellationToken);
        }
コード例 #9
0
        private void SatisfyProperties(CliControllerInstance controller, ICommandLineArguments commandLineArgs)
        {
            const BindingFlags bindingFlags = BindingFlags.GetProperty |
                                              BindingFlags.SetProperty |
                                              BindingFlags.Public |
                                              BindingFlags.Instance;

            PropertyInfo[] properties = controller.Type.GetTypeInfo()
                                        .GetProperties(bindingFlags);

            foreach (PropertyInfo property in properties)
            {
                SatisfyProperty(controller, commandLineArgs, property);
            }
        }
コード例 #10
0
        private void SatisfyProperty(CliControllerInstance controller,
                                     ICommandLineArguments commandLineArgs,
                                     PropertyInfo property)
        {
            CliSwitchAttribute switchAttribute = property.GetCustomAttribute <CliSwitchAttribute>();

            if (switchAttribute != null)
            {
                bool switchExists = false;
                switchExists |= commandLineArgs.GetSwitch(switchAttribute.ShortName);
                switchExists |= commandLineArgs.GetSwitch(switchAttribute.LongName);

                property.SetValue(controller.Instance, switchExists);
            }
        }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArgumentRules"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        /// <param name="compilationLevelHelper">
        /// The compilation level helper.
        /// </param>
        public ArgumentRules(ICommandLineArguments commandLineArguments, ICompilationLevelHelper compilationLevelHelper)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);
            Guard.ArgumentNotNull(() => compilationLevelHelper, compilationLevelHelper);

            // Setup validators
            var isValidJavaScriptFileName         = new IsValidJavaScriptFileName(commandLineArguments);
            var isValidCompilationLevelArgument   = new IsValidCompilationLevelArgument(commandLineArguments, compilationLevelHelper);
            var isValidWarningSuppressionArgument = new IsValidWarningSuppressionArgument(commandLineArguments);

            // Setup argument rule combos
            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidCompilationLevelArgument, isValidWarningSuppressionArgument));

            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidWarningSuppressionArgument));

            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidCompilationLevelArgument));

            this.argumentRuleCombos.Add(new ArgumentRuleCombo(isValidJavaScriptFileName));
        }
コード例 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArgumentRules"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        /// <param name="compilationLevelHelper">
        /// The compilation level helper.
        /// </param>
        public ArgumentRules(ICommandLineArguments commandLineArguments, ICompilationLevelHelper compilationLevelHelper)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);
            Guard.ArgumentNotNull(() => compilationLevelHelper, compilationLevelHelper);

            // Setup validators
            var isValidJavaScriptFileName = new IsValidJavaScriptFileName(commandLineArguments);
            var isValidCompilationLevelArgument = new IsValidCompilationLevelArgument(commandLineArguments, compilationLevelHelper);
            var isValidWarningSuppressionArgument = new IsValidWarningSuppressionArgument(commandLineArguments);

            // Setup argument rule combos
            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidCompilationLevelArgument, isValidWarningSuppressionArgument));

            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidWarningSuppressionArgument));

            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidCompilationLevelArgument));

            this.argumentRuleCombos.Add(new ArgumentRuleCombo(isValidJavaScriptFileName));
        }
コード例 #13
0
 public void CheckDefaults(ICommandLineArguments commandLineArguments)
 {
     ConnectionStringEnteredUpdateExportSqlTask(commandLineArguments.ConnectionString);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="IsValidWarningSuppressionArgument"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        public IsValidWarningSuppressionArgument(ICommandLineArguments commandLineArguments)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);

            this.commandLineArguments = commandLineArguments;
        }
コード例 #15
0
ファイル: Platform.cs プロジェクト: hotthink/jingxian-project
        public static int Launch(IApplicationContext context, ICommandLineArguments arguments)
        {
            int exitCode = 1;

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            Enforce.ArgumentNotNull <IApplicationContext>(context, "context");
            Enforce.ArgumentNotNullOrEmpty(context.ApplicationLaunchableId, "context.ApplicationLaunchableId");

            _logger.Debug("开始启动...");

            try
            {
                using (KernelAdapter containerAdapter = new KernelAdapter())
                {
                    containerAdapter.Connect(typeof(IApplicationContext), context);
                    containerAdapter.Connect(RuntimeConstants.AssemblyLoaderServiceId
                                             , typeof(IAssemblyLoaderService)
                                             , typeof(AssemblyLoaderService));
                    containerAdapter.Connect(RuntimeConstants.BundleServiceId
                                             , typeof(IBundleService)
                                             , typeof(BundleService));
                    containerAdapter.Connect(RuntimeConstants.ExtensionRegistryId
                                             , typeof(IExtensionRegistry)
                                             , typeof(ExtensionRegistry));
                    containerAdapter.Start();

                    IExtensionRegistry registry = containerAdapter.Get <IExtensionRegistry>();
                    IObjectBuilder     builder  = containerAdapter.Get <IObjectBuilder>();

                    using (IDisposable scope = containerAdapter.Lock())
                    {
                        IExtension[] extensions = registry.GetExtensions(Constants.Points.Services);
                        foreach (IExtension extension in extensions)
                        {
                            containerAdapter.Connect(extension.Id
                                                     , getServiceTypes(builder, extension)
                                                     , builder.GetType(extension.Implementation));
                        }

                        List <object> services = new List <object>();
                        foreach (IExtension extension in extensions)
                        {
                            services.Add(containerAdapter.GetService(extension.Id));
                        }

                        foreach (object instance in services)
                        {
                            MicroKernel.Start(instance, containerAdapter);
                        }
                    }

                    IApplicationLaunchable launchable = BuildApplicationLaunchable(context, registry);
                    exitCode = launchable.Launch(context);

                    containerAdapter.Stop();
                }
            }
            finally
            {
                const string exitMsg = "退出代码 {0}.";
                _logger.InfoFormat(exitMsg, exitCode);
                AppDomain.CurrentDomain.UnhandledException -= OnUnhandledException;
            }
            return(exitCode);
        }
コード例 #16
0
        public async Task ExecuteAsync(ICommandLineArguments commandLineArguments, CancellationToken cancellationToken)
        {
            var context = await _desktopContextFactory.Build(commandLineArguments, cancellationToken);

            await _ilrDesktopService.ProcessAsync(context, cancellationToken);
        }
コード例 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsValidJavaScriptFileName"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        public IsValidJavaScriptFileName(ICommandLineArguments commandLineArguments)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);

            this.commandLineArguments = commandLineArguments;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IsValidWarningSuppressionArgument"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        public IsValidWarningSuppressionArgument(ICommandLineArguments commandLineArguments)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);

            this.commandLineArguments = commandLineArguments;
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsValidJavaScriptFileName"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        public IsValidJavaScriptFileName(ICommandLineArguments commandLineArguments)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);

            this.commandLineArguments = commandLineArguments;
        }
コード例 #20
0
 public AppHostWebApplicationFactory(ICommandLineArguments commandLineArguments, Dictionary <string, string> settings = null)
 {
     this.commandLineArguments = commandLineArguments;
     this.settings             = settings;
 }
コード例 #21
0
        /// <summary>
        /// Parses command line arguments into the given data object.
        /// </summary>
        /// <remarks>
        /// Members of the given data object should be marked with instances of CommandLineAttribute to define parsing behaviour.
        /// </remarks>
        /// <param name="dataObject">The data object.</param>
        /// <param name="args">Arguments to parse.</param>
        public static void Parse(object dataObject, string[] args)
        {
            ICommandLineArguments helper = dataObject as ICommandLineArguments;

            IList <CommandLineMemberInfo> members         = Examine(dataObject);
            IList <CommandLineMemberInfo> requiredMembers = new List <CommandLineMemberInfo>(members.Where(m => m.Required));

            Dictionary <string, CommandLineMemberInfo> shortNames = new Dictionary <string, CommandLineMemberInfo>();
            Dictionary <string, CommandLineMemberInfo> longNames  = new Dictionary <string, CommandLineMemberInfo>();

            foreach (CommandLineMemberInfo member in members)
            {
                shortNames[member.ShortArgumentName] = member;
                longNames[member.LongArgumentName]   = member;
            }

            if (helper != null)
            {
                helper.Initialize();
            }

            for (int i = 0; i < args.Length; i++)
            {
                string name = args[i].ToLowerInvariant();

                CommandLineMemberInfo member;
                if (name.StartsWith("--"))
                {
                    string longName = name.Substring(2);
                    longNames.TryGetValue(longName, out member);
                }
                else if (name.StartsWith("-"))
                {
                    string shortName = name.Substring(1);
                    shortNames.TryGetValue(shortName, out member);
                }
                else
                {
                    member = null;
                }

                if (member == null)
                {
                    throw new Exception(string.Format("Unrecognized command line option: {0}", name));
                }

                try
                {
                    if (member.ArgumentType == typeof(bool))
                    {
                        SetValue(dataObject, member.MemberInfo, true);
                    }
                    else if (member.ArgumentType == typeof(int) || member.ArgumentType == typeof(long))
                    {
                        long value = long.Parse(args[++i]);
                        SetValue(dataObject, member.MemberInfo, true);
                    }
                    else if (member.ArgumentType == typeof(uint) || member.ArgumentType == typeof(ulong))
                    {
                        ulong value = ulong.Parse(args[++i]);
                        SetValue(dataObject, member.MemberInfo, true);
                    }
                    else if (member.ArgumentType == typeof(string))
                    {
                        SetValue(dataObject, member.MemberInfo, args[++i]);
                    }
                }
                catch
                {
                    throw new Exception(string.Format("Badly formatted command line option: {0}", name));
                }

                requiredMembers.Remove(member);
            }

            if (requiredMembers.Count > 0)
            {
                StringBuilder missingArguments = new StringBuilder();
                missingArguments.Append("Missing required command line option(s): ");
                for (int i = 0; i < requiredMembers.Count; i++)
                {
                    if (i > 0)
                    {
                        missingArguments.Append(", ");
                    }

                    CommandLineMemberInfo member = requiredMembers[i];
                    missingArguments.AppendFormat("--{0} (-{1})", member.LongArgumentName, member.ShortArgumentName);
                }

                throw new Exception(missingArguments.ToString());
            }

            if (helper != null)
            {
                helper.Validate();
            }
        }