コード例 #1
0
ファイル: HeliosValue.cs プロジェクト: appsou/Helios
        // XXX this is gross... we churn HeliosTriggerEventArgs and HeliosActionEventArgs objects for no reason.  let's have one EventArgs object that represents a value change
        // XXX and then we can reuse it through the action/trigger/action/trigger stack frames and even use it for tracing
        protected void OnFireTrigger(BindingValue value)
        {
            HeliosTriggerEventArgs args    = new HeliosTriggerEventArgs(value);
            HeliosTriggerHandler   handler = TriggerFired;

            handler?.Invoke(this, args);
        }
コード例 #2
0
ファイル: HeliosValue.cs プロジェクト: Heliflyer/helios
 protected void OnFireTrigger(BindingValue value)
 {
     HeliosTriggerEventArgs args = new HeliosTriggerEventArgs(value);
     HeliosTriggerHandler handler = TriggerFired;
     if (handler != null)
     {
         handler.Invoke(this, args);
     }
 }
コード例 #3
0
 /// <summary>
 /// Contains information to allow AutoBinding in the onProfileChanged method.
 /// </summary>
 /// <param name="childName">Name of the device which has the action</param>
 /// <param name="interfaceTriggerName">The name of the trigger when that trigger is from an interface</param>
 /// <param name="deviceActionName">The name of the action to be performed</param>
 /// <param name="deviceTriggerName">The name of the trigger if it is from a visual component</param>
 /// <param name="deviceTriggerBindingValue">Static trigger value which only used with deviceTriggerValue</param>
 public DefaultInputBinding(string childName, string interfaceTriggerName, string deviceActionName, string deviceTriggerName, BindingValue deviceTriggerBindingValue)
 {
     ChildName                 = childName;
     InterfaceTriggerName      = "";
     DeviceTriggerName         = deviceTriggerName;
     DeviceActionName          = deviceActionName;
     DeviceTriggerBindingValue = deviceTriggerBindingValue;
     Logger.Info("Default Input Binding: Trigger " + deviceTriggerName + " to action " + deviceActionName + " for child " + childName);
 }
コード例 #4
0
        public void FireTrigger(BindingValue value)
        {
            HeliosTriggerEventArgs args    = new HeliosTriggerEventArgs(value);
            HeliosTriggerHandler   handler = TriggerFired;

            if (handler != null)
            {
                handler.Invoke(this, args);
            }
        }
コード例 #5
0
        /// <summary>
        /// Executes this action.
        /// </summary>
        /// <param name="value">Value to be processed by this action.</param>
        /// <param name="bypassCascadingTriggers">If true this action will not fire additional triggers.</param>
        public void ExecuteAction(BindingValue value, bool bypassCascadingTriggers)
        {
            HeliosActionEventArgs args    = new HeliosActionEventArgs(value, bypassCascadingTriggers);
            HeliosActionHandler   handler = Execute;

            if (handler != null)
            {
                handler.Invoke(this, args);
            }
        }
コード例 #6
0
        public BindingValue ConvertUnit(BindingValue value, BindingValueUnit from, BindingValueUnit to)
        {
            BindingValueUnitConverter converter = GetUnitConverter(from, to);

            if (converter != null)
            {
                return(converter.Convert(value, from, to));
            }
            return(BindingValue.Empty);
        }
コード例 #7
0
ファイル: HeliosValue.cs プロジェクト: BlueFinBima/Helios14
        public HeliosValue(HeliosObject owner, BindingValue initialValue, string device, string name, string description, string valueDescription, BindingValueUnit unit)
        {
            _device           = device;
            _name             = name;
            _description      = description;
            _valueDescription = valueDescription;
            _owner            = new WeakReference(owner);
            _value            = initialValue;
            _unit             = unit;

            UpdateId();
        }
コード例 #8
0
ファイル: HeliosValue.cs プロジェクト: Heliflyer/helios
        public HeliosValue(HeliosObject owner, BindingValue initialValue, string device, string name, string description, string valueDescription, BindingValueUnit unit)
        {
            _device = device;
            _name = name;
            _description = description;
            _valueDescription = valueDescription;
            _owner = new WeakReference(owner);
            _value = initialValue;
            _unit = unit;

            UpdateId();
        }
