public bool RemoveItem(IDbConnection connection, string allianceName, IAllianceLocalStorageCache cache) { _checkAndInit(connection, cache); IAllianceNameSerchItem val; return(_storage.TryRemove(allianceName, out val)); }
private void _checkAndInit(IDbConnection connection, IAllianceLocalStorageCache cache) { if (!Equals(_cache, cache)) { _cache = cache; } if (_storage == null) { var repo = cache.GetRepository(); var alliances = repo.GetAllModels(connection).Select(i => new AllianceNameSerchItem { Id = i.Id, Name = i.Name, Disbandet = i.Disbandet }).ToList(); if (alliances.Any()) { var dictionary = alliances.ToDictionary <AllianceNameSerchItem, string, IAllianceNameSerchItem>(a => a.Name, a => a); _storage = new ConcurrentDictionary <string, IAllianceNameSerchItem>(dictionary); } else { _storage = new ConcurrentDictionary <string, IAllianceNameSerchItem>(); } } }
public AllianceService( IAllianceRepository aRepo, IAllianceLocalStorageCache aCache, IAllianceUserRepository aUserRepo, IAllianceUserLocalStorageCache aUserCache, IAllianceRequestMessageRepository armRepo, IAllianceRequestMessageLocalStorageCache armCache, IAllianceRoleRepository aRolesRepo, IAllianceRoleLocalStorageCache aRolesCache, IAlianceNameSercherPkCache aNameSercher, IGDetailPlanetLocalStorageCache planetDetailCache, IAllianceTechLocalStorageCache aTechCahce, IAllianceFleetLocalStorageCache aFleetCache, IAllianceTechRepository aTechRepo, IChannelService channelService, ILocalizerService localizer) { _aRepo = aRepo; _aCache = aCache; _aUserRepo = aUserRepo; _aUserCache = aUserCache; _armRepo = armRepo; _armCache = armCache; _aRolesRepo = aRolesRepo; _aRolesCache = aRolesCache; _aNameSercher = aNameSercher; _planetDetailCache = planetDetailCache; _aTechCahce = aTechCahce; _aFleetCache = aFleetCache; _aTechRepo = aTechRepo; _localizer = localizer; _channelService = (ChannelService)channelService; }
public IAllianceNameSerchItem TryGetValue(IDbConnection connection, string userName, IAllianceLocalStorageCache cache) { _checkAndInit(connection, cache); IAllianceNameSerchItem val; _storage.TryGetValue(userName, out val); return(val); }
public Dictionary <string, IAllianceNameSerchItem> TryFind(IDbConnection connection, string partName, IAllianceLocalStorageCache cache) { if (string.IsNullOrWhiteSpace(partName)) { throw new NullReferenceException(nameof(partName)); } var keys = GetAllKeys(connection, cache); var contain = keys.Where(i => i.IndexOf(partName, StringComparison.OrdinalIgnoreCase) != -1).ToList(); var result = new Dictionary <string, IAllianceNameSerchItem>(); foreach (var i in contain) { IAllianceNameSerchItem val; _storage.TryGetValue(i, out val); result.Add(i, val); } return(result); }
public bool TryUpdateKey(IDbConnection connection, IAllianceNameSerchItem newVal, string oldKeyName, string newKeyName, IAllianceLocalStorageCache cache, bool updateParentCahce = true) { _checkAndInit(connection, cache); IAllianceNameSerchItem val; if (!_storage.TryUpdateKey(oldKeyName, newKeyName, out val)) { return(false); } if (!updateParentCahce) { return(true); } var alliane = cache.GetById(connection, newVal.Id, true); alliane.Name = newKeyName; var result = cache.UpdateLocalItem(connection, alliane); return(result.Name == newKeyName); }
public Dictionary <string, IAllianceNameSerchItem> GetAll(IDbConnection connection, IAllianceLocalStorageCache cache) { _checkAndInit(connection, cache); return(_storage.Select(i => new { i.Key, i.Value }).ToDictionary(i => i.Key, i => i.Value)); }
public IAllianceNameSerchItem AddOrUpdate(IDbConnection connection, string allianceName, IAllianceNameSerchItem val, IAllianceLocalStorageCache cache) { _checkAndInit(connection, cache); return(_storage.AddOrUpdateSimple(allianceName, val)); }
public List <string> GetAllKeys(IDbConnection connection, IAllianceLocalStorageCache cache) { _checkAndInit(connection, cache); return(_storage.Select(i => i.Key).ToList()); }