private static ICalculator GetcalculatorInstnce(int operation) { ICalculator calculator = null; if (operation == 0) { calculator = new Addition(); } else if (operation == 1) { calculator = new Sub(); } else if (operation == 2) { calculator = new Multiplication(); } else if (operation == 3) { calculator = new Division(); } return(calculator); }
static void Main(string[] args) { //you should change these configurations for your own rabbitmq server string rbmqUsername = "******"; string rbmqPassword = "******"; string rbmqServerUrl = "localhost"; CalUnit cal = new CalUnit("aggregate.calUnit", "calUnit", rbmqUsername, rbmqPassword, rbmqServerUrl); Add add = new Add("chips.add", "add", rbmqUsername, rbmqPassword, rbmqServerUrl); Sub sub = new Sub("chips.sub", "sub", rbmqUsername, rbmqPassword, rbmqServerUrl); Mul mul = new Mul("chips.mul", "mul", rbmqUsername, rbmqPassword, rbmqServerUrl); Div div = new Div("chips.div", "div", rbmqUsername, rbmqPassword, rbmqServerUrl); Console.WriteLine("working..."); string line; while ((line = Console.ReadLine()).Trim() != "q") { try { var match = Regex.Match(line, @"(?<a>\d+(\.\d+)?)(?<op>[+\-*/])(?<b>\d+(\.\d+)?)"); double a = Convert.ToDouble(match.Groups["a"].Value); string op = match.Groups["op"].Value; double b = Convert.ToDouble(match.Groups["b"].Value); cal.calculate(op, a, b); } catch (Exception) { Console.WriteLine("invalid input."); } } div.stopWork(); mul.stopWork(); sub.stopWork(); add.stopWork(); cal.stopWork(); }