Skip to content

Commit 64418a9

Browse files
committed
wip
1 parent 5666911 commit 64418a9

8 files changed

+138
-35
lines changed

src/Entity/StringValue.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ internal StringValue(string name, string type, string? data)
7373
/// <type>
7474
/// Property
7575
/// </type>
76-
public bool IsNull { get => _ref == null; }
76+
public bool IsNull { get => _ref is null; }
7777

7878
/// <summary>
7979
/// Returns a self-reference to this object when its value is not null.
@@ -285,4 +285,23 @@ void ThrowIfNull()
285285
{
286286
return i.Value != other;
287287
}
288+
289+
/// <inheritdoc/>
290+
/// <nodocs/>
291+
public override bool Equals(object? obj)
292+
{
293+
if (ReferenceEquals(this, obj))
294+
{
295+
return true;
296+
}
297+
if (ReferenceEquals(obj, null))
298+
{
299+
return false;
300+
}
301+
if (obj is StringValue val)
302+
{
303+
return val.Value?.Equals(this.Value) == true;
304+
}
305+
return false;
306+
}
288307
}

src/Entity/StringValueCollection.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,23 @@ internal static StringValueCollection FromNameValueCollection(string paramName,
3030
{
3131
StringValueCollection vcol = new StringValueCollection(paramName);
3232

33-
foreach (string key in col.Keys)
33+
for (int i = 0; i < col.Keys.Count; i++)
3434
{
35-
vcol.items.Add(key, col[key]);
35+
string? keyValue = col.Keys[i];
36+
string? value;
37+
38+
if (keyValue is null)
39+
{
40+
value = col[i];
41+
if (value is null) continue;
42+
vcol.items.Add(value, "");
43+
}
44+
else
45+
{
46+
value = col[keyValue];
47+
vcol.items.Add(keyValue, value);
48+
}
3649
}
37-
3850
return vcol;
3951
}
4052

src/Http/Handlers/DefaultHttpServerHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ internal class DefaultHttpServerHandler : HttpServerHandler
1616
internal static Action<Router>? _routerSetup;
1717
internal static Action? _serverBootstraping;
1818

19-
public override void OnServerStarting(HttpServer server)
19+
protected override void OnServerStarting(HttpServer server)
2020
{
2121
base.OnServerStarting(server);
2222
if (_serverBootstraping != null) _serverBootstraping();
2323
}
2424

25-
public override void OnSetupRouter(Router router)
25+
protected override void OnSetupRouter(Router router)
2626
{
2727
base.OnSetupRouter(router);
2828
if (_routerSetup != null) _routerSetup(router);

src/Http/Handlers/HttpServerHandler.cs

+22-14
Original file line numberDiff line numberDiff line change
@@ -27,87 +27,95 @@ public abstract class HttpServerHandler
2727
/// </summary>
2828
/// <param name="server">The Http server entity which is starting.</param>
2929
/// <definition>
30-
/// public virtual void OnSetupHttpServer(HttpServer server)
30+
/// protected virtual void OnSetupHttpServer(HttpServer server)
3131
/// </definition>
3232
/// <type>
3333
/// Virtual method
3434
/// </type>
35-
public virtual void OnServerStarting(HttpServer server) { }
35+
protected virtual void OnServerStarting(HttpServer server) { }
36+
internal void InvokeOnServerStarting(HttpServer server) => OnServerStarting(server);
3637

3738
/// <summary>
3839
/// Method that is called immediately after starting the <see cref="HttpServer"/>, when it's
3940
/// ready and listening.
4041
/// </summary>
4142
/// <param name="server">The Http server entity which is ready.</param>
4243
/// <definition>
43-
/// public virtual void OnServerStarted(HttpServer server)
44+
/// protected virtual void OnServerStarted(HttpServer server)
4445
/// </definition>
4546
/// <type>
4647
/// Virtual method
4748
/// </type>
48-
public virtual void OnServerStarted(HttpServer server) { }
49+
protected virtual void OnServerStarted(HttpServer server) { }
50+
internal void InvokeOnServerStarted(HttpServer server) => OnServerStarted(server);
4951

5052
/// <summary>
5153
/// Method that is called when an <see cref="Router"/> is binded to the Http server.
5254
/// </summary>
5355
/// <param name="router">The router entity which is binded.</param>
5456
/// <definition>
55-
/// public virtual void OnSetupRouter(Router router)
57+
/// protected virtual void OnSetupRouter(Router router)
5658
/// </definition>
5759
/// <type>
5860
/// Virtual method
5961
/// </type>
60-
public virtual void OnSetupRouter(Router router) { }
62+
protected virtual void OnSetupRouter(Router router) { }
63+
64+
internal void InvokeOnSetupRouter(Router router) => OnSetupRouter(router);
6165

6266
/// <summary>
6367
/// Method that is called when an <see cref="HttpContextBagRepository"/> is created within an
6468
/// <see cref="HttpRequest"/> object.
6569
/// </summary>
6670
/// <param name="contextBag">The creating context bag.</param>
6771
/// <definition>
68-
/// public virtual void OnContextBagCreated(HttpContextBagRepository contextBag)
72+
/// protected virtual void OnContextBagCreated(HttpContextBagRepository contextBag)
6973
/// </definition>
7074
/// <type>
7175
/// Virtual method
7276
/// </type>
73-
public virtual void OnContextBagCreated(HttpContextBagRepository contextBag) { }
77+
protected virtual void OnContextBagCreated(HttpContextBagRepository contextBag) { }
78+
internal void InvokeOnContextBagCreated(HttpContextBagRepository contextBag) => OnContextBagCreated(contextBag);
7479

7580
/// <summary>
7681
/// Method that is called when an <see cref="HttpRequest"/> is received in the
7782
/// Http server.
7883
/// </summary>
7984
/// <param name="request">The connecting Http request entity.</param>
8085
/// <definition>
81-
/// public virtual void OnHttpRequestOpen(HttpRequest request)
86+
/// protected virtual void OnHttpRequestOpen(HttpRequest request)
8287
/// </definition>
8388
/// <type>
8489
/// Virtual method
8590
/// </type>
86-
public virtual void OnHttpRequestOpen(HttpRequest request) { }
91+
protected virtual void OnHttpRequestOpen(HttpRequest request) { }
92+
internal void InvokeOnHttpRequestOpen(HttpRequest request) => OnHttpRequestOpen(request);
8793

8894
/// <summary>
8995
/// Method that is called when an <see cref="HttpRequest"/> is closed in the
9096
/// Http server.
9197
/// </summary>
9298
/// <param name="result">The result of the execution of the request.</param>
9399
/// <definition>
94-
/// public virtual void OnHttpRequestClose(HttpServerExecutionResult result)
100+
/// protected virtual void OnHttpRequestClose(HttpServerExecutionResult result)
95101
/// </definition>
96102
/// <type>
97103
/// Virtual method
98104
/// </type>
99-
public virtual void OnHttpRequestClose(HttpServerExecutionResult result) { }
105+
protected virtual void OnHttpRequestClose(HttpServerExecutionResult result) { }
106+
internal void InvokeOnHttpRequestClose(HttpServerExecutionResult result) => OnHttpRequestClose(result);
100107

101108
/// <summary>
102109
/// Method that is called when an exception is caught in the Http server. This method is called
103110
/// regardless of whether <see cref="HttpServerConfiguration.ThrowExceptions"/> is enabled or not.
104111
/// </summary>
105112
/// <param name="exception">The exception object.</param>
106113
/// <definition>
107-
/// public virtual void OnException(Exception exception)
114+
/// protected virtual void OnException(Exception exception)
108115
/// </definition>
109116
/// <type>
110117
/// Virtual method
111118
/// </type>
112-
public virtual void OnException(Exception exception) { }
119+
protected virtual void OnException(Exception exception) { }
120+
internal void InvokeOnException(Exception exception) => OnException(exception);
113121
}

src/Http/Handlers/HttpServerHandlerRepository.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ private void CallEvery(Action<HttpServerHandler> action)
2626
action(handler);
2727
}
2828

