예제 #1
0
        public void SaveLoad_Data_AreEqual()
        {
            var file = new FileInfo("SaveLoad_Data_AreEqual.resx");

            var resourceFile = new XResourceFile(new List<XResourceFileData>()
            {
                new XResourceFileData("key0", "Some value 0"),
                new XResourceFileData("key1", "1.1", "comment 1.1"),
            });

            resourceFile.Save(file);

            var act = XResourceFile.Load(file);
        }
예제 #2
0
        public void SaveLoad_Data_AreEqual()
        {
            using (var dir = new TemporaryDirectory())
            {
                var resourceFile = new XResourceFile(new List<XResourceFileData>()
                {
                    new XResourceFileData("key0", "Some value 0"),
                    new XResourceFileData("key1", "1.1", "comment 1.1"),
                });

                var file = dir.CreateFile("SaveLoad_Data_AreEqual.resx");
                resourceFile.Save(file);

                var act = XResourceFile.Load(file);
                Assert.AreEqual(2, act.Data.Count);
            }
        }
예제 #3
0
        /// <summary>Generates the gender resource file.</summary>
        protected void GenerateUnknown(DirectoryInfo dir)
        {
            using (var stream = GetType().Assembly
                .GetManifestResourceStream("Qowaiv.CodeGenerator.Resources.Unknown.xls"))
            {
                var workbook = Workbook.Load(stream);
                var worksheet = workbook.Worksheets[0];

                var key_index = 0;
                var val_index = 1;
                var cmt_index = 2;

                var resx = new XResourceFile();

                var header = worksheet.Cells.GetRow(0);

                int i = 1;

                while (true)
                {
                    var row = worksheet.Cells.GetRow(i++);

                    if (row.LastColIndex == int.MinValue) { break; }

                    resx.Data.Add(new XResourceFileData(
                        row.GetCell(key_index).StringValue,
                        row.GetCell(val_index).StringValue,
                        row.GetCell(cmt_index).StringValue));
                }

                resx.Save(new FileInfo(Path.Combine(dir.FullName, "UnknownLabels.resx")));

                for (int lng_index = cmt_index + 1; lng_index <= header.LastColIndex; lng_index++)
                {
                    var resx_lng = new XResourceFile();

                    var culture = header.GetCell(lng_index).StringValue;

                    i = 1;

                    while (true)
                    {
                        var row = worksheet.Cells.GetRow(i++);
                        if (row.LastColIndex == int.MinValue) { break; }

                        var key = row.GetCell(key_index).StringValue;
                        var val = row.GetCell(lng_index).StringValue;
                        var cmd = row.GetCell(cmt_index).StringValue;
                        var def = resx[key].Value;

                        if (!string.IsNullOrEmpty(val) && def != val)
                        {
                            resx_lng.Data.Add(new XResourceFileData(key, val, cmd));
                        }
                    }
                    resx_lng.Save(new FileInfo(Path.Combine(dir.FullName, "UnknownLabels." + culture + ".resx")));
                }
            }
        }
예제 #4
0
        /// <summary>Generates the country info resource file.</summary>
        protected void GenerateCountry(DirectoryInfo dir)
        {
            using (var stream = GetType().Assembly
                .GetManifestResourceStream("Qowaiv.CodeGenerator.Resources.Country.xls"))
            {
                using (var writer = new StreamWriter(Path.Combine(dir.FullName, "CountryConstants.cs")))
                {
                    writer.WriteLine("namespace Qowaiv\r\n{\r\n    public partial struct Country\r\n    {");

                    var workbook = Workbook.Load(stream);
                    var worksheet = workbook.Worksheets[0];

                    var all = new List<string>();

                    var key_index = 1;
                    var num_index = 2;
                    var is2_index = 3;
                    var is3_index = 4;
                    //var win_index = 5;
                    var str_index = 6;
                    var end_index = 7;
                    var tel_index = 8;
                    var reg_index = 9;
                    //var nat_index = 10;
                    var def_index = 11;

                    var resx = new XResourceFile();

                    var header = worksheet.Cells.GetRow(0);

                    int i = 1;

                    while (true)
                    {
                        var row = worksheet.Cells.GetRow(i++);

                        if (row.LastColIndex == int.MinValue) { break; }

                        var key = row.GetCell(key_index).StringValue.Trim();

                        var num = row.GetCell(num_index).StringValue.Trim();
                        var iso2 = row.GetCell(is2_index).StringValue.Trim();
                        var iso3 = row.GetCell(is3_index).StringValue.Trim();
                        var start = row.GetCell(str_index).DateTimeValue;
                        DateTime? end = String.IsNullOrEmpty(row.GetCell(end_index).StringValue) ? (DateTime?)null : (DateTime?)row.GetCell(end_index).DateTimeValue;
                        var tel = row.GetCell(tel_index).StringValue.Trim();
                        var display = row.GetCell(def_index).StringValue.Trim();
                        var hasRegInfo = XmlConvert.ToBoolean(row.GetCell(reg_index).StringValue);

                        if (key != "ZZ")
                        {
                            all.Add(key);

                            writer.WriteLine("        /// <summary>Describes the country {0} ({1}).</summary>", display, key);
                            if (end.HasValue)
                            {
                                writer.WriteLine("        /// <remarks>End date is {0:yyyy-MM-dd}.</remarks>", end.Value);
                            }
                            writer.Write("        public static readonly Country {0} = new Country()", key);
                            writer.Write(" { m_Value = \"");
                            writer.Write(key);
                            writer.WriteLine("\" };");
                            writer.WriteLine();
                        }
                        key += '_';

                        resx.Data.Add(new XResourceFileData(key + "DisplayName", display));
                        resx.Data.Add(new XResourceFileData(key + "ISO", num));
                        resx.Data.Add(new XResourceFileData(key + "ISO2", iso2));
                        resx.Data.Add(new XResourceFileData(key + "ISO3", iso3));
                        resx.Data.Add(new XResourceFileData(key + "StartDate", start.ToString("yyyy-MM-dd")));

                        if (end.HasValue)
                        {
                            resx.Data.Add(new XResourceFileData(key + "EndDate", end.Value.ToString("yyyy-MM-dd")));
                        }
                        if (!String.IsNullOrEmpty(tel))
                        {
                            resx.Data.Add(new XResourceFileData(key + "CallingCode", tel));
                        }
                        if (hasRegInfo)
                        {
                            resx.Data.Add(new XResourceFileData(key + "RegionInfoExists", true.ToString()));
                        }
                    }

                    resx.Data.Add(new XResourceFileData("All", String.Join(";", all)));

                    resx.Save(new FileInfo(Path.Combine(dir.FullName, "CountryLabels.resx")));

                    for (int lng_index = def_index + 1; lng_index <= header.LastColIndex; lng_index++)
                    {
                        var resx_lng = new XResourceFile();

                        var culture = header.GetCell(lng_index).StringValue;

                        i = 1;

                        while (true)
                        {
                            var row = worksheet.Cells.GetRow(i++);
                            if (row.LastColIndex == int.MinValue) { break; }

                            var key = row.GetCell(key_index).StringValue + "_DisplayName";
                            var val = row.GetCell(lng_index).StringValue.Trim();
                            var cmd = string.Format("{0} ({1})", row.GetCell(def_index).StringValue, row.GetCell(is2_index).StringValue);
                            var def = resx[key].Value;

                            if (!string.IsNullOrEmpty(val) && def != val)
                            {
                                resx_lng.Data.Add(new XResourceFileData(key, val, cmd));
                            }
                        }
                        resx_lng.Save(new FileInfo(Path.Combine(dir.FullName, "CountryLabels." + culture + ".resx")));
                    }
                    writer.WriteLine("    }\r\n}");
                }
            }
        }
