protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance,
                                                                        IDispatchable source, object value)
        {
            if (instance == _input)
            {
                return(ValueChanged(_output, value));
            }

            return(new List <IRuleOutputChanged>());
        }
Beispiel #2
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            _timer.Stop();
            _timer.Interval = _delay.ValueInteger.Value * 1000;
            _timer.Start();


            Context.Dispatcher.DispatchValue(new RuleOutputChanged(_output, false).Instance, true);

            return(new List <IRuleOutputChanged>());
        }
Beispiel #3
0
        public MonoflopRule(IRuleContext context) : base(context)
        {
            _delay = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                a.This2RuleInterfaceTemplate == MonoflopRuleFactory.RuleParamDelay);

            _output = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                 a.This2RuleInterfaceTemplate == MonoflopRuleFactory.RuleOutput);

            _timer          = new System.Timers.Timer();
            _timer.Elapsed += _timer_Elapsed;
        }
Beispiel #4
0
        public RandomRule(IRuleContext context) : base(context)
        {
            _output = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                 a.This2RuleInterfaceTemplate == RandomRuleFactory.RuleOutput);

            _minInstance = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                      a.This2RuleInterfaceTemplate == RandomRuleFactory.RuleParamMin);

            _maxInstance = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                      a.This2RuleInterfaceTemplate == RandomRuleFactory.RuleParamMax);
        }
Beispiel #5
0
        public IfRule(IRuleContext context) : base(context)
        {
            _paramTrueValue = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                         a.This2RuleInterfaceTemplate == IfRuleFactory.RuleParamTrue);

            _paramFalseValue = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                          a.This2RuleInterfaceTemplate == IfRuleFactory.RuleParamFalse);

            _output1 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                  a.This2RuleInterfaceTemplate == IfRuleFactory.RuleOutput);
        }
Beispiel #6
0
 protected override void ParamterValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
 {
     if (instance.This2RuleInterfaceTemplate == DelayedOffRuleFactory.RuleParamDelay)
     {
         _delay = Convert.ToInt64(value);
         if (_timerRunning)
         {
             StartStopTimer();
         }
     }
     base.ParamterValueChanged(instance, source, value);
 }
Beispiel #7
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (instance.This2RuleInterfaceTemplate == RandomRuleFactory.RuleInputDisabled)
            {
                _disabled = Convert.ToBoolean(value);
            }

            if (!_disabled && instance.This2RuleInterfaceTemplate == RandomRuleFactory.RuleInputTrigger)
            {
                _i1 = _random.Next(Min, Max);
            }
            return(SingleOutputChanged(new RuleOutputChanged(_output, _i1)));
        }
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            var windowState = WindowState.Undefined;

            if (instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Ct || instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Cti)
            {
                var boolValue = !Convert.ToBoolean(value);

                if (instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Cti)
                {
                    boolValue = !boolValue;
                }
                windowState = boolValue ? WindowState.Tilt : WindowState.Closed;
            }
            if (instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Co || instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Coi)
            {
                var boolValue = !Convert.ToBoolean(value);

                if (instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Coi)
                {
                    boolValue = !boolValue;
                }

                windowState = boolValue ? WindowState.Open : WindowState.Closed;
            }
            if (instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Cl || instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Cli)
            {
                var boolValue = !Convert.ToBoolean(value);

                if (instance.This2RuleInterfaceTemplate == WindowMonitorFactory.Cli)
                {
                    boolValue = !boolValue;
                }
                windowState = boolValue ? WindowState.Unlocked : WindowState.Locked;
            }

            if (!States.ContainsKey(source.Id))
            {
                States.Add(source.Id, new Tuple <IDispatchable, WindowState>(source, windowState));
            }
            else
            {
                States[source.Id] = new Tuple <IDispatchable, WindowState>(source, windowState);
            }

            // TODO: Notify only if a state changes???

            Context.Notify.NotifyValueChanged(Context.RuleInstance, GetDataForVisu());

            return(new List <IRuleOutputChanged>());
        }
Beispiel #9
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (instance.This2RuleInterfaceTemplate == SubstractRuleFactory.RuleInput1)
            {
                _i1 = Convert.ToDouble(value);
            }

            if (instance.This2RuleInterfaceTemplate == SubstractRuleFactory.RuleInput2)
            {
                _i2 = Convert.ToDouble(value);
            }


            return(SingleOutputChanged(new RuleOutputChanged(_output, (_i1 - _i2))));
        }