29-
internal void ServerStarting(HttpServer val) => CallEvery(handler => handler.OnServerStarting(val));
30-
internal void ServerStarted(HttpServer val) => CallEvery(handler => handler.OnServerStarted(val));
31-
internal void SetupRouter(Router val) => CallEvery(handler => handler.OnSetupRouter(val));
32-
internal void ContextBagCreated(HttpContextBagRepository val) => CallEvery(handler => handler.OnContextBagCreated(val));
33-
internal void HttpRequestOpen(HttpRequest val) => CallEvery(handler => handler.OnHttpRequestOpen(val));
34-
internal void HttpRequestClose(HttpServerExecutionResult val) => CallEvery(handler => handler.OnHttpRequestClose(val));
35-
internal void Exception(Exception val) => CallEvery(handler => handler.OnException(val));
29+
internal void ServerStarting(HttpServer val) => CallEvery(handler => handler.InvokeOnServerStarting(val));
30+
internal void ServerStarted(HttpServer val) => CallEvery(handler => handler.InvokeOnServerStarted(val));
31+
internal void SetupRouter(Router val) => CallEvery(handler => handler.InvokeOnSetupRouter(val));
32+
internal void ContextBagCreated(HttpContextBagRepository val) => CallEvery(handler => handler.InvokeOnContextBagCreated(val));
33+
internal void HttpRequestOpen(HttpRequest val) => CallEvery(handler => handler.InvokeOnHttpRequestOpen(val));
34+
internal void HttpRequestClose(HttpServerExecutionResult val) => CallEvery(handler => handler.InvokeOnHttpRequestClose(val));
35+
internal void Exception(Exception val) => CallEvery(handler => handler.InvokeOnException(val));
3636
}

