CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Dashboard.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="Dashboard.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Data portal dashboard</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections;
10using System.Collections.Concurrent;
11using System.Collections.Generic;
12using System.Linq;
13using System.Threading;
14
16{
20 public class Dashboard : IDashboard
21 {
22 private readonly object _syncLock = new object();
23 private ConcurrentQueue<InterceptArgs> _initializeQueue = new ConcurrentQueue<InterceptArgs>();
24 private ConcurrentQueue<InterceptArgs> _completeQueue = new ConcurrentQueue<InterceptArgs>();
25 private readonly Timer _timerInitialize;
26 private readonly Timer _timerComplete;
27 private ConcurrentQueue<Activity> _recentActivity = new ConcurrentQueue<Activity>();
28 private const int _timerDueTime = 50;
29 private const int _timerPeriod = 500;
30
34 public Dashboard()
35 {
36 _timerInitialize = new Timer(ProcessInitializeQueue, null, _timerDueTime, _timerPeriod);
37 _timerComplete = new Timer(ProcessCompleteQueue, null, _timerDueTime, _timerPeriod);
38 FirstCall = DateTimeOffset.Now;
39 }
40
45 public int RecentActivityCount { get; set; } = 100;
46
47 private void ProcessCompleteQueue(object state)
48 {
49 if (_completeQueue.IsEmpty)
50 return;
51
52 _timerComplete.Change(Timeout.Infinite, Timeout.Infinite);
53 try
54 {
55 while (_completeQueue.TryDequeue(out InterceptArgs result))
56 {
57 if (result.Exception != null)
58 Interlocked.Add(ref _failedCalls, 1);
59 else
60 Interlocked.Add(ref _completedCalls, 1);
61 _recentActivity.Enqueue(new Activity(result));
62 }
63 // trim list to most recent items
64 while (_recentActivity.Count > RecentActivityCount)
65 _recentActivity.TryDequeue(out Activity discard);
66 }
67 finally
68 {
69 _timerComplete.Change(_timerDueTime, _timerPeriod);
70 }
71 }
72
73 private void ProcessInitializeQueue(object state)
74 {
75 if (_initializeQueue.IsEmpty)
76 return;
77
78 _timerInitialize.Change(Timeout.Infinite, Timeout.Infinite);
79 try
80 {
81 while (_initializeQueue.TryDequeue(out InterceptArgs result))
82 {
83 Interlocked.Add(ref _totalCalls, 1);
84 }
85 }
86 finally
87 {
88 _timerInitialize.Change(_timerDueTime, _timerPeriod);
89 }
90 }
91
95 public DateTimeOffset FirstCall { get; private set; }
100 public DateTimeOffset LastCall { get; private set; }
101 private long _totalCalls;
106 public long TotalCalls
107 {
108 get { return Interlocked.Read(ref _totalCalls); }
109 }
110
111 private long _completedCalls;
116 public long CompletedCalls
117 {
118 get { return Interlocked.Read(ref _completedCalls); }
119 }
120
121 private long _failedCalls;
126 public long FailedCalls
127 {
128 get { return Interlocked.Read(ref _failedCalls); }
129 }
130
134 public List<Activity> GetRecentActivity()
135 {
136 return _recentActivity.ToList();
137 }
138
140 {
141 LastCall = DateTimeOffset.Now;
142 _initializeQueue.Enqueue(e);
143 }
144
145 void IDashboard.CompleteCall(InterceptArgs e)
146 {
147 _completeQueue.Enqueue(e);
148 }
149
153 public void Dispose()
154 {
155 _timerComplete.Dispose();
156 _timerInitialize.Dispose();
157 }
158 }
159}
Information about a server-side data portal invocation.
Definition: Activity.cs:10
Data portal server dashboard.
Definition: Dashboard.cs:21
List< Activity > GetRecentActivity()
Gets the items in the recent activity queue.
Definition: Dashboard.cs:134
long FailedCalls
Gets the number of times data portal calls have failed
Definition: Dashboard.cs:127
Dashboard()
Creates an instance of the type.
Definition: Dashboard.cs:34
void Dispose()
Dispose resources used by this object.
Definition: Dashboard.cs:153
DateTimeOffset LastCall
Gets the most recent time the data portal was invoked
Definition: Dashboard.cs:100
DateTimeOffset FirstCall
Gets the time the data portal was first invoked
Definition: Dashboard.cs:95
long CompletedCalls
Gets the number of times data portal calls have successfully completed
Definition: Dashboard.cs:117
int RecentActivityCount
Gets or sets a value indicating the number of items to maintain in the recent activity list.
Definition: Dashboard.cs:45
long TotalCalls
Gets the total number of times the data portal has been invoked
Definition: Dashboard.cs:107
Arguments parameter passed to the interceptor methods.
Data portal server dashboard.
Definition: IDashboard.cs:17
void InitializeCall(InterceptArgs e)
Called by the data portal to indicate a call has been inititalized.