Exemplo n.º 1
0
        public void GenerateReligiousTags()
        {
            var _items = GetDaysWithTags();
            List <CountryConfiguration> _countries = GetCountriesFromSolution();
            var dateCountries = CalendariumConfiguration.GetCalendarium(_countries.ToArray());


            foreach (var item in _items)
            {
                foreach (var item2 in item.Value)
                {
                    foreach (var item3 in item2.Value.Dates)
                    {
                        dateCountries.GetDate(item3, item.Key);
                    }
                }
            }


            foreach (var country in _countries)
            {
                var trads = _items[country.Country];
                foreach (var period in country.Periods)
                {
                    var day = trads[period.Name] ?? trads[Helper.GetA(period.Name)];
                    if (day == null)
                    {
                        foreach (var item in trads)
                        {
                            if (item.Value.IsFix)
                            {
                                var dte = dateCountries.GetDate(item.Value.Dates.First(), country.Country, null);
                            }
                        }
                    }
                }
            }


            //foreach (var country in _c)
            //{
            //    //var _country = _items[country.Value.Country];
            //    foreach (var item in country.Value.Periods)
            //        _h.Add(item.Name);
            //}
            //foreach (var item in _h.OrderBy(c => c))
            //    Debug.WriteLine($"case \"{item}\":");
            //_h.Clear();


            //foreach (var item1 in _items)
            //    foreach (var item2 in item1.Value)
            //        foreach (var item3 in item2.Value.Translations.Where(c => c.Key == Language.English))
            //            _h.Add(item3.Value.Name.Trim('"').Trim());


            //foreach (var item in _h.OrderBy(c => c))
            //    Debug.WriteLine($"return \"{item}\";");

            //StringBuilder sb = new StringBuilder();
            //List<religious> religious = new List<religious>();
            //foreach (var item1 in _items.Values)
            //    foreach (var item2 in item1)
            //    {

            //        StringBuilder sb2 = new StringBuilder();

            //        foreach (var item in item2.Value.Translations)
            //        {
            //            sb2.Append(item.Key.ToString());
            //            sb2.Append("=");
            //            sb2.Append(item.Value.Name);
            //            int c = 0;
            //            do
            //            {
            //                c = sb2.Length;
            //                var ch = sb2[sb2.Length - 1];
            //                if (char.IsNumber(ch) || char.IsWhiteSpace(ch) || ch == '#')
            //                    sb2.Remove(sb2.Length - 1, 1);

            //            } while (sb2.Length != c);
            //            sb2.Append(",");
            //        }
            //        sb2.Append(";");

            //        sb2.Append(string.Join(',', item2.Value.Tags));
            //        sb2.Append(";");

            //        if (item2.Value.IsFix)
            //        {
            //            var dt = item2.Value.Dates.First();
            //            sb2.Append($"{dt.Month}-{dt.Day};");
            //        }
            //        else
            //        {
            //            foreach (var item3 in item2.Value.Dates)
            //            {
            //                sb2.Append(item3.ToString("d"));
            //                sb2.Append(",");
            //            }
            //        }

            //        sb2.Append(";");

            //        if (_h.Add(sb2.ToString()))
            //            sb.AppendLine(sb2.ToString());

            //        sb2.Clear();


            //    }

            //var fileReligious = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "Output", "religious.csv");
            //if (File.Exists(fileReligious))
            //    File.Delete(fileReligious);
            //File.AppendAllText(fileReligious, sb.ToString());



            //var txt = JsonConvert.SerializeObject(religious, Formatting.Indented);
            //File.AppendAllText(fileReligious, txt);
        }
Exemplo n.º 2
0
        public void TestChecked()
        {
            var dir    = new System.IO.DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..", "Black.Beard.Calendarium", "Countries"));
            var loader = new ConfigurationLoader(dir).Load(); //.Where(c => c.Country == "Algeria").ToArray();

            var result = new System.IO.FileInfo(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..", "..", "result.md"));

            //CountryDebugger.AutoStop.Rule = RuleEnum.Observed;
            //CountryDebugger.AutoStop.Country = "Algeria";
            //CountryDebugger.AutoStop.DayName = "Hijri New Year";
            //CountryDebugger.AutoStop.Year = 2013;

            var cal = CalendariumConfiguration.GetCalendarium
                      (
                loader
                      );

            List <string> listErrors = new List <string>();

            StringBuilder sb = new StringBuilder();

            sb.Mark(Mark.H1, "Check configuration result");

            foreach (var item in loader.OfType <CountryConfiguration>())
            {
                sb.Mark(Mark.H2, item.Country);
                sb.AppendLine();

                listErrors.Clear();

                var referential = Helper.Referential[item.Country]
                                  .OrderBy(c => c.DayName).ToList();

                if (Check(item.Country, referential, cal, string.Empty, listErrors))
                {
                    if (listErrors.Any())
                    {
                        foreach (var error in listErrors)
                        {
                            sb.AppendLine(error);
                        }
                    }
                    else
                    {
                        sb.AppendLine("all tests are OK");
                    }
                }
                else
                {
                    sb.Mark(Mark.Bold, "not implemented");
                }

                sb.MarkHorizontalRule();
            }

            if (result.Exists)
            {
                result.Delete();
            }

            File.AppendAllText(result.FullName, sb.ToString());
        }
Exemplo n.º 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);
        }