-
Notifications
You must be signed in to change notification settings - Fork 2k
/
TelemetryConfiguration.cs
53 lines (45 loc) · 2.03 KB
/
TelemetryConfiguration.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Orleans.Runtime.Configuration
{
[Serializable]
public class TelemetryConfiguration
{
[Serializable]
public struct ConsumerConfiguration
{
public Type ConsumerType { get; set; }
/// <summary>
/// Configuration properties for this provider instance, as name-value pairs.
/// </summary>
public IReadOnlyDictionary<string, object> Properties { get; set; }
}
public IList<ConsumerConfiguration> Consumers { get; private set; } = new List<ConsumerConfiguration>();
public void Add(string typeName, string assemblyName, IEnumerable<KeyValuePair<string, object>> properties)
{
Assembly assembly = null;
try
{
var assemblyRef = new AssemblyName(assemblyName);
assembly = Assembly.Load(assemblyRef);
}
catch (Exception exc)
{
throw new TypeLoadException($"Cannot load TelemetryConsumer class {typeName} from assembly {assembly?.FullName ?? assemblyName} - Error={exc}");
}
var pluginType = assembly.GetType(typeName);
if (pluginType == null) throw new TypeLoadException($"Cannot locate plugin class {typeName} in assembly {assembly.FullName}");
if (!typeof(ITelemetryConsumer).IsAssignableFrom(pluginType)) throw new InvalidOperationException($"Telemetry consumer class {typeName} must implement one of {nameof(ITelemetryConsumer)} based interfaces");
var extendedProperties = properties?.ToDictionary(x => x.Key, x => x.Value);
Consumers.Add(new ConsumerConfiguration { ConsumerType = pluginType, Properties = extendedProperties });
}
public TelemetryConfiguration Clone()
{
var config = new TelemetryConfiguration();
config.Consumers = this.Consumers.ToList();
return config;
}
}
}