public Task <int> Delete(IWorkContext context, string eTag = null) { if (eTag.IsEmpty() && _cache.TryGetValue(out HeaderDoc <UserRoleDoc> value)) { eTag = value?.ETag; } _cache.Clear(); return(_roleRepository.Delete(context, ActorKey.VectorKey, eTag)); }
/// <summary> /// Find certificate by thumbprint. Certificates that have expired will not /// be returned and if "throwOnNotFound" is specified, an exception will be /// thrown. /// </summary> /// <param name="tag">tag</param> /// <param name="context">work context</param> /// <param name="throwOnNotFound">if true, throw exception if not found</param> /// <exception cref="ProgramExitException">Certificate is not found</exception> /// <returns>X509 certificate</returns> /// <exception cref="CertificateNotFoundException">when certificate valid certificate was not found</exception> public X509Certificate2?GetCertificate(bool?throwOnNotFound = null) { throwOnNotFound ??= LocalCertificateKey.RequirePrivateKey; lock (_lock) { if (_cachedCertificate.TryGetValue(out X509Certificate2? certificate)) { return(certificate); } using (X509Store store = new X509Store(LocalCertificateKey.StoreName, LocalCertificateKey.StoreLocation)) { _logger.LogTrace($"Looking for certificate for {this}"); try { store.Open(OpenFlags.ReadOnly); X509Certificate2Collection certificateList = store.Certificates.Find(X509FindType.FindByThumbprint, LocalCertificateKey.Thumbprint, validOnly: false); if (certificateList?.Count != 0) { X509Certificate2?cert = certificateList ! .OfType <X509Certificate2>() .Where(x => !LocalCertificateKey.RequirePrivateKey || x.HasPrivateKey) .Where(x => DateTime.Now <= x.NotAfter) .FirstOrDefault(); if (cert == null) { _logger.LogTrace($"Certificate Not found for {this}"); if (throwOnNotFound == true) { throw new CertificateNotFoundException($"Certificate not found: {LocalCertificateKey.ToString()}"); } return(null); } _cachedCertificate.Set(cert); return(cert); } } catch (Exception ex) { _logger.LogError(ex, $"Exception: {ex}"); _cachedCertificate.Clear(); } } _cachedCertificate.Clear(); return(null); } }
public Task Remove(IWorkContext context) { context.Verify(nameof(context)).IsNotNull(); context.Telemetry.Verbose(context, $"Removing node registration {ActorKey.VectorKey}"); _cache.Clear(); return(_registerStore.Remove(context, ActorKey.VectorKey)); }
public async Task <bool> Delete(CancellationToken token) { _recordCache.Clear(); bool state = await _container.Delete(base.ActorKey.Value, token : token); await Deactivate(); return(state); }
/// <summary> /// Find certificate by thumbprint. Certificates that have expired will not /// be returned and if "throwOnNotFound" is specified, an exception will be /// thrown. /// </summary> /// <param name="tag">tag</param> /// <param name="context">work context</param> /// <param name="throwOnNotFound">if true, throw exception if not found</param> /// <exception cref="ProgramExitException">Certificate is not found</exception> /// <returns>X509 certificate</returns> /// <exception cref="CertificateNotFoundException">when certificate valid certificate was not found</exception> public X509Certificate2 GetCertificate(IWorkContext context, bool?throwOnNotFound = null) { context = context.With(_tag); X509Certificate2 certificate; Exception?saveException = null; throwOnNotFound = throwOnNotFound ?? LocalCertificateKey.RequirePrivateKey; lock (_lock) { if (_cachedCertificate.TryGetValue(out certificate)) { return(certificate); } using (X509Store store = new X509Store(LocalCertificateKey.StoreName, LocalCertificateKey.StoreLocation)) { context.Telemetry.Verbose(context, $"Looking for certificate for {this}"); try { store.Open(OpenFlags.ReadOnly); X509Certificate2Collection certificateList = store.Certificates.Find(X509FindType.FindByThumbprint, LocalCertificateKey.Thumbprint, validOnly: false); if (certificateList?.Count != 0) { _cachedCertificate.Set( certificateList .OfType <X509Certificate2>() .Where(x => !LocalCertificateKey.RequirePrivateKey || x.HasPrivateKey) .Where(x => DateTime.Now <= x.NotAfter) .FirstOrDefault() ); } } catch (Exception ex) { context.Telemetry.Warning(context, $"Exception: {ex}"); _cachedCertificate.Clear(); saveException = ex; } } context.Telemetry.Verbose(context, $"{(_cachedCertificate != null ? "Found" : "Not found")} certificate for {this}"); if (!_cachedCertificate !.TryGetValue(out certificate) && throwOnNotFound == true) { throw new CertificateNotFoundException($"Certificate not found: {LocalCertificateKey.ToString()}"); } return(certificate); } }
public async Task <bool> Delete(CancellationToken token) { _cache.Clear(); _logger.LogTrace($"{nameof(Delete)}: actorKey={base.ActorKey}"); bool state = await _acticleStore.Delete((ArticleId)base.ActorKey.Value, token : token); await Deactivate(); return(state); }
public Task Remove(IWorkContext context) { context.Telemetry.Verbose(context, $"Removing queue {ActorKey.VectorKey}"); _cache.Clear(); return(new StateManagerBuilder() .Add(new RemoveQueueState(_queueManagement, ActorKey.VectorKey)) .Build() .Set(context)); }
public async Task <bool> Delete(CancellationToken token) { _cache.Clear(); _logger.LogTrace($"{nameof(Delete)}: actorKey={ActorKey}"); bool state = await _directoryStore.Delete(token); await Deactivate(); return(state); }
public void ResetTest() { string item = "Item to be cached"; var cache = new CacheObject <string>(TimeSpan.FromMilliseconds(100)).Set(item); cache.TryGetValue(out string value).Should().BeTrue(); value.Should().NotBeNullOrEmpty(); value.Should().Be(item); cache.IsValid().Should().BeTrue(); cache.Clear(); cache.IsValid().Should().BeFalse(); }
/// <summary> /// find certificate by thumbprint /// </summary> /// <param name="tag">tag</param> /// <param name="context">work context</param> /// <param name="throwOnNotFound">if true, throw exception if not found</param> /// <exception cref="ProgramExitException">Certificate is not found</exception> /// <returns>X509 certificate</returns> public X509Certificate2 GetCertificate(IWorkContext context, bool?throwOnNotFound = null) { context = context.WithTag(_tag); Exception saveException = null; X509Certificate2 certificate = null; throwOnNotFound = throwOnNotFound ?? LocalCertificateKey.RequirePrivateKey; lock (_lock) { if (_cachedCertificate.TryGetValue(out certificate)) { return(certificate); } using (X509Store store = new X509Store(LocalCertificateKey.StoreName, LocalCertificateKey.StoreLocation)) { ToolboxEventSource.Log.Verbose(context, $"Looking for certificate for {this}"); try { store.Open(OpenFlags.ReadOnly); X509Certificate2Collection certificateList = store.Certificates.Find(X509FindType.FindByThumbprint, LocalCertificateKey.Thumbprint, validOnly: false); if (certificateList?.Count != 0) { certificate = certificateList .OfType <X509Certificate2>() .FirstOrDefault(x => !LocalCertificateKey.RequirePrivateKey || x.HasPrivateKey); _cachedCertificate.Set(certificate); } } catch (Exception ex) { ToolboxEventSource.Log.Warning(context, $"Exception: {ex}"); _cachedCertificate.Clear(); saveException = ex; } } ToolboxEventSource.Log.Verbose(context, $"{(_cachedCertificate != null ? "Found" : "Not found")} certificate for {this}"); if (certificate == null && throwOnNotFound == true) { throw new ArgumentException($"Cannot find certificate for {this}", saveException); } return(certificate); } }
public async Task <bool> Delete(CancellationToken token) { _recordCache.Clear(); return(await _container.Delete(base.ActorKey.Value, token : token)); }