blob: da585684888c7b0986e908428e5fa8993b8272ac (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Enumerations;
namespace Tango.Telemetry
{
public class TelemetryPublisherConfiguration
{
public String MachineID { get; set; }
public MachineTypes MachineType { get; set; }
public String Environment { get; set; }
public TimeSpan DiagnosticsSamplingInterval { get; set; }
public TimeSpan PendingStorageCheckInterval { get; set; }
public List<ITelemetryDestination> TelemetryDestinations { get; private set; }
public TelemetryPublisherConfiguration()
{
TelemetryDestinations = new List<ITelemetryDestination>();
DiagnosticsSamplingInterval = TimeSpan.FromSeconds(10);
PendingStorageCheckInterval = TimeSpan.FromMinutes(1);
}
public void Validate()
{
if (!MachineID.IsNotNullOrEmpty())
throw new ArgumentNullException(nameof(MachineID), "MachineID is not set or empty.");
if (!Environment.IsNotNullOrEmpty())
throw new ArgumentNullException(nameof(Environment), "Environment is not set or empty.");
if (!Enum.IsDefined(typeof(MachineTypes), MachineType))
throw new ArgumentOutOfRangeException(nameof(MachineType), "MachineType is not a valid enum value.");
if (DiagnosticsSamplingInterval.TotalSeconds < 1)
throw new ArgumentOutOfRangeException(nameof(DiagnosticsSamplingInterval), "DiagnosticsSamplingInterval must be at least 1 second.");
if (PendingStorageCheckInterval.TotalSeconds < 5)
throw new ArgumentOutOfRangeException(nameof(PendingStorageCheckInterval), "PendingStorageCheckInterval must be at least 5 seconds.");
if (TelemetryDestinations == null || TelemetryDestinations.Count == 0)
throw new InvalidOperationException("At least one telemetry destination must be provided.");
foreach (var destination in TelemetryDestinations)
{
if (destination == null)
throw new InvalidOperationException("Telemetry destination list contains a null entry.");
if (destination.SupportedSources == null || destination.SupportedSources.Count == 0)
throw new InvalidOperationException($"Telemetry destination '{destination.Name}' has no supported sources defined.");
}
}
}
}
|