コード例 #9
0
ファイル: HeliosValue.cs プロジェクト: BlueFinBima/Helios14
 /// <summary>
 /// Sets a new value for this helios value object
 /// </summary>
 /// <param name="value">Value to be sent to bindings.</param>
 /// <param name="bypassCascadingTriggers">True if bindings should not trigger further triggers.</param>
 public void SetValue(BindingValue value, bool bypassCascadingTriggers)
 {
     if ((_value == null && value != null) ||
         (_value != null && !_value.Equals(value)))
     {
         _value = value;
         if (!bypassCascadingTriggers)
         {
             OnFireTrigger(value);
         }
     }
 }
コード例 #10
0
ファイル: BindingValue.cs プロジェクト: appsou/Helios
        /// <summary>
        /// WARNING: This function returns true if the object being compared can provide an equal value, even if the types differ.
        /// Use IsIdenticalTo to check for complete equality (same type and value)
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            object compareObject = obj;

            if (obj == this)
            {
                return(true);
            }
            else if (obj == Empty || this == Empty)
            {
                return(false);
            }

            if (obj is BindingValue)
            {
                BindingValue bvObj = (BindingValue)obj;
                switch (bvObj._nativeValueType)
                {
                case BindingValueType.Boolean:
                    compareObject = bvObj.BoolValue;
                    break;

                case BindingValueType.String:
                    compareObject = bvObj.StringValue;
                    break;

                case BindingValueType.Double:
                    compareObject = bvObj.DoubleValue;
                    break;
                }
            }

            // XXX rewrite.  this is insanely inefficient to use a type check here to check what branch we took above
            if (compareObject is string)
            {
                return(StringValue.Equals(compareObject));
            }
            else if (compareObject is double)
            {
                return(DoubleValue.Equals(compareObject));
            }
            else if (compareObject is bool)
            {
                return(BoolValue.Equals(compareObject));
            }


            return(false);
        }
コード例 #11
0
        public override bool Equals(object obj)
        {
            object compareObject = obj;

            if (obj == this)
            {
                return(true);
            }
            else if (obj == Empty || this == Empty)
            {
                return(false);
            }

            if (obj is BindingValue)
            {
                BindingValue bvObj = (BindingValue)obj;
                switch (bvObj._nativeValueType)
                {
                case BindingValueType.Boolean:
                    compareObject = bvObj.BoolValue;
                    break;

                case BindingValueType.String:
                    compareObject = bvObj.StringValue;
                    break;

                case BindingValueType.Double:
                    compareObject = bvObj.DoubleValue;
                    break;
                }
            }

            if (compareObject is string)
            {
                return(StringValue.Equals(compareObject));
            }
            else if (compareObject is double)
            {
                return(DoubleValue.Equals(compareObject));
            }
            else if (compareObject is bool)
            {
                return(BoolValue.Equals(compareObject));
            }


            return(false);
        }
