internal static SecurityActivityHistory GetHistory()
        {
            SecurityActivityHistory result;
            var list = new List <SecurityActivityHistoryItem>(_history.Length);

            lock (_lock)
            {
                for (var i = _position; i < _history.Length; i++)
                {
                    if (_history[i] != null)
                    {
                        list.Add(_history[i]);
                    }
                }
                for (var i = 0; i < _position; i++)
                {
                    if (_history[i] != null)
                    {
                        list.Add(_history[i]);
                    }
                }

                result = new SecurityActivityHistory
                {
                    State  = SecurityActivityQueue.GetCurrentState(),
                    Recent = list.ToArray()
                };
            }
            return(result);
        }
Beispiel #2
0
 public Serializer(SecurityActivityQueue securityActivityQueue, SecurityActivityHistoryController activityHistory,
                   DataHandler dataHandler)
 {
     _securityActivityQueue = securityActivityQueue;
     _activityHistory       = activityHistory;
     _dataHandler           = dataHandler;
 }
        internal static SecurityActivityHistory Reset()
        {
            SecurityActivityHistory result;

            lock (_lock)
            {
                for (var i = 0; i < _history.Length; i++)
                {
                    _history[i] = null;
                }

                _position   = 0;
                _unfinished = 0;

                result = new SecurityActivityHistory
                {
                    State  = SecurityActivityQueue.GetCurrentState(),
                    Recent = new SecurityActivityHistoryItem[0]
                };
            }
            return(result);
        }
Beispiel #4
0
        internal static void HealthCheck()
        {
            if (IsWorking())
            {
                SnTrace.Security.Write("SAQ: Health check triggered but ignored.");
                return;
            }
            SnTrace.Security.Write("SAQ: Health check triggered.");

            var state      = TerminationHistory.GetCurrentState();
            var gapsLength = state.Gaps.Length;

            if (gapsLength > 0)
            {
                SnTrace.SecurityQueue.Write("SAQ: Health checker is processing {0} gap{1}.", gapsLength, gapsLength > 1 ? "s" : "");

                var notLoaded = state.Gaps.ToList();
                foreach (var activity in new SecurityActivityLoader(state.Gaps, false))
                {
                    SecurityActivityQueue.ExecuteActivity(activity);
                    // memorize executed
                    notLoaded.Remove(activity.Id);
                }
                // forget not loaded activities.
                TerminationHistory.RemoveFromGaps(notLoaded);
            }

            var lastId   = TerminationHistory.GetLastTerminatedId();
            var lastDbId = DataHandler.GetLastSecurityActivityId(SecurityContext.StartedAt);

            if (lastId < lastDbId)
            {
                SnTrace.SecurityQueue.Write("SAQ: Health checker is processing activities from {0} to {1}", lastId + 1, lastDbId);
                foreach (var activity in new SecurityActivityLoader(lastId + 1, lastDbId, false))
                {
                    SecurityActivityQueue.ExecuteActivity(activity);
                }
            }
        }
        // for testing purposes we need a parameterless method because ElapsedEventArgs has only internal constructor
        private static void Timer_Elapsed()
        {
            if (Debugger.IsAttached)
            {
                return;
            }

            var timerEnabled = _timer.Enabled;

            _timer.Enabled = false;
            try
            {
                SecurityActivityQueue.HealthCheck();
                DataHandler.CleanupSecurityActivities();
            }
            catch (Exception ex) //logged
            {
                SnLog.WriteException(ex, EventMessage.Error.HealthCheck, EventId.RepositoryRuntime);
            }
            finally
            {
                _timer.Enabled = timerEnabled;
            }
        }
 internal static CompletionState GetCurrent()
 {
     return(SecurityActivityQueue.GetCurrentCompletionState());
 }