Repository navigation
Expand file tree
/
Copy pathApplication.cs
More file actions
60 lines (51 loc) · 1.92 KB
/
Copy pathApplication.cs
File metadata and controls
60 lines (51 loc) · 1.92 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Opserver.Data.Exceptions
{
/// <summary>
/// Represents an application and its store location
/// </summary>
public class Application
{
public string Name { get; internal set; }
public string StoreName { get; internal set; }
public ExceptionStore Store { get; internal set; }
public int ExceptionCount { get; internal set; }
public int RecentExceptionCount { get; internal set; }
public DateTime? MostRecent { get; internal set; }
private static readonly Regex _shortLogStripRegex = new Regex(@"[^A-Za-z_0-9_\-_\.\/]", RegexOptions.Compiled);
private string _shortName;
public string ShortName => _shortName ??= _shortLogStripRegex.Replace(Name, "");
public JSONApplication ToJSON()
{
return new JSONApplication
{
Name = Name,
ExceptionCount = ExceptionCount,
MostRecent = MostRecent?.ToRelativeTime()
};
}
public void ClearCounts()
{
ExceptionCount = 0;
RecentExceptionCount = 0;
MostRecent = null;
}
}
public class ApplicationGroup
{
public string Name { get; internal set; }
public List<Application> Applications { get; internal set; } = new List<Application>();
public int Total => Applications.Sum(a => a.ExceptionCount);
public Application this[string name] =>
Applications.Find(a => a.Name == name) ?? Applications.Find(a => a.ShortName == name);
}
public class JSONApplication
{
public string Name { get; internal set; }
public int ExceptionCount { get; internal set; }
public string MostRecent { get; internal set; }
}
}