本文整理汇总了C#中FeatureCollection.Set方法的典型用法代码示例。如果您正苦于以下问题:C# FeatureCollection.Set方法的具体用法?C# FeatureCollection.Set怎么用?C# FeatureCollection.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FeatureCollection
的用法示例。
在下文中一共展示了FeatureCollection.Set方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateServer
public IServer CreateServer(IConfiguration configuration)
{
var information = new KestrelServerInformation(configuration);
var serverFeatures = new FeatureCollection();
serverFeatures.Set<IKestrelServerInformation>(information);
serverFeatures.Set<IServerAddressesFeature>(information);
return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"));
}
示例2: CreateServer
public IServer CreateServer(IConfiguration configuration)
{
var information = new ServerInformation(configuration);
var serverFeatures = new FeatureCollection();
serverFeatures.Set<IServerInformation>(information);
serverFeatures.Set<IServerAddressesFeature>(information);
return new Server(serverFeatures, _appLifetime, _loggerFactory.CreateLogger(Server.ConfigServerAssembly));
}
示例3: Initialize
public IFeatureCollection Initialize(IConfiguration configuration)
{
var information = new KestrelServerInformation();
information.Initialize(configuration);
var serverFeatures = new FeatureCollection();
serverFeatures.Set<IKestrelServerInformation>(information);
serverFeatures.Set<IServerAddressesFeature>(information);
return serverFeatures;
}
示例4: CreateServer
public IServer CreateServer(IConfiguration configuration)
{
var information = new RioSharpServerInformation();
information.Initialize(configuration);
var serverFeatures = new FeatureCollection();
serverFeatures.Set<IRioSharpServerInformation>(information);
serverFeatures.Set<IServerAddressesFeature>(information);
return new RioSharpServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("RioSharp.Aspnet"), _httpContextFactory);
}
示例5: Initialize
public IFeatureCollection Initialize(IConfiguration configuration)
{
// TODO: Parse config
var builder = ServerBuilder.New()
.SetAddress(IPAddress.Any)
.SetPort(configuration["port"] != null ? Int32.Parse(configuration["port"]) : 8080)
.SetOwinApp(OwinWebSocketAcceptAdapter.AdaptWebSockets(HandleRequest));
var serverFeatures = new FeatureCollection();
serverFeatures.Set<NowinServerInformation>(new NowinServerInformation(builder));
return serverFeatures;
}
示例6: Initialize
public IFeatureCollection Initialize(IConfiguration configuration)
{
var builder = ServerBuilder.New()
.SetAddress(IPAddress.Any)
.SetPort(5000)
.SetOwinApp(HandleRequest);
var serverFeatures = new FeatureCollection();
serverFeatures.Set<INowinServerInformation>(new NowinServerInformation(builder));
return serverFeatures;
}
示例7: CreateServer
private static KestrelServer CreateServer(Func<IConfiguration, IKestrelServerInformation> serverInformationFactory)
{
var configuration = new ConfigurationBuilder().Build();
var information = serverInformationFactory(configuration);
var features = new FeatureCollection();
features.Set(information);
var lifetime = new LifetimeNotImplemented();
var logger = new TestKestrelTrace.TestLogger();
return new KestrelServer(features, lifetime, logger);
}
示例8: Initialize
public IFeatureCollection Initialize(IConfiguration configuration)
{
var features = new FeatureCollection();
features.Set<IServerAddressesFeature>(new ServerAddressesFeature());
return features;
}
示例9: RequestState
public RequestState(Uri uri, PathString pathBase, CancellationToken cancellationToken, IHttpApplication<Context> application)
{
_clientWebSocketTcs = new TaskCompletionSource<WebSocket>();
_application = application;
// HttpContext
var contextFeatures = new FeatureCollection();
contextFeatures.Set<IHttpRequestFeature>(new RequestFeature());
contextFeatures.Set<IHttpResponseFeature>(new ResponseFeature());
Context = _application.CreateContext(contextFeatures);
var httpContext = Context.HttpContext;
// Request
var request = httpContext.Request;
request.Protocol = "HTTP/1.1";
var scheme = uri.Scheme;
scheme = (scheme == "ws") ? "http" : scheme;
scheme = (scheme == "wss") ? "https" : scheme;
request.Scheme = scheme;
request.Method = "GET";
var fullPath = PathString.FromUriComponent(uri);
PathString remainder;
if (fullPath.StartsWithSegments(pathBase, out remainder))
{
request.PathBase = pathBase;
request.Path = remainder;
}
else
{
request.PathBase = PathString.Empty;
request.Path = fullPath;
}
request.QueryString = QueryString.FromUriComponent(uri);
request.Headers.Add("Connection", new string[] { "Upgrade" });
request.Headers.Add("Upgrade", new string[] { "websocket" });
request.Headers.Add("Sec-WebSocket-Version", new string[] { "13" });
request.Headers.Add("Sec-WebSocket-Key", new string[] { CreateRequestKey() });
request.Body = Stream.Null;
// Response
var response = httpContext.Response;
response.Body = Stream.Null;
response.StatusCode = 200;
// WebSocket
httpContext.Features.Set<IHttpWebSocketFeature>(this);
}
示例10: RequestState
internal RequestState(HttpRequestMessage request, PathString pathBase, IHttpApplication<Context> application)
{
_request = request;
_application = application;
_responseTcs = new TaskCompletionSource<HttpResponseMessage>();
_requestAbortedSource = new CancellationTokenSource();
_pipelineFinished = false;
if (request.RequestUri.IsDefaultPort)
{
request.Headers.Host = request.RequestUri.Host;
}
else
{
request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped);
}
var contextFeatures = new FeatureCollection();
contextFeatures.Set<IHttpRequestFeature>(new RequestFeature());
_responseFeature = new ResponseFeature();
contextFeatures.Set<IHttpResponseFeature>(_responseFeature);
Context = application.CreateContext(contextFeatures);
var httpContext = Context.HttpContext;
var serverRequest = httpContext.Request;
serverRequest.Protocol = "HTTP/" + request.Version.ToString(2);
serverRequest.Scheme = request.RequestUri.Scheme;
serverRequest.Method = request.Method.ToString();
var fullPath = PathString.FromUriComponent(request.RequestUri);
PathString remainder;
if (fullPath.StartsWithSegments(pathBase, out remainder))
{
serverRequest.PathBase = pathBase;
serverRequest.Path = remainder;
}
else
{
serverRequest.PathBase = PathString.Empty;
serverRequest.Path = fullPath;
}
serverRequest.QueryString = QueryString.FromUriComponent(request.RequestUri);
foreach (var header in request.Headers)
{
serverRequest.Headers.Append(header.Key, header.Value.ToArray());
}
var requestContent = request.Content;
if (requestContent != null)
{
foreach (var header in request.Content.Headers)
{
serverRequest.Headers.Append(header.Key, header.Value.ToArray());
}
}
_responseStream = new ResponseStream(ReturnResponseMessage, AbortRequest);
httpContext.Response.Body = _responseStream;
httpContext.Response.StatusCode = 200;
httpContext.RequestAborted = _requestAbortedSource.Token;
}
示例11: UpdateFeatures_ClearsCachedFeatures
public void UpdateFeatures_ClearsCachedFeatures()
{
var features = new FeatureCollection();
features.Set<IHttpRequestFeature>(new HttpRequestFeature());
features.Set<IHttpResponseFeature>(new HttpResponseFeature());
features.Set<IHttpWebSocketFeature>(new TestHttpWebSocketFeature());
// featurecollection is set. all cached interfaces are null.
var context = new DefaultHttpContext(features);
TestAllCachedFeaturesAreNull(context, features);
Assert.Equal(3, features.Count());
// getting feature properties populates feature collection with defaults
TestAllCachedFeaturesAreSet(context, features);
Assert.NotEqual(3, features.Count());
// featurecollection is null. and all cached interfaces are null.
// only top level is tested because child objects are inaccessible.
context.Uninitialize();
TestCachedFeaturesAreNull(context, null);
var newFeatures = new FeatureCollection();
newFeatures.Set<IHttpRequestFeature>(new HttpRequestFeature());
newFeatures.Set<IHttpResponseFeature>(new HttpResponseFeature());
newFeatures.Set<IHttpWebSocketFeature>(new TestHttpWebSocketFeature());
// featurecollection is set to newFeatures. all cached interfaces are null.
context.Initialize(newFeatures);
TestAllCachedFeaturesAreNull(context, newFeatures);
Assert.Equal(3, newFeatures.Count());
// getting feature properties populates new feature collection with defaults
TestAllCachedFeaturesAreSet(context, newFeatures);
Assert.NotEqual(3, newFeatures.Count());
}