예제 #1
0
        /// <summary>
        ///     Set Request.
        /// </summary>
        /// <param name="value">
        ///     The <see cref="ThreatListUpdateRequest" /> made to the Google Safe Browsing API for which the threat
        ///     list update response has been returned.
        /// </param>
        /// <returns>
        ///     This threat list update response builder.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="value" /> is a null reference.
        /// </exception>
        public ThreatListUpdateResponseBuilder SetRequest(ThreatListUpdateRequest value)
        {
            Guard.ThrowIf(nameof(value), value).Null();

            this.Request = value;
            return(this);
        }
        public ThreatListUpdateResponse(ThreatListUpdateRequest request, IEnumerable <ThreatListUpdateResult> results)
        {
            Guard.ThrowIf(nameof(request), request).Null();

            this.Request = request;
            this.Results = results != null?results.ToArray() : Array.Empty <ThreatListUpdateResult>();
        }
예제 #3
0
        /// <summary>
        ///     Get Threat List Updates Asynchronously.
        /// </summary>
        /// <param name="request">
        ///     A <see cref="ThreatListUpdateRequest" />.
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token to cancel the asynchronous operation with.
        /// </param>
        /// <returns>
        ///     A <see cref="ThreatListUpdateResponse" />.
        /// </returns>
        /// <exception cref="Gee.External.Browsing.Clients.BrowsingClientException">
        ///     Thrown if an error communicating with the Google Safe Browsing API occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="request" /> 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>
        /// <exception cref="System.TimeoutException">
        ///     Thrown if communication with the Google Safe Browsing API times out.
        /// </exception>
        public async Task <ThreatListUpdateResponse> GetThreatListUpdatesAsync(ThreatListUpdateRequest request, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();
            try {
                var getThreatListUpdatesTask = this._client.GetThreatListUpdatesAsync(request, cancellationToken);
                var response = await getThreatListUpdatesTask.ConfigureAwait(false);

                return(response);
            }
            catch (ArgumentNullException) {
                throw;
            }
            catch (BrowsingClientException) {
                throw;
            }
            catch (ObjectDisposedException) {
                this.Dispose();
                throw;
            }
            catch (OperationCanceledException) {
                throw;
            }
            catch (TimeoutException) {
                throw;
            }
            catch (Exception ex) {
                const string detailMessage = "An HTTP request to the Google Safe Browsing API failed.";
                throw new BrowsingClientException(detailMessage, HttpStatusCode.BadRequest, ex);
            }
        }
예제 #4
0
        public Task <ThreatListUpdateResponse> GetThreatListUpdatesAsync(ThreatListUpdateRequest request, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();

            Func <Task <ThreatListUpdateResponse> > resiliencyPolicyAction = () => this._client.GetThreatListUpdatesAsync(request, cancellationToken);
            var executeResiliencyPolicyTask = this.ExecuteResiliencyPolicyAsync(resiliencyPolicyAction);

            return(executeResiliencyPolicyTask);
        }
예제 #5
0
        /// <summary>
        ///     Set Request.
        /// </summary>
        /// <param name="valueAction">
        ///     An action to create the <see cref="ThreatListUpdateRequest" /> made to the Google Safe Browsing API
        ///     for which the threat list update response has been returned.
        /// </param>
        /// <returns>
        ///     This threat list update response builder.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="valueAction" /> is a null reference.
        /// </exception>
        public ThreatListUpdateResponseBuilder SetRequest(Func <ThreatListUpdateRequestBuilder, ThreatListUpdateRequest> valueAction)
        {
            Guard.ThrowIf(nameof(valueAction), valueAction).Null();

            // ...
            //
            // Throws an exception if the operation fails.
            var threatListUpdateRequestBuilder = ThreatListUpdateRequest.Build();
            var threatListUpdateRequest        = valueAction(threatListUpdateRequestBuilder);

            this.SetRequest(threatListUpdateRequest);

            return(this);
        }
