示例#1
0
        public static void Main(string[] args)
        {
            int argumentsCount = args.Length;

            if ((argumentsCount == CorrectArgumnetsCount) || ((argumentsCount == CorrectArgumnetsCount - 1) && (args[OperationParameterIndex].Equals("sqrt"))))
            {
                string operation = args[OperationParameterIndex];
                if (CalculatorOperations.Keys.Contains(operation))
                {
                    double[] operationArguments;
                    if (!TryParseArguments(args, out operationArguments))
                    {
                        Console.WriteLine("Invalid arguments");
                    }
                    else
                    {
                        using (var calculatorClient = new CalculatorReference.CalculatorClient())
                        {
                            PerformCalculation(operation, operationArguments, calculatorClient);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Invalid operation");
                }
            }
            else
            {
                Console.WriteLine("Invalid arguments count");
            }
        }
示例#2
0
 private static void PerformCalculation(string operation, double[] args, CalculatorReference.CalculatorClient calculatorClient)
 {
     try
     {
         double operationResult = CalculatorOperations[operation](args, calculatorClient);
         Console.WriteLine(operationResult);
     }
     catch (FaultException e)
     {
         Console.WriteLine(e.Reason);
     }
     catch (CommunicationException)
     {
         Console.WriteLine("Connection error");
     }
 }