private static void ApplySessionTimeout(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.SESSION_IDLE_TIMEOUT))
     {
         builder.WithSessionTimeoutInMilliseconds(attributes.SessionTimeoutInMilliseconds);
     }
 }
            public Builder(IResponseAttributes defaults)
            {
                SetAttributes = new HashSet <ResponseAttribute>();

                MaxBeaconSizeInBytes             = defaults.MaxBeaconSizeInBytes;
                MaxSessionDurationInMilliseconds = defaults.MaxSessionDurationInMilliseconds;
                MaxEventsPerSession          = defaults.MaxEventsPerSession;
                SessionTimeoutInMilliseconds = defaults.SessionTimeoutInMilliseconds;
                SendIntervalInMilliseconds   = defaults.SendIntervalInMilliseconds;
                VisitStoreVersion            = defaults.VisitStoreVersion;

                IsCapture                = defaults.IsCapture;
                IsCaptureCrashes         = defaults.IsCaptureCrashes;
                IsCaptureErrors          = defaults.IsCaptureErrors;
                TrafficControlPercentage = defaults.TrafficControlPercentage;
                ApplicationId            = defaults.ApplicationId;

                Multiplicity = defaults.Multiplicity;
                ServerId     = defaults.ServerId;
                Status       = defaults.Status;

                TimestampInMilliseconds = defaults.TimestampInMilliseconds;

                foreach (var attribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
                {
                    if (defaults.IsAttributeSet(attribute))
                    {
                        SetAttribute(attribute);
                    }
                }
            }
 private static void ApplyCaptureErrors(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.IS_CAPTURE_ERRORS))
     {
         builder.WithCaptureErrors(attributes.IsCaptureErrors);
     }
 }
 private static void ApplyCapture(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.IS_CAPTURE))
     {
         builder.WithCapture(attributes.IsCapture);
     }
 }
 private static void ApplyCaptureCrashes(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.IS_CAPTURE_CRASHES))
     {
         builder.WithCaptureCrashes(attributes.IsCaptureCrashes);
     }
 }
 private static void ApplyApplicationId(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.APPLICATION_ID))
     {
         builder.WithApplicationId(attributes.ApplicationId);
     }
 }
 private static void ApplyVisitStoreVersion(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.VISIT_STORE_VERSION))
     {
         builder.WithVisitStoreVersion(attributes.VisitStoreVersion);
     }
 }
 private static void ApplyEventsPerSession(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.MAX_EVENTS_PER_SESSION))
     {
         builder.WithMaxEventsPerSession(attributes.MaxEventsPerSession);
     }
 }
            /// <summary>
            /// Creates a new builder instance with pre-initialized fields from the given <see cref="IResponseAttributes"/>.
            /// </summary>
            /// <param name="responseAttributes">response attributes used for initializing this builder.</param>
            public Builder(IResponseAttributes responseAttributes)
            {
                IsCaptureEnabled        = responseAttributes.IsCapture;
                IsCrashReportingEnabled = responseAttributes.IsCaptureCrashes;
                IsErrorReportingEnabled = responseAttributes.IsCaptureErrors;
                ServerId          = responseAttributes.ServerId;
                BeaconSizeInBytes = responseAttributes.MaxBeaconSizeInBytes;
                Multiplicity      = responseAttributes.Multiplicity;

                SendIntervalInMilliseconds = responseAttributes.SendIntervalInMilliseconds;

                MaxSessionDurationInMilliseconds       = responseAttributes.MaxSessionDurationInMilliseconds;
                IsSessionSplitBySessionDurationEnabled =
                    responseAttributes.IsAttributeSet(ResponseAttribute.MAX_SESSION_DURATION);

                MaxEventsPerSession           = responseAttributes.MaxEventsPerSession;
                IsSessionSplitByEventsEnabled =
                    responseAttributes.IsAttributeSet(ResponseAttribute.MAX_EVENTS_PER_SESSION);

                SessionTimeoutInMilliseconds       = responseAttributes.SessionTimeoutInMilliseconds;
                IsSessionSplitByIdleTimeoutEnabled =
                    responseAttributes.IsAttributeSet(ResponseAttribute.SESSION_IDLE_TIMEOUT);

                VisitStoreVersion = responseAttributes.VisitStoreVersion;
            }
 private static void ApplyBeaconSize(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.MAX_BEACON_SIZE))
     {
         builder.WithMaxBeaconSizeInBytes(attributes.MaxBeaconSizeInBytes);
     }
 }
 private static void ApplySessionDuration(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.MAX_SESSION_DURATION))
     {
         builder.WithMaxSessionDurationInMilliseconds(attributes.MaxSessionDurationInMilliseconds);
     }
 }
 private static void ApplyServerId(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.SERVER_ID))
     {
         builder.WithServerId(attributes.ServerId);
     }
 }
 private static void ApplyMultiplicity(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.MULTIPLICITY))
     {
         builder.WithMultiplicity(attributes.Multiplicity);
     }
 }
 private static void ApplyStatus(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.STATUS))
     {
         builder.WithStatus(attributes.Status);
     }
 }
 private static void ApplyTimestamp(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.TIMESTAMP))
     {
         builder.WithTimestampInMilliseconds(attributes.TimestampInMilliseconds);
     }
 }
 private static void ApplyTrafficControlPercentage(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.TRAFFIC_CONTROL_PERCENTAGE))
     {
         builder.WithTrafficControlPercentage(attributes.TrafficControlPercentage);
     }
 }
 private static void ApplySendInterval(Builder builder, IResponseAttributes attributes)
 {
     if (attributes.IsAttributeSet(ResponseAttribute.SEND_INTERVAL))
     {
         builder.WithSendIntervalInMilliseconds(attributes.SendIntervalInMilliseconds);
     }
 }
 private StatusResponse(ILogger logger, IResponseAttributes responseAttributes, int responseCode,
                        Dictionary <string, List <string> > headers)
 {
     this.logger        = logger;
     ResponseCode       = responseCode;
     Headers            = headers;
     ResponseAttributes = responseAttributes;
 }
        /// <summary>
        /// Creates a new server configuration from the given <see cref="IResponseAttributes"/>.
        /// </summary>
        /// <param name="responseAttributes">the response attributes from which to create the server configuration.</param>
        /// <returns>the newly created server configuration.</returns>
        public static IServerConfiguration From(IResponseAttributes responseAttributes)
        {
            if (responseAttributes == null)
            {
                return(null);
            }

            return(new Builder(responseAttributes).Build());
        }
        public void Setup()
        {
            mockAttributes = Substitute.For <IResponseAttributes>();
            mockResponse   = Substitute.For <IStatusResponse>();
            mockResponse.ResponseCode.Returns(StatusResponse.HttpOk);
            mockResponse.IsErroneousResponse.Returns(false);
            mockResponse.ResponseAttributes.Returns(mockAttributes);

            mockHttpClient = Substitute.For <IHttpClient>();
            mockHttpClient.SendStatusRequest(Arg.Any <IAdditionalQueryParameters>()).Returns(mockResponse);

            mockContext = Substitute.For <IBeaconSendingContext>();
            mockContext.GetHttpClient().Returns(mockHttpClient);
        }
