forked from SparkDevNetwork/Rock
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathExceptionLogsController.Partial.cs
132 lines (121 loc) · 4.63 KB
/
ExceptionLogsController.Partial.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// <copyright>
// Copyright by the Spark Development Network
//
// Licensed under the Rock Community License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.rockrms.com/license
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web.Http;
using Rock.Chart;
using Rock.Data;
using Rock.Rest.Filters;
namespace Rock.Rest.Controllers
{
/// <summary>
/// ExceptionLogs REST API
/// </summary>
public partial class ExceptionLogsController
{
/// <summary>
/// Gets the exceptions grouped by date.
/// </summary>
/// <returns></returns>
[Authenticate, Secured]
[System.Web.Http.Route( "api/ExceptionLogs/GetChartData" )]
[Rock.SystemGuid.RestActionGuid( "403444AE-0267-408A-B9A8-7E5D70AA594F" )]
[RockObsolete( "1.14.0" )]
[Obsolete( "This method is no longer used by the Exception List block." )]
public IEnumerable<IChartData> GetChartData()
{
// Load data into a List so we can so all the aggregate calculations in C# instead making the Database do it
var exceptionList = this.Get()
.Where( x => x.HasInnerException == false && x.CreatedDateTime != null ).Select( s => new
{
s.CreatedDateTime,
s.ExceptionType
} ).ToList();
var exceptionSummaryList = exceptionList.GroupBy( x => x.CreatedDateTime.Value.Date )
.Select( eg => new
{
DateValue = eg.Key,
ExceptionCount = eg.Count(),
UniqueExceptionCount = eg.Select( y => y.ExceptionType ).Distinct().Count()
} )
.OrderBy( eg => eg.DateValue ).ToList();
var allCountsQry = exceptionSummaryList.Select( c => new ExceptionChartData
{
DateTimeStamp = c.DateValue.ToJavascriptMilliseconds(),
YValue = c.ExceptionCount,
SeriesName = "Total Exceptions"
} );
var uniqueCountsQry = exceptionSummaryList.Select( c => new ExceptionChartData
{
DateTimeStamp = c.DateValue.ToJavascriptMilliseconds(),
YValue = c.UniqueExceptionCount,
SeriesName = "Unique Exceptions"
} );
var result = allCountsQry.Union( uniqueCountsQry );
return result;
}
/// <summary>
/// Logs the exception.
/// </summary>
/// <param name="ex">The ex.</param>
[Authenticate, Secured]
[System.Web.Http.Route( "api/ExceptionLogs/LogException" )]
[HttpPost]
[Rock.SystemGuid.RestActionGuid( "3BE0D16F-C372-4483-8A99-D5DE9278BD41" )]
public void LogException( Exception ex )
{
var personAlias = this.GetPersonAlias();
Rock.Model.ExceptionLogService.LogException( ex, System.Web.HttpContext.Current, null, null, personAlias );
}
/// <summary>
///
/// </summary>
public class ExceptionChartData : IChartData
{
/// <summary>
/// Gets the date time stamp.
/// </summary>
/// <value>
/// The date time stamp.
/// </value>
public long DateTimeStamp { get; set; }
/// <summary>
/// Gets the y value.
/// </summary>
/// <value>
/// The y value.
/// </value>
public decimal? YValue { get; set; }
/// <summary>
/// Gets or sets the name of the series. This will be the default name of the series if MetricValuePartitionEntityIds can't be resolved
/// </summary>
/// <value>
/// The name of the series.
/// </value>
public string SeriesName { get; set; }
/// <summary>
/// Gets the metric value partitions as a comma-delimited list of EntityTypeId|EntityId
/// </summary>
/// <value>
/// The metric value entityTypeId,EntityId partitions
/// </value>
public string MetricValuePartitionEntityIds { get; set; }
}
}
}