Skip to content

Commit e4ad26f

Browse files
committed
Reporters fixed
1 parent 874f437 commit e4ad26f

File tree

7 files changed

+34
-8
lines changed

7 files changed

+34
-8
lines changed

DevProxy.Abstractions/Plugins/BasePlugin.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.Extensions.Configuration;
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Microsoft.Extensions.Logging;
13-
using Unobtanium.Web.Proxy.Events;
1413

1514
namespace DevProxy.Abstractions.Plugins;
1615

@@ -27,16 +26,19 @@ public abstract class BasePlugin(
2726
/// <summary>
2827
/// Implement this to handle requests, if you won't be modifying requests or respond, use <see cref="OnRequestLogAsync"/>.
2928
/// </summary>
29+
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
3030
public virtual Func<RequestArguments, CancellationToken, Task<PluginResponse>>? OnRequestAsync { get; }
3131

3232
/// <summary>
3333
/// Implement this to log requests, you cannot modify the request or response here.
3434
/// </summary>
35+
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
3536
public virtual Func<RequestArguments, CancellationToken, Task>? OnRequestLogAsync { get; }
3637

3738
/// <summary>
3839
/// Implement this to modify responses from the remote server.
3940
/// </summary>
41+
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
4042
public virtual Func<ResponseArguments, CancellationToken, Task<PluginResponse?>>? OnResponseAsync { get; }
4143

4244
/// <summary>

DevProxy.Abstractions/Plugins/IPlugin.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,46 @@ public interface IPlugin
2323
/// <summary>
2424
/// Implement this to handle requests.
2525
/// </summary>
26+
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
2627
Func<RequestArguments, CancellationToken, Task<PluginResponse>>? OnRequestAsync { get; }
2728

2829
/// <summary>
2930
/// Implement this to log requests, you cannot modify the request or response here.
3031
/// </summary>
32+
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
3133
Func<RequestArguments, CancellationToken, Task>? OnRequestLogAsync { get; }
3234

3335
/// <summary>
3436
/// Implement this to modify responses from the remote server.
3537
/// </summary>
38+
/// <remarks>This is <see langword="null"/> by default, so we can filter plugins based on implementation.</remarks>
3639
Func<ResponseArguments, CancellationToken, Task<PluginResponse?>>? OnResponseAsync { get; }
3740

3841
/// <summary>
39-
/// Implement this to modify responses from the remote server.
42+
/// Implement this to log responses from the remote server.
4043
/// </summary>
44+
/// <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>
4145
Func<ResponseArguments, CancellationToken, Task>? OnResponseLogAsync { get; }
46+
4247
Task BeforeRequestAsync(ProxyRequestArgs e, CancellationToken cancellationToken);
4348
Task BeforeResponseAsync(ProxyResponseArgs e, CancellationToken cancellationToken);
4449
Task AfterResponseAsync(ProxyResponseArgs e, CancellationToken cancellationToken);
50+
51+
/// <summary>
52+
/// Receiving RequestLog messages for each <see cref="Microsoft.Extensions.Logging.ILoggerExtensions.LogRequest(Microsoft.Extensions.Logging.ILogger, string, MessageType, HttpRequestMessage)"/> call.
53+
/// </summary>
54+
/// <remarks>This is for collecting log messages not requests itself</remarks>
55+
/// <param name="e"></param>
56+
/// <param name="cancellationToken"></param>
57+
/// <returns></returns>
4558
Task AfterRequestLogAsync(RequestLogArgs e, CancellationToken cancellationToken);
59+
60+
/// <summary>
61+
/// Executes post-processing tasks after a recording has stopped.
62+
/// </summary>
63+
/// <param name="e">The arguments containing details about the recording that has stopped.</param>
64+
/// <param name="cancellationToken">A token to monitor for cancellation requests.</param>
65+
/// <returns>A task that represents the asynchronous operation.</returns>
4666
Task AfterRecordingStopAsync(RecordingArgs e, CancellationToken cancellationToken);
4767
Task MockRequestAsync(EventArgs e, CancellationToken cancellationToken);
4868
}

DevProxy.Abstractions/Proxy/ProxyEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private RequestLog(string message, MessageType messageType, string? method, stri
9898
//}
9999
}
100100

101-
public class RecordingArgs(IEnumerable<RequestLog> requestLogs) : ProxyEventArgsBase
101+
public class RecordingArgs(IEnumerable<RequestLog> requestLogs)// : ProxyEventArgsBase
102102
{
103103
public IEnumerable<RequestLog> RequestLogs { get; set; } = requestLogs ??
104104
throw new ArgumentNullException(nameof(requestLogs));

DevProxy.Plugins/Reporters/BaseReporter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace DevProxy.Plugins.Reporters;
1111

1212
public abstract class BaseReporter(
1313
ILogger logger,
14-
ISet<UrlToWatch> urlsToWatch) : BasePlugin(logger, urlsToWatch)
14+
ISet<UrlToWatch> urlsToWatch,
15+
IProxyStorage proxyStorage) : BasePlugin(logger, urlsToWatch)
1516
{
1617
public abstract string FileExtension { get; }
1718

@@ -23,7 +24,7 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation
2324

2425
await base.AfterRecordingStopAsync(e, cancellationToken);
2526

26-
if (!e.GlobalData.TryGetValue(ProxyUtils.ReportsKey, out var value) ||
27+
if (!proxyStorage.GlobalData.TryGetValue(ProxyUtils.ReportsKey, out var value) ||
2728
value is not Dictionary<string, object> reports ||
2829
reports.Count == 0)
2930
{

DevProxy.Plugins/Reporters/JsonReporter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace DevProxy.Plugins.Reporters;
1212

1313
public class JsonReporter(
1414
ILogger<JsonReporter> logger,
15-
ISet<UrlToWatch> urlsToWatch) : BaseReporter(logger, urlsToWatch)
15+
ISet<UrlToWatch> urlsToWatch,
16+
IProxyStorage proxyStorage) : BaseReporter(logger, urlsToWatch, proxyStorage)
1617
{
1718
private string _fileExtension = ".json";
1819

DevProxy.Plugins/Reporters/MarkdownReporter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace DevProxy.Plugins.Reporters;
1010

1111
public class MarkdownReporter(
1212
ILogger<MarkdownReporter> logger,
13-
ISet<UrlToWatch> urlsToWatch) : BaseReporter(logger, urlsToWatch)
13+
ISet<UrlToWatch> urlsToWatch,
14+
IProxyStorage proxyStorage) : BaseReporter(logger, urlsToWatch, proxyStorage)
1415
{
1516
public override string Name => nameof(MarkdownReporter);
1617
public override string FileExtension => ".md";

DevProxy.Plugins/Reporters/PlainTextReporter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace DevProxy.Plugins.Reporters;
1010

1111
public class PlainTextReporter(
1212
ILogger<PlainTextReporter> logger,
13-
ISet<UrlToWatch> urlsToWatch) : BaseReporter(logger, urlsToWatch)
13+
ISet<UrlToWatch> urlsToWatch,
14+
IProxyStorage proxyStorage) : BaseReporter(logger, urlsToWatch, proxyStorage)
1415
{
1516
public override string Name => nameof(PlainTextReporter);
1617
public override string FileExtension => ".txt";

0 commit comments

Comments
 (0)