protected internal static T get(string key, VincoloType vincoloType) { //string ky = Convert.ToString(key); bool exsist = false; if (HttpContext.Current.Cache[key] != null) { return((T)HttpContext.Current.Cache[key]); } switch (vincoloType) { case VincoloType.NONE: if (exsist) { return((T)HttpContext.Current.Cache[key]); } else { return(default(T)); } case VincoloType.FILESYSTEM: if (typeof(T) == typeof(System.Xml.XmlDocument) || typeof(T).BaseType == typeof(System.Xml.XmlDocument)) { T data = default(T); data = getXml(key.ToString(), typeof(T)); return(data); } if (typeof(T) == typeof(System.Xml.Xsl.XslCompiledTransform)) { T data = default(T); data = getXslt(key.ToString()); return(data); } if ((typeof(T)).BaseType == typeof(System.Data.DataSet) || typeof(T) == typeof(System.Data.DataSet)) { return(getDatasetFromFileSystem(key.ToString())); } if ((typeof(T)).BaseType == typeof(BinaryResource) || typeof(T) == typeof(BinaryResource)) { return(getBinary(key.ToString(), typeof(T))); } break; case VincoloType.BACKEND: return(getClassFromBackEnd(key.ToString())); default: throw new Exception("CACHEMANAGER:Tipo di sorgente non valido:"); } return(default(T)); }
public static T get(CacheKeys key, VincoloType vincoloType, System.Xml.Xsl.XsltSettings settings) { return(get(Convert.ToString(key), vincoloType, settings)); }
public static T get(CacheKeys key, VincoloType vincoloType) { return(get(Convert.ToString(key), vincoloType)); }
/// <summary> /// Carica il dizionario da un file xml con strutture ripetute chiave valore. /// La conversione del valore da stringa a T funziona per i tipi base. /// In caso di tipi personalizzati ridefinire la conversione... /// </summary> /// <param name="dictionaryName"></param> /// <returns></returns> protected static Dictionary <string, T> getDictionary(string key, VincoloType vincoloType) { if (!(typeof(T).IsPrimitive)) { throw new Exception("Non ancora sviluppato per tipi non primitivi"); } bool exsist = false; if (HttpContext.Current.Cache[key] != null) { return((Dictionary <string, T>)HttpContext.Current.Cache[key]); } switch (vincoloType) { case VincoloType.NONE: if (exsist) { return((Dictionary <string, T>)HttpContext.Current.Cache[key]); } else { return(new Dictionary <string, T>()); } case VincoloType.FILESYSTEM: Dictionary <string, T> data = new Dictionary <string, T>(); try { string path = getResourcePath(key + ".xml", "XML"); XmlDocument doc = new XmlDocument(); doc.Load(path); foreach (XmlElement e in doc.DocumentElement.ChildNodes) { data.Add(e.SelectSingleNode("key").InnerText, (T)Convert.ChangeType(e.SelectSingleNode("value").InnerText, typeof(T))); } HttpContext.Current.Cache.Add(key, data, new System.Web.Caching.CacheDependency(path), System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null); } catch (System.Exception errore) { ErrorLog error = new ErrorLog(); error.freeTextDetails = errore.Message; error.logCode = "CACHE_07"; //error.loggingAppCode = "WEB"; error.loggingTime = System.DateTime.Now; error.uniqueLogID = System.DateTime.Now.Ticks.ToString(); log.Error(error); throw new Exception("Impossibile caricare il Dizionario", errore); } return(data); case VincoloType.BACKEND: throw new Exception("Non ancora sviluppato"); default: throw new Exception("CACHEMANAGER:Tipo di sorgente non valido:"); } }