< Summary

Class:Microsoft.Azure.Batch.Protocol.RequestInterceptor
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\Protocol\Interceptors.cs
Covered lines:11
Uncovered lines:2
Coverable lines:13
Total lines:118
Line coverage:84.6% (11 of 13)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
.ctor(...)-100%100%
get_ModificationInterceptHandler()-0%100%
set_ModificationInterceptHandler(...)-100%100%
NOOP(...)-0%100%
ReplacementInterceptHandler(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\Protocol\Interceptors.cs

#LineLine coverage
 1namespace Microsoft.Azure.Batch.Protocol
 2{
 3    using System;
 4    using System.Collections.Generic;
 5    using System.Reflection;
 6
 7    /// <summary>
 8    /// Represents a method that intercepts a request to the Batch service in order
 9    /// to modify the parameters.
 10    /// </summary>
 11    /// <param name="request">The parameters of the request being intercepted.</param>
 12    public delegate void BatchRequestModificationInterceptHandler(Protocol.IBatchRequest request);
 13
 14    /// <summary>
 15    /// Represents a method that intercepts a request to the Batch service in order
 16    /// to replace the parameters and/or operation context.
 17    /// </summary>
 18    /// <param name="request">The parameters of the request being intercepted.</param>
 19    public delegate void BatchRequestReplacementInterceptHandler(ref Protocol.IBatchRequest request);
 20
 21    /// <summary>
 22    /// Derived classes can inspect, replace or modify a BatchRequest.
 23    /// </summary>
 24    public class RequestReplacementInterceptor : BatchClientBehavior
 25    {
 26        /// <summary>
 27        /// Initializes a new instance of RequestReplacementInterceptor.
 28        /// </summary>
 29        public RequestReplacementInterceptor()
 30        {
 31            this.ReplacementInterceptHandler = RequestReplacementInterceptor.NOOP; // benign noop.
 32        }
 33
 34        /// <summary>
 35        /// Initializes a new instance of RequestReplacementInterceptor
 36        /// </summary>
 37        /// <param name="replacementInterceptor"></param>
 38        public RequestReplacementInterceptor(BatchRequestReplacementInterceptHandler replacementInterceptor)
 39        {
 40            this.ReplacementInterceptHandler = replacementInterceptor;
 41        }
 42
 43        /// <summary>
 44        /// Does nothing.
 45        /// </summary>
 46        private static void NOOP(ref Protocol.IBatchRequest request)
 47        {
 48        }
 49
 50        /// <summary>
 51        /// Gets or sets a method that will be called just before a <see cref="IBatchRequest"/> is executed.
 52        /// The request can be inspected, replaced, modified or ignored.
 53        /// </summary>
 54        public BatchRequestReplacementInterceptHandler ReplacementInterceptHandler
 55        {
 56            get;
 57            set;
 58        }
 59    }
 60
 61    /// <summary>
 62    /// This class enables an interceptor to inspect, modify or ignore a <see cref="IBatchRequest"/>.
 63    /// </summary>
 64    public class RequestInterceptor : RequestReplacementInterceptor
 65    {
 66        private BatchRequestModificationInterceptHandler _modInterceptor;
 67
 68        /// <summary>
 69        /// Initializes a new instance of RequestInterceptor.
 70        /// </summary>
 68571        public RequestInterceptor()
 72        {
 68573            this.ModificationInterceptHandler = RequestInterceptor.NOOP; // benign default
 68574        }
 75
 76        /// <summary>
 77        /// Initializes a new instance of RequestInterceptor that calls a given BatchRequestModificationInterceptHandler
 78        /// </summary>
 79        /// <param name="interceptor">A delegate that will be allowed to inspect, modify or ignore a BatchRequest.</para
 37380        public RequestInterceptor(BatchRequestModificationInterceptHandler interceptor)
 81        {
 37382            this.ModificationInterceptHandler = interceptor;
 37383        }
 84
 85        /// <summary>
 86        /// Gets or sets the BatchRequestModificationInterceptHandler.
 87        /// </summary>
 88        public BatchRequestModificationInterceptHandler ModificationInterceptHandler
 89        {
 90            get
 91            {
 092                return _modInterceptor;
 93            }
 94            set
 95            {
 174396                _modInterceptor = value;
 174397                base.ReplacementInterceptHandler = this.ReplacementInterceptHandler;
 174398            }
 99        }
 100
 101        /// <summary>
 102        /// An interceptor that does nothing.
 103        /// </summary>
 104        /// <param name="request"></param>
 105        /// <returns></returns>
 106        private static void NOOP(object request)
 107        {
 0108        }
 109
 110        /// <summary>
 111        /// A replacment interceptor that calls our modification interceptor.
 112        /// </summary>
 113        private new void ReplacementInterceptHandler(ref Protocol.IBatchRequest request)
 114        {
 266115            _modInterceptor(request);
 199116        }
 117    }
 118}