예제 #5
0
        private void GenerateInternetMediaType(DirectoryInfo dir)
        {
            using (var stream = GetType().Assembly
                .GetManifestResourceStream("Qowaiv.CodeGenerator.Resources.Web.InternetMediaType.xls"))
            {
                var workbook = Workbook.Load(stream);
                var worksheet = workbook.Worksheets[0];

                var key_index = 0;
                var val_index = 1;
                var cmt_index = 2;

                var resx = new XResourceFile();

                var header = worksheet.Cells.GetRow(0);

                int i = 1;

                while (true)
                {
                    var row = worksheet.Cells.GetRow(i++);

                    if (row.LastColIndex == int.MinValue) { break; }

                    resx.Data.Add(new XResourceFileData(
                        row.GetCell(key_index).StringValue,
                        row.GetCell(val_index).StringValue,
                        row.GetCell(cmt_index).StringValue));
                }

                resx.Save(new FileInfo(Path.Combine(dir.FullName, "InternetMediaType.FromFile.resx")));
            }
        }
예제 #6
0
        /// <summary>Generates the country info resource file.</summary>
        protected void GenerateCountryToCurrency(DirectoryInfo dir)
        {
            using (var stream = GetType().Assembly
                .GetManifestResourceStream("Qowaiv.CodeGenerator.Resources.CountryToCurrency.xls"))
            {
                using (var writer = new StreamWriter(Path.Combine(dir.FullName, "CountryToCurrencyMappings.cs")))
                {
                    writer.WriteLine("using Qowaiv.Globalization;");
                    writer.WriteLine("using System.Collections.Generic;");
                    writer.WriteLine("using System.Collections.ObjectModel;");
                    writer.WriteLine();

                    writer.WriteLine("namespace Qowaiv.Financial\r\n{\r\n\tinternal partial struct CountryToCurrency\r\n\t{");

                    writer.WriteLine("\t\tpublic static readonly ReadOnlyCollection<CountryToCurrency> All = new ReadOnlyCollection<CountryToCurrency>(new List<CountryToCurrency>()\r\n\t\t{");

                    var workbook = Workbook.Load(stream);
                    var worksheet = workbook.Worksheets[0];

                    var all = new List<string>();

                    var country_index = 1;
                    var currency_index = 2;
                    var date_index = 0;

                    var resx = new XResourceFile();

                    var header = worksheet.Cells.GetRow(0);

                    int i = 1;

                    while (true)
                    {
                        var row = worksheet.Cells.GetRow(i++);

                        if (row.LastColIndex == int.MinValue) { break; }

                        var country = row.GetCell(country_index).StringValue.Trim();
                        var cur = row.GetCell(currency_index).StringValue.Trim();
                        Date start = Date.Parse(row.GetCell(date_index).StringValue);

                        if (start == Date.MinValue)
                        {
                            writer.WriteLine("\t\t\tnew CountryToCurrency(Country.{0}, Currency.{1}),", country, cur);
                        }
                        else
                        {
                            writer.WriteLine("\t\t\tnew CountryToCurrency(Country.{0}, Currency.{1}, new Date({2:yyyy, MM, dd})),", country, cur, start);
                        }

                    }
                    writer.WriteLine("\t\t});\r\n\t}\r\n}");
                }
            }
        }