//private static void ClearCache() //{ // DataCache.RemoveCache(RedirectConfigCacheKey); // DataCache.RemoveCache(RedirectMappingsDictionaryCacheKey(true)); // DataCache.RemoveCache(RedirectMappingsDictionaryCacheKey(false)); //} //public static bool Exists() //{ // return File.Exists(Common.RedirectConfigFile()); //} private static RedirectConfig FromFile(string filename) { // create the file if it doesn't exsist //if (!File.Exists(filename)) // CreateFile(filename); RedirectConfig retval = null; FileStream fs = null; try { // if it exists we can just open it // otherwise return new configuration if (File.Exists(filename)) { fs = new FileStream(filename, FileMode.Open); retval = (RedirectConfig)XmlSer.Deserialize(fs); } else { retval = new RedirectConfig(); } } catch (Exception ex) { Exceptions.LogException(ex); } finally { if (fs != null) { fs.Close(); fs.Dispose(); } } return(retval); }
private static RedirectConfig GetConfig() { RedirectConfig config = null; //if (useCache) // try // { // config = DataCache.GetCache<RedirectConfig>(RedirectConfigCacheKey); // } // catch (Exception e) // { // /* do nothing */ // } // if there are no mappings, the use of this module is pointless // so we'll assume something went wrong reading the file in that case if (config == null || config.Mappings == null || config.Mappings.Count == 0) { lock (getConfigLockObject) { var file = Common.RedirectConfigFile(); config = FromFile(file); // set the id's if they're empty. This comes in handy for backwards compatibility if (config.Mappings.Any(m => String.IsNullOrEmpty(m.Id))) { foreach (var mapping in config.Mappings.Where(m => String.IsNullOrEmpty(m.Id))) { mapping.Id = Guid.NewGuid().ToString(); } config.ToFile(file); } //DataCache.SetCache(RedirectConfigCacheKey, config, new DNNCacheDependency(file)); } } return(config); }
public static void CreateFile(string filename) { var emptyConfig = new RedirectConfig(); emptyConfig.ToFile(filename); }