|
@@ -10,11 +10,15 @@ using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using Vit.Core.Module.Log;
|
|
using Vit.Core.Module.Log;
|
|
using Vit.Extensions;
|
|
using Vit.Extensions;
|
|
|
|
+using Vit.Extensions.ObjectExt;
|
|
|
|
|
|
namespace Sers.Serslot
|
|
namespace Sers.Serslot
|
|
{
|
|
{
|
|
public class SerslotServer : IServer
|
|
public class SerslotServer : IServer
|
|
{
|
|
{
|
|
|
|
+ /// <summary>
|
|
|
|
+ ///
|
|
|
|
+ /// </summary>
|
|
public IServiceProvider serviceProvider { get; set; }
|
|
public IServiceProvider serviceProvider { get; set; }
|
|
|
|
|
|
#region PairingToken
|
|
#region PairingToken
|
|
@@ -57,6 +61,14 @@ namespace Sers.Serslot
|
|
var _responseFeature = new HttpResponseFeature() { Body = new MemoryStream() };
|
|
var _responseFeature = new HttpResponseFeature() { Body = new MemoryStream() };
|
|
features.Set<IHttpResponseFeature>(_responseFeature);
|
|
features.Set<IHttpResponseFeature>(_responseFeature);
|
|
|
|
|
|
|
|
+
|
|
|
|
+ //IHttpResponseBodyFeature
|
|
|
|
+ if (Type_IResponseBodyFeature != null)
|
|
|
|
+ {
|
|
|
|
+ features[Type_IResponseBodyFeature] = Activator.CreateInstance(Type_ResponseBodyFeature, _responseFeature.Body);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
OnProcessRequest(features);
|
|
OnProcessRequest(features);
|
|
|
|
|
|
return _responseFeature;
|
|
return _responseFeature;
|
|
@@ -65,6 +77,14 @@ namespace Sers.Serslot
|
|
#region SerslotResponseFeature
|
|
#region SerslotResponseFeature
|
|
class SerslotResponseFeature : IHttpResponseFeature
|
|
class SerslotResponseFeature : IHttpResponseFeature
|
|
{
|
|
{
|
|
|
|
+ public SerslotResponseFeature()
|
|
|
|
+ {
|
|
|
|
+ StatusCode = 200;
|
|
|
|
+ Headers = new HeaderDictionary();
|
|
|
|
+ Body = Stream.Null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
public int StatusCode
|
|
public int StatusCode
|
|
{
|
|
{
|
|
get;
|
|
get;
|
|
@@ -91,12 +111,7 @@ namespace Sers.Serslot
|
|
|
|
|
|
public virtual bool HasStarted { get; set; } = false;
|
|
public virtual bool HasStarted { get; set; } = false;
|
|
|
|
|
|
- public SerslotResponseFeature()
|
|
|
|
- {
|
|
|
|
- StatusCode = 200;
|
|
|
|
- Headers = new HeaderDictionary();
|
|
|
|
- Body = Stream.Null;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
private Stack<KeyValuePair<Func<object, Task>, object>> _onStarting;
|
|
private Stack<KeyValuePair<Func<object, Task>, object>> _onStarting;
|
|
@@ -110,7 +125,7 @@ namespace Sers.Serslot
|
|
{
|
|
{
|
|
if (HasStarted)
|
|
if (HasStarted)
|
|
{
|
|
{
|
|
- throw new InvalidOperationException(nameof(OnStarting));
|
|
|
|
|
|
+ throw new InvalidOperationException(nameof(OnStarting));
|
|
}
|
|
}
|
|
|
|
|
|
if (_onStarting == null)
|
|
if (_onStarting == null)
|
|
@@ -183,7 +198,7 @@ namespace Sers.Serslot
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
#region OnCompleted
|
|
#region OnCompleted
|
|
public virtual void OnCompleted(Func<object, Task> callback, object state)
|
|
public virtual void OnCompleted(Func<object, Task> callback, object state)
|
|
@@ -237,7 +252,9 @@ namespace Sers.Serslot
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
+ Type Type_IResponseBodyFeature = Vit.Core.Util.Reflection.ObjectLoader.GetType("Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature", assemblyName: "Microsoft.AspNetCore.Http.Features");
|
|
|
|
|
|
|
|
+ Type Type_ResponseBodyFeature = Vit.Core.Util.Reflection.ObjectLoader.GetType("Microsoft.AspNetCore.Http.StreamResponseBodyFeature", assemblyName: "Microsoft.AspNetCore.Http");
|
|
|
|
|
|
|
|
|
|
public IFeatureCollection Features { get; } = new FeatureCollection();
|
|
public IFeatureCollection Features { get; } = new FeatureCollection();
|
|
@@ -255,15 +272,27 @@ namespace Sers.Serslot
|
|
|
|
|
|
var httpContext = application.CreateContext(features);
|
|
var httpContext = application.CreateContext(features);
|
|
try
|
|
try
|
|
- {
|
|
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ //var httpContext_ = httpContext.GetProperty<object>("HttpContext");
|
|
|
|
+ //if (httpContext_ is Microsoft.AspNetCore.Http.HttpContext defaultHttpContext)
|
|
|
|
+ //{
|
|
|
|
+ // //if (defaultHttpContext.Response.Body == null)
|
|
|
|
+ // defaultHttpContext.Response.Body = features.Get<IHttpResponseFeature>().Body;
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
// Run the application code for this request
|
|
// Run the application code for this request
|
|
- application.ProcessRequestAsync(httpContext).GetAwaiter().GetResult();
|
|
|
|
|
|
+ // application.ProcessRequestAsync(httpContext).GetAwaiter().GetResult();
|
|
|
|
+ application.ProcessRequestAsync(httpContext).Wait();
|
|
|
|
+
|
|
|
|
|
|
//var _responseFeature = features.Get<IHttpResponseFeature>() as SerslotResponseFeature;
|
|
//var _responseFeature = features.Get<IHttpResponseFeature>() as SerslotResponseFeature;
|
|
//if (_responseFeature != null)
|
|
//if (_responseFeature != null)
|
|
//{
|
|
//{
|
|
// _responseFeature.FireOnStarting();
|
|
// _responseFeature.FireOnStarting();
|
|
-
|
|
|
|
// _responseFeature.FireOnCompleted();
|
|
// _responseFeature.FireOnCompleted();
|
|
//}
|
|
//}
|
|
}
|
|
}
|
|
@@ -281,7 +310,7 @@ namespace Sers.Serslot
|
|
|
|
|
|
#region (x.x.1) Init
|
|
#region (x.x.1) Init
|
|
ServiceStation.ServiceStation.Init();
|
|
ServiceStation.ServiceStation.Init();
|
|
- Sers.Core.Module.App.SersApplication.onStop += () =>
|
|
|
|
|
|
+ Sers.Core.Module.App.SersApplication.onStop += () =>
|
|
{
|
|
{
|
|
if (serviceProvider.GetService(typeof(IApplicationLifetime)) is IApplicationLifetime lifetime)
|
|
if (serviceProvider.GetService(typeof(IApplicationLifetime)) is IApplicationLifetime lifetime)
|
|
{
|
|
{
|
|
@@ -295,8 +324,8 @@ namespace Sers.Serslot
|
|
|
|
|
|
ServiceStation.ServiceStation.Instance.LoadApi();
|
|
ServiceStation.ServiceStation.Instance.LoadApi();
|
|
|
|
|
|
- ServiceStation.ServiceStation.Instance.localApiService.LoadSerslotApi(Assembly.GetEntryAssembly(),this);
|
|
|
|
-
|
|
|
|
|
|
+ ServiceStation.ServiceStation.Instance.localApiService.LoadSerslotApi(Assembly.GetEntryAssembly(), this);
|
|
|
|
+
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
@@ -326,7 +355,7 @@ namespace Sers.Serslot
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
Logger.Error(ex);
|
|
Logger.Error(ex);
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// Ungraceful shutdown
|
|
// Ungraceful shutdown
|
|
@@ -336,6 +365,6 @@ namespace Sers.Serslot
|
|
cancelledTokenSource.Cancel();
|
|
cancelledTokenSource.Cancel();
|
|
StopAsync(cancelledTokenSource.Token).GetAwaiter().GetResult();
|
|
StopAsync(cancelledTokenSource.Token).GetAwaiter().GetResult();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|