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