コード例 #1
0
        /// <summary>
        /// Initializes the specified application.
        /// </summary>
        /// <param name="app">The application.</param>
        /// <returns></returns>
        public static CustomCommandLineApplication Initialize(this CustomCommandLineApplication app)
        {
            AnsiConsole.GetError(true);

            app.HelpOption(HelpFlag);
            app.VersionOption(VersionFlag, Constants.ShortVersion, Constants.LongVersion);

            app.Name             = Constants.Name;
            app.Description      = Constants.ProgramHelpDescription;
            app.ExtendedHelpText = Constants.ExtendedHelpText;

            var methods = typeof(Command).GetMethods(BindingFlags.Public | BindingFlags.Static)
                          .Where(c => c.Name != "Initialize").ToList();

            methods = methods.Where(c =>
                                    typeof(CustomCommandLineApplication).IsAssignableFrom(c.ReturnType) &&
                                    c.GetParameters() is ParameterInfo[] u &&
                                    u.Length == 1 &&
                                    typeof(CommandLineApplication).IsAssignableFrom(u[0].ParameterType)
                                    ).ToList();

            foreach (MethodInfo method in methods)
            {
                try
                {
                    method.Invoke(null, new object[] { app });
                }
                catch (Exception e)
                {
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        System.Diagnostics.Debugger.Break();
                    }
                    throw;
                }
            }

            return(app);
        }
コード例 #2
0
        public static CustomCommandLineApplication CommandSchemas(this CustomCommandLineApplication app)
        {
            var cmd = app.Command("generate", config =>
            {
                config.Description = "generate tools";
                config.HelpOption(HelpFlag);
            });

            /*
             *  exe generate schemas
             */
            cmd.Command("schemas", config =>
            {
                config.Description = "generates schemas";
                config.HelpOption(HelpFlag);

                var validator = new GroupArgument(config);

                var argSource = validator.Argument("<path>", "root path where your project is located."
                                                   , ValidatorExtension.EvaluateDirectoryPathIsValid
                                                   , ValidatorExtension.EvaluateRequired
                                                   );

                var argSchemaTarget = validator.Argument("<schema path>", "path where the schemas are stored."
                                                         , ValidatorExtension.EvaluateDirectoryPathIsValid
                                                         );

                var optHold = validator.OptionNoValue("--h", "hold the process. for listen change and regenerate every time");

                config.OnExecute(() =>
                {
                    if (!validator.Evaluate(out int errorNum))
                    {
                        return(errorNum);
                    }

                    using (var rep = new ModelRepository(argSource.Value, new Diagnostic()))
                    {
                        rep.ItemFileHasChanged = (repository, transaction) =>
                        {
                            switch (transaction.File.Schema.Kind)
                            {
                            case Galileo.KindSchemaEnum.SchemaEntity:
                            case Galileo.KindSchemaEnum.SchemaLink:
                            case Galileo.KindSchemaEnum.Entity:

                                break;


                            case Galileo.KindSchemaEnum.Relationship:
                                break;


                            case Galileo.KindSchemaEnum.SchemaDefinitions:

                                List <ModelDefinition> _items = transaction.Added.OfType <ModelDefinition>().ToList();
                                _items.AddRange(transaction.Updated.OfType <ModelDefinition>());
                                if (!string.IsNullOrEmpty(argSchemaTarget.Value))
                                {
                                    repository.SchemaManager.GenerateDefinition(_items, new DirectoryInfo(argSchemaTarget.Value));
                                }
                                else
                                {
                                    repository.SchemaManager.GenerateDefinition(_items);
                                }

                                if (!string.IsNullOrEmpty(argSchemaTarget.Value))
                                {
                                    rep.SchemaManager.GenerateSchemas(new DirectoryInfo(argSchemaTarget.Value));
                                }
                                else
                                {
                                    rep.SchemaManager.GenerateSchemas();
                                }
                                break;

                            case Galileo.KindSchemaEnum.SchemaLayerDefinitions:
                                if (!string.IsNullOrEmpty(argSchemaTarget.Value))
                                {
                                    rep.SchemaManager.GenerateSchemas(new DirectoryInfo(argSchemaTarget.Value));
                                }
                                else
                                {
                                    rep.SchemaManager.GenerateSchemas();
                                }
                                break;

                            case Galileo.KindSchemaEnum.Definition:
                            case Galileo.KindSchemaEnum.Schema:
                            case Galileo.KindSchemaEnum.CooperationViewpoint:
                            case Galileo.KindSchemaEnum.Undefined:
                            default:
                                break;
                            }
                        };

                        rep.Initialize();


                        if (optHold.HasValue())
                        {
                            Console.WriteLine("Please enter to quit");
                            Console.ReadLine();
                        }
                    }

                    return(0);
                });
            });