コード例 #12
0
ファイル: BindingValue.cs プロジェクト: appsou/Helios
        public int NonConvertingCompare(BindingValue right)
        {
            if (ReferenceEquals(right, this))
            {
                return(0);
            }

            bool thisIsEmpty = (ReferenceEquals(this, Empty));

            if (ReferenceEquals(right, Empty))
            {
                // empty is less than all values
                return(thisIsEmpty ? 0 : 1);
            }

            int typeDifference = _nativeValueType - right._nativeValueType;

            if (typeDifference != 0)
            {
                // different types sort by type
                return(typeDifference);
            }

            switch (_nativeValueType)
            {
            case BindingValueType.Boolean:
                return(BoolValue.CompareTo(right.BoolValue));

            case BindingValueType.String:
                return(string.Compare(StringValue, right.StringValue, StringComparison.InvariantCulture));

            case BindingValueType.Double:
                return(DoubleValue.CompareTo(right.DoubleValue));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #13
0
ファイル: HeliosBinding.cs プロジェクト: Heliflyer/helios
 private void Execute(BindingValue value, bool bypass)
 {
     Action.ExecuteAction(value, bypass);
 }
コード例 #14
0
 public HeliosActionEventArgs(BindingValue value, bool bypassCascadingTriggers)
 {
     _value = value;
     _bypass = bypassCascadingTriggers;
 }
コード例 #15
0
 private void Execute(BindingValue value, bool bypass)
 {
     Action.ExecuteAction(value, bypass);
 }
コード例 #16
0
        public void OnTriggerFired(object trigger, HeliosTriggerEventArgs e)
        {
            if (IsActive)
            {
                if (_executing)
                {
                    ConfigManager.LogManager.LogWarning("Binding loop condition detected, binding aborted. (Binding=\"" + Description + "\")");
                }
                else
                {
                    if (ConfigManager.LogManager.LogLevel >= LogLevel.Info)
                    {
                        ConfigManager.LogManager.LogInfo("Binding triggered. (Binding=\"" + Description + "\", Value=\"" + e.Value.StringValue + "\")");
                    }
                    try
                    {
                        _executing = true;
                        BindingValue value = BindingValue.Empty;
                        //LuaInterpreter["TriggerValue"] = e.Value.NaitiveValue;
                        switch (e.Value.NaitiveType)
                        {
                        case BindingValueType.Boolean:
                            LuaInterpreter["TriggerValue"] = e.Value.BoolValue;
                            break;

                        case BindingValueType.String:
                            LuaInterpreter["TriggerValue"] = e.Value.StringValue;
                            break;

                        case BindingValueType.Double:
                            LuaInterpreter["TriggerValue"] = e.Value.DoubleValue;
                            break;
                        }

                        if (HasCondition)
                        {
                            try
                            {
                                object[] conditionReturnValues = LuaInterpreter.DoString(_condition);
                                if (conditionReturnValues.Length >= 1)
                                {
                                    BindingValue returnValue = CreateBindingValue(conditionReturnValues[0]);
                                    if (returnValue.BoolValue == false)
                                    {
                                        if (ConfigManager.LogManager.LogLevel >= LogLevel.Debug)
                                        {
                                            ConfigManager.LogManager.LogDebug("Binding condition evaluated to false, binding aborted. (Binding=\"" + Description + "\")");
                                        }
                                        return;
                                    }
                                }
                            }
                            catch (LuaScriptException luaException)
                            {
                                ConfigManager.LogManager.LogWarning("Binding condition lua error. (Error=\"" + luaException.Message + "\", Condition Script=\"" + Condition + "\", Binding=\"" + Description + "\")");
                            }
                            catch (Exception conditionException)
                            {
                                ConfigManager.LogManager.LogError("Binding condition has thown an unhandled exception. (Binding=\"" + Description + "\", Condition=\"" + Condition + "\")", conditionException);
                                return;
                            }
                        }

                        switch (ValueSource)
                        {
                        case BindingValueSources.StaticValue:
                            value = _value;
                            break;

                        case BindingValueSources.TriggerValue:
                            if (_needsConversion && _converter != null)
                            {
                                value = _converter.Convert(e.Value, Trigger.Unit, Action.Unit);
                                if (ConfigManager.LogManager.LogLevel >= LogLevel.Debug)
                                {
                                    ConfigManager.LogManager.LogDebug("Binding converted value. (Binding=\"" + Description + "\", Original Value=\"" + e.Value.StringValue + "\", New Value=\"" + value.StringValue + "\")");
                                }
                            }
                            else
                            {
                                value = e.Value;
                            }
                            break;

                        case BindingValueSources.LuaScript:
                            try
                            {
                                object[] returnValues = LuaInterpreter.DoString(Value);
                                if (returnValues.Length >= 1)
                                {
                                    value = CreateBindingValue(returnValues[0]);
                                    if (ConfigManager.LogManager.LogLevel >= LogLevel.Debug)
                                    {
                                        ConfigManager.LogManager.LogDebug("Binding value lua script evaluated (Binding=\"" + Description + "\", Expression=\"" + Value + "\", TriggerValue=\"" + LuaInterpreter["TriggerValue"] + "\", ReturnValue=\"" + returnValues[0] + "\")");
                                    }
                                }
                                else
                                {
                                    ConfigManager.LogManager.LogWarning("Binding value lua script did not return a value. (Binding=\"" + Description + "\", Expression=\"" + Value + "\", TriggerValue=\"" + LuaInterpreter["TriggerValue"] + "\")");
                                }
                            }
                            catch (LuaScriptException luaException)
                            {
                                ConfigManager.LogManager.LogWarning("Binding value lua error. (Error=\"" + luaException.Message + "\", Value Script=\"" + Value + "\", Binding=\"" + Description + "\")");
                            }
                            catch (Exception valueException)
                            {
                                ConfigManager.LogManager.LogError("Binding value lua script has thown an unhandled exception. (Binding=\"" + Description + "\", Value Script=\"" + Value + "\")", valueException);
                            }
                            break;
                        }
                        if (Action.Target.Dispatcher == null)
                        {
                            // if we don't have a dispatcher, likely because this is a composite device, we use the dispatcher object from the owner of the trigger
                            // this seems to work and was the best I could come up with, but it is very much a kludge because I could not work out the proper way
                            // to have a dispatcher created for Actions
                            Action.Target.Dispatcher = Trigger.Owner.Dispatcher;
                        }
                        Action.Target.Dispatcher.Invoke(new Action <BindingValue, bool>(Execute), value, BypassCascadingTriggers);
                    }
                    catch (Exception ex)
                    {
                        ConfigManager.LogManager.LogError("Binding threw unhandled exception. (Binding=\"" + Description + "\")", ex);
                    }
                    _executing = false;
                }
            }
        }
コード例 #17
0
 public HeliosTriggerEventArgs(BindingValue value)
 {
     _value = value;
 }
コード例 #18
0
 public HeliosActionEventArgs(BindingValue value, bool bypassCascadingTriggers)
 {
     _value  = value;
     _bypass = bypassCascadingTriggers;
 }
コード例 #19
0
ファイル: ModuleManager.cs プロジェクト: Heliflyer/helios
 public BindingValue ConvertUnit(BindingValue value, BindingValueUnit from, BindingValueUnit to)
 {
     BindingValueUnitConverter converter = GetUnitConverter(from, to);
     if (converter != null)
     {
         return converter.Convert(value, from, to);
     }
     return BindingValue.Empty;
 }
コード例 #20
0
ファイル: HeliosValue.cs プロジェクト: Heliflyer/helios
 /// <summary>
 /// Sets a new value for this helios value object
 /// </summary>
 /// <param name="value">Value to be sent to bindings.</param>
 /// <param name="bypassCascadingTriggers">True if bindings should not trigger further triggers.</param>
 public void SetValue(BindingValue value, bool bypassCascadingTriggers)
 {
     if ((_value == null && value != null)
         || (_value != null && !_value.Equals(value)))
     {
         _value = value;
         if (!bypassCascadingTriggers)
         {
             OnFireTrigger(value);
         }
     }
 }
コード例 #21
0
ファイル: BindingValue.cs プロジェクト: appsou/Helios
 public bool IsIdenticalTo(BindingValue other)
 {
     return(0 == NonConvertingCompare(other));
 }
コード例 #22
0
 public HeliosTriggerEventArgs(BindingValue value)
 {
     _value = value;
 }
コード例 #23
0
        private HeliosBinding CreateNewBinding(IBindingTrigger trigger, IBindingAction action, BindingValue bindingValue)
        {
            HeliosBinding binding = new HeliosBinding(trigger, action);

            binding.BypassCascadingTriggers = true;

            if (action.ActionRequiresValue && (ConfigManager.ModuleManager.CanConvertUnit(trigger.Unit, action.Unit)))
            {
                binding.ValueSource = BindingValueSources.TriggerValue;
            }
            else
            {
                binding.ValueSource = BindingValueSources.StaticValue;
                if (bindingValue is null)
                {
                }
                else
                {
                    if (action.Unit.ShortName == "Boolean")
                    {
                        binding.Value = bindingValue.BoolValue ? "True" : "False";
                    }
                    else
                    {
                        binding.Value = bindingValue.StringValue;
                    }
                }
            }
            return(binding);
        }
コード例 #24
0
ファイル: HeliosAction.cs プロジェクト: Heliflyer/helios
 /// <summary>
 /// Executes this action.
 /// </summary>
 /// <param name="value">Value to be processed by this action.</param>
 /// <param name="bypassCascadingTriggers">If true this action will not fire additional triggers.</param>
 public void ExecuteAction(BindingValue value, bool bypassCascadingTriggers)
 {
     HeliosActionEventArgs args = new HeliosActionEventArgs(value, bypassCascadingTriggers);
     HeliosActionHandler handler = Execute;
     if (handler != null)
     {
         handler.Invoke(this, args);
     }
 }