)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Country (Ia.Cl.Model)

Public general use code classes and xml files that we've compiled and used over the years:

Country geographic coordinates and standard UN naming conventions.

    1: using System;
    2: using System.Collections;
    3: using System.Collections.Generic;
    4: using System.IO;
    5: using System.Linq;
    6: using System.Reflection;
    7: using System.Xml.Linq;
    8:  
    9: namespace Ia.Cl.Model
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Country geographic coordinates and standard UN naming conventions.
   15:     /// </summary>
   16:     /// <remarks> 
   17:     /// Copyright © 2001-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     ///
   19:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   20:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   21:     ///
   22:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   23:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   24:     /// 
   25:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   26:     /// 
   27:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   28:     /// </remarks> 
   29:     public class Country
   30:     {
   31:         private static Hashtable fipsToIso2Hashtable, iso2ToFipsHashtable;
   32:         private static XDocument xd;
   33:  
   34:         // # FIPS 10-4 to ISO 3166-1 country codes
   35:         // # Created by OpenGeoCode.Org, Submitted into the Public Domain June 4, 2014 (Version 5)
   36:         // #
   37:         // # Last FIPS 10-4 Revision, as Published by CIA World Factbook, Jan. 2014
   38:         // # Metadata
   39:         // # FIPS 10-4, 
   40:         // # ISO 3166-1 alpha-2, 
   41:         // # ISO 3166-1 alpha-3, 
   42:         // # ISO 3166-1 numeric-3,
   43:         // # Inclusive in Country 
   44:  
   45:         private static List<string> fipsIsoList = new List<string> {
   46:             "AF", "AF", "AFB", "004",
   47:             //"AX", "", "", "",
   48:             //"GB",
   49:             "AL", "AL", "ALB", "008",
   50:             "AG", "DZ", "DZA", "012",
   51:             "AQ", "AS", "ASM", "016",
   52:             "AN", "AD", "AND", "020",
   53:             "AO", "AO", "AGO", "024",
   54:             "AV", "AI", "AIA", "660",
   55:             "AY", "AQ", "ATA", "010",
   56:             "AC", "AG", "ATG", "028",
   57:             "AR", "AR", "ARG", "032",
   58:             "AM", "AM", "ARM", "051",
   59:             "AA", "AW", "ABW", "533",
   60:             //"AT", "", "", "", "AU",
   61:             "AS", "AU", "AUS", "036",
   62:             "AU", "AT", "AUT", "040",
   63:             "AJ", "AZ", "AZE", "031",
   64:             "BF", "BS", "BHS", "044",
   65:             "BA", "BH", "BHR", "048",
   66:             //"FQ", "", "", "", "UM",
   67:             "BG", "BD", "BGD", "050",
   68:             "BB", "BB", "BRB", "052",
   69:             //"BS", "", "", "", "FR",
   70:             "BO", "BY", "BLR", "112",
   71:             "BE", "BE", "BEL", "056",
   72:             "BH", "BZ", "BLZ", "084",
   73:             "BN", "BJ", "BEN", "204",
   74:             "BD", "BM", "BMU", "060",
   75:             "BT", "BT", "BTN", "064",
   76:             "BL", "BO", "BOL", "068",
   77:             "BK", "BA", "BIH", "070",
   78:             "BC", "BW", "BWA", "072",
   79:             "BV", "BV", "BVT", "074",
   80:             "BR", "BR", "BRA", "076",
   81:             "IO", "IO", "IOT", "086",
   82:             "VI", "VG", "VGB", "092",
   83:             "BX", "BN", "BRN", "096",
   84:             "BU", "BG", "BGR", "100",
   85:             "UV", "BF", "BFA", "854",
   86:             "BM", "MM", "MMR", "104",
   87:             "BY", "BI", "BDI", "108",
   88:             "CV", "CV", "CPV", "132",
   89:             "CB", "KH", "KHM", "116",
   90:             "CM", "CM", "CMR", "120",
   91:             "CA", "CA", "CAN", "124",
   92:             "CJ", "KY", "CYM", "136",
   93:             "CT", "CF", "CAF", "140",
   94:             "CD", "TD", "TCD", "148",
   95:             "CI", "CL", "CHL", "152",
   96:             "CH", "CN", "CHN", "156",
   97:             "KT", "CX", "CXR", "162",
   98:             //"IP", "", "", "", "FR",
   99:             "CK", "CC", "CCK", "166",
  100:             "CO", "CO", "COL", "170",
  101:             "CN", "KM", "COM", "174",
  102:             "CG", "CD", "COD", "180",
  103:             "CF", "CG", "COG", "178",
  104:             "CW", "CK", "COK", "184",
  105:             //"CR", "", "", "", "AU",
  106:             "CS", "CR", "CRI", "188",
  107:             "IV", "CI", "CIV", "384",
  108:             "HR", "HR", "HRV", "191",
  109:             "CU", "CU", "CUB", "192",
  110:             "UC", "CW", "CUW", "531",
  111:             "CY", "CY", "CYP", "196",
  112:             "EZ", "CZ", "CZE", "203",
  113:             "DA", "DK", "DNK", "208",
  114:             //"DX", "", "", "", "GB",
  115:             "DJ", "DJ", "DJI", "262",
  116:             "DO", "DM", "DMA", "212",
  117:             "DR", "DO", "DOM", "214",
  118:             "EC", "EC", "ECU", "218",
  119:             "EG", "EG", "EGY", "818",
  120:             "ES", "SV", "SLV", "222",
  121:             "EK", "GQ", "GNQ", "226",
  122:             "ER", "ER", "ERI", "232",
  123:             "EN", "EE", "EST", "233",
  124:             "ET", "ET", "ETH", "231",
  125:             //"EU", "", "", "", "FR",
  126:             "FK", "FK", "FLK", "238",
  127:             "FO", "FO", "FRO", "234",
  128:             "FJ", "FJ", "FJI", "242",
  129:             "FI", "FI", "FIN", "246",
  130:             "FR", "FR", "FRA", "250",
  131:             //"", "FX", "FXX", "249",
  132:             "FG", "GF", "GUF", "254",
  133:             "FP", "PF", "PYF", "258",
  134:             "FS", "TF", "ATF", "260",
  135:             "GB", "GA", "GAB", "266",
  136:             "GA", "GM", "GMB", "270",
  137:             "GZ", "PS", "PSE", "275",
  138:             "GG", "GE", "GEO", "268",
  139:             "GM", "DE", "DEU", "276",
  140:             "GH", "GH", "GHA", "288",
  141:             "GI", "GI", "GIB", "292",
  142:             //"GO", "", "", "", "FR",
  143:             "GR", "GR", "GRC", "300",
  144:             "GL", "GL", "GRL", "304",
  145:             "GJ", "GD", "GRD", "308",
  146:             "GP", "GP", "GLP", "312",
  147:             "GQ", "GU", "GUM", "316",
  148:             "GT", "GT", "GTM", "320",
  149:             "GK", "GG", "GGY", "831",
  150:             "GV", "GN", "GIN", "324",
  151:             "PU", "GW", "GNB", "624",
  152:             "GY", "GY", "GUY", "328",
  153:             "HA", "HT", "HTI", "332",
  154:             "HM", "HM", "HMD", "334",
  155:             "VT", "VA", "VAT", "336",
  156:             "HO", "HN", "HND", "340",
  157:             "HK", "HK", "HKG", "344",
  158:             //"HQ", "", "", "", "UM",
  159:             "HU", "HU", "HUN", "348",
  160:             "IC", "IS", "ISL", "352",
  161:             "IN", "IN", "IND", "356",
  162:             "ID", "ID", "IDN", "360",
  163:             "IR", "IR", "IRN", "364",
  164:             "IZ", "IQ", "IRQ", "368",
  165:             "EI", "IE", "IRL", "372",
  166:             "IM", "IM", "IMN", "833",
  167:             "IS", "IL", "ISR", "376",
  168:             "IT", "IT", "ITA", "380",
  169:             "JM", "JM", "JAM", "388",
  170:             //"JN", "", "", "", "SV",
  171:             "JA", "JP", "JPN", "392",
  172:             //"DQ", "", "", "", "UM",
  173:             "JE", "JE", "JEY", "832",
  174:             //"JQ", "", "", "", "UM",
  175:             "JO", "JO", "JOR", "400",
  176:             //"JU", "", "", "", "FR",
  177:             "KZ", "KZ", "KAZ", "398",
  178:             "KE", "KE", "KEN", "404",
  179:             //"KQ", "", "", "", "UM",
  180:             "KR", "KI", "KIR", "296",
  181:             "KN", "KP", "PRK", "408",
  182:             "KS", "KR", "KOR", "410",
  183:             //"KV", "XK", "XKS", "",
  184:             "KU", "KW", "KWT", "414",
  185:             "KG", "KG", "KGZ", "417",
  186:             "LA", "LA", "LAO", "418",
  187:             "LG", "LV", "LVA", "428",
  188:             "LE", "LB", "LBN", "422",
  189:             "LT", "LS", "LSO", "426",
  190:             "LI", "LR", "LBR", "430",
  191:             "LY", "LY", "LBY", "434",
  192:             "LS", "LI", "LIE", "438",
  193:             "LH", "LT", "LTU", "440",
  194:             "LU", "LU", "LUX", "442",
  195:             "MC", "MO", "MAC", "446",
  196:             "MK", "MK", "MKD", "807",
  197:             "MA", "MG", "MDG", "450",
  198:             "MI", "MW", "MWI", "454",
  199:             "MY", "MY", "MYS", "458",
  200:             "MV", "MV", "MDV", "462",
  201:             "ML", "ML", "MKI", "466",
  202:             "MT", "MT", "MLT", "470",
  203:             "RM", "MH", "MHL", "584",
  204:             "MB", "MQ", "MTQ", "474",
  205:             "MR", "MR", "MRT", "478",
  206:             "MP", "MU", "MUS", "480",
  207:             "MF", "YT", "MYT", "175",
  208:             "MX", "MX", "MEX", "484",
  209:             "FM", "FM", "FSM", "583",
  210:             //"MQ", "", "", "", "UM",
  211:             "MD", "MD", "MDA", "498",
  212:             "MN", "MC", "MCO", "492",
  213:             "MG", "MN", "MNG", "496",
  214:             "MJ", "ME", "MNE", "499",
  215:             "MH", "MS", "MSR", "500",
  216:             "MO", "MA", "MAR", "504",
  217:             "MZ", "MZ", "MOZ", "508",
  218:             "WA", "NA", "NAM", "516",
  219:             "NR", "NR", "NRU", "520",
  220:             //"BQ", "", "", "", "UM",
  221:             "NP", "NP", "NPL", "524",
  222:             "NL", "NL", "NLT", "528",
  223:             //"NT", "", "", "",
  224:             "NC", "NC", "NCL", "540",
  225:             "NZ", "NZ", "NZL", "554",
  226:             "NU", "NI", "NIC", "558",
  227:             "NG", "NE", "NER", "562",
  228:             "NI", "NG", "NGA", "566",
  229:             "NE", "NU", "NIU", "570",
  230:             "NF", "NF", "NFK", "574",
  231:             "CQ", "MP", "MNP", "580",
  232:             "NO", "NO", "NOR", "578",
  233:             "MU", "OM", "OMN", "512",
  234:             "PK", "PK", "PAK", "586",
  235:             "PS", "PW", "PLW", "585",
  236:             //"LQ", "", "", "", "UM",
  237:             "PM", "PA", "PAN", "591",
  238:             "PP", "PG", "PNG", "592",
  239:             //"PF", "", "", "",
  240:             "PA", "PY", "PRY", "600",
  241:             "PE", "PE", "PER", "604",
  242:             "RP", "PH", "PHL", "608",
  243:             "PC", "PN", "PCN", "612",
  244:             "PL", "PL", "POL", "616",
  245:             "PO", "PT", "PRT", "620",
  246:             "RQ", "PR", "PRI", "630",
  247:             "QA", "QA", "QAT", "634",
  248:             "RE", "RE", "REU", "638",
  249:             "RO", "RO", "ROU", "642",
  250:             "RS", "RU", "RUS", "643",
  251:             "RW", "RW", "RWA", "646",
  252:             "TB", "BL", "BLM", "652",
  253:             "SH", "SH", "SHN", "654",
  254:             "SC", "KN", "KNA", "659",
  255:             "ST", "LC", "LCA", "662",
  256:             "RN", "MF", "MAF", "663",
  257:             "SB", "PM", "SPM", "666",
  258:             "VC", "VC", "VCT", "670",
  259:             "WS", "WS", "WSM", "882",
  260:             "SM", "SM", "SMR", "674",
  261:             "TP", "ST", "STP", "678",
  262:             "SA", "SA", "SAU", "682",
  263:             "SG", "SN", "SEN", "686",
  264:             "RI", "RS", "SRB", "688",
  265:             "SE", "SC", "SYC", "690",
  266:             "SL", "SL", "SLE", "694",
  267:             "SN", "SG", "SGP", "702",
  268:             "NN", "SX", "SXM", "534",
  269:             "LO", "SK", "SVK", "703",
  270:             "SI", "SI", "SVN", "705",
  271:             "BP", "SB", "SLB", "090",
  272:             "SO", "SO", "SOM", "706",
  273:             "SF", "ZA", "ZAF", "710",
  274:             "SX", "GS", "SGS", "239",
  275:             "OD", "SS", "SSD", "728",
  276:             "SP", "ES", "ESP", "724",
  277:             //"PG", "", "", "",
  278:             "CE", "LK", "LKA", "144",
  279:             "SU", "SD", "SDN", "729",
  280:             "NS", "SR", "SUR", "740",
  281:             "SV", "SJ", "SJM", "744",
  282:             "WZ", "SZ", "SWZ", "748",
  283:             "SW", "SE", "SWE", "752",
  284:             "SZ", "CH", "CHE", "756",
  285:             "SY", "SY", "SYR", "760",
  286:             "TW", "TW", "TWN", "158",
  287:             "TI", "TJ", "TJK", "762",
  288:             "TZ", "TZ", "TZA", "834",
  289:             "TH", "TH", "THA", "764",
  290:             "TT", "TL", "TLS", "626",
  291:             "TO", "TG", "TGO", "768",
  292:             "TL", "TK", "TKL", "772",
  293:             "TN", "TO", "TON", "776",
  294:             "TD", "TT", "TTO", "780",
  295:             //"TE", "", "", "", "FR",
  296:             "TS", "TN", "TUN", "788",
  297:             "TU", "TR", "TUR", "792",
  298:             "TX", "TM", "TKM", "795",
  299:             "TK", "TC", "TCA", "796",
  300:             "TV", "TV", "TUV", "798",
  301:             "UG", "UG", "UGA", "800",
  302:             "UP", "UA", "UKR", "804",
  303:             "AE", "AE", "ARE", "784",
  304:             "UK", "GB", "GBR", "826",
  305:             "US", "US", "USA", "840",
  306:             //"", "UM", "UMI", "581",
  307:             "UY", "UY", "URY", "858",
  308:             "UZ", "UZ", "UZB", "860",
  309:             "NH", "VU", "VUT", "548",
  310:             "VE", "VE", "VEN", "862",
  311:             "VM", "VN", "VNH", "704",
  312:             "VQ", "VI", "VIR", "850",
  313:             //"WQ", "", "", "", "UM",
  314:             "WF", "WF", "WLF", "876",
  315:             "WE", "PS", "PSE", "275",
  316:             "WI", "EH", "ESH", "732",
  317:             "YM", "YE", "YEM", "887",
  318:             "ZA", "ZM", "ZMB", "894",
  319:             "ZI", "ZW", "ZWE", "716" };
  320:  
  321:         private static List<Country> countryList;
  322:  
  323:         /// <summary/>
  324:         /// [Key]
  325:         public int Itu { get; set; }
  326:         /// <summary/>
  327:         public string Name { get; set; }
  328:         /// <summary/>
  329:         public string ArabicName { get; set; }
  330:         /// <summary/>
  331:         public string NativeName { get; set; }
  332:         /// <summary/>
  333:         public Dictionary<string, string> NameDictionary { get; set; }
  334:         /// <summary/>
  335:         public string Latitude { get; set; }
  336:         /// <summary/>
  337:         public string Longitude { get; set; }
  338:         /// <summary/>
  339:         public string Capital { get; set; }
  340:         /// <summary/>
  341:         public string CapitalLatitude { get; set; }
  342:         /// <summary/>
  343:         public string CapitalLongitude { get; set; }
  344:         /// <summary/>
  345:         public string Iso2 { get; set; }
  346:         /// <summary/>
  347:         public string Iso3 { get; set; }
  348:         /// <summary/>
  349:         public string Iana { get; set; }
  350:         /// <summary/>
  351:         public string Un { get; set; }
  352:         /// <summary/>
  353:         public string Ioc { get; set; }
  354:         /// <summary/>
  355:         public string Fips { get; set; }
  356:         /// <summary/>
  357:         public string SpokenLanguageIso6391ListString { get; set; }
  358:  
  359:  
  360:         ////////////////////////////////////////////////////////////////////////////
  361:  
  362:         /// <summary>
  363:         /// 
  364:         /// </summary>
  365:         public Country() { }
  366:  
  367:         ////////////////////////////////////////////////////////////////////////////
  368:  
  369:         /// <summary>
  370:         ///
  371:         /// </summary>
  372:         public static List<Country> List
  373:         {
  374:             get
  375:             {
  376:                 if (countryList == null || countryList.Count == 0)
  377:                 {
  378:                     countryList = (from c in XDocument.Elements("countryList").Elements("country")
  379:                                    where c.Attribute("itu").Value != "" && c.Attribute("iso2").Value != "" && Iso2ToFipsHashtable.ContainsKey(c.Attribute("iso2").Value)
  380:                                    select new Country
  381:                                    {
  382:                                        Itu = int.Parse(c.Attribute("itu").Value.Replace("-", "")),
  383:                                        Name = Ia.Cl.Models.Default.ToTitleCase(c.Attribute("name").Value),
  384:                                        ArabicName = c.Attribute("arabicName").Value,
  385:                                        NativeName = c.Attribute("nativeName").Value,
  386:                                        NameDictionary = _NameDictionary(c),
  387:                                        Latitude = c.Attribute("latitude").Value,
  388:                                        Longitude = c.Attribute("longitude").Value,
  389:                                        Capital = c.Attribute("capital").Value,
  390:                                        CapitalLatitude = c.Attribute("capitalLatitude").Value,
  391:                                        CapitalLongitude = c.Attribute("capitalLongitude").Value,
  392:                                        Iso2 = c.Attribute("iso2").Value,
  393:                                        Iso3 = c.Attribute("iso3").Value,
  394:                                        Iana = c.Attribute("iana").Value,
  395:                                        Un = c.Attribute("un").Value,
  396:                                        Ioc = c.Attribute("ioc").Value,
  397:                                        Fips = Iso2ToFipsHashtable[c.Attribute("iso2").Value].ToString(),
  398:                                        SpokenLanguageIso6391ListString = c.Attribute("spokenLanguageIso6391List").Value
  399:                                    }
  400:                     ).ToList<Country>();
  401:                 }
  402:  
  403:                 return countryList;
  404:             }
  405:         }
  406:  
  407:         ////////////////////////////////////////////////////////////////////////////
  408:  
  409:         /// <summary>
  410:         ///
  411:         /// </summary>
  412:         public static Ia.Cl.Models.Country ByIso2(string iso2)
  413:         {
  414:             var country = (from c in List where c.Iso2 == iso2 select c).SingleOrDefault();
  415:  
  416:             return country;
  417:         }
  418:  
  419:         ////////////////////////////////////////////////////////////////////////////
  420:  
  421:         /// <summary>
  422:         ///
  423:         /// </summary>
  424:         public static Ia.Cl.Models.Country ByIso3(string iso3)
  425:         {
  426:             var country = (from c in List where c.Iso3 == iso3 select c).SingleOrDefault();
  427:  
  428:             return country;
  429:         }
  430:  
  431:         ////////////////////////////////////////////////////////////////////////////
  432:  
  433:         /// <summary>
  434:         /// 
  435:         /// </summary>
  436:         private static Dictionary<string, string> _NameDictionary(XElement xElement)
  437:         {
  438:             IEnumerable<XAttribute> xAttributeList;
  439:             Dictionary<string, string> dictionary;
  440:  
  441:             dictionary = new Dictionary<string, string>();
  442:  
  443:             // name="Japan" arabicName="" nativeName="日本" japaneseName="日本"
  444:  
  445:             if (xElement.HasAttributes)
  446:             {
  447:                 xAttributeList = xElement.Attributes();
  448:  
  449:                 foreach (XAttribute xa in xAttributeList)
  450:                 {
  451:                     switch (xa.Name.LocalName)
  452:                     {
  453:                         case "name": dictionary.Add("en", xa.Value); break;
  454:                         case "arabicName": dictionary.Add("ar", xa.Value); break;
  455:                         case "spanishName": dictionary.Add("es", xa.Value); break;
  456:                         case "frenchName": dictionary.Add("fr", xa.Value); break;
  457:                         case "germanName": dictionary.Add("de", xa.Value); break;
  458:                         case "dutchName": dictionary.Add("nl", xa.Value); break;
  459:                         case "russianName": dictionary.Add("ru", xa.Value); break;
  460:  
  461:                         case "chineseTraditionalName": dictionary.Add("zh_traditional", xa.Value); break;
  462:                         case "chineseSimplifiedName": dictionary.Add("zh_simplified", xa.Value); break;
  463:  
  464:                         case "japaneseName": dictionary.Add("ja", xa.Value); break;
  465:                         case "koreanName": dictionary.Add("ko", xa.Value); break;
  466:                         case "catalanName": dictionary.Add("ca", xa.Value); break;
  467:                         case "portugueseName": dictionary.Add("pt", xa.Value); break;
  468:                         case "italianName": dictionary.Add("it", xa.Value); break;
  469:                         case "danishName": dictionary.Add("da", xa.Value); break;
  470:                         case "faroeseName": dictionary.Add("fo", xa.Value); break;
  471:  
  472:                         case "hindiName": dictionary.Add("hi", xa.Value); break;
  473:                         case "bengaliName": dictionary.Add("bn", xa.Value); break;
  474:                         case "gujaratiName": dictionary.Add("gu", xa.Value); break;
  475:                         case "kashmiriName": dictionary.Add("ks", xa.Value); break;
  476:                         case "malayalamName": dictionary.Add("ml", xa.Value); break;
  477:                         case "marathiName": dictionary.Add("mr", xa.Value); break;
  478:                         case "oriyaName": dictionary.Add("or", xa.Value); break;
  479:                         case "punjabiName": dictionary.Add("pa", xa.Value); break;
  480:                         case "tamilName": dictionary.Add("ta", xa.Value); break;
  481:                         case "teluguName": dictionary.Add("te", xa.Value); break;
  482:                         case "urduName": dictionary.Add("ur", xa.Value); break;
  483:                         case "kannadaName": dictionary.Add("kn", xa.Value); break;
  484:                         case "assameseName": dictionary.Add("as", xa.Value); break;
  485:                         case "sanskritName": dictionary.Add("sa", xa.Value); break;
  486:                         case "sindhiName": dictionary.Add("sd", xa.Value); break;
  487:  
  488:                         case "armenianName": dictionary.Add("hy", xa.Value); break;
  489:                         case "persianName": dictionary.Add("fa", xa.Value); break;
  490:  
  491:                         case "pushtoName": dictionary.Add("ps", xa.Value); break;
  492:                         case "kirghizName": dictionary.Add("ky", xa.Value); break;
  493:                         case "turkmenName": dictionary.Add("tk", xa.Value); break;
  494:                         case "khmerName": dictionary.Add("km", xa.Value); break;
  495:  
  496:                         case "somaliName": dictionary.Add("so", xa.Value); break;
  497:                         case "afarName": dictionary.Add("aa", xa.Value); break;
  498:  
  499:                         case "icelandicName": dictionary.Add("is", xa.Value); break;
  500:                         case "swedishName": dictionary.Add("sv", xa.Value); break;
  501:                         case "norwegianName": dictionary.Add("no", xa.Value); break;
  502:                         case "kazakhName": dictionary.Add("kk", xa.Value); break;
  503:  
  504:                         case "laoName": dictionary.Add("lo", xa.Value); break;
  505:  
  506:                         case "afrikaansName": dictionary.Add("af", xa.Value); break;
  507:                         case "swahiliName": dictionary.Add("sw", xa.Value); break;
  508:  
  509:                         case "albanianName": dictionary.Add("sq", xa.Value); break;
  510:                         case "greekName": dictionary.Add("el", xa.Value); break;
  511:  
  512:                         case "indonesianName": dictionary.Add("id", xa.Value); break;
  513:                         case "latvianName": dictionary.Add("lv", xa.Value); break;
  514:                         case "lithuanianName": dictionary.Add("lt", xa.Value); break;
  515:  
  516:                         case "macedonianName": dictionary.Add("mk", xa.Value); break;
  517:                         case "turkishName": dictionary.Add("tr", xa.Value); break;
  518:                         case "serbianName": dictionary.Add("sr", xa.Value); break;
  519:  
  520:                         case "nauruanName": dictionary.Add("na", xa.Value); break;
  521:  
  522:                         case "filipinoName": dictionary.Add("tl", xa.Value); break;
  523:  
  524:                         case "romanianName": dictionary.Add("ro", xa.Value); break;
  525:                         case "hungarianName": dictionary.Add("hu", xa.Value); break;
  526:  
  527:                         case "tajikName": dictionary.Add("tg", xa.Value); break;
  528:  
  529:                         case "ukrainianName": dictionary.Add("uk", xa.Value); break;
  530:                         case "polishName": dictionary.Add("pl", xa.Value); break;
  531:  
  532:                         case "ShonaNam": dictionary.Add("sn", xa.Value); break;
  533:                         case "NorthNdebeleName": dictionary.Add("nd", xa.Value); break;
  534:                         case "SouthNdebeleName": dictionary.Add("nr", xa.Value); break;
  535:  
  536:                         case "fijianName": dictionary.Add("fj", xa.Value); break;
  537:                         case "kurdishName": dictionary.Add("ku", xa.Value); break;
  538:  
  539:                         case "zuluName": dictionary.Add("zu", xa.Value); break;
  540:                         case "xhosaName": dictionary.Add("xh", xa.Value); break;
  541:                         case "malagasyName": dictionary.Add("mg", xa.Value); break;
  542:  
  543:                         case "nepaliName": dictionary.Add("ne", xa.Value); break;
  544:  
  545:                         case "hebrewName": dictionary.Add("he", xa.Value); break;
  546:  
  547:                         case "vietnameseName": dictionary.Add("vi", xa.Value); break;
  548:  
  549:                         default: break;
  550:                     }
  551:                 }
  552:             }
  553:  
  554:             return dictionary;
  555:         }
  556:  
  557:         ////////////////////////////////////////////////////////////////////////////
  558:  
  559:         /// <summary>
  560:         ///
  561:         /// </summary>
  562:         public static List<Country> List2
  563:         {
  564:             // used for special cases
  565:             get
  566:             {
  567:                 int i;
  568:  
  569:                 if (countryList == null || countryList.Count == 0)
  570:                 {
  571:                     countryList = (from q in XDocument.Elements("countryList").Elements("country")
  572:                                    select new Country
  573:                                    {
  574:                                        Itu = int.TryParse(q.Attribute("itu").Value.Replace("-", ""), out i) ? i : 0,
  575:                                        Name = Ia.Cl.Models.Default.ToTitleCase(q.Attribute("name").Value),
  576:                                        ArabicName = q.Attribute("arabicName").Value,
  577:                                        NativeName = q.Attribute("nativeName").Value,
  578:                                        Latitude = q.Attribute("latitude").Value,
  579:                                        Longitude = q.Attribute("longitude").Value,
  580:                                        Capital = q.Attribute("capital").Value,
  581:                                        CapitalLatitude = q.Attribute("capitalLatitude").Value,
  582:                                        CapitalLongitude = q.Attribute("capitalLongitude").Value,
  583:                                        Iso2 = q.Attribute("iso2").Value,
  584:                                        Iso3 = q.Attribute("iso3").Value,
  585:                                        Iana = q.Attribute("iana").Value,
  586:                                        Un = q.Attribute("un").Value,
  587:                                        Ioc = q.Attribute("ioc").Value,
  588:                                        Fips = (q.Attribute("iso2").Value != "" && Iso2ToFipsHashtable.ContainsKey(q.Attribute("iso2").Value)) ? Iso2ToFipsHashtable[q.Attribute("iso2").Value].ToString() : "",
  589:                                        SpokenLanguageIso6391ListString = q.Attribute("spokenLanguageIso6391List").Value
  590:                                    }
  591:                     ).ToList<Country>();
  592:                 }
  593:  
  594:                 return countryList;
  595:             }
  596:         }
  597:  
  598:         ////////////////////////////////////////////////////////////////////////////
  599:  
  600:         /// <summary>
  601:         ///
  602:         /// </summary>
  603:         public static Hashtable FipsToIso2Hashtable
  604:         {
  605:             get
  606:             {
  607:                 if (fipsToIso2Hashtable == null || fipsToIso2Hashtable.Count == 0)
  608:                 {
  609:                     fipsToIso2Hashtable = new Hashtable(fipsIsoList.Count / 4);
  610:  
  611:                     for (int i = 0; i < fipsIsoList.Count; i += 4)
  612:                     {
  613:                         fipsToIso2Hashtable[fipsIsoList[i]] = fipsIsoList[i + 1];
  614:                     }
  615:                 }
  616:  
  617:                 return fipsToIso2Hashtable;
  618:             }
  619:         }
  620:  
  621:         ////////////////////////////////////////////////////////////////////////////
  622:  
  623:         /// <summary>
  624:         ///
  625:         /// </summary>
  626:         public static Hashtable Iso2ToFipsHashtable
  627:         {
  628:             get
  629:             {
  630:                 if (iso2ToFipsHashtable == null || iso2ToFipsHashtable.Count == 0)
  631:                 {
  632:                     iso2ToFipsHashtable = new Hashtable(fipsIsoList.Count / 4);
  633:  
  634:                     for (int i = 0; i < fipsIsoList.Count; i += 4)
  635:                     {
  636:                         iso2ToFipsHashtable[fipsIsoList[i + 1]] = fipsIsoList[i];
  637:                     }
  638:                 }
  639:  
  640:                 return iso2ToFipsHashtable;
  641:             }
  642:         }
  643:  
  644:         ////////////////////////////////////////////////////////////////////////////
  645:  
  646:         /// <summary>
  647:         ///
  648:         /// </summary>
  649:         public static string FipsFromIso2(string iso2)
  650:         {
  651:             string fips;
  652:  
  653:             if (Iso2ToFipsHashtable.ContainsKey(iso2)) fips = Iso2ToFipsHashtable[iso2].ToString();
  654:             else fips = null;
  655:  
  656:             return fips;
  657:         }
  658:  
  659:         ////////////////////////////////////////////////////////////////////////////
  660:  
  661:         /// <summary>
  662:         ///
  663:         /// </summary>
  664:         public static string Iso2FromFips(string fips)
  665:         {
  666:             string iso2;
  667:  
  668:             if (FipsToIso2Hashtable.ContainsKey(fips)) iso2 = FipsToIso2Hashtable[fips].ToString();
  669:             else iso2 = null;
  670:  
  671:             return iso2;
  672:         }
  673:  
  674:         ////////////////////////////////////////////////////////////////////////////
  675:  
  676:         /// <summary>
  677:         ///
  678:         /// </summary>
  679:         public List<Ia.Cl.Models.Language> SpokenLanguageList
  680:         {
  681:             get
  682:             {
  683:                 string s;
  684:                 List<Ia.Cl.Models.Language> list;
  685:  
  686:                 if (!string.IsNullOrEmpty(SpokenLanguageIso6391ListString))
  687:                 {
  688:                     s = "," + SpokenLanguageIso6391ListString;
  689:  
  690:                     list = (from l in Ia.Cl.Models.Language.List where s.Contains("," + l.Iso6391) select l).ToList();
  691:                 }
  692:                 else list = null;
  693:  
  694:                 return list;
  695:             }
  696:         }
  697:  
  698:         ////////////////////////////////////////////////////////////////////////////
  699:  
  700:         /// <summary>
  701:         /// 
  702:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  703:         /// 
  704:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  705:         /// 2. Add "using System.Reflection".
  706:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  707:         /// 
  708:         /// </summary>
  709:  
  710:         private static XDocument XDocument
  711:         {
  712:             get
  713:             {
  714:                 Assembly _assembly;
  715:                 StreamReader streamReader;
  716:  
  717:                 xd = null;
  718:                 _assembly = Assembly.GetExecutingAssembly();
  719:                 streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Cl.model.country.country.xml"));
  720:  
  721:                 try
  722:                 {
  723:                     if (streamReader.Peek() != -1)
  724:                     {
  725:                         xd = System.Xml.Linq.XDocument.Load(streamReader);
  726:                     }
  727:                 }
  728:                 catch (Exception)
  729:                 {
  730:                 }
  731:                 finally
  732:                 {
  733:                 }
  734:  
  735:                 return xd;
  736:             }
  737:         }
  738:  
  739:         ////////////////////////////////////////////////////////////////////////////
  740:         ////////////////////////////////////////////////////////////////////////////
  741:     }
  742: }