Esempio n. 1
0
        /// <summary>
        /// Updates the ZoneConcurrentList for UserSession's zone-enter and zone-last-seen timestamps
        /// </summary>
        /// <returns></returns>
        private async Task UpdateZoneConcurrentListAsync()
        {
            try
            {
                bool isDataModified = false;
                _zoneConcurrentList = await _dataClient?.TransientData?.ObtainZoneConcurrentListAsync();

                if (_zoneConcurrentList != null)
                {
                    // Retrieve the User's respective UserSession
                    var userSession = _zoneConcurrentList.ObtainZoneSession(_locationDevice.ZoneID.Value)?.UserConcurrentList?.ObtainUserSession(_userID.Value);
                    if (userSession != null)
                    {
                        userSession.EnteredIntoZoneAt = userSession.EnteredIntoZoneAt ?? DateTime.UtcNow;
                        userSession.LastSeenInZoneAt  = DateTime.UtcNow;
                        isDataModified = true;
                    }
                }

                if (isDataModified)
                {
                    // Save the updated UserSessions
                    await _dataClient.TransientData.SaveZoneConcurrentListAsync();

                    Context.Logger.LogLine("UserSessions updated");
                }
            }
            catch (Exception ex)
            {
                Context.Logger.LogLine("ZoneConcurrentList ERROR: " + ex.Message);
            }
        }
Esempio n. 2
0
 private void ResetDataMembers()
 {
     _userID                = null;
     _dataClient            = null;
     _locationDevice        = null;
     _displayConcurrentList = null;
     _zoneConcurrentList    = null;
 }
Esempio n. 3
0
        /// <summary>
        /// Flushes ZoneConcurrentList
        /// </summary>
        /// <param name="dataClientConfig"></param>
        private async Task FlushZoneConcurrentListAsync()
        {
            try
            {
                bool isDataModified = false;
                _zoneConcurrentList = await _dataClient?.TransientData?.ObtainZoneConcurrentListAsync();

                if (_zoneConcurrentList?.ZoneSessions?.Any() ?? false)
                {
                    // Traverse through all ZoneSessions in ZoneConcurrentList
                    foreach (ZoneSession zoneSession in _zoneConcurrentList.ZoneSessions)
                    {
                        if (zoneSession?.UserConcurrentList != null)
                        {
                            // Flush the UserConcurrentList's UserSessions
                            UserConcurrentList userConcurrentList = zoneSession.UserConcurrentList;
                            if (userConcurrentList.UserSessions?.Any() ?? false)
                            {
                                List <UserSession> userSessionsToRemove = new List <UserSession>();

                                // Traverse through all UserSessions in UserConcurrentList
                                foreach (UserSession userSession in userConcurrentList.UserSessions)
                                {
                                    if (userSession != null)
                                    {
                                        if (userSession.LastSeenInZoneAt != null)
                                        {
                                            // Remove UserSession from the Zone if the combination of the time the User is last seen in the Zone and
                                            // UserSession zone-timeout threshold is lesser than current time
                                            var combinedTs = userSession.LastSeenInZoneAt.Value.AddSeconds(Config.UserSessionZoneTimeoutThreshold).ToUniversalTime();
                                            if (combinedTs < DateTime.UtcNow)
                                            {
                                                userSessionsToRemove.Add(userSession);
                                            }
                                        }
                                        else
                                        {
                                            userSessionsToRemove.Add(userSession);
                                        }
                                    }
                                }

                                // Removing UserSessions from the UserConcurrentList
                                if (userSessionsToRemove.Any())
                                {
                                    foreach (UserSession userSessionToRemove in userSessionsToRemove)
                                    {
                                        userConcurrentList.UserSessions.Remove(userSessionToRemove);
                                    }
                                    userConcurrentList.LastFlushedAt = DateTime.UtcNow;
                                    isDataModified = true;
                                }
                            }
                        }
                    }
                }

                if (isDataModified)
                {
                    // Save the updated ZoneConcurrentList
                    await _dataClient.TransientData.SaveZoneConcurrentListAsync();

                    Context.Logger.LogLine("ZoneConcurrentList updated");
                }
            }
            catch (Exception ex)
            {
                Context.Logger.LogLine("ZoneConcurrentList ERROR: " + ex.Message);
            }
        }
Esempio n. 4
0
 private void ResetDataMembers()
 {
     _dataClient         = null;
     _zoneConcurrentList = null;
 }