src/Http/Hosting/HttpServerHostContextBuilder.cs

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ internal HttpServerHostContextBuilder()
5858
_context = new HttpServerHostContext(server);
5959
}
6060

61+
/// <summary>
62+
/// Gets or sets the Server Configuration object.
63+
/// </summary>
64+
/// <definition>
65+
/// public HttpServerConfiguration ServerConfiguration { get; set; }
66+
/// </definition>
67+
/// <type>
68+
/// Property
69+
/// </type>
70+
public HttpServerConfiguration ServerConfiguration { get => _context.ServerConfiguration; set => value = _context.ServerConfiguration; }
71+
6172
/// <summary>
6273
/// Builds an <see cref="HttpServerHostContext"/> with the specified parameters.
6374
/// </summary>

src/Http/HttpContextBagRepository.cs

+28-2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ public bool IsSet<T>() where T : notnull
107107
return _values.ContainsKey(GetTypeKeyName(typeof(T)));
108108
}
109109

110+
/// <summary>
111+
/// Determines whether the specified <typeparamref name="T"/> singleton is defined in this context and tries to
112+
/// output it.
113+
/// </summary>
114+
/// <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
115+
/// <returns>true if the object is find with the specified key; otherwise, false.</returns>
116+
/// <typeparam name="T">The singleton type.</typeparam>
117+
/// <definition>
118+
/// public bool IsSet{{T}}([NotNullWhen(true)] out T value) where T : notnull
119+
/// </definition>
120+
/// <type>
121+
/// Method
122+
/// </type>
123+
public bool IsSet<T>([NotNullWhen(true)] out T? value) where T : notnull
124+
{
125+
return TryGetValue(GetTypeKeyName(typeof(T)), out value);
126+
}
127+
110128
/// <summary>
111129
/// Removes an singleton object from it's type <typeparamref name="T"/>.
112130
/// </summary>
@@ -269,8 +287,16 @@ public Boolean TryGetValue(String key, [MaybeNullWhen(false)] out Object? value)
269287
public Boolean TryGetValue<TResult>(String key, [MaybeNullWhen(false)] out TResult? value)
270288
{
271289
bool b = _values.TryGetValue(key, out Object? v);
272-
value = (TResult?)v;
273-
return b;
290+
if (b)
291+
{
292+
value = (TResult?)v;
293+
return true;
294+
}
295+
else
296+
{
297+
value = default;
298+
return false;
299+
}
274300
}
275301

