Esempio n. 1
0
        /// <summary>
        /// Creates a new session and adds it to the beacon sender. The top level action count is reset to zero and the
        /// last interaction time is set to the current timestamp.
        /// <para>
        /// In case the given <code>initialServerConfig</code> is not null, the new session will be initialized with
        /// this server configuration. The created session however will not be in state
        /// <see cref="ISessionState.IsConfigured">configured</see>, meaning new session requests will be performed for
        /// this session.
        /// </para>
        /// <para>
        /// In case the given <code>updatedServerConfig</code> is not null, the new session will be updated with this
        /// server configuration. The created session will be in state
        /// <see cref="ISessionState.IsConfigured">configured</see>, meaning new session requests will be omitted.
        /// </para>
        /// </summary>
        /// <param name="initialServerConfig">
        /// the server configuration with which the session will be initialized. Can be <code>null</code>
        /// </param>
        /// <param name="updatedServerConfig">
        /// the server configuration with which the session will be updated. Can be <code>null</code>.
        /// </param>
        private void CreateAndAssignCurrentSession(IServerConfiguration initialServerConfig,
                                                   IServerConfiguration updatedServerConfig)
        {
            var session = sessionCreator.CreateSession(this);
            var beacon  = session.Beacon;

            beacon.OnServerConfigurationUpdate += OnServerConfigurationUpdate;

            ThisComposite.StoreChildInList(session);

            lastInteractionTime = beacon.SessionStartTime;
            topLevelActionCount = 0;

            if (initialServerConfig != null)
            {
                session.InitializeServerConfiguration(initialServerConfig);
            }

            if (updatedServerConfig != null)
            {
                session.UpdateServerConfiguration(updatedServerConfig);
            }

            lock (lockObject)
            {
                // synchronize access
                currentSession = session;
            }

            beaconSender.AddSession(currentSession);
        }
Esempio n. 2
0
 public void SetUp()
 {
     mockLogger = Substitute.For <ILogger>();
     mockLogger.IsDebugEnabled.Returns(true);
     mockBeacon  = Substitute.For <IBeacon>();
     mockSession = Substitute.For <ISessionInternals>();
 }
Esempio n. 3
0
 // when starting a new Session, put it into open Sessions
 void IBeaconSender.AddSession(ISessionInternals session)
 {
     if (logger.IsDebugEnabled)
     {
         logger.Debug($"{GetType().Name} AddSession()");
     }
     context.AddSession(session);
 }
Esempio n. 4
0
 /// <summary>
 /// Constructor for creating a new root action instance
 /// </summary>
 /// <param name="logger">the logger used to log information</param>
 /// <param name="parentSession">the session to which this root action belongs to</param>
 /// <param name="name">the name of this root action</param>
 /// <param name="beacon">the beacon for retrieving certain data and for sending data</param>
 public RootAction(
     ILogger logger,
     ISessionInternals parentSession,
     string name,
     IBeacon beacon)
     : base(logger, parentSession, name, beacon)
 {
 }
        public void SetUp()
        {
            mockLogger = Substitute.For <ILogger>();
            mockLogger.IsDebugEnabled.Returns(true);

            mockContext = Substitute.For <ISessionWatchdogContext>();
            mockSession = Substitute.For <ISessionInternals>();

            threadEvent = new ManualResetEvent(false);
        }
Esempio n. 6
0
        /// <summary>
        /// Will end the current active session, enque the old one for closing, and create a new session.
        ///
        /// <para>
        /// The new session is created using the <see cref="CreateInitialSession(IServerConfiguration)"/> method.
        /// </para>
        ///
        /// <para>
        /// This method must be called only when the <see cref="lockObject"/> is held.
        /// </para>
        /// </summary>
        private void SplitAndCreateNewInitialSession()
        {
            CloseOrEnqueueCurrentSessionForClosing();

            // create a completely new Session
            sessionCreator.Reset();
            currentSession = CreateInitialSession(serverConfiguration);

            ReTagCurrentSession();
        }
Esempio n. 7
0
        public void SetUp()
        {
            mockTimingProvider = Substitute.For <ITimingProvider>();
            mockSession        = Substitute.For <ISessionInternals>();

            mockThreadSuspender = Substitute.For <IInterruptibleThreadSuspender>();
            mockThreadSuspender.Sleep(Arg.Any <int>()).Returns(true);

            mockSessionProxy = Substitute.For <ISessionProxy>();
        }
Esempio n. 8
0
        private ISessionInternals GetOrSplitCurrentSessionByEvents()
        {
            if (IsSessionSplitByEventsRequired())
            {
                CloseOrEnqueueCurrentSessionForClosing();
                currentSession = CreateSplitSession(serverConfiguration);

                ReTagCurrentSession();
            }

            return(currentSession);
        }
