Beispiel #1
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);
        }
Beispiel #2
0
 public void Clone(HeliosBinding binding)
 {
     Trigger                 = binding.Trigger;
     Action                  = binding.Action;
     ValueSource             = binding.ValueSource;
     Value                   = binding.Value;
     BypassCascadingTriggers = binding.BypassCascadingTriggers;
 }
Beispiel #3
0
        private HeliosBinding CreateNewBinding(IBindingTrigger trigger, IBindingAction action)
        {
            HeliosBinding binding = new HeliosBinding(trigger, action);

            if (action.ActionRequiresValue && (ConfigManager.ModuleManager.CanConvertUnit(trigger.Unit, action.Unit)))
            {
                binding.ValueSource = BindingValueSources.TriggerValue;
            }
            else
            {
                binding.ValueSource = BindingValueSources.StaticValue;
            }
            return(binding);
        }
Beispiel #4
0
        public void SerializeBinding(HeliosBinding binding, XmlWriter xmlWriter)
        {
            TypeConverter boolConverter = TypeDescriptor.GetConverter(typeof(bool));

            if (binding.Action != null && binding.Trigger != null)
            {
                xmlWriter.WriteStartElement("Binding");

                xmlWriter.WriteAttributeString("BypassCascadingTriggers", boolConverter.ConvertToInvariantString(binding.BypassCascadingTriggers));

                xmlWriter.WriteStartElement("Trigger");
                xmlWriter.WriteAttributeString("Source", GetReferenceName(binding.Trigger.Source));
                xmlWriter.WriteAttributeString("Name", binding.Trigger.TriggerID);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Action");
                xmlWriter.WriteAttributeString("Target", GetReferenceName(binding.Action.Target));
                xmlWriter.WriteAttributeString("Name", binding.Action.ActionID);
                xmlWriter.WriteEndElement();

                switch (binding.ValueSource)
                {
                case BindingValueSources.StaticValue:
                    xmlWriter.WriteElementString("StaticValue", binding.Value);
                    break;

                case BindingValueSources.TriggerValue:
                    xmlWriter.WriteStartElement("TriggerValue");
                    xmlWriter.WriteEndElement();
                    break;

                case BindingValueSources.LuaScript:
                    xmlWriter.WriteElementString("LuaScript", binding.Value);
                    break;
                }

                if (binding.HasCondition)
                {
                    xmlWriter.WriteElementString("Condition", binding.Condition);
                }

                xmlWriter.WriteEndElement(); // Binding
            }
            else
            {
                Logger.Warn("Dangling bindings found during save.");
            }
        }
Beispiel #5
0
 private IEnumerable <HeliosBinding> DeserializeBindings(HeliosProfile profile, HeliosVisual root, string copyRoot, List <HeliosVisual> localObjects, XmlReader xmlReader)
 {
     if (!xmlReader.IsEmptyElement)
     {
         xmlReader.ReadStartElement("Bindings");
         while (xmlReader.NodeType != XmlNodeType.EndElement)
         {
             HeliosBinding binding = DeserializeBinding(profile, root, copyRoot, localObjects, xmlReader);
             if (binding?.Action != null && binding.Trigger != null)
             {
                 yield return(binding);
             }
         }
         xmlReader.ReadEndElement();
     }
     else
     {
         xmlReader.Read();
     }
 }
Beispiel #6
0
        private HeliosBindingCollection DeserializeBindings(HeliosProfile profile, HeliosVisual root, string copyRoot, List <HeliosVisual> localObjects, XmlReader xmlReader)
        {
            HeliosBindingCollection bindings = new HeliosBindingCollection();

            if (!xmlReader.IsEmptyElement)
            {
                xmlReader.ReadStartElement("Bindings");
                while (xmlReader.NodeType != XmlNodeType.EndElement)
                {
                    HeliosBinding binding = DeserializeBinding(profile, root, copyRoot, localObjects, xmlReader);
                    if (binding != null && binding.Action != null && binding.Trigger != null)
                    {
                        bindings.Add(binding);
                    }
                }
                xmlReader.ReadEndElement();
            }
            else
            {
                xmlReader.Read();
            }

            return(bindings);
        }
