Пример #1
0
        protected override void DoExecute(IBeaconSendingContext context)
        {
            // every two hours a time sync shall be performed
            if (BeaconSendingTimeSyncState.IsTimeSyncRequired(context))
            {
                // transition to time sync state. if cature on is still true after time sync we will end up in the CaputerOnState again
                context.NextState = new BeaconSendingTimeSyncState();
                return;
            }

            context.Sleep();

            // send new session request for all sessions that are new
            SendNewSessionRequests(context);

            statusResponse = null;

            // send all finished sessions
            SendFinishedSessions(context);

            // check if we need to send open sessions & do it if necessary
            SendOpenSessions(context);

            // check if send interval spent -> send current beacon(s) of open Sessions
            HandleStatusResponse(context, statusResponse);
        }
        protected override void DoExecute(IBeaconSendingContext context)
        {
            // every two hours a time sync shall be performed
            if (BeaconSendingTimeSyncState.IsTimeSyncRequired(context))
            {
                // transition to time sync state. if cature on is still true after time sync we will end up in the CaputerOnState again
                context.NextState = new BeaconSendingTimeSyncState();
                return;
            }

            context.Sleep();

            // send new session request for all sessions that are new
            var newSessionsResponse = SendNewSessionRequests(context);

            if (BeaconSendingResponseUtil.IsTooManyRequestsResponse(newSessionsResponse))
            {
                // server is currently overloaded, temporarily switch to capture off
                context.NextState = new BeaconSendingCaptureOffState(newSessionsResponse.GetRetryAfterInMilliseconds());
                return;
            }

            // send all finished sessions
            var finishedSessionsResponse = SendFinishedSessions(context);

            if (BeaconSendingResponseUtil.IsTooManyRequestsResponse(finishedSessionsResponse))
            {
                // server is currently overloaded, temporarily switch to capture off
                context.NextState = new BeaconSendingCaptureOffState(finishedSessionsResponse.GetRetryAfterInMilliseconds());
                return;
            }

            // check if we need to send open sessions & do it if necessary
            var openSessionsResponse = SendOpenSessions(context);

            if (BeaconSendingResponseUtil.IsTooManyRequestsResponse(openSessionsResponse))
            {
                // server is currently overloaded, temporarily switch to capture off
                context.NextState = new BeaconSendingCaptureOffState(openSessionsResponse.GetRetryAfterInMilliseconds());
                return;
            }

            // collect the last status response
            var lastStatusResponse = newSessionsResponse;

            if (openSessionsResponse != null)
            {
                lastStatusResponse = openSessionsResponse;
            }
            else if (finishedSessionsResponse != null)
            {
                lastStatusResponse = finishedSessionsResponse;
            }

            // check if send interval spent -> send current beacon(s) of open Sessions
            HandleStatusResponse(context, lastStatusResponse);
        }