forked from dotnet/dotnet-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassThroughAction.cs
84 lines (69 loc) · 2.95 KB
/
PassThroughAction.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Diagnostics.Monitoring.WebApi;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Diagnostics.Monitoring.TestCommon
{
internal sealed class PassThroughActionFactory : ICollectionRuleActionFactory<PassThroughOptions>
{
public ICollectionRuleAction Create(IProcessInfo processInfo, PassThroughOptions options)
{
return new PassThroughAction(options);
}
}
internal sealed class PassThroughAction : ICollectionRuleAction
{
private readonly PassThroughOptions _options;
private readonly TaskCompletionSource _startCompletionSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
public PassThroughAction(PassThroughOptions options)
{
_options = options;
}
public Task Started => _startCompletionSource.Task;
public Task StartAsync(CollectionRuleMetadata collectionRuleMetadata, CancellationToken token)
{
return StartAsync(token);
}
public Task StartAsync(CancellationToken token)
{
_startCompletionSource.TrySetResult();
return Task.CompletedTask;
}
public Task<CollectionRuleActionResult> WaitForCompletionAsync(CancellationToken token)
{
CollectionRuleActionResult result = new CollectionRuleActionResult() { OutputValues = new Dictionary<string, string>() };
result.OutputValues.Add("Output1", _options.Input1);
result.OutputValues.Add("Output2", _options.Input2);
result.OutputValues.Add("Output3", _options.Input3);
return Task.FromResult(result);
}
}
internal sealed class PassThroughActionDescriptor : ICollectionRuleActionDescriptor
{
public string ActionName => nameof(PassThroughAction);
public Type OptionsType => typeof(PassThroughOptions);
public Type FactoryType => typeof(PassThroughActionFactory);
public void BindOptions(IConfigurationSection settingsSection, out object settings)
{
PassThroughOptions options = new();
settingsSection.Bind(options);
settings = options;
}
}
internal sealed record class PassThroughOptions : BaseRecordOptions
{
[ActionOptionsDependencyProperty]
public string Input1 { get; set; }
[ActionOptionsDependencyProperty]
public string Input2 { get; set; }
[ActionOptionsDependencyProperty]
public string Input3 { get; set; }
}
}