public static void LoadResourceLookupFromDb(IResourceLookupRepository resourceLookupRepository)
 {
     ListLock.EnterWriteLock();
     try {
         ResourceLookupList.Clear();
         ResourceLookupByteList.Clear();
         var items = resourceLookupRepository.GetActiveValues();
         if (items.Length > 0) {
             var lookupName = items[0].LookupName;
             var language = items[0].Language;
             var list = new List<LookupItem>();
             foreach (var item in items) {
                 if (item.LookupName == lookupName && item.Language == language) {
                     var lookupItem = new LookupItem {Key = item.ResourceKey, Value = item.Value, Order = item.Order, ByteValue = item.LookupValue};
                     var found = list.Any(i => i.Key == lookupItem.Key);
                     if(!found)
                         list.Add(lookupItem);
                     else {
                         Debug.WriteLine("Double " + lookupItem.Key);
                     }
                 } else {
                     try {
                         list.Sort(CompareLookupItem);
                         var key = lookupName + language;
                         if (ResourceLookupList.ContainsKey(key)) {
                             ResourceLookupList.Add(key, list.ToDictionary(r => r.Key, r => r.Value));
                         } else {
                             ResourceLookupList[key] = list.ToDictionary(r => r.Key, r => r.Value);
                         }
                         if (ResourceLookupByteList.ContainsKey(key)) {
                             ResourceLookupByteList.Add(key, list.ToDictionary(r => r.Key, r => r.ByteValue));
                         } else {
                             ResourceLookupByteList[key] = list.ToDictionary(r => r.Key, r => r.ByteValue);
                         }
                     } catch (Exception ex) {
                         throw new KatushaResourceLookupException(lookupName, ex);
                     }
                     lookupName = item.LookupName;
                     language = item.Language;
                     list = new List<LookupItem> { new LookupItem { Key = item.ResourceKey, Value = item.Value, Order = item.Order, ByteValue = item.LookupValue } };
                 }
             }
         }
     } finally {
         ListLock.ExitWriteLock();
     }
 }
Example #2
0
 public static void LoadResourceLookupFromDb(IResourceLookupRepository resourceLookupRepository)
 {
     ListLock.EnterWriteLock();
     try {
         ResourceLookupList.Clear();
         ResourceLookupByteList.Clear();
         var items = resourceLookupRepository.GetActiveValues();
         if (items.Length > 0)
         {
             var lookupName = items[0].LookupName;
             var language   = items[0].Language;
             var list       = new List <LookupItem>();
             foreach (var item in items)
             {
                 if (item.LookupName == lookupName && item.Language == language)
                 {
                     var lookupItem = new LookupItem {
                         Key = item.ResourceKey, Value = item.Value, Order = item.Order, ByteValue = item.LookupValue
                     };
                     var found = list.Any(i => i.Key == lookupItem.Key);
                     if (!found)
                     {
                         list.Add(lookupItem);
                     }
                     else
                     {
                         Debug.WriteLine("Double " + lookupItem.Key);
                     }
                 }
                 else
                 {
                     try {
                         list.Sort(CompareLookupItem);
                         var key = lookupName + language;
                         if (ResourceLookupList.ContainsKey(key))
                         {
                             ResourceLookupList.Add(key, list.ToDictionary(r => r.Key, r => r.Value));
                         }
                         else
                         {
                             ResourceLookupList[key] = list.ToDictionary(r => r.Key, r => r.Value);
                         }
                         if (ResourceLookupByteList.ContainsKey(key))
                         {
                             ResourceLookupByteList.Add(key, list.ToDictionary(r => r.Key, r => r.ByteValue));
                         }
                         else
                         {
                             ResourceLookupByteList[key] = list.ToDictionary(r => r.Key, r => r.ByteValue);
                         }
                     } catch (Exception ex) {
                         throw new KatushaResourceLookupException(lookupName, ex);
                     }
                     lookupName = item.LookupName;
                     language   = item.Language;
                     list       = new List <LookupItem> {
                         new LookupItem {
                             Key = item.ResourceKey, Value = item.Value, Order = item.Order, ByteValue = item.LookupValue
                         }
                     };
                 }
             }
         }
     } finally {
         ListLock.ExitWriteLock();
     }
 }