private async Task AddTeamCompetitorAsync(ExportableTeamCompetitorCI item) { if (_cache.Contains(item.Id)) { var itemId = URN.Parse(item.Id); try { var ci = (CompetitorCI)_cache.Get(item.Id); var teamCI = ci == null ? (TeamCompetitorCI)_cache.Get(item.Id) : ci as TeamCompetitorCI; if (teamCI != null) { await WaitTillIdIsAvailableAsync(_mergeUrns, itemId).ConfigureAwait(false); teamCI.Import(item); } else { await WaitTillIdIsAvailableAsync(_mergeUrns, itemId).ConfigureAwait(false); teamCI = new TeamCompetitorCI(ci); teamCI.Import(item); _cache.Set(item.Id, teamCI, GetCorrectCacheItemPolicy(URN.Parse(item.Id))); } } catch (Exception ex) { ExecutionLog.LogError(ex, $"Error importing team competitor for id={item.Id}."); } finally { if (!_isDisposed) { await ReleaseIdAsync(_mergeUrns, itemId).ConfigureAwait(false); } } } else { _cache.Add(item.Id, new TeamCompetitorCI(item, _dataRouterManager), GetCorrectCacheItemPolicy(URN.Parse(item.Id))); } }
private void AddTeamCompetitor(ExportableTeamCompetitorCI item) { if (_cache.Contains(item.Id)) { var itemId = URN.Parse(item.Id); try { var competitorCI = (CompetitorCI)_cache.Get(item.Id); var teamCI = competitorCI as TeamCompetitorCI; if (teamCI != null) { WaitTillIdIsAvailable(_mergeUrns, itemId); teamCI.Import(item); } else { WaitTillIdIsAvailable(_mergeUrns, itemId); teamCI = new TeamCompetitorCI(competitorCI); teamCI.Import(item); _cache.Set(item.Id, teamCI, GetCorrectCacheItemPolicy(URN.Parse(item.Id))); } } catch (Exception ex) { ExecutionLog.Error($"Error importing team competitor for id={item.Id}.", ex); } finally { if (!_isDisposed) { ReleaseId(_mergeUrns, itemId); } } } else { _cache.Add(item.Id, new TeamCompetitorCI(item, _dataRouterManager), GetCorrectCacheItemPolicy(URN.Parse(item.Id))); } }
private void AddTeamCompetitor(ExportableTeamCompetitorCI item) { if (_cache.Contains(item.Id)) { try { var ci = (CompetitorCI)_cache.Get(item.Id); var teamCI = ci as TeamCompetitorCI; if (teamCI != null) { _semaphoreCacheMerge.Wait(); teamCI.Import(item); } else { _semaphoreCacheMerge.Wait(); teamCI = new TeamCompetitorCI(ci); teamCI.Import(item); _cache.Set(item.Id, teamCI, GetCorrectCacheItemPolicy(URN.Parse(item.Id))); } } catch (Exception ex) { ExecutionLog.LogError($"Error importing team competitor for id={item.Id}.", ex); } finally { if (!_isDisposed) { _semaphoreCacheMerge.Release(); } } } else { _cache.Add(item.Id, new TeamCompetitorCI(item, _dataRouterManager), GetCorrectCacheItemPolicy(URN.Parse(item.Id))); } }