Пример #1
0
        static async Task MainAsync(string[] args)
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            CancellationToken       cancellationToken = cts.Token;

            await new MainController(TraceSourceFactory.GetDefaultTraceSource()).RunAsync(cancellationToken);
        }
 internal static TcpClientController CreateTcpServerController()
 {
     return(new TcpClientController(
                TraceSourceFactory.GetDefaultTraceSource(),
                "localhost", 8080,
                new NetworkStreamReader(Constants.MaxReadRetry, Constants.ReadRetryDelaySeconds),
                new NetworkStreamWriter(Constants.MaxWriteRetry, Constants.WriteRetryDelaySeconds)));
 }
Пример #3
0
        public IEnumerable <Task> CreateMainTasks(CancellationToken cancellationToken)
        {
            string serverListeningAddress;
            Task   tcpServer         = TcpServerControllerFactory.CreateTcpServerController(out serverListeningAddress).RunAsync(cancellationToken);
            Task   commandProcessing = new CommandProcessingController(TraceSourceFactory.GetDefaultTraceSource()).RunAsync(cancellationToken);
            Task   broadcasting      = new HeartbeatController(serverListeningAddress, TraceSourceFactory.GetDefaultTraceSource()).RunAsync(cancellationToken);

            yield return(tcpServer);

            yield return(commandProcessing);

            yield return(broadcasting);
        }
        internal static TcpServerController CreateTcpServerController(out string address)
        {
            var server = new TcpListener(IPAddress.Loopback, TCP_PORT);

            server.Start();
            address = server.LocalEndpoint.ToString();

            return(new TcpServerController(
                       server,
                       TraceSourceFactory.GetDefaultTraceSource(),
                       new ClientStore(),
                       new NetworkStreamReader(Constants.MaxReadRetry, 1),
                       new NetworkStreamWriter(Constants.MaxWriteRetry, Constants.WriteRetryDelaySeconds)));
        }