Esempio n. 1
0
        private static async Task <decimal> CalcAsync(string method, decimal x, decimal y)
        {
            var args = new Dictionary <string, string>
            {
                { "X", x.ToString(CultureInfo.InvariantCulture) },
                { "Y", y.ToString(CultureInfo.InvariantCulture) }
            };
            var result = await PipeInteropDispatcher.ProcessRequestAsync(new PipeMessage(method, args));

            return(decimal.Parse(result["Result"]));
        }
Esempio n. 2
0
        private static async Task RunDemo(Operation operation)
        {
            try
            {
                var methods = EnumHelper.GetValues <Operation>().ToDictionary(d => d, d => d.ToString());

                if (!methods.ContainsKey(operation))
                {
                    throw new InvalidOperationException("Invalid Operation ID");
                }

                if (operation == Operation.PingServer)
                {
                    await PipeInteropDispatcher.ProcessRequestAsync(new PipeMessage("Ping"));
                }
                else if (operation == Operation.KillServer)
                {
                    await PipeInteropDispatcher.ProcessRequestAsync(new PipeMessage("ExitProcess"));
                }
                else
                {
                    Console.Write("Enter value of X: ");
                    var x = decimal.Parse(Console.ReadLine());
                    Console.Write("Enter value of Y: ");
                    var y = decimal.Parse(Console.ReadLine());

                    var result = await CalcAsync(methods[operation], x, y);

                    var color = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("\nRESULT: {0}", result);
                    Console.ForegroundColor = color;
                }
            }
            catch (Exception ex)
            {
                var color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine();
                Console.WriteLine(ex.Message);
                Console.ForegroundColor = color;
            }
        }