예제 #1
0
 private static string GetSetId(ConfigWrapper cs)
 {
     return string.Format("{0}-{1}",cs.Id,cs.Environment);
 }
예제 #2
0
 private static string GetFileContent(ConfigWrapper config)
 {
     return EncryptFiles() ? JsonConvert.SerializeObject(config).Encrypt(LocalEncryptionKey) : JsonConvert.SerializeObject(config);
 }
예제 #3
0
 public static void UpdateCache(string localFile, ConfigurationSet newConfigSet, ConfigWrapper cs)
 {
     if (UseDiscreteFiles)
     {
         localFile = localFile.Replace("\\\\", "\\").ToLowerInvariant();
         var config = new ConfigWrapper { Set = newConfigSet, Environment = cs.Environment, Id = cs.Id };
         ConfigWrapper oldConfig;
         if (!cache.TryGetValue(localFile, out oldConfig)) cache.TryAdd(localFile, config);
         else
         {
             if (long.Parse(oldConfig.Set.ETag) <= long.Parse(newConfigSet.ETag)) cache.TryUpdate(localFile, config, oldConfig);
         }
         File.WriteAllText(localFile, GetFileContent(config));
     }
     else
     {
         lock (triowing)
         {
             GetOrCreateConsolidatedFile();
             var config = new ConfigWrapper { Set = newConfigSet, Environment = cs.Environment, Id = cs.Id };
             if (consolidatedWrapper.ConfigWrappers.ContainsKey(GetSetId(cs))) consolidatedWrapper.ConfigWrappers.Remove(GetSetId(cs));
             consolidatedWrapper.ConfigWrappers.Add(GetSetId(cs), config);
             
         }
         SaveConsolidatedFile();
     }
 }