/// <summary>
 ///     Put an Unsafe Cache Entry Asynchronously.
 /// </summary>
 /// <param name="unsafeCacheEntry">
 ///     An <see cref="UnsafeCacheEntry" /> to cache.
 /// </param>
 /// <param name="cancellationToken">
 ///     A cancellation token to cancel the asynchronous operation with.
 /// </param>
 /// <returns>
 ///     A task representing the asynchronous operation.
 /// </returns>
 /// <exception cref="Gee.External.Browsing.Cache.BrowsingCacheException">
 ///     Thrown if a caching error occurs.
 /// </exception>
 /// <exception cref="System.ArgumentNullException">
 ///     Thrown if <paramref name="unsafeCacheEntry" /> is a null reference.
 /// </exception>
 /// <exception cref="System.ObjectDisposedException">
 ///     Thrown if the object is disposed.
 /// </exception>
 /// <exception cref="System.OperationCanceledException">
 ///     Thrown if the asynchronous operation is cancelled.
 /// </exception>
 public async Task PutUnsafeCacheEntryAsync(UnsafeCacheEntry unsafeCacheEntry, CancellationToken cancellationToken)
 {
     this.ThrowIfDisposed();
     try {
         var putUnsafeCacheEntryTask = this._cache.PutUnsafeCacheEntryAsync(unsafeCacheEntry, cancellationToken);
         await putUnsafeCacheEntryTask.ConfigureAwait(false);
     }
     catch (ArgumentNullException) {
         throw;
     }
     catch (BrowsingCacheException) {
         throw;
     }
     catch (ObjectDisposedException) {
         this.Dispose();
         throw;
     }
     catch (OperationCanceledException) {
         throw;
     }
     catch (Exception ex) {
         const string detailMessage = "An unsafe cache entry could not be cached.";
         throw new BrowsingCacheException(detailMessage, ex);
     }
 }
Beispiel #2
0
        /// <summary>
        ///     Put an Unsafe Cache Entry Asynchronously.
        /// </summary>
        /// <param name="this">
        ///     A <see cref="IBrowsingCache" />.
        /// </param>
        /// <param name="unsafeCacheEntry">
        ///     An <see cref="UnsafeCacheEntry" /> to cache.
        /// </param>
        /// <returns>
        ///     A task representing the asynchronous operation.
        /// </returns>
        /// <exception cref="Gee.External.Browsing.Cache.BrowsingCacheException">
        ///     Thrown if a caching error occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="unsafeCacheEntry" /> is a null reference.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        ///     Thrown if <paramref name="this" /> is disposed.
        /// </exception>
        public static Task PutUnsafeCacheEntryAsync(this IBrowsingCache @this, UnsafeCacheEntry unsafeCacheEntry)
        {
            Guard.ThrowIf(nameof(@this), @this).Null();

            var putUnsafeCacheEntryTask = @this.PutUnsafeCacheEntryAsync(unsafeCacheEntry, CancellationToken.None);

            return(putUnsafeCacheEntryTask);
        }
        public Task PutUnsafeCacheEntryAsync(UnsafeCacheEntry unsafeCacheEntry, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();

            Func <Task> resiliencyPolicyAction      = () => this._cache.PutUnsafeCacheEntryAsync(unsafeCacheEntry, cancellationToken);
            var         executeResiliencyPolicyTask = this.ExecuteResiliencyPolicyAsync(resiliencyPolicyAction);

            return(executeResiliencyPolicyTask);
        }
Beispiel #4
0
        /// <summary>
        ///     Put an Unsafe Cache Entry Asynchronously.
        /// </summary>
        /// <param name="this">
        ///     A <see cref="IBrowsingCache" />.
        /// </param>
        /// <param name="threatSha256Hash">
        ///     A full SHA256 hash, formatted as a hexadecimal encoded string, identifying a threat to cache.
        /// </param>
        /// <param name="unsafeThreats">
        ///     A collection of <see cref="UnsafeThreat" /> to cache.
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token to cancel the asynchronous operation with.
        /// </param>
        /// <returns>
        ///     A task representing the asynchronous operation.
        /// </returns>
        /// <exception cref="Gee.External.Browsing.Cache.BrowsingCacheException">
        ///     Thrown if a caching error occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="this" /> is a null reference, or if <paramref name="threatSha256Hash" /> is a
        ///     null reference, or if <paramref name="unsafeThreats" /> is a null reference.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        ///     Thrown if <paramref name="this"/> is disposed.
        /// </exception>
        /// <exception cref="System.OperationCanceledException">
        ///     Thrown if the asynchronous operation is cancelled.
        /// </exception>
        public static Task PutUnsafeCacheEntryAsync(this IBrowsingCache @this, string threatSha256Hash, IEnumerable <UnsafeThreat> unsafeThreats, CancellationToken cancellationToken)
        {
            Guard.ThrowIf(nameof(@this), @this).Null();

            // ...
            //
            // Throws an exception if the operation fails.
            var unsafeCacheEntry        = new UnsafeCacheEntry(threatSha256Hash, unsafeThreats);
            var putUnsafeCacheEntryTask = @this.PutUnsafeCacheEntryAsync(unsafeCacheEntry, cancellationToken);

            return(putUnsafeCacheEntryTask);
        }
Beispiel #5
0
        public Task PutUnsafeCacheEntryAsync(UnsafeCacheEntry unsafeCacheEntry, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();

            // ...
            //
            // Throws an exception if the operation fails.
            var threatSha256Hash = unsafeCacheEntry?.ThreatSha256Hash;

            this._unsafeCache.AddOrUpdate(threatSha256Hash, unsafeCacheEntry, (k, v) => unsafeCacheEntry);
            return(Task.CompletedTask);
        }