Skip to content

Commit 95ae22a

Browse files
committed
revert IDE**** fixes
1 parent db0b9fa commit 95ae22a

17 files changed

+136
-115
lines changed

src/MicroBatchFramework.WebHosting/BatchEngineMiddleware.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ public override string ToString()
8989

9090
public class BatchEngineMiddleware
9191
{
92-
private readonly RequestDelegate next;
93-
private readonly IServiceProvider provider;
94-
private readonly ILogger<BatchEngine> logger;
95-
private readonly IBatchInterceptor interceptor;
92+
readonly RequestDelegate next;
93+
readonly IServiceProvider provider;
94+
readonly ILogger<BatchEngine> logger;
95+
readonly IBatchInterceptor interceptor;
9696

97-
private readonly Dictionary<string, MethodInfo> methodLookup;
97+
readonly Dictionary<string, MethodInfo> methodLookup;
9898

9999
public BatchEngineMiddleware(RequestDelegate next, ILogger<BatchEngine> logger, IBatchInterceptor interceptor, IServiceProvider provider, TargetBatchTypeCollection targetTypes)
100100
{
@@ -115,7 +115,7 @@ public async Task Invoke(HttpContext httpContext)
115115
}
116116

117117
// create args
118-
string[] args;
118+
string[] args = null;
119119
try
120120
{
121121
if (httpContext.Request.HasFormContentType)

src/MicroBatchFramework.WebHosting/BatchEngineSwaggerMiddleware.cs

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ namespace MicroBatchFramework.WebHosting
99
{
1010
public class BatchEngineSwaggerMiddleware
1111
{
12-
private readonly RequestDelegate next;
13-
private readonly MethodInfo[] handlers;
14-
private readonly SwaggerOptions options;
12+
static readonly Task EmptyTask = Task.FromResult(0);
13+
14+
readonly RequestDelegate next;
15+
readonly MethodInfo[] handlers;
16+
readonly SwaggerOptions options;
1517

1618
public BatchEngineSwaggerMiddleware(RequestDelegate next, TargetBatchTypeCollection targetTypes, SwaggerOptions options)
1719
{
@@ -42,69 +44,86 @@ public async Task Invoke(HttpContext httpContext)
4244

4345
var myAssembly = typeof(BatchEngineSwaggerMiddleware).GetTypeInfo().Assembly;
4446

45-
using var stream = myAssembly.GetManifestResourceStream(filePath);
46-
if (options.ResolveCustomResource == null)
47+
using (var stream = myAssembly.GetManifestResourceStream(filePath))
4748
{
48-
if (stream == null)
49+
if (options.ResolveCustomResource == null)
4950
{
50-
// not found, standard request.
51-
await next(httpContext);
52-
return;
53-
}
51+
if (stream == null)
52+
{
53+
// not found, standard request.
54+
await next(httpContext);
55+
return;
56+
}
5457

55-
httpContext.Response.Headers["Content-Type"] = new[] { mediaType };
56-
httpContext.Response.StatusCode = 200;
57-
var response = httpContext.Response.Body;
58-
await stream.CopyToAsync(response);
59-
}
60-
else
61-
{
62-
byte[] bytes;
63-
if (stream == null)
64-
{
65-
bytes = options.ResolveCustomResource(path, null);
58+
httpContext.Response.Headers["Content-Type"] = new[] { mediaType };
59+
httpContext.Response.StatusCode = 200;
60+
var response = httpContext.Response.Body;
61+
await stream.CopyToAsync(response);
6662
}
6763
else
6864
{
69-
using var ms = new MemoryStream();
70-
await stream.CopyToAsync(ms);
71-
bytes = options.ResolveCustomResource(path, ms.ToArray());
72-
}
65+
byte[] bytes;
66+
if (stream == null)
67+
{
68+
bytes = options.ResolveCustomResource(path, null);
69+
}
70+
else
71+
{
72+
using (var ms = new MemoryStream())
73+
{
74+
await stream.CopyToAsync(ms);
75+
bytes = options.ResolveCustomResource(path, ms.ToArray());
76+
}
77+
}
7378

74-
if (bytes == null)
75-
{
76-
// not found, standard request.
77-
await next(httpContext);
78-
return;
79-
}
79+
if (bytes == null)
80+
{
81+
// not found, standard request.
82+
await next(httpContext);
83+
return;
84+
}
8085

81-
httpContext.Response.Headers["Content-Type"] = new[] { mediaType };
82-
httpContext.Response.StatusCode = 200;
83-
var response = httpContext.Response.Body;
84-
await response.WriteAsync(bytes, 0, bytes.Length);
86+
httpContext.Response.Headers["Content-Type"] = new[] { mediaType };
87+
httpContext.Response.StatusCode = 200;
88+
var response = httpContext.Response.Body;
89+
await response.WriteAsync(bytes, 0, bytes.Length);
90+
}
8591
}
8692
}
8793

88-
private static string GetMediaType(string path)
94+
static string GetMediaType(string path)
8995
{
9096
var extension = path.Split('.').Last();
9197

92-
return extension switch
98+
switch (extension)
9399
{
94-
"css" => "text/css",
95-
"js" => "text/javascript",
96-
"json" => "application/json",
97-
"gif" => "image/gif",
98-
"png" => "image/png",
99-
"eot" => "application/vnd.ms-fontobject",
100-
"woff" => "application/font-woff",
101-
"woff2" => "application/font-woff2",
102-
"otf" => "application/font-sfnt",
103-
"ttf" => "application/font-sfnt",
104-
"svg" => "image/svg+xml",
105-
"ico" => "image/x-icon",
106-
_ => "text/html",
107-
};
100+
case "css":
101+
return "text/css";
102+
case "js":
103+
return "text/javascript";
104+
case "json":
105+
return "application/json";
106+
case "gif":
107+
return "image/gif";
108+
case "png":
109+
return "image/png";
110+
case "eot":
111+
return "application/vnd.ms-fontobject";
112+
case "woff":
113+
return "application/font-woff";
114+
case "woff2":
115+
return "application/font-woff2";
116+
case "otf":
117+
return "application/font-sfnt";
118+
case "ttf":
119+
return "application/font-sfnt";
120+
case "svg":
121+
return "image/svg+xml";
122+
case "ico":
123+
return "image/x-icon";
124+
default:
125+
return "text/html";
126+
}
108127
}
109128
}
110129
}

