Commit 612c63d1 authored by yangxiaodong's avatar yangxiaodong

addserver

parent 31006371
...@@ -6,35 +6,76 @@ using Microsoft.AspNetCore.Hosting; ...@@ -6,35 +6,76 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Hosting.Server.Features;
using System.Reflection;
using Cap.Consistency.Server.Internal.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
namespace Cap.Consistency.Server namespace Cap.Consistency.Server
{ {
public class ConsistencyServer : IServer public class ConsistencyServer : IServer
{ {
public ConsistencyServer(IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory) private Stack<IDisposable> _disposables;
{ private readonly IApplicationLifetime _applicationLifetime;
if (applicationLifetime == null) private readonly ILogger _logger;
{ private readonly IServerAddressesFeature _serverAddresses;
private readonly IConsumer _consumer;
public ConsistencyServer(IOptions<ConsistencyServerOptions> options, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory) {
if (options == null) {
throw new ArgumentNullException(nameof(options));
}
if (applicationLifetime == null) {
throw new ArgumentNullException(nameof(applicationLifetime)); throw new ArgumentNullException(nameof(applicationLifetime));
} }
if (loggerFactory==null) if (loggerFactory == null) {
{ throw new ArgumentNullException(nameof(loggerFactory));
throw new ArgumentNullException(nameof(loggerFactory));
} }
}
public void Start<TContext>(IHttpApplication<TContext> application) Options = options.Value ?? new ConsistencyServerOptions();
{ _applicationLifetime = applicationLifetime;
throw new NotImplementedException(); _logger = loggerFactory.CreateLogger(typeof(ConsistencyServer).GetTypeInfo().Namespace);
_consumer = Options.ApplicationServices.GetService<IConsumer>();
Features = new FeatureCollection();
_serverAddresses = new ServerAddressesFeature();
Features.Set(_serverAddresses);
} }
public IFeatureCollection Features { get; } public IFeatureCollection Features { get; }
public void Dispose() public ConsistencyServerOptions Options { get; }
{
public void Start<TContext>(IHttpApplication<TContext> application) {
throw new NotImplementedException(); if (_disposables != null) {
// The server has already started and/or has not been cleaned up yet
throw new InvalidOperationException("Server has already started.");
}
_disposables = new Stack<IDisposable>();
var trace = new ConsistencyTrace(_logger);
_disposables.Push(_consumer);
var threadCount = Options.ThreadCount;
if (threadCount <= 0) {
throw new ArgumentOutOfRangeException(nameof(threadCount),
threadCount,
"ThreadCount must be positive.");
}
_consumer.Start();
}
public void Dispose() {
if (_disposables != null) {
while (_disposables.Count > 0) {
_disposables.Pop().Dispose();
}
_disposables = null;
}
} }
} }
} }
\ No newline at end of file
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"buildOptions": { "buildOptions": {
"debugType": "portable" "debugType": "portable"
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Hosting": "1.1.0-*", "Microsoft.AspNetCore.Hosting": "1.1.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.1.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.1.0-*",
"NETStandard.Library": "1.6.1" "Microsoft.Extensions.Options": "1.1.0",
}, "NETStandard.Library": "1.6.1"
},
"frameworks": { "frameworks": {
"netstandard1.6": { "netstandard1.6": {
"imports": "dnxcore50" "imports": "dnxcore50"
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Cap.Consistency.Test
{
public class ConsistencyOptionsTest
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment