public IEnumerable <T> Parse <T>(Stream stream) { var data = _memoryCache.Get(XmlFileKey); if (data != null) { return((IEnumerable <T>)data); } RefectorUtility utility = new RefectorUtility(); XDocument xDoc = XDocument.Parse(ReadFile(stream)); XElement xElement = xDoc.Element("Mappings"); List <TableClassMapping> mappings = new List <TableClassMapping>(); if (xElement != null) { var mapElements = xElement.Descendants("Map"); Dictionary <string, string> attributeValueMappingDictionary = new Dictionary <string, string>(); foreach (XElement mapElement in mapElements) { foreach (XAttribute xAttribute in mapElement.Attributes()) { if (attributeValueMappingDictionary.ContainsKey(xAttribute.Name.LocalName)) { attributeValueMappingDictionary[xAttribute.Name.LocalName] = xAttribute.Value; } else { attributeValueMappingDictionary.Add(xAttribute.Name.LocalName, xAttribute.Value); } } var mappedClass = utility.ParseColumn(typeof(TableClassMapping), attributeValueMappingDictionary) as TableClassMapping; mappings.Add(mappedClass); } } var cacheItemPolicy = new CacheItemPolicy(); cacheItemPolicy.AbsoluteExpiration = DateTimeOffset.MaxValue; cacheItemPolicy.SlidingExpiration = TimeSpan.FromDays(365); cacheItemPolicy.Priority = CacheItemPriority.Default; var cacheItem = new CacheItem(XmlFileKey, mappings); _memoryCache.Add(cacheItem, cacheItemPolicy); return((IEnumerable <T>)mappings); }
/// <summary> ///This method used for get array list. /// </summary> /// <param name="spName">pass store processer name</param> /// <param name="tableName">pass table name</param> /// <param name="lastCheckedDateTime">pass last checked datetime</param> /// <param name="className">pass class name</param> /// <param name="assemblyName">pass assembly name</param> /// <returns></returns> private async Task <ArrayList> GetArrayList(string spName, string tableName, DateTime lastCheckedDateTime, string className, string assemblyName) { RefectorUtility utility = new RefectorUtility(); List <SqlParameter> parameters = new List <SqlParameter> { new SqlParameter("@TableName", SqlDbType.VarChar) { Value = tableName }, new SqlParameter("@LastCheckedDateTime", SqlDbType.DateTime) { Value = lastCheckedDateTime } }; ArrayList arrayList = new ArrayList(); using (var dataReader = await ExecuteStoreProcedure(spName, parameters)) { Dictionary <string, string> columnRow = new Dictionary <string, string>(); //This will initialize dictionary with all the column names while (dataReader.Read()) { for (int i = 0; i < dataReader.FieldCount; i++) { if (columnRow.ContainsKey(dataReader.GetName(i))) { columnRow[dataReader.GetName(i)] = Convert.ToString(dataReader[i]); } else { columnRow.Add(dataReader.GetName(i), Convert.ToString(dataReader[i])); } } var row = utility.ParseColumn(utility.GetTypeFromString(className, assemblyName), columnRow); arrayList.Add(row); } } return(arrayList); }