Skip to content

Commit

Permalink
Reformats the code (#440)
Browse files Browse the repository at this point in the history
* Reformats the code

* Adds one more file
  • Loading branch information
waldekmastykarz authored Dec 19, 2023
1 parent f12b3cb commit ba462ba
Show file tree
Hide file tree
Showing 52 changed files with 2,652 additions and 2,240 deletions.
49 changes: 27 additions & 22 deletions dev-proxy-abstractions/BaseProxyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,34 @@

namespace Microsoft.DevProxy.Abstractions;

public abstract class BaseProxyPlugin: IProxyPlugin {
protected ISet<UrlToWatch>? _urlsToWatch;
protected ILogger? _logger;

public virtual string Name => throw new NotImplementedException();
public virtual void Register(IPluginEvents pluginEvents,
IProxyContext context,
ISet<UrlToWatch> urlsToWatch,
IConfigurationSection? configSection = null) {
if (pluginEvents is null) {
throw new ArgumentNullException(nameof(pluginEvents));
}
public abstract class BaseProxyPlugin : IProxyPlugin
{
protected ISet<UrlToWatch>? _urlsToWatch;
protected ILogger? _logger;

if (context is null || context.Logger is null) {
throw new ArgumentException($"{nameof(context)} must not be null and must supply a non-null Logger", nameof(context));

}
public virtual string Name => throw new NotImplementedException();
public virtual void Register(IPluginEvents pluginEvents,
IProxyContext context,
ISet<UrlToWatch> urlsToWatch,
IConfigurationSection? configSection = null)
{
if (pluginEvents is null)
{
throw new ArgumentNullException(nameof(pluginEvents));
}

if (urlsToWatch is null || urlsToWatch.Count == 0) {
throw new ArgumentException($"{nameof(urlsToWatch)} cannot be null or empty", nameof(urlsToWatch));
}
if (context is null || context.Logger is null)
{
throw new ArgumentException($"{nameof(context)} must not be null and must supply a non-null Logger", nameof(context));

_urlsToWatch = urlsToWatch;
_logger = context.Logger;
}
}

if (urlsToWatch is null || urlsToWatch.Count == 0)
{
throw new ArgumentException($"{nameof(urlsToWatch)} cannot be null or empty", nameof(urlsToWatch));
}

_urlsToWatch = urlsToWatch;
_logger = context.Logger;
}
}
30 changes: 15 additions & 15 deletions dev-proxy-abstractions/FuncExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ namespace Microsoft.DevProxy.Abstractions;

public static class FuncExtensions
{
internal static async Task InvokeAsync<T>(this AsyncEventHandler<T> callback, object sender, T args, ExceptionHandler? exceptionFunc)
{
var invocationList = callback.GetInvocationList();

foreach (var @delegate in invocationList)
await InternalInvokeAsync((AsyncEventHandler<T>)@delegate, sender, args, exceptionFunc);
}

private static async Task InternalInvokeAsync<T>(AsyncEventHandler<T> callback, object sender, T args, ExceptionHandler? exceptionFunc)
{
try
internal static async Task InvokeAsync<T>(this AsyncEventHandler<T> callback, object sender, T args, ExceptionHandler? exceptionFunc)
{
await callback(sender, args);
var invocationList = callback.GetInvocationList();

foreach (var @delegate in invocationList)
await InternalInvokeAsync((AsyncEventHandler<T>)@delegate, sender, args, exceptionFunc);
}
catch (Exception e)

private static async Task InternalInvokeAsync<T>(AsyncEventHandler<T> callback, object sender, T args, ExceptionHandler? exceptionFunc)
{
exceptionFunc?.Invoke(new Exception("Exception thrown in user event", e));
try
{
await callback(sender, args);
}
catch (Exception e)
{
exceptionFunc?.Invoke(new Exception("Exception thrown in user event", e));
}
}
}
}
6 changes: 4 additions & 2 deletions dev-proxy-abstractions/GraphBatchRequestPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

namespace Microsoft.DevProxy.Abstractions;

public class GraphBatchRequestPayload {
public class GraphBatchRequestPayload
{
[JsonPropertyName("requests")]
public GraphBatchRequestPayloadRequest[] Requests { get; set; } = Array.Empty<GraphBatchRequestPayloadRequest>();
}

public class GraphBatchRequestPayloadRequest {
public class GraphBatchRequestPayloadRequest
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("method")]
Expand Down
12 changes: 8 additions & 4 deletions dev-proxy-abstractions/GraphBatchResponsePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

namespace Microsoft.DevProxy.Abstractions;

public class GraphBatchResponsePayload {
public class GraphBatchResponsePayload
{
[JsonPropertyName("responses")]
public GraphBatchResponsePayloadResponse[] Responses { get; set; } = Array.Empty<GraphBatchResponsePayloadResponse>();
}

public class GraphBatchResponsePayloadResponse {
public class GraphBatchResponsePayloadResponse
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("status")]
Expand All @@ -21,12 +23,14 @@ public class GraphBatchResponsePayloadResponse {
public Dictionary<string, string>? Headers { get; set; }
}

public class GraphBatchResponsePayloadResponseBody {
public class GraphBatchResponsePayloadResponseBody
{
[JsonPropertyName("error")]
public GraphBatchResponsePayloadResponseBodyError? Error { get; set; }
}

public class GraphBatchResponsePayloadResponseBodyError {
public class GraphBatchResponsePayloadResponseBodyError
{
[JsonPropertyName("code")]
public string Code { get; set; } = string.Empty;
[JsonPropertyName("message")]
Expand Down
12 changes: 8 additions & 4 deletions dev-proxy-abstractions/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace Microsoft.DevProxy.Abstractions;

public enum MessageType {
public enum MessageType
{
Normal,
InterceptedRequest,
PassedThrough,
Expand All @@ -17,7 +18,8 @@ public enum MessageType {
InterceptedResponse
}

public class LoggingContext {
public class LoggingContext
{
public SessionEventArgs Session { get; }

public LoggingContext(SessionEventArgs session)
Expand All @@ -26,7 +28,8 @@ public LoggingContext(SessionEventArgs session)
}
}

public enum LogLevel {
public enum LogLevel
{
[EnumMember(Value = "debug")]
Debug,
[EnumMember(Value = "info")]
Expand All @@ -37,7 +40,8 @@ public enum LogLevel {
Error
}

public interface ILogger: ICloneable {
public interface ILogger : ICloneable
{
public LogLevel LogLevel { get; set; }

public void LogRequest(string[] message, MessageType messageType, LoggingContext? context = null);
Expand Down
6 changes: 4 additions & 2 deletions dev-proxy-abstractions/IProxyConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace Microsoft.DevProxy.Abstractions;

public enum LabelMode {
public enum LabelMode
{
[EnumMember(Value = "text")]
Text,
[EnumMember(Value = "icon")]
Expand All @@ -14,7 +15,8 @@ public enum LabelMode {
NerdFont
}

public interface IProxyConfiguration {
public interface IProxyConfiguration
{
int Port { get; }
string? IPAddress { get; }
LabelMode LabelMode { get; }
Expand Down
3 changes: 2 additions & 1 deletion dev-proxy-abstractions/IProxyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace Microsoft.DevProxy.Abstractions;

public interface IProxyPlugin {
public interface IProxyPlugin
{
string Name { get; }
void Register(IPluginEvents pluginEvents,
IProxyContext context,
Expand Down
Loading

0 comments on commit ba462ba

Please sign in to comment.