Esempio n. 1
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 resx = new XResourceFile();

                const int key_index = 0;
                const int val_index = 1;
                const int cmt_index = 2;
                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")));
            }
        }
Esempio n. 2
0
 public void Load_NullStream_ThrowArgumentNullException()
 {
     ExceptionAssert.CatchArgumentNullException(() =>
     {
         XResourceFile.Load((Stream)null);
     },
                                                "stream");
 }
Esempio n. 3
0
 public void Load_NullFileThrowArgumentNullException()
 {
     ExceptionAssert.CatchArgumentNullException(() =>
     {
         XResourceFile.Load((FileInfo)null);
     },
                                                "file");
 }
Esempio n. 4
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}");
                }
            }
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
        /// <summary>Generates the gender resource file.</summary>
        private 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];

                const int key_index = 0;
                const int val_index = 1;
                const int 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)));
                }
            }
        }
Esempio n. 7
0
        /// <summary>Generates the country info resource file.</summary>
        private void GenerateCurrency(DirectoryInfo dir)
        {
            using (var stream = GetType().Assembly
                                .GetManifestResourceStream("Qowaiv.CodeGenerator.Resources.Currency.xls"))
            {
                using (var writer = new StreamWriter(Path.Combine(dir.FullName, "CurrencyConstants.cs")))
                {
                    writer.WriteLine("namespace Qowaiv.Financial\r\n{\r\n    public partial struct Currency\r\n    {");

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

                    var all = new List <string>();

                    const int key_index = 1;
                    const int iso_index = 2;
                    const int num_index = 3;
                    const int dig_index = 4;
                    const int sym_index = 5;
                    const int str_index = 6;
                    const int end_index = 7;
                    const int def_index = 8;

                    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      iso     = row.GetCell(iso_index).StringValue.Trim();
                        int      num     = string.IsNullOrEmpty(row.GetCell(num_index).StringValue) ? 0 : (int)(double)row.GetCell(num_index).Value;
                        int      dig     = string.IsNullOrEmpty(row.GetCell(dig_index).StringValue) ? 0 : (int)(double)row.GetCell(dig_index).Value;
                        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      sym     = row.GetCell(sym_index).StringValue.Trim();
                        var      display = row.GetCell(def_index).StringValue.Trim();

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

                            writer.WriteLine("        /// <summary>Describes the currency {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 Currency {0} = new Currency()", 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 + "Num", num.ToString("000")));
                        resx.Data.Add(new XResourceFileData(key + "ISO", iso));
                        resx.Data.Add(new XResourceFileData(key + "Digits", dig.ToString()));

                        resx.Data.Add(new XResourceFileData(key + "StartDate", start.ToString(DateFromat)));

                        if (!string.IsNullOrEmpty(sym))
                        {
                            resx.Data.Add(new XResourceFileData(key + "Symbol", sym));
                        }

                        if (end.HasValue)
                        {
                            resx.Data.Add(new XResourceFileData(key + "EndDate", end.Value.ToString(DateFromat)));
                        }
                    }

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

                    resx.Save(new FileInfo(Path.Combine(dir.FullName, "CurrencyLabels.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(iso_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, "CurrencyLabels." + culture + Resx)));
                    }
                    writer.WriteLine("    }\r\n}");
                }
            }
        }
Esempio n. 8
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.Globalization\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 nat_index = 9;
                    var def_index = 10;

                    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 : row.GetCell(end_index).DateTimeValue;
                        var      tel     = row.GetCell(tel_index).StringValue.Trim();
                        var      display = row.GetCell(def_index).StringValue.Trim();

                        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));
                        }
                    }

                    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}");
                }
            }
        }