void TestFactory3() { //构造间隔回路 SwitchController sc = ControllerFactory.Create <SwitchController>(); sc.GetInstance(3); SwitchModel sm1 = new SwitchModel(50, 40, 10, 2); SwitchModel sm2 = new SwitchModel(50, 45, 10, 2); SwitchModel sm3 = new SwitchModel(50, 52, 10, 2); SwitchModel sm4 = new SwitchModel(50, 61, 10, 2); SwitchModel sm5 = new SwitchModel(50, 56, 10, 2); sc.AddModel(sm1); sc.AddModel(sm2); sc.AddModel(sm3); sc.AddModel(sm4); sc.AddModel(sm5); //构造加热炉回路 FurnaceController fc = ControllerFactory.Create <FurnaceController>(100); List <PIDConstant> pidcs2 = new List <PIDConstant>(); PIDConstant pidcIn = new PIDConstant(120, 200, 30, PIDControlAlgorithm.IPD); PIDConstant pidcOut = new PIDConstant(300, 30, 0, PIDControlAlgorithm.PID); pidcs2.Add(pidcIn); pidcs2.Add(pidcOut); FurnaceManage manage = new FurnaceManage(20, 5); fc.GetInstance(pidcs2, manage, 1); FurnaceModel fm1 = new FurnaceModel(50, 51, 52, 53, 1); FurnaceModel fm2 = new FurnaceModel(50, 52, 52, 55, 1); FurnaceModel fm3 = new FurnaceModel(50, 50.5, 52, 54, 1); FurnaceModel fm4 = new FurnaceModel(50, 50, 52, 52, 1); FurnaceModel fm5 = new FurnaceModel(50, 51.2, 52, 53, 1); FurnaceModel fm6 = new FurnaceModel(50, 53, 52, 56, 1); FurnaceModel fm7 = new FurnaceModel(50, 52.2, 52, 54, 1); FurnaceModel fm8 = new FurnaceModel(50, 51.6, 52, 55, 1); fc.AddModel(fm1); fc.AddModel(fm2); fc.AddModel(fm3); fc.AddModel(fm4); fc.AddModel(fm5); fc.AddModel(fm6); fc.AddModel(fm7); fc.AddModel(fm8); }
public static T Create <T>(int maximun = 100) where T : ControllerBase, new() { ControllerBase controller = null; var props = new T().GetType().GetProperties(); var p = props.Single(pro => pro.Name == "ControllerType"); ControllerType ct = (ControllerType)p.GetValue(new T(), null); if (ct == ControllerType.Single) { controller = new SingleController(maximun); } else if (ct == ControllerType.Cascade) { controller = new CascadeController(maximun); } else if (ct == ControllerType.MultiCascade) { controller = new MultiCascadeController(maximun); } else if (ct == ControllerType.Feed) { controller = new FeedController(maximun); } else if (ct == ControllerType.Radio) { controller = new RadioController(maximun); } else if (ct == ControllerType.ComplexRadio) { controller = new ComplexRadioController(maximun); } else if (ct == ControllerType.Switch) { controller = new SwitchController(); } else if (ct == ControllerType.Furnace) { controller = new FurnaceController(maximun); } else if (ct == ControllerType.SplitRanging) { //controller = new ComplexRadioController(); } return(controller as T); }