Beispiel #1
0
        /// <summary>
        /// Calculates and returns a summary of each of the stored statistic types.
        /// </summary>
        public void GetSummary(out List <OperationRollup> operations, out List <OperationRollup> commands, out List <TaskStats> runningTasks, out List <TaskStats> completedTasks)
        {
            operations     = new List <OperationRollup>();
            commands       = new List <OperationRollup>();
            runningTasks   = new List <TaskStats>();
            completedTasks = new List <TaskStats>();

            try
            {
                lock (_rollupLock)
                {
                    foreach (string name in _operationRollups.Keys)
                    {
                        OperationRollup r = RollupRollups(_operationRollups[name], _lastSwap);
                        if (r != null)
                        {
                            operations.Add(r);
                        }
                    }
                    foreach (string name in _commandRollups.Keys)
                    {
                        OperationRollup r = RollupRollups(_commandRollups[name], _lastSwap);
                        if (r != null)
                        {
                            commands.Add(r);
                        }
                    }
                }
                lock (_taskLock)
                {
                    DateTime now         = DateTime.Now;
                    DateTime sixHoursAgo = now.Subtract(TimeSpan.FromHours(6));
                    while ((_completedTasks.Count > 0) && (_completedTasks[0].EndTime < sixHoursAgo))
                    {
                        _completedTasks.RemoveAt(0);
                    }
                    foreach (Guid id in _runningTasks.Keys)
                    {
                        TaskStats t = _runningTasks[id].Clone();
                        runningTasks.Add(t);
                    }
                    foreach (TaskStats tx in _completedTasks)
                    {
                        TaskStats t = tx.Clone();
                        completedTasks.Add(t);
                    }
                }
                operations     = operations.OrderBy(x => x.Name).ToList();
                commands       = commands.OrderBy(x => x.Name).ToList();
                runningTasks   = runningTasks.OrderBy(x => x.StartTime).ToList();
                completedTasks = completedTasks.OrderBy(x => x.StartTime).ToList();
            }
            catch (Exception ex)
            {
                if (_errorHandler != null)
                {
                    _errorHandler.LogError(ex);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates running task with new number of completed iterations.
        /// This number can be just the number of new iterations since the last update, or the total number of iterations since the task was started.
        /// </summary>
        public void UpdateTask(Guid id, long completedIterations, bool isTotal)
        {
            try
            {
                if (id == Guid.Empty)
                {
                    return;
                }

                lock (_taskLock)
                {
                    if (_runningTasks.ContainsKey(id))
                    {
                        TaskStats t = _runningTasks[id];
                        t.UpdateTask(completedIterations, isTotal);
                    }
                }
            }
            catch (Exception ex)
            {
                if (_errorHandler != null)
                {
                    _errorHandler.LogError(ex);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sets the total number of iterations after a task has been started, when the total isn't known until later.
        /// </summary>
        public void SetTaskIterations(Guid id, long totalIterations)
        {
            try
            {
                if (id == Guid.Empty)
                {
                    return;
                }

                lock (_taskLock)
                {
                    if (_runningTasks.ContainsKey(id))
                    {
                        TaskStats t = _runningTasks[id];
                        t.SetTotalIterations(totalIterations);
                    }
                }
            }
            catch (Exception ex)
            {
                if (_errorHandler != null)
                {
                    _errorHandler.LogError(ex);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Ends the specified task.
        /// </summary>
        public void EndTask(Guid id)
        {
            try
            {
                if (id == Guid.Empty)
                {
                    return;
                }

                TaskStats t = null;
                lock (_taskLock)
                {
                    if (_runningTasks.ContainsKey(id))
                    {
                        t = _runningTasks[id];
                        _runningTasks.Remove(id);
                    }

                    if (t != null)
                    {
                        t.EndTask();
                        _completedTasks.Add(t);
                        DateTime now         = DateTime.Now;
                        DateTime sixHoursAgo = now.Subtract(TimeSpan.FromHours(6));
                        while ((_completedTasks.Count > 0) && (_completedTasks[0].EndTime < sixHoursAgo))
                        {
                            _completedTasks.RemoveAt(0);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (_errorHandler != null)
                {
                    _errorHandler.LogError(ex);
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Starts a long running task and returns the task's ID.
 /// Task must be ended after completion.
 /// </summary>
 public Guid BeginTask(string name, long totalIterations)
 {
     try
     {
         var t = new TaskStats(name, totalIterations);
         lock (_taskLock)
         {
             if (!_runningTasks.ContainsKey(t.ID))
             {
                 _runningTasks.Add(t.ID, t);
             }
         }
         return(t.ID);
     }
     catch (Exception ex)
     {
         if (_errorHandler != null)
         {
             _errorHandler.LogError(ex);
         }
     }
     return(Guid.Empty);
 }
Beispiel #6
0
        /// <summary>
        /// Returns a clone of the current object.
        /// </summary>
        public TaskStats Clone()
        {
            TaskStats t = new TaskStats(_id, _name, _startTime, _endTime, _totalIterations, _completedIterations, _isComplete);

            return(t);
        }