Beispiel #21
0
        internal BeaconSendingContext(
            ILogger logger,
            IHttpClientConfiguration httpClientConfiguration,
            IHttpClientProvider httpClientProvider,
            ITimingProvider timingProvider,
            IInterruptibleThreadSuspender threadSuspender,
            AbstractBeaconSendingState initialState
            )
        {
            this.logger = logger;
            this.httpClientConfiguration = httpClientConfiguration;
            serverConfiguration          = ServerConfiguration.Default;
            HttpClientProvider           = httpClientProvider;
            this.timingProvider          = timingProvider;
            this.threadSuspender         = threadSuspender;
            lastResponseAttributes       = ResponseAttributes.WithUndefinedDefaults().Build();

            CurrentState = initialState;
        }
Beispiel #22
0
        public IResponseAttributes Merge(IResponseAttributes responseAttributes)
        {
            var builder = new Builder(this);

            ApplyBeaconSize(builder, responseAttributes);
            ApplySessionDuration(builder, responseAttributes);
            ApplyEventsPerSession(builder, responseAttributes);
            ApplySessionTimeout(builder, responseAttributes);
            ApplySendInterval(builder, responseAttributes);
            ApplyVisitStoreVersion(builder, responseAttributes);
            ApplyCapture(builder, responseAttributes);
            ApplyCaptureCrashes(builder, responseAttributes);
            ApplyCaptureErrors(builder, responseAttributes);
            ApplyApplicationId(builder, responseAttributes);
            ApplyMultiplicity(builder, responseAttributes);
            ApplyServerId(builder, responseAttributes);
            ApplyStatus(builder, responseAttributes);
            ApplyTimestamp(builder, responseAttributes);

            return(builder.Build());
        }
 public void SetUp()
 {
     logger     = Substitute.For <ILogger>();
     attributes = ResponseAttributes.WithJsonDefaults().Build();
 }
 public IResponseAttributes Merge(IResponseAttributes responseAttributes)
 {
     return(responseAttributes);
 }
 public static StatusResponse CreateSuccessResponse(ILogger logger, IResponseAttributes responseAttributes,
                                                    int responseCode, Dictionary <string, List <string> > headers)
 {
     return(new StatusResponse(logger, responseAttributes, responseCode, headers));
 }