Beispiel #10
0
        public TriggerRule(IRuleContext context) : base(context)
        {
            _context = context;
            _output1 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                  a.This2RuleInterfaceTemplate == TriggerRuleFactory.RuleOutput);

            _paramDelay = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                     a.This2RuleInterfaceTemplate == TriggerRuleFactory.DelayParameter);

            var paramValue = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                                        a.This2RuleInterfaceTemplate == TriggerRuleFactory.ValueParameter);

            if (paramValue != null)
            {
                _outputValue = paramValue.Value;
            }
        }
Beispiel #11
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (value != null && instance.This2RuleInterfaceTemplate == NotRuleFactory.RuleInput1)
            {
                _i1 = Convert.ToBoolean(value);
            }

            if (_i1.HasValue)
            {
                _o = !_i1.Value;
            }

            return(new List <IRuleOutputChanged>
            {
                new RuleOutputChanged(_output1, _o)
            });
        }
 public BinaryDecoderRule(IRuleContext context) : base(context)
 {
     _output1 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleOutput1);
     _output2 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleOutput2);
     _output3 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleOutput3);
     _output4 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleOutput4);
     _output5 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleOutput5);
     _output6 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleOutput6);
     _output7 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleOutput7);
     _output8 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleOutput8);
 }
        public RuleOutputChanged(RuleInterfaceInstance instance, object value, string sourceInformation = "")
        {
            Instance          = new RuleInterfaceInstanceDispatchable(instance);
            Value             = value;
            SourceInformation = sourceInformation;

            if (value != null && double.TryParse(value.ToString(), out double dblValue))
            {
                ValueDouble = dblValue;
            }
            if (value != null && int.TryParse(value.ToString(), out int intValue))
            {
                ValueInteger = intValue;
            }
            if (value != null && Boolean.TryParse(value.ToString(), out bool bValue))
            {
                ValueBoolean = bValue;
            }
        }
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (value != null && instance.This2RuleInterfaceTemplate == StateToImpulsRuleFactory.RuleInput)
            {
                _i1 = Convert.ToInt32(value);
            }

            if (_i1.HasValue && _i1.Value > 0)
            {
                Task.Run(() =>
                {
                    var change = new RuleOutputChanged(_output1, 0);
                    Thread.Sleep(Delay);
                    _context.Dispatcher.DispatchValue(change.Instance, change.Value);
                });
            }

            return(new List <IRuleOutputChanged>());
        }
Beispiel #15
0
        /// <summary>
        ///  Will be called from <see cref="ValueChanged(RuleInterfaceInstance, object)"/>
        ///  Source will be set
        /// </summary>
        /// <param name="instance">The <see cref="RuleInterfaceInstance"/> instance</param>
        /// <param name="source">The source who dispatched the value (<see cref="IDispatchable"/>)</param>
        /// <param name="value">The changed value</param>
        /// <returns></returns>
        public IList <IRuleOutputChanged> ValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            lock (_lock)
            {
                if (instance.This2RuleInterfaceTemplateNavigation.This2RuleInterfaceDirection ==
                    (long)Base.Templates.RuleInterfaceDirection.Param)
                {
                    ParamterValueChanged(instance, source, value);

                    Context.Logger.LogDebug($"RuleParameter changed {instance.This2RuleInstanceNavigation.Name} - {instance.This2RuleInterfaceTemplateNavigation.Name} from {source.GetType()}-{source.Name} value {value}");
                    return(new List <IRuleOutputChanged>());
                }
                Context.Logger.LogDebug($"RuleInput changed {instance.This2RuleInstanceNavigation.Name} - {instance.This2RuleInterfaceTemplateNavigation.Name} from {source.GetType()}-{source.Name} value {value}");

                var values = InputValueChanged(instance, source, value);

                try
                {
                    foreach (var ruleOutValue in values)
                    {
                        Context.Logger.LogDebug($"RuleOutput changed {ruleOutValue.Instance.Name} value {ruleOutValue.Value}");

                        if (!_valueDictionary.ContainsKey(ruleOutValue.Instance.RuleInterfaceInstance))
                        {
                            _valueDictionary.Add(ruleOutValue.Instance.RuleInterfaceInstance, ruleOutValue.Value);
                        }
                        else
                        {
                            _valueDictionary[ruleOutValue.Instance.RuleInterfaceInstance] = ruleOutValue.Value;
                        }
                    }
                }
                catch (Exception)
                {
                    //Ignore for the current test
                }


                return(values);
            }
        }
