public HeaterController(Controller controller)
     : base (controller)
 {
     if (string.IsNullOrEmpty(controller.Configuration))
     {
         configuration = ControllerConfiguration.Default;
         controller.SetConfiguration(configuration);
     }
     else
         configuration = controller.GetConfiguration(typeof(ControllerConfiguration));
 }
        private static ControllerBase CastController(Controller controller)
        {
            switch (controller.Type)
            {
                case ControllerType.Heater: return new HeaterController(controller);
                case ControllerType.ScheduledSwitch: return new SwitchController(controller);
                case ControllerType.WaterLevel: return new WaterLevelController(controller);

                default: return null;
            }
        }
        private object apiAddController(HttpRequestParams request)
        {
            var name = request.GetRequiredString("name");
            var type = (ControllerType)request.GetRequiredInt32("type");

            var ctrl = new Controller()
            {
                Id = Guid.NewGuid(),
                Name = name,
                Type = type,
                IsAutoMode = false
            };

            ControllerBase controller = CastController(ctrl);
            if (controller != null)
            {
                controller.Init(Context);
                controller.SaveToDB();
                controllers.Add(controller);

                NotifyForSignalR(new { MsgId = "ControllerAdded", Data = BuildControllerWebModel(ctrl) });
            }

            return null;
        }
        public object BuildControllerWebModel(Controller controller)
        {
            if (controller == null)
                return null;

            return new
            {
                Id = controller.Id,
                Name = controller.Name,
                Type = (int)controller.Type,
                TypeName = controller.Type.GetEnumDescription(),
                IsAutoMode = controller.IsAutoMode,
                Configuration = controller.Configuration
            };
        }
Ejemplo n.º 5
0
 public ControllerBase(Controller controller)
 {
     this.controller = controller;
 }