Exemplo n.º 1
0
        private static void MainLifetime(string[] args, LifetimeDefinition lifetimeDefinition)
        {
            var lifetime = lifetimeDefinition.Lifetime;

            var reflectionSerializers = new ReflectionSerializersFacade();
            var serializers           = new Serializers(reflectionSerializers.Registrar);

            var      scheduler = SingleThreadScheduler.RunOnSeparateThread(lifetime, "Scheduler");
            Protocol protocol;

            SocketWire.Base wire;


            var isServer = args.Length == 0 ? Util.Fork(args) : args[0] == "server";

            if (isServer)
            {
                Console.Title = "Server";
                wire          = new SocketWire.Server(lifetime, scheduler, ourIpEndPoint);
                protocol      = new Protocol("Server", serializers, new Identities(IdKind.Server), scheduler, wire, lifetime);
            }
            else
            {
                Console.Title = "Client";
                wire          = new SocketWire.Client(lifetime, scheduler, ourIpEndPoint);
                protocol      = new Protocol("Client", serializers, new Identities(IdKind.Client), scheduler, wire, lifetime);
            }

            scheduler.Queue(() => RunApplication(isServer, reflectionSerializers, lifetime, protocol));

            wire.Connected.Change.Advise(lifetime, value =>
            {
                if (value)
                {
                    Console.Title += ": connected";
                }
                else
                {
                    lifetimeDefinition.Terminate();
                }
            });

            while (lifetime.IsAlive)
            {
                if (Console.KeyAvailable && OnChar != null)
                {
                    scheduler.Queue(() => OnChar?.Invoke(Console.ReadKey(true).KeyChar));
                }

                Thread.Sleep(100);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Apparently this is the only method in TextWriter that needs to be overridden.
        /// AQll other write methods call this.
        /// </summary>
        /// <param name="value"></param>
        public override void Write(char value)
        {
            OnChar.SafeCall(this, value);

            if ((value == '\r') || (value == '\n'))
            {
                if (currentLine.Length > 0)
                {
                    OnLine.SafeCall(this, currentLine.ToString());
                }
                currentLine.Clear();
            }
            else
            {
                currentLine.Append(value);
            }
        }
Exemplo n.º 3
0
 private void Form_KeyPress(object sender, KeyPressEventArgs e)
 {
     OnChar?.Invoke(e.KeyChar);
 }