public async virtual Task RemoveAsync(TCacheKey key, bool?hideErrors = null, CancellationToken token = default) { async Task RemoveRealCache() { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; try { await Cache.RemoveAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); } catch (Exception ex) { if (hideErrors == true) { await HandleExceptionAsync(ex); return; } throw; } } await RemoveRealCache(); }
/// <summary> /// Gets a cache item with the given key. If no cache item is found for the given key then returns null. /// </summary> /// <param name="key">The key of cached item to be retrieved from the cache.</param> /// <param name="hideErrors">Indicates to throw or hide the exceptions for the distributed cache.</param> /// <param name="token">The <see cref="T:System.Threading.CancellationToken" /> for the task.</param> /// <returns>The cache item, or null.</returns> public virtual async Task <TCacheItem> GetAsync( string key, bool?hideErrors = null, CancellationToken token = default) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; byte[] cachedBytes; try { cachedBytes = await Cache.GetAsync( NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token) ); } catch (Exception ex) { if (hideErrors == true) { Logger.LogException(ex, LogLevel.Warning); return(null); } throw; } if (cachedBytes == null) { return(null); } return(Serializer.Deserialize <TCacheItem>(cachedBytes)); }
public HeroesOfTheStorm( ILogger <HeroesOfTheStorm> logger, IOptions <Settings> settings, CancellationTokenProvider tokenProvider, CaptureStrategy captureStrategy) : base(tokenProvider, captureStrategy, logger, settings, Constants.HEROES_PROCESS_NAME) { }
public async Task <TCacheItem> GetAsync(TCacheKey key, bool?hideErrors = null, CancellationToken token = default) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; byte[] cachedBytes; try { cachedBytes = await Cache.GetAsync( NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token) ); } catch (Exception ex) { if (hideErrors == true) { await HandleExceptionAsync(ex); return(null); } throw; } return(ToCacheItem(cachedBytes)); }
/// <summary> /// Gets or Adds a cache item with the given key. If no cache item is found for the given key then adds a cache item /// provided by <paramref name="factory" /> delegate and returns the provided cache item. /// </summary> /// <param name="key">The key of cached item to be retrieved from the cache.</param> /// <param name="factory">The factory delegate is used to provide the cache item when no cache item is found for the given <paramref name="key" />.</param> /// <param name="optionsFactory">The cache options for the factory delegate.</param> /// <param name="hideErrors">Indicates to throw or hide the exceptions for the distributed cache.</param> /// <param name="token">The <see cref="T:System.Threading.CancellationToken" /> for the task.</param> /// <returns>The cache item.</returns> public async Task <TCacheItem> GetOrAddAsync( string key, Func <Task <TCacheItem> > factory, Func <DistributedCacheEntryOptions> optionsFactory = null, bool?hideErrors = null, CancellationToken token = default) { token = CancellationTokenProvider.FallbackToProvider(token); var value = await GetAsync(key, hideErrors, token); if (value != null) { return(value); } using (await SyncSemaphore.LockAsync(token)) { value = await GetAsync(key, hideErrors, token); if (value != null) { return(value); } value = await factory(); await SetAsync(key, value, optionsFactory?.Invoke(), hideErrors, token); } return(value); }
/// <summary> /// Sets the cache item value for the provided key. /// </summary> /// <param name="key">The key of cached item to be retrieved from the cache.</param> /// <param name="value">The cache item value to set in the cache.</param> /// <param name="options">The cache options for the value.</param> /// <param name="hideErrors">Indicates to throw or hide the exceptions for the distributed cache.</param> /// <param name="token">The <see cref="T:System.Threading.CancellationToken" /> for the task.</param> /// <returns>The <see cref="T:System.Threading.Tasks.Task" /> indicating that the operation is asynchronous.</returns> public virtual async Task SetAsync( string key, TCacheItem value, DistributedCacheEntryOptions options = null, bool?hideErrors = null, CancellationToken token = default) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; try { await Cache.SetAsync( NormalizeKey(key), Serializer.Serialize(value), options ?? DefaultCacheOptions, CancellationTokenProvider.FallbackToProvider(token) ); } catch (Exception ex) { if (hideErrors == true) { Logger.LogException(ex, LogLevel.Warning); return; } throw; } }
public async Task SetAsync(TCacheKey key, TCacheItem value, DistributedCacheEntryOptions options = null, bool?hideErrors = null, CancellationToken token = default) { async Task SetRealCache() { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; try { await Cache.SetAsync( NormalizeKey(key), Serializer.Serialize(value), options ?? DefaultCacheOptions, CancellationTokenProvider.FallbackToProvider(token) ); } catch (Exception ex) { if (hideErrors == true) { await HandleExceptionAsync(ex); return; } throw; } } await SetRealCache(); }
public SpectateReportCsvWriter(IGameData gameData, AppSettings settings, IReplayProvider provider, IReplayAnalyzer analyzer, CancellationTokenProvider tokenProvider) { this.gameData = gameData ?? throw new ArgumentNullException(nameof(gameData)); this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.provider = provider ?? throw new ArgumentNullException(nameof(provider)); this.analyzer = analyzer ?? throw new ArgumentNullException(nameof(analyzer)); this.tokenProvider = tokenProvider ?? throw new ArgumentNullException(nameof(tokenProvider)); }
public ObsController(ILogger <ObsController> logger, IReplayContext context, AppSettings settings, OBSWebsocket obs, CancellationTokenProvider tokenProvider) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.context = context ?? throw new ArgumentNullException(nameof(context)); this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.obs = obs ?? throw new ArgumentNullException(nameof(obs)); this.tokenProvider = tokenProvider ?? throw new ArgumentNullException(nameof(tokenProvider)); }
public SaltySadism(ILogger <SaltySadism> logger, IGameManager gameManager, IGameData gameData, IReplayProvider replayProvider, CancellationTokenProvider tokenProvider) { this.logger = logger; this.gameManager = gameManager; this.gameData = gameData; this.replayProvider = replayProvider; this.tokenProvider = tokenProvider; }
public GameController(ILogger <GameController> logger, Settings settings, CaptureStrategy captureStrategy, OcrEngine engine, CancellationTokenProvider tokenProvider) { this.logger = logger; this.settings = settings; this.captureStrategy = captureStrategy; this.engine = engine; this.tokenProvider = tokenProvider; }
public virtual Task SetAsync(string key, TCacheItem value, DistributedCacheEntryOptions options = null, CancellationToken token = default) { return(Cache.SetAsync( NormalizeKey(key), ObjectSerializer.Serialize(value), options ?? DefaultCacheOptions, CancellationTokenProvider.FallbackToProvider(token) )); }
public GameController(ILogger <GameController> logger, IReplayContext context, AppSettings settings, CaptureStrategy captureStrategy, OcrEngine engine, CancellationTokenProvider tokenProvider) { this.logger = logger ?? throw new ArgumentNullException(nameof(settings)); this.context = context ?? throw new ArgumentNullException(nameof(context)); this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.captureStrategy = captureStrategy ?? throw new ArgumentNullException(nameof(settings)); this.ocrEngine = engine ?? throw new ArgumentNullException(nameof(settings));; this.tokenProvider = tokenProvider ?? throw new ArgumentNullException(nameof(settings)); }
public StubOfTheStorm( ILogger <HeroesOfTheStorm> logger, IOptions <Settings> settings, CancellationTokenProvider tokenProvider, CaptureStrategy captureStrategy, ReplayHelper replayHelper) : base(logger, settings, tokenProvider, captureStrategy) { this.replayHelper = replayHelper; this.timer = TimeSpan.Zero; }
public virtual async Task <TCacheItem> GetAsync(string key, CancellationToken token = default) { var cachedBytes = await Cache.GetAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); if (cachedBytes == null) { return(null); } return(ObjectSerializer.Deserialize <TCacheItem>(cachedBytes)); }
public virtual Task SetAsync(string key, TCacheItem value, DistributedCacheEntryOptions options = null, CancellationToken token = default) { return(Cache.SetAsync( NormalizeKey(key), ObjectSerializer.Serialize(value), options ?? new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(20) }, //TODO: implement per cache item and global defaults!!! CancellationTokenProvider.FallbackToProvider(token) )); }
// POST api/search public void Post(SearchRequest request) { var webPageLinkParser = new WebPageLinkParser(); var ctProvider = new CancellationTokenProvider(); //UserGuid uses as User identifier. I didn't want to use authorization :) //Collect users and their CancellationTokenSources ctProvider.Add(request.UserGuid); var token = ctProvider.GetToken(request.UserGuid); Task.Run(() => webPageLinkParser.Parse(request, token)); }
public ReplayConsumer( ILogger <ReplayConsumer> logger, CancellationTokenProvider tokenProvider, IReplayProvider provider, ReplayRunner runner, ReplayDetailsWriter writer) { this.tokenProvider = tokenProvider; this.logger = logger; this.provider = provider; this.runner = runner; this.writer = writer; }
public ProcessWrapper( CancellationTokenProvider tokenProvider, CaptureStrategy captureStrategy, ILogger <ProcessWrapper> logger, IOptions <Settings> settings, string processName) { Logger = logger; Settings = settings.Value; this.tokenProvider = tokenProvider; CaptureStrategy = captureStrategy; ProcessName = processName; }
public void Init() { var subbedPeerClient = Substitute.For <IPeerClient>(); _testSettings = PeerSettingsHelper.TestPeerSettings(); _cancellationProvider = new CancellationTokenProvider(TimeSpan.FromSeconds(10)); _peerChallengeRequest = new PeerChallengeRequest( Substitute.For <ILogger>(), subbedPeerClient, _testSettings, 10 ); }
public PeerQueryTipTests(ITestOutputHelper output) : base(output) { var subbedPeerClient = Substitute.For <IPeerClient>(); _testSettings = PeerSettingsHelper.TestPeerSettings(); _cancellationProvider = new CancellationTokenProvider(TimeSpan.FromSeconds(10)); _peerQueryTipRequest = new PeerQueryTipRequestRequest( Substitute.For <ILogger>(), subbedPeerClient, _testSettings, _cancellationProvider ); }
public Engine( ILogger <Engine> logger, ITwitchBot twitchBot, IGameManager gameManager, IGameData gameData, IReplayProvider replayProvider, CancellationTokenProvider consoleTokenProvider) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.twitchBot = twitchBot ?? throw new ArgumentNullException(nameof(twitchBot)); this.gameManager = gameManager ?? throw new ArgumentNullException(nameof(gameManager)); this.gameData = gameData ?? throw new ArgumentNullException(nameof(gameData)); this.replayProvider = replayProvider ?? throw new ArgumentNullException(nameof(replayProvider)); this.consoleTokenProvider = consoleTokenProvider ?? throw new ArgumentNullException(nameof(consoleTokenProvider)); }
public FakeTwitchBot( ILogger <FakeTwitchBot> logger, AppSettings settings, IOnRewardHandler onRewardHandler, IOnMessageHandler onMessageHandler, ICustomRewardsHolder rewardsHolder, CancellationTokenProvider tokenProvider) { this.logger = logger; this.settings = settings; this.onRewardHandler = onRewardHandler; this.onMessageHandler = onMessageHandler; this.rewardsHolder = rewardsHolder; this.tokenProvider = tokenProvider; }
public void Init() { this.Setup(TestContext.CurrentContext); var subbedPeerClient = Substitute.For <IPeerClient>(); _testSettings = PeerSettingsHelper.TestPeerSettings(); _cancellationProvider = new CancellationTokenProvider(TimeSpan.FromSeconds(10)); _peerQueryTipRequest = new PeerQueryTipRequestRequest( Substitute.For <ILogger>(), subbedPeerClient, _testSettings, _cancellationProvider ); }
public async Task SetManyAsync(IEnumerable <KeyValuePair <TCacheKey, TCacheItem> > items, DistributedCacheEntryOptions options = null, bool?hideErrors = null, CancellationToken token = default) { var itemsArray = items.ToArray(); var cacheSupportsMultipleItems = Cache as ICacheSupportsMultipleItems; if (cacheSupportsMultipleItems == null) { await SetManyFallbackAsync( itemsArray, options, hideErrors, token ); return; } async Task SetRealCache() { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; try { await cacheSupportsMultipleItems.SetManyAsync( ToRawCacheItems(itemsArray), options ?? DefaultCacheOptions, CancellationTokenProvider.FallbackToProvider(token) ); } catch (Exception ex) { if (hideErrors == true) { await HandleExceptionAsync(ex); return; } throw; } } await SetRealCache(); }
public async Task <KeyValuePair <TCacheKey, TCacheItem>[]> GetManyAsync(IEnumerable <TCacheKey> keys, bool?hideErrors = null, CancellationToken token = default) { var keyArray = keys.ToArray(); var cacheSupportsMultipleItems = Cache as ICacheSupportsMultipleItems; if (cacheSupportsMultipleItems == null) { return(await GetManyFallbackAsync( keyArray, hideErrors, token )); } var notCachedKeys = new List <TCacheKey>(); var cachedValues = new List <KeyValuePair <TCacheKey, TCacheItem> >(); hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; byte[][] cachedBytes; var readKeys = notCachedKeys.Any() ? notCachedKeys.ToArray() : keyArray; try { cachedBytes = await cacheSupportsMultipleItems.GetManyAsync( readKeys.Select(NormalizeKey), CancellationTokenProvider.FallbackToProvider(token) ); } catch (Exception ex) { if (hideErrors == true) { await HandleExceptionAsync(ex); return(ToCacheItemsWithDefaultValues(keyArray)); } throw; } return(cachedValues.Concat(ToCacheItems(cachedBytes, readKeys)).ToArray()); }
public virtual Task RemoveAsync(string key, bool?hideErrors = null, CancellationToken token = default) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; try { return(Cache.RemoveAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token))); } catch (Exception ex) { if ((bool)hideErrors) { Logger.LogException(ex, LogLevel.Warning); return(Task.CompletedTask); } throw; } }
public TwitchExtensionService( ILogger <TwitchExtensionService> logger, HttpClient httpClient, CancellationTokenProvider tokenProvider, AppSettings settings) { notifyContent = new(new Dictionary <string, string> { { ExtensionFormKeys.TwitchKey, settings.TwitchExtension.ApiKey }, { ExtensionFormKeys.Email, settings.TwitchExtension.ApiEmail }, { ExtensionFormKeys.TwitchUserName, settings.TwitchExtension.TwitchUserName }, { ExtensionFormKeys.UserId, settings.TwitchExtension.ApiUserId } }); this.logger = logger; this.httpClient = httpClient; this.tokenProvider = tokenProvider; this.httpClient.BaseAddress = settings.HeroesProfileApi.TwitchBaseUri; }
public Spectator( ILogger <Spectator> logger, AppSettings settings, IReplayContext sessionHolder, IGameController controller, ITalentNotifier talentsNotifier, CancellationTokenProvider tokenProvider) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.context = sessionHolder ?? throw new ArgumentNullException(nameof(sessionHolder)); this.controller = controller ?? throw new ArgumentNullException(nameof(controller)); this.talentsNotifier = talentsNotifier ?? throw new ArgumentNullException(nameof(talentsNotifier)); consoleTokenProvider = tokenProvider ?? throw new ArgumentNullException(nameof(tokenProvider)); panelTimes = new() { { Panel.Talents, settings.PanelTimes.Talents }, { Panel.DeathDamageRole, settings.PanelTimes.DeathDamageRole },
public virtual async Task RefreshAsync(string key, bool?hideErrors = null, CancellationToken token = default) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; try { await Cache.RefreshAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); } catch (Exception ex) { if (hideErrors == true) { Logger.LogException(ex, LogLevel.Warning); return; } throw; } }