276302
/// <inheritdoc />

src/Http/LogStream.cs

+33-6
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,16 @@ public RotatingLogPolicy RotatingPolicy
136136
/// </type>
137137
public Encoding Encoding { get; set; } = Encoding.UTF8;
138138

139-
private LogStream()
139+
/// <summary>
140+
/// Creates an new <see cref="LogStream"/> instance with no predefined outputs.
141+
/// </summary>
142+
/// <definition>
143+
/// public LogStream()
144+
/// </definition>
145+
/// <type>
146+
/// Constructor
147+
/// </type>
148+
public LogStream()
140149
{
141150
loggingThread = new Thread(new ThreadStart(ProcessQueue));
142151
loggingThread.IsBackground = true;
@@ -367,9 +376,9 @@ private void ProcessQueue()
367376
/// </type>
368377
public virtual void WriteException(Exception exp)
369378
{
370-
StringBuilder sexc = new StringBuilder();
371-
WriteExceptionInternal(sexc, exp, 0);
372-
WriteLine(sexc.ToString(), Array.Empty<object?>());
379+
StringBuilder excpStr = new StringBuilder();
380+
WriteExceptionInternal(excpStr, exp, 0);
381+
WriteLine(excpStr.ToString(), Array.Empty<object?>());
373382
}
374383

375384
/// <summary>
@@ -446,9 +455,26 @@ public void WriteLine(string message)
446455
/// </type>
447456
public virtual void WriteLine(string format, params object?[] args)
448457
{
458+
EnqueueMessageLine(string.Format(format, args));
459+
}
460+
461+
/// <summary>
462+
/// Represents the method that enqueues a message to the queue of messages to be written to output streams.
463+
/// </summary>
464+
/// <param name="message">The message which will be written.</param>
465+
/// <exception cref="ArgumentNullException">Thrown when the message is null.</exception>
466+
/// <definition>
467+
/// protected void EnqueueMessage(string message)
468+
/// </definition>
469+
/// <type>
470+
/// Method
471+
/// </type>
472+
protected void EnqueueMessageLine(string message)
473+
{
474+
ArgumentNullException.ThrowIfNull(message, nameof(message));
449475
lock (logQueue)
450476
{
451-
logQueue.Enqueue(string.Format(format, args));
477+
logQueue.Enqueue(message);
452478
setWatcher();
453479
}
454480
}
@@ -499,7 +525,7 @@ public void Dispose()
499525
/// <param name="maximumSize">The non-negative size threshold of the log file size in byte count.</param>
500526
/// <param name="dueTime">The time interval between checks.</param>
501527
/// <definition>
502-
/// public void Configure(long maximumSize, TimeSpan due)
528+
/// public void ConfigureRotatingPolicy(long maximumSize, TimeSpan due)
503529
/// </definition>
504530
/// <type>
505531
/// Method
@@ -509,6 +535,7 @@ public void ConfigureRotatingPolicy(long maximumSize, TimeSpan dueTime)
509535
var policy = RotatingPolicy;
510536
policy.Configure(maximumSize, dueTime);
511537
}
538+
512539
void WriteExceptionInternal(StringBuilder exceptionSbuilder, Exception exp, int currentDepth = 0)
513540
{
514541
if (currentDepth == 0)

0 commit comments

Comments
 (0)