Example #1
0
        public async Task <ControllerAction> AddOrUpdateControllerActionAsync(
            ControllerEvent controllerEvent,
            string deviceId,
            int channel,
            bool isInvert,
            ControllerButtonType buttonType,
            ControllerAxisType axisType,
            ControllerAxisCharacteristic axisCharacteristic,
            int maxOutputPercent,
            int axisDeadZonePercent,
            ChannelOutputType channelOutputType,
            int maxServoAngle,
            int servoBaseAngle,
            int stepperAngle,
            string sequenceName)
        {
            using (await _asyncLock.LockAsync())
            {
                var controllerAction = controllerEvent.ControllerActions.FirstOrDefault(ca => ca.DeviceId == deviceId && ca.Channel == channel);
                if (controllerAction != null)
                {
                    controllerAction.IsInvert            = isInvert;
                    controllerAction.ButtonType          = buttonType;
                    controllerAction.AxisType            = axisType;
                    controllerAction.AxisCharacteristic  = axisCharacteristic;
                    controllerAction.MaxOutputPercent    = maxOutputPercent;
                    controllerAction.AxisDeadZonePercent = axisDeadZonePercent;
                    controllerAction.ChannelOutputType   = channelOutputType;
                    controllerAction.MaxServoAngle       = maxServoAngle;
                    controllerAction.ServoBaseAngle      = servoBaseAngle;
                    controllerAction.StepperAngle        = stepperAngle;
                    controllerAction.SequenceName        = sequenceName;
                    await _creationRepository.UpdateControllerActionAsync(controllerAction);
                }
                else
                {
                    controllerAction = new ControllerAction
                    {
                        DeviceId            = deviceId,
                        Channel             = channel,
                        IsInvert            = isInvert,
                        ButtonType          = buttonType,
                        AxisType            = axisType,
                        AxisCharacteristic  = axisCharacteristic,
                        MaxOutputPercent    = maxOutputPercent,
                        AxisDeadZonePercent = axisDeadZonePercent,
                        ChannelOutputType   = channelOutputType,
                        MaxServoAngle       = maxServoAngle,
                        ServoBaseAngle      = servoBaseAngle,
                        StepperAngle        = stepperAngle,
                        SequenceName        = sequenceName
                    };
                    await _creationRepository.InsertControllerActionAsync(controllerEvent, controllerAction);
                }

                return(controllerAction);
            }
        }
        public async Task UpdateControllerActionAsync(
            ControllerAction controllerAction,
            string deviceId,
            int channel,
            bool isInvert,
            ControllerButtonType buttonType,
            ControllerAxisType axisType,
            ControllerAxisCharacteristic axisCharacteristic,
            int maxOutputPercent,
            int axisActiveZonePercent,
            int axisDeadZonePercent,
            ChannelOutputType channelOutputType,
            int maxServoAngle,
            int servoBaseAngle,
            int stepperAngle,
            string sequenceName)
        {
            using (await _asyncLock.LockAsync())
            {
                var otherControllerAction = controllerAction.ControllerEvent.ControllerActions.FirstOrDefault(ca => ca.Id != controllerAction.Id && ca.DeviceId == deviceId && ca.Channel == channel);
                if (otherControllerAction != null)
                {
                    var parent = otherControllerAction.ControllerEvent;
                    await _creationRepository.DeleteControllerActionAsync(otherControllerAction);

                    parent.ControllerActions.Remove(otherControllerAction);
                }

                controllerAction.DeviceId              = deviceId;
                controllerAction.Channel               = channel;
                controllerAction.IsInvert              = isInvert;
                controllerAction.ButtonType            = buttonType;
                controllerAction.AxisType              = axisType;
                controllerAction.AxisCharacteristic    = axisCharacteristic;
                controllerAction.MaxOutputPercent      = maxOutputPercent;
                controllerAction.AxisActiveZonePercent = axisActiveZonePercent;
                controllerAction.AxisDeadZonePercent   = axisDeadZonePercent;
                controllerAction.ChannelOutputType     = channelOutputType;
                controllerAction.MaxServoAngle         = maxServoAngle;
                controllerAction.ServoBaseAngle        = servoBaseAngle;
                controllerAction.StepperAngle          = stepperAngle;
                controllerAction.SequenceName          = sequenceName;
                await _creationRepository.UpdateControllerActionAsync(controllerAction);
            }
        }