src/MicroBatchFramework.WebHosting/Swagger/SwaggerDefinitionBuilder.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ namespace MicroBatchFramework.WebHosting.Swagger
1616
{
1717
public class SwaggerDefinitionBuilder
1818
{
19-
private readonly SwaggerOptions options;
20-
private readonly HttpContext httpContext;
21-
private readonly IEnumerable<MethodInfo> handlers;
19+
readonly SwaggerOptions options;
20+
readonly HttpContext httpContext;
21+
readonly IEnumerable<MethodInfo> handlers;
2222

23-
private ILookup<Tuple<string, string>, XmlCommentStructure> xDocLookup;
23+
ILookup<Tuple<string, string>, XmlCommentStructure> xDocLookup;
2424

2525
public SwaggerDefinitionBuilder(SwaggerOptions options, HttpContext httpContext, IEnumerable<MethodInfo> handlers)
2626
{
@@ -44,15 +44,13 @@ public byte[] BuildSwaggerJson()
4444
: null;
4545
}
4646

47-
var doc = new SwaggerDocument
48-
{
49-
info = options.Info,
50-
host = (options.CustomHost != null) ? options.CustomHost(httpContext) : httpContext.Request.Headers["Host"][0],
51-
basePath = options.ApiBasePath,
52-
schemes = (options.ForceSchemas.Length == 0) ? new[] { httpContext.Request.IsHttps ? "https" : httpContext.Request.Scheme } : options.ForceSchemas,
53-
paths = new Dictionary<string, PathItem>(),
54-
definitions = new Dictionary<string, Schema>()
55-
};
47+
var doc = new SwaggerDocument();
48+
doc.info = options.Info;
49+
doc.host = (options.CustomHost != null) ? options.CustomHost(httpContext) : httpContext.Request.Headers["Host"][0];
50+
doc.basePath = options.ApiBasePath;
51+
doc.schemes = (options.ForceSchemas.Length == 0) ? new[] { httpContext.Request.IsHttps ? "https" : httpContext.Request.Scheme } : options.ForceSchemas;
52+
doc.paths = new Dictionary<string, PathItem>();
53+
doc.definitions = new Dictionary<string, Schema>();
5654

5755
// tags.
5856
var xmlServiceName = (xDocLookup != null)
@@ -105,17 +103,19 @@ public byte[] BuildSwaggerJson()
105103
doc.paths.Add("/" + declaringTypeName + "/" + item.Name, new PathItem { post = operation }); // everything post.
106104
}
107105

108-
using var ms = new MemoryStream();
109-
using var sw = new StreamWriter(ms, new UTF8Encoding(false));
110-
var serializer = new JsonSerializer()
106+
using (var ms = new MemoryStream())
107+
using (var sw = new StreamWriter(ms, new UTF8Encoding(false)))
111108
{
112-
NullValueHandling = NullValueHandling.Ignore,
113-
ContractResolver = IgnoreEmptyEnumerablesResolver.Instance // omit empty collection.
114-
};
115-
serializer.Serialize(sw, doc);
109+
var serializer = new JsonSerializer()
110+
{
111+
NullValueHandling = NullValueHandling.Ignore,
112+
ContractResolver = IgnoreEmptyEnumerablesResolver.Instance // omit empty collection.
113+
};
114+
serializer.Serialize(sw, doc);
116115

117-
sw.Flush();
118-
return ms.ToArray();
116+
sw.Flush();
117+
return ms.ToArray();
118+
}
119119
}
120120
catch (Exception ex)
121121
{
@@ -203,7 +203,8 @@ string BuildSchema(IDictionary<string, Schema> definitions, Type type)
203203
var fullName = type.FullName;
204204
if (fullName == null) return ""; // safety(TODO:IDictionary<> is not supported)
205205

206-
if (definitions.TryGetValue(fullName, out Schema schema)) return "#/definitions/" + fullName;
206+
Schema schema;
207+
if (definitions.TryGetValue(fullName, out schema)) return "#/definitions/" + fullName;
207208

208209
var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
209210
var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

src/MicroBatchFramework.WebHosting/Swagger/SwaggerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace MicroBatchFramework.WebHosting.Swagger
66
{
77
public class SwaggerOptions
88
{
9-
public string ApiBasePath { get; }
9+
public string ApiBasePath { get; private set; }
1010
public Info Info { get; set; }
1111

1212
/// <summary>

src/MicroBatchFramework.WebHosting/TargetBatchTypeCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace MicroBatchFramework.WebHosting
66
{
77
public class TargetBatchTypeCollection : IEnumerable<Type>
88
{
9-
private readonly IEnumerable<Type> types;
9+
readonly IEnumerable<Type> types;
1010

1111
public TargetBatchTypeCollection(IEnumerable<Type> types)
1212
{

src/MicroBatchFramework/BatchContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace MicroBatchFramework
66
{
77
public class BatchContext
88
{
9-
public string[] Arguments { get; }
10-
public DateTime Timestamp { get; }
11-
public CancellationToken CancellationToken { get; }
12-
public ILogger<BatchEngine> Logger { get; }
9+
public string[] Arguments { get; private set; }
10+
public DateTime Timestamp { get; private set; }
11+
public CancellationToken CancellationToken { get; private set; }
12+
public ILogger<BatchEngine> Logger { get; private set; }
1313

1414
public BatchContext(string[] arguments, DateTime timestamp, CancellationToken cancellationToken, ILogger<BatchEngine> logger)
1515
{

src/MicroBatchFramework/BatchEngine.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ namespace MicroBatchFramework
1313
{
1414
public class BatchEngine
1515
{
16-
private readonly ILogger<BatchEngine> logger;
17-
private readonly IServiceProvider provider;
18-
private readonly IBatchInterceptor interceptor;
19-
private readonly CancellationToken cancellationToken;
16+
readonly ILogger<BatchEngine> logger;
17+
readonly IServiceProvider provider;
18+
readonly IBatchInterceptor interceptor;
19+
readonly CancellationToken cancellationToken;
2020

2121
public BatchEngine(ILogger<BatchEngine> logger, IServiceProvider provider, IBatchInterceptor interceptor, CancellationToken cancellationToken)
2222
{
@@ -118,8 +118,9 @@ public async Task RunAsync(Type type, string[] args)
118118

119119
async Task RunCore(BatchContext ctx, Type type, MethodInfo methodInfo, string[] args, int argsOffset)
120120
{
121-
object instance;
122-
object[] invokeArgs;
121+
object instance = null;
122+
object[] invokeArgs = null;
123+
123124
try
124125
{
125126
if (!TryGetInvokeArguments(methodInfo.GetParameters(), args, argsOffset, out invokeArgs, out var errorMessage))

src/MicroBatchFramework/BatchEngineHostBuilderExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace MicroBatchFramework
1010
{
1111
public static class BatchEngineHostBuilderExtensions
1212
{
13-
private const string ListCommand = "list";
14-
private const string HelpCommand = "help";
13+
const string ListCommand = "list";
14+
const string HelpCommand = "help";
1515

1616
public static IHostBuilder UseBatchEngine(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null)
1717
{
@@ -153,7 +153,7 @@ public static Task RunBatchEngineAsync<T>(this IHostBuilder hostBuilder, string[
153153
return UseBatchEngine<T>(hostBuilder, args, interceptor).Build().RunAsync();
154154
}
155155

156-
private static void ShowMethodList()
156+
static void ShowMethodList()
157157
{
158158
Console.WriteLine("list of methods:");
159159
var list = GetBatchTypes();
@@ -166,7 +166,7 @@ private static void ShowMethodList()
166166
}
167167
}
168168

169-
private static List<Type> GetBatchTypes()
169+
static List<Type> GetBatchTypes()
170170
{
171171
List<Type> batchBaseTypes = new List<Type>();
172172

@@ -196,7 +196,7 @@ private static List<Type> GetBatchTypes()
196196
return batchBaseTypes;
197197
}
198198

199-
private static (Type, MethodInfo) GetTypeFromAssemblies(string arg0)
199+
static (Type, MethodInfo) GetTypeFromAssemblies(string arg0)
200200
{
201201
var batchBaseTypes = GetBatchTypes();
202202
if (batchBaseTypes == null)

src/MicroBatchFramework/BatchEngineService.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ namespace MicroBatchFramework
99
{
1010
public sealed class BatchEngineService : IHostedService
1111
{
12-
private readonly string[] args;
13-
private readonly Type type;
14-
private readonly MethodInfo methodInfo;
15-
private readonly IApplicationLifetime appLifetime;
16-
private readonly ILogger<BatchEngine> logger;
17-
private readonly IServiceProvider provider;
18-
private readonly IBatchInterceptor interceptor;
19-
private Task runningTask;
20-
private readonly CancellationTokenSource cancellationTokenSource;
12+
string[] args;
13+
Type type;
14+
MethodInfo methodInfo;
15+
IApplicationLifetime appLifetime;
16+
ILogger<BatchEngine> logger;
17+
IServiceProvider provider;
18+
IBatchInterceptor interceptor;
19+
Task runningTask;
20+
CancellationTokenSource cancellationTokenSource;
2121

2222
public BatchEngineService(IApplicationLifetime appLifetime, Type type, string[] args, ILogger<BatchEngine> logger, IServiceProvider provider)
2323
: this(appLifetime, type, null, args, logger, provider)

src/MicroBatchFramework/CompositeBatchInterceptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace MicroBatchFramework
99
{
1010
public class CompositeBatchInterceptor : IBatchInterceptor
1111
{
12-
private readonly IBatchInterceptor[] interceptors;
12+
readonly IBatchInterceptor[] interceptors;
1313

1414
public CompositeBatchInterceptor(params IBatchInterceptor[] interceptors)
1515
{
@@ -87,7 +87,7 @@ public async ValueTask OnBatchRunCompleteAsync(BatchContext context, string erro
8787

8888
internal struct AggregateExceptionHolder
8989
{
90-
private List<ExceptionDispatchInfo> exceptions;
90+
List<ExceptionDispatchInfo> exceptions;
9191

9292
public void Add(Exception ex)
9393
{

0 commit comments

Comments
 (0)