Beispiel #16
0
 protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
 {
     if (instance.This2RuleInterfaceTemplate == DelayedOffRuleFactory.RuleTrigger)
     {
         if (!Convert.ToBoolean(value))
         {
             Context.Logger.LogDebug($">>> Stoping timer <<<");
             _timer.Stop();
             return(new List <IRuleOutputChanged>());
         }
         Context.Logger.LogDebug($">>> Starting timer - ticks in {_delay * 1000} <<<");
         StartStopTimer();
     }
     else if (instance.This2RuleInterfaceTemplate == DelayedOffRuleFactory.RuleReset)
     {
         Context.Logger.LogDebug($">>> Stoping timer <<<");
         _timer.Stop();
         _timerRunning = false;
     }
     return(new List <IRuleOutputChanged>());
 }
Beispiel #17
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (value != null)
            {
                if (instance.This2RuleInterfaceTemplate == SmallerRuleFactory.RuleInput1)
                {
                    _i1 = Convert.ToDouble(value);
                }

                if (instance.This2RuleInterfaceTemplate == SmallerRuleFactory.RuleInput2)
                {
                    _i2 = Convert.ToDouble(value);
                }
            }
            if (_i1 == null || _i2 == null)
            {
                return(new List <IRuleOutputChanged>());
            }

            return(SingleOutputChanged(new RuleOutputChanged(_output, _i1 < _i2)));
        }
Beispiel #18
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (instance.This2RuleInterfaceTemplate == EnOceanWindowHandleLogicFactory.RuleInput)
            {
                var numericValue = Convert.ToInt32(value);

                switch (numericValue)
                {
                case 13:
                    return(SingleOutputChanged(new RuleOutputChanged(_output, 0)));

                case 12:
                case 14:
                    return(SingleOutputChanged(new RuleOutputChanged(_output, 1)));

                case 15:
                    return(SingleOutputChanged(new RuleOutputChanged(_output, 2)));
                }
            }
            return(base.InputValueChanged(instance, source, value));
        }
Beispiel #19
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (value != null)
            {
                if (instance.This2RuleInterfaceTemplate == IfRuleFactory.RuleInput1)
                {
                    _o1 = value;
                }

                if (instance.This2RuleInterfaceTemplate == IfRuleFactory.RuleInput2)
                {
                    _o2 = value;
                }
            }

            if (_o1 != null && _o2 != null)
            {
                _i1 = ConvertToInt(_o1);
                _i2 = ConvertToInt(_o2);

                if (_i1 == _i2)
                {
                    _o = _paramTrueValue.Value;
                }
                else
                {
                    _o = _paramFalseValue.Value;
                }
            }
            else
            {
                _o = _paramFalseValue.Value;
            }

            return(new List <IRuleOutputChanged>
            {
                new RuleOutputChanged(_output1, _o)
            });
        }
Beispiel #20
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (instance.This2RuleInterfaceTemplate == StringConcatFactory.RuleInput1)
            {
                _i1 = value?.ToString();
            }

            if (instance.This2RuleInterfaceTemplate == StringConcatFactory.RuleInput2)
            {
                _i2 = value?.ToString();
            }
            if (instance.This2RuleInterfaceTemplate == StringConcatFactory.RuleInput3)
            {
                _i3 = value?.ToString();
            }
            if (instance.This2RuleInterfaceTemplate == StringConcatFactory.RuleInput4)
            {
                _i4 = value?.ToString();
            }

            return(SingleOutputChanged(new RuleOutputChanged(_output, $"{_i1}{_i2}{_i3}{_i4}")));
        }
Beispiel #21
0
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (instance.This2RuleInterfaceTemplate == AdditionRuleFactory.RuleInput1)
            {
                _i1 = Convert.ToDouble(value);
            }

            if (instance.This2RuleInterfaceTemplate == AdditionRuleFactory.RuleInput2)
            {
                _i2 = Convert.ToDouble(value);
            }
            if (instance.This2RuleInterfaceTemplate == AdditionRuleFactory.RuleInput3)
            {
                _i3 = Convert.ToDouble(value);
            }
            if (instance.This2RuleInterfaceTemplate == AdditionRuleFactory.RuleInput4)
            {
                _i4 = Convert.ToDouble(value);
            }


            return(SingleOutputChanged(new RuleOutputChanged(_output, _i1 + _i2 + _i3 + _i4)));
        }
