Example #1
0
        public static CommandLineApplication CommandCountries(this CommandLineApplication app)
        {
            var cmd = app.Command("config", config1 =>
            {
                config1.Description = "manage country's configuration";
                config1.HelpOption(HelpFlag);

                var cmd2 = config1.Command("list", config2 =>
                {
                    config2.Description = "return the list of available countries";
                    config2.HelpOption(HelpFlag);

                    var validator = new GroupArgument(config2, false);

                    config2.OnExecute(() =>
                    {
                        if (validator.Evaluate() > 0)
                        {
                            return(2);
                        }

                        try
                        {
                            DownloadCountryList();
                            Output.WriteLine("list successfull downloaded");
                        }
                        catch (Exception)
                        {
                            Output.WriteLine("Fail to resolve remote list of configuration. Working with local list");
                            throw;
                        }


                        ConvertToDatatable.ConvertList <CountryParameter>(Helper.Parameters.Countries
                                                                          , "available countries parameters"
                                                                          , c => c.Name
                                                                          , c => c.Included
                                                                          , c => c.OnlineVersion
                                                                          , c => c.OnlineVersion
                                                                          )
                        .PrintList()
                        ;

                        return(0);
                    });
                });

                var cmd3 = config1.Command("add", config2 =>
                {
                    config2.Description = "add a new country in the local configuration";
                    config2.HelpOption(HelpFlag);

                    var validator = new GroupArgument(config2, false);

                    var countryName = validator.Argument("CountryName",
                                                         "name of the country must be added in the configuration. (this argument is required)"
                                                         , ValidatorExtension.EvaluateRequired
                                                         , ValidatorExtension.EvaluateCountryName
                                                         );

                    config2.OnExecute(() =>
                    {
                        if (Helper.Parameters.Countries.Count == 0)
                        {
                            GetDictionnaryCountry();
                            Output.WriteLine("list successfull downloaded");
                        }

                        if (validator.Evaluate() > 0)
                        {
                            return(2);
                        }

                        var country       = countryName.Value.ToLower();
                        var _country      = Helper.Parameters.Countries.FirstOrDefault(c => c.Name.ToLower() == country);
                        _country.Included = true;


                        var rootPath = GetTempFolder();
                        RefreshConfigCountry(_country, rootPath);
                        rootPath.DeleteDirectoryTree();


                        ConvertToDatatable.ConvertList <CountryParameter>(Helper.Parameters.Countries.Where(c => c.Included)
                                                                          , "available countries parameters"
                                                                          , c => c.Name
                                                                          , c => c.Included
                                                                          , c => c.OnlineVersion
                                                                          , c => c.OnlineVersion
                                                                          )
                        .PrintList()
                        ;

                        return(0);
                    });
                });

                var cmd4 = config1.Command("refresh", config2 =>
                {
                    config2.Description = "refresh list of country's configuration";
                    config2.HelpOption(HelpFlag);

                    var validator = new GroupArgument(config2, false);

                    var countryName = validator.Argument("CountryName",
                                                         "name of the country must be added in the configuration. (when argument is missing, all configuration are refreshed)"
                                                         //, ValidatorExtension.
                                                         );

                    config2.OnExecute(() =>
                    {
                        if (validator.Evaluate() > 0)
                        {
                            return(2);
                        }

                        var rootPath = GetTempFolder();

                        foreach (var item in Helper.Parameters.Countries.Where(c => c.Included))
                        {
                            if (item.LocalVersion != null && item.LocalVersion == item.OnlineVersion)
                            {
                                var target = new FileInfo(Path.Combine(Constants.RootPathConfig.FullName, item.Name) + ".json");
                                if (target.Exists)
                                {
                                    Output.WriteLine($"{item.Name} up to date in the version {item.LocalVersion}");
                                    continue;
                                }
                            }

                            RefreshConfigCountry(item, rootPath);
                        }


                        Output.WriteLine($"Clean");
                        rootPath.DeleteDirectoryTree();

                        Output.WriteLine("successfull updated");

                        return(0);
                    });
                });
            });

            return(app);
        }
