public static CommandLineApplication CommandDownloadNuget(this CommandLineApplication app)
        {
            var cmd = app.Command("download", config =>
            {
                config.Description = "Download nuget at " + Constants.urlNuget;
                config.HelpOption(HelpFlag);

                var validator = new GroupArgument(config, false);

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

                    var uri          = new Uri(Constants.urlNuget);
                    BbClientHttp cli = new BbClientHttp(uri);


                    try
                    {
                        if (Constants.NugetFile.Exists)
                        {
                            Output.WriteLine("remove current version of nuget.exe in " + Constants.NugetFile.Directory.FullName);
                            Constants.NugetFile.Delete();
                        }
                    }
                    catch (Exception ex1)
                    {
                        throw new Exception("failed to remove current version of nuget.exe", ex1);
                    }

                    try
                    {
                        Output.WriteLine("download lastest version of nuget.exe in " + Constants.NugetFile.Directory.FullName);
                        BbClientHttp.DownloadAsync(uri, Constants.NugetFile.FullName).Wait();
                    }
                    catch (Exception ex2)
                    {
                        throw new Exception("failed to to downlod nuget.exe", ex2);
                    }

                    Output.WriteLine("download successfull");

                    Result = Constants.NugetFile;

                    return(0);
                });
            });

            return(app);
        }
Example #2
0
        private static object GroupedFunctionCall(FunctionCall funCall, GroupArgument group, Scope scope)
        {
            var name       = funCall.FunctionName.Value;
            var paramCount = funCall.Parameters.Count;
            var rows       = group.Rows.Select(x => new RowArgument(x));

            switch (name.ToLower())
            {
            case "sum" when paramCount == 1:
                var expr0 = funCall.Parameters[0];
                return(rows.Sum(x => Evaluate <int>(expr0, x, scope)));

            case "avg" when paramCount == 1:
                var expr1 = funCall.Parameters[0];
                return(rows.Average(x => Evaluate <int>(expr1, x, scope)));

            case "min" when paramCount == 1:
                var expr2 = funCall.Parameters[0];
                return(rows.Min(x => Evaluate <int>(expr2, x, scope)));

            case "max" when paramCount == 1:
                var expr3 = funCall.Parameters[0];
                return(rows.Max(x => Evaluate <int>(expr3, x, scope)));

            case "count" when paramCount == 1:
                var expr4 = funCall.Parameters[0];
                return(rows.Count(x => Evaluate(expr4, x, scope) != null));

            case "count_big" when paramCount == 1:
                var expr5 = funCall.Parameters[0];
                return(rows.LongCount(x => Evaluate(expr5, x, scope) != null));

            default:
                throw FeatureNotSupportedException.Value(funCall);
            }
        }
Example #3
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 #4
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 #5
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);
        }