Exemple #1
0
 List <Models.ControllerStateInformation> GetStates(ISqLiteContext ctx, Models.Controller controller)
 {
     return(ctx.ControllerStateInformation
            .Where(stateInfo => stateInfo.ControllerId == controller.Id)
            .Select(state => _modelFactory.CreateControllerStateInformation(state))
            .ToList());
 }
        public ControllerStateHistory ActivateState(ISqLiteContext ctx, ControllerStateInformation controllerStateInformation, DateTime startTime)
        {
            var history = _entityFactory.CreateStateHistory(controllerStateInformation, startTime);

            ctx.Add(history);

            return(history);
        }
        public ControllerStateHistory ReplaceState(ISqLiteContext ctx, Models.ControllerStateInformation newStateModel, Models.ControllerStateInformation oldStateModel)
        {
            var newState = _entityFactory.CreateControllerStateInformation(newStateModel);
            var oldState = _entityFactory.CreateControllerStateInformation(oldStateModel);

            var terminationDate = TerminateState(ctx, oldState);

            return(ActivateState(ctx, newState, terminationDate));
        }
        public bool IsUpgradeNeeded(ISqLiteContext ctx)
        {
            if (!ctx.VersionHistory.Any())
            {
                return(true);
            }

            return(false);
        }
Exemple #5
0
        void InsertControllerState(ISqLiteContext ctx, Controller controller, IControllerState controllerState)
        {
            var stateModel = new ControllerStateInformation();

            stateModel.State            = controllerState.State;
            stateModel.PowerConsumption = controllerState.PowerConsumption;
            stateModel.Controller       = controller;

            ctx.Add(stateModel);
        }
Exemple #6
0
        List <IControllerState> GetUnknownStates(ISqLiteContext ctx, Controller controller, List <IControllerState> states)
        {
            if (states?.Any() != true)
            {
                return(new List <IControllerState>());
            }

            var existingStates = ctx.ControllerStateInformation.Where(stateInfo => stateInfo.ControllerId == controller.Id);

            return(states.Where(state => !existingStates.Any(existingState => existingState.State == state.State)).ToList());
        }
Exemple #7
0
        Controller InsertController(ISqLiteContext ctx, IMqttAdapter mqttAdapter)
        {
            var controller = _entityFactory.CreateController();

            controller.Identifier = mqttAdapter.Identifier;
            controller.Type       = mqttAdapter.Type;
            controller.InitializationArguments = _jsonSerializerService.Serialize(mqttAdapter.GetInitializationArguments());

            ctx.Add(controller);

            return(controller);
        }
        public DateTime TerminateState(ISqLiteContext ctx, ControllerStateInformation state)
        {
            var terminateDate = DateTime.UtcNow;

            var history = ctx.ControllerStateHistory.FirstOrDefault(h => h.ControllerStateInformationId == state.Id && h.EndTime == DateTime.MinValue);

            if (history != null)
            {
                history.EndTime = terminateDate;
            }

            return(terminateDate);
        }