internal static Operate OperateHandle(Operate item, List <DeviceOperate> subList, DateTime sendTime) { item.RetryCount += 1; //只要发送次数超过5次,则视为发送失败 if (item.RetryCount > 5) { item.State = OperateState.Error; return(item); } if (!Main.online.ContainsKey(item.ClientCode) || string.IsNullOrEmpty(Main.online[item.ClientCode])) { return(item); } try { IOperate operate = OperateFactory.Create(item.FunctionCode, subList, sendTime); SendMessage msg = operate.Handle(ref item); Main.listener.Send(Main.online[item.ClientCode], msg.ToByte()); } catch (Exception ex) { LogHelper.WriteLog("创建并下发命令时出错", ex.Message, ex.StackTrace); } return(item); }
//static void FactoryMethod() //{ // IFruitFactory appleFac = new AFactory(); // Fruit apple = appleFac.CreateFruit(); // apple.PrintfColor(); // apple.PrintfName(); // IFruitFactory orangeFac = new OrangeFactory(); // Fruit orage = orangeFac.CreateFruit(); // orage.PrintfColor(); // orage.PrintfName(); //} void SimpleFactory() { Console.WriteLine("请选择操作符号(+、-、*、/)"); string operateStr = Console.ReadLine(); Operate operate = OperateFactory.GetOperateFactory(operateStr); operate.NumberA = 10; operate.NumberB = 4; double result = operate.GetResult(); Console.WriteLine(result); Console.ReadKey(); }
//面向对象的计算器 父类:运算 //Operate--> Add Sub Mul Div operating(int,int) static void Main(string[] args) { //Operate o =OperateFactory.GetOperate("+"); //int result=o.operating(3, 10); //Console.WriteLine(result); string s = Console.ReadLine(); //23+25 string[] ss = s.Split('+', '-', '*', '/'); int a = Convert.ToInt32(ss[0]); int b = Convert.ToInt32(ss[1]); string s2 = s.Substring(ss[0].Length, 1); char c = Convert.ToChar(s2); Operate o = OperateFactory.GetOperate(c); int result = o.operating(a, b); Console.WriteLine(result); }