-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathIPlugin.cs
More file actions
111 lines (93 loc) · 4.82 KB
/
IPlugin.cs
File metadata and controls
111 lines (93 loc) · 4.82 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
99
100
101
102
103
104
105
106
107
108
109
110
111
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using DevProxy.Abstractions.Proxy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.CommandLine;
namespace DevProxy.Abstractions.Plugins;
/// <summary>
/// The interface that all plugins must implement.
/// </summary>
/// <remarks>We made it easy for you with the <see cref="BasePlugin"/></remarks>
public interface IPlugin
{
/// <summary>
/// Name of the plugin.
/// </summary>
string Name { get; }
/// <summary>
/// Whether the plugin is enabled or not.
/// </summary>
bool Enabled { get; }
Option[] GetOptions();
Command[] GetCommands();
/// <summary>
/// Called once after the plugin is constructed, but before any requests are handled.
/// </summary>
/// <param name="e"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task InitializeAsync(InitArgs e, CancellationToken cancellationToken);
/// <summary>
/// Handles the event triggered when options are successfully loaded.
/// </summary>
/// <param name="e">An <see cref="OptionsLoadedArgs"/> instance containing the event data, including the loaded options.</param>
void OptionsLoaded(OptionsLoadedArgs e);
/// <summary>
/// Implement this to handle requests.
/// </summary>
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
Func<RequestArguments, CancellationToken, Task<PluginResponse>>? OnRequestAsync { get; }
/// <summary>
/// Implement this to provide guidance for requests, you cannot modify the request or response here.
/// </summary>
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
Func<RequestArguments, CancellationToken, Task>? ProvideRequestGuidanceAsync { get; }
/// <summary>
/// Implement this to modify responses from the remote server.
/// </summary>
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
Func<ResponseArguments, CancellationToken, Task<PluginResponse?>>? OnResponseAsync { get; }
/// <summary>
/// Implement this to provide guidance based on responses from the remote server.
/// </summary>
/// <remarks>Think caching after the fact, combined with <see cref="OnRequestAsync"/>. This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
Func<ResponseArguments, CancellationToken, Task>? ProvideResponseGuidanceAsync { get; }
/// <summary>
/// Implement this to receive RequestLog messages for each <see cref="Microsoft.Extensions.Logging.ILoggerExtensions.LogRequest(Microsoft.Extensions.Logging.ILogger, string, MessageType, HttpRequestMessage)"/> call.
/// </summary>
Func<RequestLogArgs, CancellationToken, Task>? HandleRequestLogAsync { get; }
/// <summary>
/// Executes post-processing tasks after a recording has stopped.
/// </summary>
Func<RecordingArgs, CancellationToken, Task>? HandleRecordingStopAsync { get; }
/// <summary>
/// Receiving RequestLog messages for each <see cref="Microsoft.Extensions.Logging.ILoggerExtensions.LogRequest(Microsoft.Extensions.Logging.ILogger, string, MessageType, HttpRequestMessage)"/> call.
/// </summary>
/// <remarks>This is for collecting log messages not requests itself</remarks>
/// <param name="e"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
//Task AfterRequestLogAsync(RequestLogArgs e, CancellationToken cancellationToken);
/// <summary>
/// Executes post-processing tasks after a recording has stopped.
/// </summary>
/// <param name="e">The arguments containing details about the recording that has stopped.</param>
/// <param name="cancellationToken">A token to monitor for cancellation requests.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
//Task AfterRecordingStopAsync(RecordingArgs e, CancellationToken cancellationToken);
/// <summary>
///
/// </summary>
/// <param name="e"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task MockRequestAsync(EventArgs e, CancellationToken cancellationToken);
}
public interface IPlugin<TConfiguration> : IPlugin
{
TConfiguration Configuration { get; }
IConfigurationSection ConfigurationSection { get; }
void Register(IServiceCollection services, TConfiguration configuration);
}