예제 #1
0
        private void GenerateDelphiFile(KnownHolidays knownHolidays, List <HolidayRow> holidayList,
                                        HtmlAgilityPack.HtmlDocument htmlDocument, string country)
        {
            var filename = $@"C:\Users\Jens\source\repos\Holidays\Demo\CalendricalCalculations\NationalHolidays\{country}U.pas";

            if (File.Exists(filename))
            {
                return;
            }
            var lines = new List <string>
            {
                $"unit {country}U;",
                "",
                "interface",
                "",
                "uses",
                "  BaseNationalHolidaysU;",
                "",
                "type",
                $"  {country} = class sealed(TBaseNationalHolidays)",
                "  public",
                "    function MakeHolydays: TBaseNationalHolidays; override;",
                "    function SundayName: string; override;",
                "  end;",
                "",
                "implementation",
                "",
                "{ " + country + " }",
                "",
                $"function {country}.MakeHolydays: TBaseNationalHolidays;",
                "begin"
            };

            foreach (var element in holidayList)
            {
                var knownHoliday = knownHolidays.FirstOrDefault(e => e.Date == element.Date);

                if (knownHoliday != null)
                {
                    lines.Add($"  Add({knownHoliday.EnglishName}, '{element.Name.Replace("'", "''") }');");
                }
                else
                {
                    var s = "TMonth." + Enum.GetName(typeof(KnownHolidays.Month), element.Date.Month);
                    lines.Add($"  Add(Year, {s}, {element.Date.Day}, '{element.Name.Replace("'", "''")}');");
                }
            }

            lines.AddRange(
                new[] {
                "end;",
                "",
                $"function {country}.SundayName: string;",
                "begin",
                "  Result := 'Sunday';",
                "end;"
            });

            lines.Add("");

            var ulNode = htmlDocument.DocumentNode.Descendants("ul").Where(e => e.HasAttributes).FirstOrDefault(e => e.Attributes.First().Value == "circle_list");

            if (ulNode != null)
            {
                lines.Add("(*");
                lines.Add("  Notes");

                foreach (var element in ulNode.Descendants("li"))
                {
                    lines.Add("    * " + element.InnerText.Trim());
                }
                lines.Add("*)");
            }

            lines.Add("end.");

            File.WriteAllLines(filename, lines);
            lines.Clear();

            foreach (var element in holidayList.Where(e => !string.IsNullOrEmpty(e.Comment)))
            {
                lines.Add(element.Name + "\t\t\t\t" + element.Comment);
            }

            textBox1.Text = string.Join(Environment.NewLine, lines);
        }
예제 #2
0
        private void GenerateCSharpFile(KnownHolidays knownHolidays, List <HolidayRow> holidayList, HtmlAgilityPack.HtmlDocument htmlDocument, string country)
        {
            var filename = $"C:\\Users\\Jens\\source\\repos\\HolidayTest\\CalendricalCalculations\\NationalHolidays\\{country}.cs";

            if (File.Exists(filename))
            {
                return;
            }

            var lines = new List <string>
            {
                "namespace CalendricalCalculation.NationalHolidays",
                "{",
                $"    public class {country} : BaseNationalHolidays",
                "    {",
                "        public override string SundayName { get; } = \"Sunday\";",
                "        public override BaseNationalHolidays MakeHolydays()",
                "        {"
            };


            foreach (var element in holidayList)
            {
                var knownHoliday = knownHolidays.FirstOrDefault(e => e.Date == element.Date);

                if (knownHoliday != null)
                {
                    lines.Add($"            Add({knownHoliday.EnglishName}, \"{element.Name}\");");
                }
                else
                {
                    var s = "Month." + Enum.GetName(typeof(KnownHolidays.Month), element.Date.Month);
                    lines.Add($"            Add(Year, {s}, {element.Date.Day}, \"{element.Name}\");");
                }
            }


            lines.Add("            return this;");
            lines.Add("        }");
            lines.Add("    }");
            lines.Add("}");

            lines.Add("");

            var ulNode = htmlDocument.DocumentNode.Descendants("ul").Where(e => e.HasAttributes).FirstOrDefault(e => e.Attributes.First().Value == "circle_list");

            if (ulNode != null)
            {
                lines.Add("/*");
                lines.Add("  Notes");

                foreach (var element in ulNode.Descendants("li"))
                {
                    lines.Add("    * " + element.InnerText.Trim());
                }
                lines.Add("*/");
            }

            File.WriteAllLines(filename, lines);
            lines.Clear();

            foreach (var element in holidayList.Where(e => !string.IsNullOrEmpty(e.Comment)))
            {
                lines.Add(element.Name + "\t\t\t\t" + element.Comment);
            }

            textBox1.Text = string.Join(Environment.NewLine, lines);
        }