Esempio n. 9
0
        void ISessionWatchdogContext.CloseOrEnqueueForClosing(ISessionInternals session, long closeGracePeriodInMillis)
        {
            if (session.TryEnd())
            {
                return;
            }

            var closeTime = timingProvider.ProvideTimestampInMilliseconds() + closeGracePeriodInMillis;

            session.SplitByEventsGracePeriodEndTimeInMillis = closeTime;
            sessionsToClose.Put(session);
        }
Esempio n. 10
0
        internal SessionProxy(
            ILogger logger,
            IOpenKitComposite parent,
            ISessionCreator sessionCreator,
            ITimingProvider timingProvider,
            IBeaconSender beaconSender,
            ISessionWatchdog sessionWatchdog)
        {
            this.logger          = logger;
            this.parent          = parent;
            this.sessionCreator  = sessionCreator;
            this.timingProvider  = timingProvider;
            this.beaconSender    = beaconSender;
            this.sessionWatchdog = sessionWatchdog;

            var currentServerConfig = beaconSender.LastServerConfiguration;

            currentSession = CreateInitialSession(currentServerConfig);
        }
        public void SetUp()
        {
            mockSession1Open     = Substitute.For <ISessionInternals>();
            mockSession2Open     = Substitute.For <ISessionInternals>();
            mockSession3Finished = Substitute.For <ISessionInternals>();
            mockSession4Finished = Substitute.For <ISessionInternals>();
            mockSession5New      = Substitute.For <ISessionInternals>();
            mockSession6New      = Substitute.For <ISessionInternals>();

            mockLogger = Substitute.For <ILogger>();

            var okResponse = Substitute.For <IStatusResponse>();

            okResponse.ResponseCode.Returns(StatusResponse.HttpOk);
            okResponse.IsErroneousResponse.Returns(false);

            var errorResponse = Substitute.For <IStatusResponse>();

            errorResponse.ResponseCode.Returns(404);
            errorResponse.IsErroneousResponse.Returns(true);

            mockSession1Open.IsDataSendingAllowed.Returns(true);
            mockSession1Open.SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(okResponse);
            mockSession2Open.SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(errorResponse);

            var mockHttpClientProvider = Substitute.For <IHttpClientProvider>();

            mockContext = Substitute.For <IBeaconSendingContext>();
            mockContext.HttpClientProvider.Returns(mockHttpClientProvider);
            mockContext.CurrentTimestamp.Returns(42);
            mockContext.GetAllNotConfiguredSessions().Returns(new List <ISessionInternals>());
            mockContext.GetAllOpenAndConfiguredSessions().Returns(new List <ISessionInternals>
            {
                mockSession1Open, mockSession2Open
            });
            mockContext.GetAllFinishedAndConfiguredSessions().Returns(new List <ISessionInternals>
            {
                mockSession3Finished, mockSession4Finished
            });
        }
        public void Setup()
        {
            var mockResponse = Substitute.For <IStatusResponse>();

            mockResponse.ResponseCode.Returns(StatusResponse.HttpOk);
            mockResponse.IsErroneousResponse.Returns(false);

            mockSession1Open = Substitute.For <ISessionInternals>();
            mockSession1Open.IsDataSendingAllowed.Returns(true);
            mockSession1Open.SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(mockResponse);

            mockSession2Open = Substitute.For <ISessionInternals>();
            mockSession2Open.IsDataSendingAllowed.Returns(true);
            mockSession2Open.SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(mockResponse);

            mockSession3Closed = Substitute.For <ISessionInternals>();
            mockSession3Closed.IsDataSendingAllowed.Returns(true);
            mockSession3Closed.SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(mockResponse);

            var mockHttpClient = Substitute.For <IHttpClient>();

            mockContext = Substitute.For <IBeaconSendingContext>();
            mockContext.GetHttpClient().Returns(mockHttpClient);
            mockContext.GetAllNotConfiguredSessions().Returns(new List <ISessionInternals>());
            mockContext.GetAllOpenAndConfiguredSessions().Returns(new List <ISessionInternals>
            {
                mockSession1Open, mockSession2Open
            });
            mockContext.GetAllFinishedAndConfiguredSessions().Returns(new List <ISessionInternals>
            {
                mockSession3Closed, mockSession2Open, mockSession1Open
            });
        }
Esempio n. 13
0
 void ISessionWatchdog.DequeueFromClosing(ISessionInternals session)
 {
     context.DequeueFromClosing(session);
 }
Esempio n. 14
0
 void ISessionWatchdog.CloseOrEnqueueForClosing(ISessionInternals session, int closeGracePeriodInMillis)
 {
     context.CloseOrEnqueueForClosing(session, closeGracePeriodInMillis);
 }
Esempio n. 15
0
 void ISessionWatchdogContext.DequeueFromClosing(ISessionInternals session)
 {
     sessionsToClose.Remove(session);
 }