Esempio n. 1
0
        public static double Calculate(string request)
        {
            string[] splitedRequest = request.Split(':');

            string operation = splitedRequest[0];
            double firstValue;
            double secondValue;
            bool   f = double.TryParse(splitedRequest[1], out firstValue);
            bool   s = double.TryParse(splitedRequest[2], out secondValue);

            if (!(f && s))
            {
                throw new Exception("Invalid imput!");
            }

            IMathService mathService = new MathService();

            switch (operation)
            {
            case "+":
                return(mathService.Add(firstValue, secondValue));

            case "-":
                return(mathService.Sub(firstValue, secondValue));

            case "*":
                return(mathService.Mult(firstValue, secondValue));

            case "/":
                return(mathService.Div(firstValue, secondValue));

            default:
                throw new Exception("Invalid operation!");
            }
        }
Esempio n. 2
0
        public static void Manage(object obj)
        {
            Tuple <object, object> tuple = obj as Tuple <object, object>;
            IServer service = tuple.Item1 as IServer;
            object  client  = tuple.Item2;

            while (true)
            {
                string request = service.Receive(client);

                double result = MathService.Calculate(request);

                service.Send(client, result.ToString());
            }
        }
Esempio n. 3
0
 public static void Main(String[] args)
 {
     MathService.MathService ms = new MathService.MathService();
     Console.WriteLine(ms.Add(1,2));
 }
Esempio n. 4
0
 public static void Main(String[] args)
 {
     MathService.MathService ms = new MathService.MathService();
     Console.WriteLine(ms.Add(1, 2));
 }