Ejemplo n.º 1
0
        public ClientProcessor(MathsProccessor.MathsProccessorClient client, ICalcIO calcIO, ICalcInputParser parser)
        {
            this.client = client;
            this.calcIO = calcIO;
            this.parser = parser;

            operationsCount = 0;
            clientID        = Guid.NewGuid().ToString();

            mathOperations = new Dictionary <char, Func <Arguments, Result> >
            {
                ['='] = (args) => client.Set(args),
                ['+'] = (args) => client.Add(args),
                ['-'] = (args) => client.Sub(args),
                ['*'] = (args) => client.Mul(args),
                ['/'] = (args) => client.Div(args),
            };

            systemOperations = new Dictionary <char, Func <bool> >
            {
                ['q'] = () => false,
                ['#'] = () =>
                {
                    var input  = parser.ReadInt(x => x > 0 && x <= operationsCount);
                    var result = client.Jmp(new Arguments()
                    {
                        ID = clientID, Input = input
                    }).Value;

                    calcIO.WriteLine($"[#{++operationsCount}] = {result}");
                    return(true);
                },
            };
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            var ip   = args[0];
            var port = args[1];

            var channel = new Channel($"{ip}:{port}", ChannelCredentials.Insecure);
            var client  = new MathsProccessor.MathsProccessorClient(channel);

            var calcIO    = new ConsoleCalcIO();
            var parser    = new CalcInputParser(calcIO);
            var processor = new ClientProcessor(client, calcIO, parser);

            try
            {
                // Test connection
                client.Set(new Arguments()
                {
                    ID = "0", Input = 0
                });
                processor.Start();
            }
            catch (RpcException e)
            {
                calcIO.WriteLine($"Error: {e.Status.Detail}");
                calcIO.ReadString();
            }

            channel.ShutdownAsync().Wait();
        }