예제 #6
0
        /// <summary>
        ///     Build a Threat List Update Request.
        /// </summary>
        /// <returns>
        ///     A <see cref="ThreatListUpdateRequest" />.
        /// </returns>
        public ThreatListUpdateRequest Build()
        {
            var threatListUpdateRequest = new ThreatListUpdateRequest(this);

            // ...
            //
            // Reinitialize the builder's state to prevent it from corrupting the immutable built object's state after
            // its built. If the object holds a reference to the builder's state, any mutation to the builder's state
            // will be reflected in the built object's state.
            this.ClientMetadata = ClientMetadata.Default;
            this.Queries        = new HashSet <ThreatListUpdateQuery>();

            return(threatListUpdateRequest);
        }
        /// <summary>
        ///     Get Threat List Updates Asynchronously.
        /// </summary>
        /// <param name="this">
        ///     A <see cref="IBrowsingClient" />.
        /// </param>
        /// <param name="threatList">
        ///     A <see cref="ThreatList" /> to retrieve.
        /// </param>
        /// <param name="updateConstraints">
        ///     The <see cref="ThreatListUpdateConstraints" /> to apply when <paramref name="threatList" /> is
        ///     retrieved. A null reference indicates no <see cref="ThreatListUpdateConstraints" /> should be applied.
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token to cancel the asynchronous operation with.
        /// </param>
        /// <returns>
        ///     A <see cref="ThreatListUpdateResponse" />.
        /// </returns>
        /// <exception cref="Gee.External.Browsing.Clients.BrowsingClientException">
        ///     Thrown if an error communicating with the Google Safe Browsing API occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="this" /> is a null reference, or if <paramref name="threatList" /> is a
        ///     null reference.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        ///     Thrown if the <paramref name="this" /> is disposed.
        /// </exception>
        /// <exception cref="System.OperationCanceledException">
        ///     Thrown if the asynchronous operation is cancelled.
        /// </exception>
        /// <exception cref="System.TimeoutException">
        ///     Thrown if communication with the Google Safe Browsing API times out.
        /// </exception>
        public static Task <ThreatListUpdateResponse> GetThreatListUpdatesAsync(this IBrowsingClient @this, ThreatList threatList, ThreatListUpdateConstraints updateConstraints, CancellationToken cancellationToken)
        {
            Guard.ThrowIf(nameof(@this), @this).Null();
            Guard.ThrowIf(nameof(threatList), threatList).Null();

            var threatListUpdateRequestBuilder = ThreatListUpdateRequest.Build();

            threatListUpdateRequestBuilder.AddQuery(b => {
                b.SetThreatListDescriptor(threatList.Descriptor);
                b.SetThreatListState(threatList.State);
                b.SetUpdateConstraints(updateConstraints);
                return(b.Build());
            });

            // ...
            //
            // Throws an exception if the operation fails.
            var threatListUpdateRequest  = threatListUpdateRequestBuilder.Build();
            var getThreatListUpdatesTask = @this.GetThreatListUpdatesAsync(threatListUpdateRequest, cancellationToken);

            return(getThreatListUpdatesTask);
        }
 /// <summary>
 ///     Create a Threat List Update Response.
 /// </summary>
 /// <param name="request">
 ///     The <see cref="ThreatListUpdateRequest" /> made to the Google Safe Browsing API for which the threat
 ///     list update response has been returned.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 ///     Thrown if <paramref name="request" /> is a null reference.
 /// </exception>
 public ThreatListUpdateResponse(ThreatListUpdateRequest request) : this(request, null)
 {
 }
        /// <summary>
        ///     Get Threat List Updates Asynchronously.
        /// </summary>
        /// <param name="this">
        ///     A <see cref="IBrowsingClient" />.
        /// </param>
        /// <param name="request">
        ///     A <see cref="ThreatListUpdateRequest" />.
        /// </param>
        /// <returns>
        ///     A <see cref="ThreatListUpdateResponse" />.
        /// </returns>
        /// <exception cref="Gee.External.Browsing.Clients.BrowsingClientException">
        ///     Thrown if an error communicating with the Google Safe Browsing API occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="this" /> is a null reference, or if <paramref name="request" /> is a null
        ///     reference.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        ///     Thrown if <paramref name="this" /> is disposed.
        /// </exception>
        /// <exception cref="System.TimeoutException">
        ///     Thrown if communication with the Google Safe Browsing API times out.
        /// </exception>
        public static Task <ThreatListUpdateResponse> GetThreatListUpdatesAsync(this IBrowsingClient @this, ThreatListUpdateRequest request)
        {
            Guard.ThrowIf(nameof(@this), @this).Null();

            // ...
            //
            // Throws an exception if the operation fails.
            var getThreatListUpdatesTask = @this.GetThreatListUpdatesAsync(request, CancellationToken.None);

            return(getThreatListUpdatesTask);
        }