Beispiel #22
0
        public RuleInstance CreateRuleInstanceFromTemplate(RuleTemplate template)
        {
            var rule = new RuleInstance();

            foreach (var i in template.RuleInterfaceTemplate)
            {
                var intInst = new RuleInterfaceInstance();

                intInst.This2RuleInstanceNavigation          = rule;
                intInst.This2RuleInterfaceTemplateNavigation = i;
                intInst.This2RuleInterfaceTemplate           = i.ObjId;
                intInst.Value = i.DefaultValue;

                rule.RuleInterfaceInstance.Add(intInst);
            }

            rule.Name = template.Name;
            rule.This2RuleTemplate           = template.ObjId;
            rule.This2RuleTemplateNavigation = template;


            return(rule);
        }
        protected override IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
        {
            if (value != null && instance.This2RuleInterfaceTemplate == BinaryDecoderRuleFactory.RuleInput1)
            {
                var i1 = Convert.ToInt64(value);
                _b1 = BitConverter.GetBytes(i1)[0];
            }

            if (_b1.HasValue)
            {
                return(new List <IRuleOutputChanged>
                {
                    new RuleOutputChanged(_output1, (_b1.Value & 1) > 0),
                    new RuleOutputChanged(_output2, (_b1.Value & 2) > 0),
                    new RuleOutputChanged(_output3, (_b1.Value & 4) > 0),
                    new RuleOutputChanged(_output4, (_b1.Value & 8) > 0),
                    new RuleOutputChanged(_output5, (_b1.Value & 16) > 0),
                    new RuleOutputChanged(_output6, (_b1.Value & 32) > 0),
                    new RuleOutputChanged(_output7, (_b1.Value & 64) > 0),
                    new RuleOutputChanged(_output8, (_b1.Value & 128) > 0),
                });
            }
            return(new List <IRuleOutputChanged>());
        }
Beispiel #24
0
 /// <summary>
 /// Will be called if a input parameter of the <see cref="IRule"/> has changed
 /// </summary>
 /// <param name="instance">The <see cref="RuleInterfaceInstance"/> instance</param>
 /// <param name="value">The changed value</param>
 /// <returns></returns>
 public IList <IRuleOutputChanged> ValueChanged(RuleInterfaceInstance instance, object value)
 {
     return(ValueChanged(instance, null, value));
 }
Beispiel #25
0
 /// <summary>
 /// Internal method to notify a parameter value has changed, if the parameter changed needs no notify a dispatch of a value, use the <see cref="Context.Dispatcher.DispatchValue"> DispatchValue</see>
 /// </summary>
 /// <param name="instance">The <see cref="RuleInterfaceInstance"/> instance</param>
 /// <param name="source">The source who dispatched the value (<see cref="IDispatchable"/>)</param>
 /// <param name="value">The changed value</param>
 /// <returns></returns>
 protected virtual void ParamterValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
 {
 }
Beispiel #26
0
 /// <summary>
 /// Internal method to calculate new output values
 /// </summary>
 /// <param name="instance">The <see cref="RuleInterfaceInstance"/> instance</param>
 /// <param name="source">The source who dispatched the value (<see cref="IDispatchable"/>)</param>
 /// <param name="value">The changed value</param>
 /// <returns></returns>
 protected virtual IList <IRuleOutputChanged> InputValueChanged(RuleInterfaceInstance instance, IDispatchable source, object value)
 {
     return(new List <IRuleOutputChanged>());
 }
Beispiel #27
0
 public EnOceanWindowHandleLogic(IRuleContext context) : base(context)
 {
     _output = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                          a.This2RuleInterfaceTemplate == EnOceanWindowHandleLogicFactory.RuleOutput);
 }
Beispiel #28
0
 public async Task NotifyValueChanged(RuleInterfaceInstance instance, object value)
 {
     await _hub.Clients.All.SendAsync("RuleInstanceValueChanged", instance.ObjId, value);
 }
Beispiel #29
0
 public AndRule(IRuleContext context) : base(context)
 {
     _output1 = context.RuleInstance.RuleInterfaceInstance.SingleOrDefault(a =>
                                                                           a.This2RuleInterfaceTemplate == AndRuleFactory.RuleOutput);
 }
        private void ValueDispatchToRule(IDispatchable dispatchable, object o, Guid toRule, RuleInterfaceInstance toInterface)
        {
            lock (_lock)
            {
                Task.Run(async() =>
                {
                    await _ruleInstanceVisuNotifier.NotifyValueChanged(toInterface, o);
                }).ConfigureAwait(false);

                foreach (var rule in _logicInstancesStore.Dictionary())
                {
                    if (rule.Key.ObjId == toRule)
                    {
                        try
                        {
                            SystemLogger.Instance.LogDebug(
                                $"ValueDispatchToRule: {dispatchable.Name} write value {o} to {toInterface.This2RuleInterfaceTemplateNavigation.Name}");
                            var ruleResults = rule.Value.ValueChanged(toInterface, dispatchable, o);

                            foreach (var result in ruleResults)
                            {
                                Task.Run(async() =>
                                {
                                    await _dispatcher.DispatchValue(result.Instance, result.Value);
                                }).ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            SystemLogger.Instance.LogError(e, $"Error writing value ({o}) to {dispatchable.Name}");
                        }
                    }
                }
            }
        }