Beispiel #7
0
        private HeliosBinding DeserializeBinding(HeliosProfile profile, HeliosVisual root, string copyRoot, List <HeliosVisual> localObjects, XmlReader xmlReader)
        {
            TypeConverter boolConverter = TypeDescriptor.GetConverter(typeof(bool));

            HeliosBinding binding = (HeliosBinding)CreateNewObject("Binding", "");

            binding.BypassCascadingTriggers = (bool)boolConverter.ConvertFromString(null, CultureInfo.InvariantCulture, xmlReader.GetAttribute("BypassCascadingTriggers"));
            xmlReader.ReadStartElement("Binding");

            HeliosObject source = ResolveReferenceName(profile, root, copyRoot, localObjects, xmlReader.GetAttribute("Source"));

            if (source != null)
            {
                string trigger = xmlReader.GetAttribute("Name");
                if (source is IDynamicBindings dynamic)
                {
                    binding.Trigger = dynamic.ResolveTrigger(trigger);
                }
                else if (source.Triggers.ContainsKey(trigger))
                {
                    binding.Trigger = source.Triggers[trigger];
                }
                else if (source is HeliosVisual)
                {
                    HeliosVisual parent = ((HeliosVisual)source).Parent;
                    if (parent.Triggers.ContainsKey(trigger))
                    {
                        source          = parent;
                        binding.Trigger = source.Triggers[trigger];
                    }
                }
            }
            else
            {
                Logger.Error("Binding Source Reference Unresolved: " + xmlReader.GetAttribute("Source"));
            }
            xmlReader.Read();

            HeliosObject target = ResolveReferenceName(profile, root, copyRoot, localObjects, xmlReader.GetAttribute("Target"));

            if (target != null)
            {
                string action = xmlReader.GetAttribute("Name");
                if (target is IDynamicBindings dynamic)
                {
                    binding.Action = dynamic.ResolveAction(action);
                }
                else if (target.Actions.ContainsKey(action))
                {
                    binding.Action = target.Actions[action];
                }
                else if (target is HeliosVisual)
                {
                    HeliosVisual parent = ((HeliosVisual)target).Parent;
                    if (parent.Actions.ContainsKey(action))
                    {
                        target         = parent;
                        binding.Action = target.Actions[action];
                    }
                }
            }
            else
            {
                Logger.Error("Binding Target Reference Unresolved: " + xmlReader.GetAttribute("Target"));
            }
            xmlReader.Read();
            switch (xmlReader.Name)
            {
            case "StaticValue":
                binding.ValueSource = BindingValueSources.StaticValue;
                binding.Value       = xmlReader.ReadElementString("StaticValue");
                break;

            case "TriggerValue":
                binding.ValueSource = BindingValueSources.TriggerValue;
                xmlReader.Read();
                break;

            case "LuaScript":
                binding.ValueSource = BindingValueSources.LuaScript;
                binding.Value       = xmlReader.ReadElementString("LuaScript");
                break;
            }

            if (xmlReader.Name.Equals("Condition"))
            {
                binding.Condition = xmlReader.ReadElementString("Condition");
            }

            xmlReader.ReadEndElement();

            return(binding);
        }
Beispiel #8
0
 public void Clone(HeliosBinding binding)
 {
     Trigger = binding.Trigger;
     Action = binding.Action;
     ValueSource = binding.ValueSource;
     Value = binding.Value;
     BypassCascadingTriggers = binding.BypassCascadingTriggers;
 }
Beispiel #9
0
        public void SerializeBinding(HeliosBinding binding, XmlWriter xmlWriter)
        {
            TypeConverter boolConverter = TypeDescriptor.GetConverter(typeof(bool));

            if (binding.Action != null && binding.Trigger != null)
            {

                xmlWriter.WriteStartElement("Binding");

                xmlWriter.WriteAttributeString("BypassCascadingTriggers", boolConverter.ConvertToInvariantString(binding.BypassCascadingTriggers));

                xmlWriter.WriteStartElement("Trigger");
                xmlWriter.WriteAttributeString("Source", GetReferenceName(binding.Trigger.Source));
                xmlWriter.WriteAttributeString("Name", binding.Trigger.TriggerID);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Action");
                xmlWriter.WriteAttributeString("Target", GetReferenceName(binding.Action.Target));
                xmlWriter.WriteAttributeString("Name", binding.Action.ActionID);
                xmlWriter.WriteEndElement();

                switch (binding.ValueSource)
                {
                    case BindingValueSources.StaticValue:
                        xmlWriter.WriteElementString("StaticValue", binding.Value);
                        break;
                    case BindingValueSources.TriggerValue:
                        xmlWriter.WriteStartElement("TriggerValue");
                        xmlWriter.WriteEndElement();
                        break;
                    case BindingValueSources.LuaScript:
                        xmlWriter.WriteElementString("LuaScript", binding.Value);
                        break;
                }

                if (binding.HasCondition)
                {
                    xmlWriter.WriteElementString("Condition", binding.Condition);
                }

                xmlWriter.WriteEndElement(); // Binding
            }
            else
            {
                ConfigManager.LogManager.LogWarning("Dangling bindings found during save.");
            }
        }