Example #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);
                });
            });
Example #3
0
        public static CommandLineApplication CommandCompute(this CommandLineApplication app)
        {
            var cmd = app.Command("compute", (Action <CommandLineApplication>)(config1 =>
            {
                config1.Description = "compute country";
                config1.HelpOption(HelpFlag);

                var validator = new GroupArgument(config1, false);

                var outputName = validator.Argument("outputName",
                                                    "name of the output csv file"
                                                    , ValidatorExtension.EvaluateRequired
                                                    );

                var countYear = validator.Argument("CountYears",
                                                   "count of years must be computed. (this argument is required)"
                                                   , ValidatorExtension.EvaluateShort
                                                   );

                var countryName = validator.Argument("CountryName",
                                                     "name of the country must be computed. (if this argument is missing all config will be computed)"
                                                     , ValidatorExtension.EvaluateCountryName
                                                     );
                countryName.MultipleValues = true;



                //var countYear = validator.Option("",
                //   "count of years must be computed. (1 year by default)"
                //   , Va



                config1.OnExecute((Func <int>)(() =>
                {
                    if (validator.Evaluate() > 0)
                    {
                        return(2);
                    }

                    // Resolve arguments
                    var Namecountries = countryName.Values.Select(c => c.ToLower()).ToList();
                    string file       = outputName.Value;
                    var d             = Path.Combine(Directory.GetCurrentDirectory(), outputName.Value);
                    short cYear       = 1;
                    if (short.TryParse((string)countYear.Value.ToString(), out short cc))
                    {
                        cYear = cc;
                    }

                    // Initialisation parameters
                    var loader = new ConfigurationLoader(Constants.RootPathConfig);
                    List <CountryParameter> countriesToCompute = BuildListOfCountriesMustBeComputed(Namecountries);
                    List <DefaultCountryConfiguration> _list   = LoadConfigurations(countriesToCompute, loader);
                    var _countries = CalendariumConfiguration.GetCalendarium(_list.ToArray());

                    // Init file
                    if (File.Exists(d))
                    {
                        File.Delete(d);
                    }
                    var t = "Name;StartDate;EndDate;ObservedDate;Country;Culture;Free;Calendar";
                    File.AppendAllLines(d, new string[] { t });

                    List <EventDate> dates = new List <EventDate>();
                    foreach (var countryToCompute in countriesToCompute)
                    {
                        if (countryToCompute.OnlineVersion != countryToCompute.LocalVersion)
                        {
                            Output.WriteLine($"{countryToCompute.Name} is not up to date");
                        }

                        var items = _countries.GetNextDates(DateTime.Now, countryToCompute.Name, cYear * 365);

                        foreach (var item in items)
                        {
                            foreach (var item2 in item.Value.Events)
                            {
                                dates.Add(item2);

                                var dateEnd      = item2.DateEnd?.ToString() ?? string.Empty;
                                var dateObserved = item2.Observed?.ToString() ?? string.Empty;

                                var y = $"{item2.Name};{item.Value.Date};{dateEnd};{dateObserved};{item2.Country};{item2.Culture};{item2.Free.ToString().ToLower()};{item2.CalendarUsedToBuild.ToString().Split('.')[2].Replace("Calendar", "")}";
                                File.AppendAllLines(d, new string[] { y });
                            }
                        }
                    }

                    dates.ConvertList(
                        "computed dates"
                        , c => c.Name
                        , c => c.Country
                        , c => c.Culture
                        , c => c.Date
                        , c => c.DateEnd
                        , c => c.Observed
                        , c => c.Free
                        , c => c.Region
                        )
                    .PrintList()
                    ;

                    return(0);
                }));
            }));

            return(app);
        }