private static void initializeMappingsCache() { _displayMappingToDataCache = new Dictionary <FieldDisplayType, List <FieldDataType> >(); _dataMappingToDisplayCache = new Dictionary <FieldDataType, List <FieldDisplayType> >(); // let's load up the mapping string resourceName = "MemberSuite.SDK.Web.Controls.FieldDataDisplayMapping.xml"; XDocument xd = EmbeddedResource.LoadAsXmlLinq(resourceName, Assembly.GetAssembly(typeof(CascadingDropDownManager))); // iterate through all of the data types IEnumerable <XElement> displayTypes = from m in xd.Descendants("DisplayType") select m; // now, let's add them to a dictionary foreach (XElement displayType in displayTypes) { var dependencies = new List <FieldDataType>(); XAttribute dtAttr = displayType.Attribute("Value"); if (dtAttr == null) { throw new ApplicationException("No value specified for " + displayType.Value); } var displayTypeName = dtAttr.Value.ToEnum <FieldDisplayType>(); // go through all of the dependencies tied to the current display type foreach (string d in (from d in displayType.Descendants("Dependency") select d.Value)) { // ok, first add the dependcy, easy var dataType = d.ToEnum <FieldDataType>(); dependencies.Add(dataType); // now - do we have a list for this data type already List <FieldDisplayType> relatedDisplayTypes; if (!_dataMappingToDisplayCache.TryGetValue(dataType, out relatedDisplayTypes)) { relatedDisplayTypes = new List <FieldDisplayType>(); _dataMappingToDisplayCache.Add(dataType, relatedDisplayTypes); } // now add the current display type relatedDisplayTypes.Add(displayTypeName); } _displayMappingToDataCache[displayTypeName] = dependencies; } }
private static void initializeCurrenciesFromEmbeddedResource() { // we're going to get the embedded xml file and load up all of the world currencies // we'll keep 'em in a static dictionary, below currency_dic = new Dictionary <string, world_currency>(); // get the resource var pathToResource = typeof(CurrencyManager).Namespace + ".WorldCurrencies.xml"; var currencyMap = EmbeddedResource.LoadAsXmlLinq(pathToResource); if (currencyMap == null) { throw new Exception(string.Format("Unable to locate resource {0} - cannot manage currencies.", pathToResource)); } // now, we'll pull all of the currencies var currencies = from c in currencyMap.Descendants("currency") select c; // for each item in the currency, we add it to a dictionary foreach (var c in currencies) { // pull the item string code = c.Attribute("code").Value.ToUpper(); string symbol = _convertUnicodeValuesToString(c.Attribute("unicode-decimal").Value); string name = c.Value; // create it var wc = new world_currency(code, symbol, name); if (currency_dic.ContainsKey(code)) { throw new Exception("Dictionary already has " + code); } currency_dic.Add(code, wc); // add it to the dictionary } }