forked from Azure/azure-sdk-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathActiveMetadataModel.cs
More file actions
98 lines (83 loc) · 3.65 KB
/
ActiveMetadataModel.cs
File metadata and controls
98 lines (83 loc) · 3.65 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
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
using System.Collections.Generic;
using System.Linq;
using Azure.Sdk.Tools.TestProxy.Common;
using System.Collections.Concurrent;
using Azure.Sdk.Tools.TestProxy.Common.Exceptions;
namespace Azure.Sdk.Tools.TestProxy.Models
{
public class ActiveMetadataModel : RunTimeMetaDataModel
{
public ActiveMetadataModel(string recordingId)
{
RecordingId = recordingId;
}
public ActiveMetadataModel(RecordingHandler pageRecordingHandler)
{
Descriptions = _populateFromHandler(pageRecordingHandler, "");
}
public ActiveMetadataModel(RecordingHandler pageRecordingHandler, string recordingId)
{
RecordingId = recordingId;
Descriptions = _populateFromHandler(pageRecordingHandler, recordingId);
}
public string RecordingId { get; set; }
private List<ActionDescription> _populateFromHandler(RecordingHandler handler, string recordingId)
{
var transforms = (IEnumerable<ResponseTransform>) handler.Transforms;
var matcher = handler.Matcher;
List<ConcurrentDictionary<string, ModifiableRecordSession>> searchCollections = new List<ConcurrentDictionary<string, ModifiableRecordSession>>()
{
handler.PlaybackSessions,
handler.RecordingSessions,
handler.InMemorySessions
};
var sanitizers = handler.SanitizerRegistry.GetRegisteredSanitizers();
var recordingFound = false;
if (!string.IsNullOrWhiteSpace(recordingId)){
foreach (var sessionDict in searchCollections)
{
if (sessionDict.TryGetValue(recordingId, out var session))
{
sanitizers = handler.SanitizerRegistry.GetRegisteredSanitizers(session);
transforms = transforms.Concat(session.AdditionalTransforms);
if (session.CustomMatcher != null)
{
matcher = session.CustomMatcher;
}
recordingFound = true;
break;
}
}
if (!recordingFound)
{
throw new SessionNotActiveException($"{recordingId} is not found in any Playback, Recording, or In-Memory sessions.");
}
}
List<ActionDescription> descriptions = new List<ActionDescription>();
var docXML = GetDocCommentXML();
descriptions.AddRange(sanitizers.Select(x => new ActionDescription()
{
ActionType = MetaDataType.Sanitizer,
Name = x.Sanitizer.GetType().Name,
SanitizerId = x.Id,
ConstructorDetails = GetInstanceDetails(x.Sanitizer),
Description = GetClassDocComment(x.Sanitizer.GetType(), docXML)
}));
descriptions.AddRange(handler.Transforms.Select(x => new ActionDescription()
{
ActionType = MetaDataType.Transform,
Name = x.GetType().Name,
ConstructorDetails = GetInstanceDetails(x),
Description = GetClassDocComment(x.GetType(), docXML)
}));
descriptions.Add(new ActionDescription()
{
ActionType = MetaDataType.Matcher,
Name = matcher.GetType().Name,
ConstructorDetails = GetInstanceDetails(matcher),
Description = GetClassDocComment(matcher.GetType(), docXML)
});
return descriptions;
}
}
}