Example #1
0
        private static HeliosVisual GetVisualByPath(HeliosVisual visual, Queue <string> nameQueue)
        {
            HeliosVisual returnValue = null;

            string name = nameQueue.Dequeue();

            if (visual.Name.Equals(name))
            {
                if (nameQueue.Count == 0)
                {
                    returnValue = visual;
                }
                else
                {
                    string childName = nameQueue.Peek();
                    foreach (HeliosVisual child in visual.Children)
                    {
                        if (childName.Equals(child.Name))
                        {
                            returnValue = GetVisualByPath(child, nameQueue);
                            if (returnValue != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(returnValue);
        }
Example #2
0
 public NonClickableZone(Rect nonClickableZone, ToggleSwitchPosition position, HeliosVisual childVisual, ToggleSwitchPosition guardedChildPosition)
 {
     _pastToChildZone       = nonClickableZone;
     PositionWhenApplicable = position;
     ChildVisual            = childVisual;
     GuardedChildPosition   = guardedChildPosition;
 }
Example #3
0
        private object DispCreateNewObject(string type, string typeId)
        {
            switch (type)
            {
            case "Monitor":
                return(new Monitor());

            case "Visual":
                HeliosVisual visual = ConfigManager.ModuleManager.CreateControl(typeId);
                visual.Dispatcher = _dispatcher;
                return(visual);

            case "Interface":
                HeliosInterfaceDescriptor descriptor      = ConfigManager.ModuleManager.InterfaceDescriptors[typeId];
                HeliosInterface           heliosInterface = descriptor != null?descriptor.CreateInstance() : null;

                if (heliosInterface != null)
                {
                    heliosInterface.Dispatcher = _dispatcher;
                }
                return(heliosInterface);

            case "Binding":
                return(new HeliosBinding());
            }
            return(null);
        }
Example #4
0
        public static string GetReferenceName(HeliosObject refObject)
        {
            StringBuilder sb = new StringBuilder("");

            HeliosInterface refInterface = refObject as HeliosInterface;

            if (refInterface != null)
            {
                sb.Append("Interface;;");
            }

            HeliosVisual refControl = refObject as HeliosVisual;

            if (refControl != null)
            {
                sb.Append("Visual;");
                sb.Append(GetVisualPath(refControl));
                sb.Append(";");
            }

            sb.Append(refObject.TypeIdentifier);
            sb.Append(";");
            sb.Append(refObject.Name);
            sb.Append("");

            return(sb.ToString());
        }
Example #5
0
 public void SerializeBindings(HeliosVisual visual, XmlWriter xmlWriter)
 {
     SerializeBindings(visual.OutputBindings, xmlWriter);
     foreach (HeliosVisual control in visual.Children)
     {
         SerializeBindings(control, xmlWriter);
     }
 }
Example #6
0
        protected object CreateNewObject(string type, string typeId, ComponentUnsupportedSeverity ifUnsupported = ComponentUnsupportedSeverity.Error)
        {
            switch (type)
            {
            case "Monitor":
                return(new Monitor());

            case "Visual":
                HeliosVisual visual = ConfigManager.ModuleManager.CreateControl(typeId);
                if (visual == null)
                {
                    Logger.Error("Ignoring control not supported by this version of Helios: " + typeId);
                    return(null);
                }
                return(visual);

            case "Interface":
                HeliosInterfaceDescriptor descriptor = ConfigManager.ModuleManager.InterfaceDescriptors[typeId];
                if (descriptor == null)
                {
                    switch (ifUnsupported)
                    {
                    case ComponentUnsupportedSeverity.Error:
                        Logger.Error("Ignoring interface not supported by this version of Helios: {TypeId}; bindings to this interface will fail", typeId);
                        return(null);

                    case ComponentUnsupportedSeverity.Warning:
                        Logger.Warn("Ignoring interface not supported by this version of Helios: {TypeId}; bindings to this interface will fail", typeId);
                        return(null);

                    case ComponentUnsupportedSeverity.Ignore:
                        Logger.Info("Ignoring interface not supported by this version of Helios: {TypeId}; bindings to this interface will be silently ignored", typeId);
                        // create a dummy interface that preserves the XML and ignores but allows writing of all bindings
                        UnsupportedInterface dummy = new UnsupportedInterface();
                        dummy.RepresentedTypeIdentifier = typeId;

                        // record interface type alias, but don't install it yet because we may read more instances of this interface
                        // alias will allow resolution of the unsupported class to our dummy for use in places where we try to instantiate the editor
                        HeliosInterfaceDescriptor dummyDescriptor = ConfigManager.ModuleManager.InterfaceDescriptors[UnsupportedInterface.TYPE_IDENTIFIER];
                        if (DiscoveredAliases != null)
                        {
                            DiscoveredAliases[typeId] = dummyDescriptor;
                        }
                        return(dummy);

                    default:
                        throw new ArgumentOutOfRangeException(nameof(ifUnsupported), ifUnsupported, null);
                    }
                }
                return(descriptor.CreateInstance());

            case "Binding":
                return(new HeliosBinding());
            }
            return(null);
        }
Example #7
0
        public HeliosVisual CreateControl(string typeIdentifier)
        {
            HeliosVisual     control    = null;
            HeliosDescriptor descriptor = _controlDescriptors[typeIdentifier];

            if (descriptor != null)
            {
                control = (HeliosVisual)Activator.CreateInstance(descriptor.ControlType);
            }
            return(control);
        }
Example #8
0
        public static string GetVisualPath(HeliosVisual visual)
        {
            List <string> names    = new List <string>();
            HeliosVisual  pathItem = visual;

            while (pathItem != null)
            {
                names.Add(pathItem.Name);
                pathItem = pathItem.Parent;
            }
            names.Reverse();
            return(string.Join(".", names));
        }
Example #9
0
        private static HeliosVisual GetVisualByPath(HeliosProfile profile, string path)
        {
            HeliosVisual visual = null;

            foreach (HeliosVisual monitor in profile.Monitors)
            {
                visual = GetVisualByPath(monitor, path);
                if (visual != null)
                {
                    break;
                }
            }
            return(visual);
        }
Example #10
0
        private static HeliosVisual GetVisualByPath(List <HeliosVisual> visuals, string path)
        {
            HeliosVisual returnVisual = null;

            foreach (HeliosVisual child in visuals)
            {
                returnVisual = GetVisualByPath(child, path);
                if (returnVisual != null)
                {
                    break;
                }
            }
            return(returnVisual);
        }
Example #11
0
 public HeliosTemplate(HeliosVisual control)
 {
     _user = true;
     _typeIdentifier = control.TypeIdentifier;
     _name = control.Name;
     StringWriter templateWriter = new StringWriter();
     XmlWriter xmlWriter = new XmlTextWriter(templateWriter);
     xmlWriter.WriteStartElement("TemplateValues");
     control.WriteXml(xmlWriter);
     xmlWriter.WriteEndElement();
     xmlWriter.Close();
     templateWriter.Close();
     _templateControl = templateWriter.ToString();
 }
Example #12
0
        private static HeliosObject ResolveReferenceName(HeliosProfile profile, HeliosVisual root, string copyRoot, List <HeliosVisual> localObjects, string reference)
        {
            string[] components;
            if (reference.StartsWith("{"))
            {
                components = reference.Substring(1, reference.Length - 2).Split(';');
            }
            else
            {
                components = reference.Split(';');
            }
            string refType = components[0];
            string path    = components[1];
            string typeId  = components[2];
            string name    = components[3];

            switch (refType)
            {
            case "Visual":

                HeliosVisual visual = null;
                if (!string.IsNullOrWhiteSpace(copyRoot) && !path.Equals(copyRoot, StringComparison.InvariantCultureIgnoreCase) && path.StartsWith(copyRoot, StringComparison.InvariantCultureIgnoreCase))
                {
                    visual = GetVisualByPath(localObjects, path.Substring(copyRoot.Length + 1));
                }

                if (visual == null)
                {
                    if (root == null)
                    {
                        visual = GetVisualByPath(profile, path);
                    }
                    else
                    {
                        visual = GetVisualByPath(root, path);
                    }
                }
                return(visual);

            case "Interface":
                if (profile.Interfaces.ContainsKey(name))
                {
                    return(profile.Interfaces[name]);
                }
                break;
            }

            return(null);
        }
Example #13
0
        public HeliosTemplate(HeliosVisual control)
        {
            _user           = true;
            _typeIdentifier = control.TypeIdentifier;
            _name           = control.Name;
            StringWriter templateWriter = new StringWriter();
            XmlWriter    xmlWriter      = new XmlTextWriter(templateWriter);

            xmlWriter.WriteStartElement("TemplateValues");
            control.WriteXml(xmlWriter);
            xmlWriter.WriteEndElement();
            xmlWriter.Close();
            templateWriter.Close();
            _templateControl = templateWriter.ToString();
        }
Example #14
0
        public HeliosVisualRenderer CreaterRenderer(HeliosVisual visual)
        {
            HeliosVisualRenderer renderer = null;
            Type visualType = visual.GetType();

            HeliosDescriptor descriptor = _controlDescriptors[visualType];

            if (descriptor != null)
            {
                renderer        = (HeliosVisualRenderer)Activator.CreateInstance(descriptor.Renderer);
                renderer.Visual = visual;
            }

            return(renderer);
        }
Example #15
0
        public IEnumerable <string> DeserializeControl(HeliosVisualCollection controls, XmlReader xmlReader)
        {
            TypeConverter boolConverter = TypeDescriptor.GetConverter(typeof(bool));

            HeliosVisual control = (HeliosVisual)CreateNewObject("Visual", xmlReader.GetAttribute("TypeIdentifier"));

            if (control != null)
            {
                string name = xmlReader.GetAttribute("Name");
                if (xmlReader.GetAttribute("SnapTarget") != null)
                {
                    control.IsSnapTarget = (bool)boolConverter.ConvertFromInvariantString(xmlReader.GetAttribute("SnapTarget"));
                }
                if (xmlReader.GetAttribute("Locked") != null)
                {
                    control.IsLocked = (bool)boolConverter.ConvertFromInvariantString(xmlReader.GetAttribute("Locked"));
                }

                if (xmlReader.IsEmptyElement)
                {
                    xmlReader.Read();
                }
                else
                {
                    xmlReader.ReadStartElement("Control");
                    control.ReadXml(xmlReader);
                    foreach (string progress in DeserializeControls(control.Children, xmlReader))
                    {
                        yield return(progress);
                    }
                    ;
                    xmlReader.ReadEndElement();
                }
                control.Name = name;
                controls.Add(control);
                yield return($"loaded {control.TypeIdentifier}");
            }
            else
            {
                xmlReader.Skip();
                yield return("failed to load a control");
            }
        }
Example #16
0
 public void DeserializeControls(HeliosVisualCollection controls, XmlReader xmlReader)
 {
     if (!xmlReader.IsEmptyElement)
     {
         xmlReader.ReadStartElement("Children");
         while (xmlReader.NodeType != XmlNodeType.EndElement)
         {
             HeliosVisual control = DeserializeControl(xmlReader);
             if (control != null)
             {
                 controls.Add(control);
             }
         }
         xmlReader.ReadEndElement();
     }
     else
     {
         xmlReader.Read();
     }
 }
Example #17
0
        public void SerializeControl(HeliosVisual control, XmlWriter xmlWriter)
        {
            TypeConverter boolConverter = TypeDescriptor.GetConverter(typeof(bool));

            xmlWriter.WriteStartElement("Control");
            xmlWriter.WriteAttributeString("TypeIdentifier", control.TypeIdentifier);
            xmlWriter.WriteAttributeString("Name", control.Name);
            xmlWriter.WriteAttributeString("SnapTarget", boolConverter.ConvertToInvariantString(control.IsSnapTarget));
            xmlWriter.WriteAttributeString("Locked", boolConverter.ConvertToInvariantString(control.IsLocked));
            control.WriteXml(xmlWriter);
            if (control.PersistChildren)
            {
                SerializeControls(control.Children, xmlWriter);
            }
            else
            {
                xmlWriter.WriteStartElement("Children");
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();
        }
Example #18
0
        public HeliosVisual DeserializeControl(XmlReader xmlReader)
        {
            TypeConverter boolConverter = TypeDescriptor.GetConverter(typeof(bool));

            HeliosVisual control = (HeliosVisual)CreateNewObject("Visual", xmlReader.GetAttribute("TypeIdentifier"));

            if (control != null)
            {
                string name = xmlReader.GetAttribute("Name");
                if (xmlReader.GetAttribute("SnapTarget") != null)
                {
                    control.IsSnapTarget = (bool)boolConverter.ConvertFromInvariantString(xmlReader.GetAttribute("SnapTarget"));
                }
                if (xmlReader.GetAttribute("Locked") != null)
                {
                    control.IsLocked = (bool)boolConverter.ConvertFromInvariantString(xmlReader.GetAttribute("Locked"));
                }

                if (xmlReader.IsEmptyElement)
                {
                    xmlReader.Read();
                }
                else
                {
                    xmlReader.ReadStartElement("Control");
                    control.ReadXml(xmlReader);
                    DeserializeControls(control.Children, xmlReader);
                    xmlReader.ReadEndElement();
                }
                control.Name = name;
            }
            else
            {
                xmlReader.Skip();
            }

            return(control);
        }
Example #19
0
        private object DispCreateNewObject(string type, string typeId)
        {
            switch (type)
            {
            case "Monitor":
                return(new Monitor());

            case "Visual":
                HeliosVisual visual = ConfigManager.ModuleManager.CreateControl(typeId);
                if (visual == null)
                {
                    ConfigManager.LogManager.LogError("Ignoring control not supported by this version of Helios: " + typeId);
                    return(null);
                }
                visual.Dispatcher = _dispatcher;
                return(visual);

            case "Interface":
                HeliosInterfaceDescriptor descriptor = ConfigManager.ModuleManager.InterfaceDescriptors[typeId];
                if (descriptor == null)
                {
                    ConfigManager.LogManager.LogError("Ignoring interface not supported by this version of Helios: " + typeId);
                    return(null);
                }
                HeliosInterface heliosInterface = descriptor != null?descriptor.CreateInstance() : null;

                if (heliosInterface != null)
                {
                    heliosInterface.Dispatcher = _dispatcher;
                }
                return(heliosInterface);

            case "Binding":
                return(new HeliosBinding());
            }
            return(null);
        }
Example #20
0
        public HeliosVisual CreateInstance()
        {
            HeliosVisual control = ConfigManager.ModuleManager.CreateControl(_typeIdentifier);

            if (control != null)
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments   = true;
                settings.IgnoreWhitespace = true;
                settings.CloseInput       = true;

                StringReader templateReader = new StringReader(_templateControl);
                XmlReader    xmlReader      = XmlReader.Create(templateReader, settings);
                xmlReader.ReadStartElement("TemplateValues");
                control.ReadXml(xmlReader);
                xmlReader.ReadEndElement();
                xmlReader.Close();
                templateReader.Close();

                control.Name = Name;
            }

            return(control);
        }
Example #21
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);
        }
Example #22
0
 public IEnumerable <HeliosBinding> DeserializeBindings(HeliosVisual root, string copyRoot, List <HeliosVisual> localObjects, XmlReader xmlReader)
 {
     return(DeserializeBindings(root.Profile, root, copyRoot, localObjects, xmlReader));
 }
Example #23
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();
     }
 }
Example #24
0
 public static string GetVisualPath(HeliosVisual visual)
 {
     List<string> names = new List<string>();
     HeliosVisual pathItem = visual;
     while (pathItem != null)
     {
         names.Add(pathItem.Name);
         pathItem = pathItem.Parent;
     }
     names.Reverse();
     return string.Join(".", names);
 }
Example #25
0
 public SnapTarget(HeliosVisual visual)
 {
     _rectangle = visual.DisplayRectangle;
     _tag = visual;
 }
Example #26
0
 private static HeliosVisual GetVisualByPath(HeliosVisual visual, string path)
 {
     return(GetVisualByPath(visual, new Queue <string>(path.Split('.'))));
 }
Example #27
0
        private static HeliosObject ResolveReferenceName(HeliosProfile profile, HeliosVisual root, string copyRoot, List<HeliosVisual> localObjects, string reference)
        {
            string[] components;
            if (reference.StartsWith("{"))
            {
                components = reference.Substring(1, reference.Length - 2).Split(';');
            }
            else
            {
                components = reference.Split(';');
            }
            string refType = components[0];
            string path = components[1];
            string typeId = components[2];
            string name = components[3];

            switch (refType)
            {
                case "Visual":

                    HeliosVisual visual = null;
                    if (!string.IsNullOrWhiteSpace(copyRoot) && !path.Equals(copyRoot, StringComparison.InvariantCultureIgnoreCase) && path.StartsWith(copyRoot, StringComparison.InvariantCultureIgnoreCase))
                    {
                        visual = GetVisualByPath(localObjects, path.Substring(copyRoot.Length + 1));
                    }

                    if (visual == null)
                    {
                        if (root == null)
                        {
                            visual = GetVisualByPath(profile, path);
                        }
                        else
                        {
                            visual = GetVisualByPath(root, path);
                        }
                    }
                    return visual;

                case "Interface":
                    if (profile.Interfaces.ContainsKey(name))
                    {
                        return profile.Interfaces[name];
                    }
                    break;
            }

            return null;
        }
Example #28
0
 private static HeliosVisual GetVisualByPath(HeliosVisual visual, string path)
 {
     return GetVisualByPath(visual, new Queue<string>(path.Split('.')));
 }
Example #29
0
        private static HeliosVisual GetVisualByPath(HeliosVisual visual, Queue<string> nameQueue)
        {
            HeliosVisual returnValue = null;

            string name = nameQueue.Dequeue();
            if (visual.Name.Equals(name))
            {
                if (nameQueue.Count == 0)
                {
                    returnValue = visual;
                }
                else
                {
                    string childName = nameQueue.Peek();
                    foreach (HeliosVisual child in visual.Children)
                    {
                        if (childName.Equals(child.Name))
                        {
                            returnValue = GetVisualByPath(child, nameQueue);
                            if (returnValue != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return returnValue;
        }
Example #30
0
        public HeliosVisualRenderer CreaterRenderer(HeliosVisual visual)
        {
            HeliosVisualRenderer renderer = null;
            Type visualType = visual.GetType();

            HeliosDescriptor descriptor = _controlDescriptors[visualType];
            if (descriptor != null)
            {
                renderer = (HeliosVisualRenderer)Activator.CreateInstance(descriptor.Renderer);
                renderer.Visual = visual;
            }

            return renderer;
        }
Example #31
0
 public IEnumerable <HeliosCapabilityEditorDescriptor> GetCapabilityEditors(HeliosVisual visual)
 {
     // NOTE: we could check for each interface and keep a list of editors for that interface, but that
     // complexity is not reasonable, considering it will typically be 1:1
     return(_capabilityEditors.Where(editor => editor.InterfaceType.IsInstanceOfType(visual)));
 }
Example #32
0
 public static HeliosObject ResolveReferenceName(HeliosVisual root, string copyRoot, string reference)
 {
     return(ResolveReferenceName(root.Profile, root, copyRoot, EMPTYLOCALS, reference));
 }
Example #33
0
        void Child_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            HeliosVisual control = sender as HeliosVisual;

            OnPropertyChanged("Controls." + control.Name, (PropertyNotificationEventArgs)e);
        }
Example #34
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, System.Globalization.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.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];
                    }
                }
            }
            xmlReader.Read();

            HeliosObject target = ResolveReferenceName(profile, root, copyRoot, localObjects, xmlReader.GetAttribute("Target"));
            if (target != null)
            {
                string action = xmlReader.GetAttribute("Name");
                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];
                    }
                }
            }
            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;
        }
Example #35
0
 public static HeliosObject ResolveReferenceName(HeliosVisual root, string copyRoot, string reference)
 {
     return ResolveReferenceName(root.Profile, root, copyRoot, EMPTYLOCALS, reference);
 }
Example #36
0
 public void SerializeBindings(HeliosVisual visual, XmlWriter xmlWriter)
 {
     SerializeBindings(visual.OutputBindings, xmlWriter);
     foreach (HeliosVisual control in visual.Children)
     {
         SerializeBindings(control, xmlWriter);
     }
 }
Example #37
0
 public HeliosBindingCollection DeserializeBindings(HeliosVisual root, string copyRoot, List<HeliosVisual> localObjects, XmlReader xmlReader)
 {
     return DeserializeBindings(root.Profile, root, copyRoot, localObjects, xmlReader);
 }
Example #38
0
 public NonClickableZone(Rect nonClickableZone, bool allPosition, HeliosVisual childVisual)
 {
     _pastToChildZone = nonClickableZone;
     AllPositions     = allPosition;
     ChildVisual      = childVisual;
 }
Example #39
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;
        }
Example #40
0
        protected override void OnProfileChanged(HeliosProfile oldProfile)
        {
            base.OnProfileChanged(oldProfile);
            if (!DesignMode)
            {
                return;
            }

            /// grab the default interface, if it exists
            if (_defaultInterfaceName == "")
            {
                return;
            }
            if (!Profile.Interfaces.ContainsKey(_defaultInterfaceName))
            {
                ConfigManager.LogManager.LogError("Cannot find default interface " + _defaultInterfaceName);
                return;
            }
            _defaultInterface = Profile.Interfaces[_defaultInterfaceName];

            /// looping for all default input bindings to assign the value
            foreach (DefaultInputBinding defaultBinding in _defaultInputBindings)
            {
                if (!Children.ContainsKey(defaultBinding.ChildName))
                {
                    ConfigManager.LogManager.LogError("Cannot find child " + defaultBinding.ChildName);
                    continue;
                }
                ConfigManager.LogManager.LogDebug("Auto binding child " + defaultBinding.ChildName);
                HeliosVisual child = Children[defaultBinding.ChildName];
                if (!child.Actions.ContainsKey(defaultBinding.DeviceActionName))
                {
                    ConfigManager.LogManager.LogError("Cannot find action " + defaultBinding.DeviceActionName);
                    continue;
                }
                if (!_defaultInterface.Triggers.ContainsKey(defaultBinding.InterfaceTriggerName))
                {
                    ConfigManager.LogManager.LogError("Cannot find interface trigger " + defaultBinding.InterfaceTriggerName);
                    continue;
                }
                ConfigManager.LogManager.LogDebug("Auto binding trigger " + defaultBinding.InterfaceTriggerName + " to " + defaultBinding.DeviceActionName);
                child.OutputBindings.Add(CreateNewBinding(_defaultInterface.Triggers[defaultBinding.InterfaceTriggerName],
                                                          child.Actions[defaultBinding.DeviceActionName]));

                //child.OutputBindings.Add(
                //    new HeliosBinding(_defaultInterface.Triggers[defaultBinding.InterfaceTriggerName],
                //        child.Actions[defaultBinding.DeviceActionName]));
            }

            /// now looping for all default output bindings to assign the value
            foreach (DefaultOutputBinding defaultBinding in _defaultOutputBindings)
            {
                if (!Children.ContainsKey(defaultBinding.ChildName))
                {
                    ConfigManager.LogManager.LogError("Cannot find child " + defaultBinding.ChildName);
                    continue;
                }
                HeliosVisual child = Children[defaultBinding.ChildName];
                if (!child.Triggers.ContainsKey(defaultBinding.DeviceTriggerName))
                {
                    ConfigManager.LogManager.LogError("Cannot find trigger " + defaultBinding.DeviceTriggerName);
                    continue;
                }
                if (!_defaultInterface.Actions.ContainsKey(defaultBinding.InterfaceActionName))
                {
                    ConfigManager.LogManager.LogError("Cannot find action " + defaultBinding.InterfaceActionName);
                    continue;
                }
                ConfigManager.LogManager.LogDebug("Child Output binding trigger " + defaultBinding.DeviceTriggerName + " to " + defaultBinding.InterfaceActionName);
                child.OutputBindings.Add(CreateNewBinding(child.Triggers[defaultBinding.DeviceTriggerName],
                                                          _defaultInterface.Actions[defaultBinding.InterfaceActionName]));
                //            child.OutputBindings.Add(
                //new HeliosBinding(child.Triggers[defaultBinding.DeviceTriggerName],
                //                  _defaultInterface.Actions[defaultBinding.InterfaceActionName]));
            }
        }
Example #41
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);
        }
Example #42
0
        protected override void OnProfileChanged(HeliosProfile oldProfile)
        {
            base.OnProfileChanged(oldProfile);
            if (!DesignMode)
            {
                return;
            }

            // grab the default interface, if it exists
            foreach (Type supportedInterface in SupportedInterfaces)
            {
                _defaultInterface = Profile.Interfaces.FirstOrDefault(i => supportedInterface.IsInstanceOfType(i));
                if (_defaultInterface != null)
                {
                    Logger.Info($"{Name} auto binding to interface '{_defaultInterface.Name}'");
                    break;
                }
            }

            if (_defaultInterface == null)
            {
                Logger.Info($"{Name} could not locate any supported interface for auto binding");
                return;
            }

            // looping for all default input bindings to assign the value
            foreach (DefaultInputBinding defaultBinding in _defaultInputBindings)
            {
                if (!Children.ContainsKey(defaultBinding.ChildName))
                {
                    Logger.Error("Cannot find child " + defaultBinding.ChildName);
                    continue;
                }
                Logger.Debug("Auto binding child " + defaultBinding.ChildName);
                HeliosVisual child = Children[defaultBinding.ChildName];
                if (!child.Actions.ContainsKey(defaultBinding.DeviceActionName))
                {
                    Logger.Error("Cannot find action " + defaultBinding.DeviceActionName);
                    continue;
                }
                if (defaultBinding.InterfaceTriggerName != "")
                {
                    if (!_defaultInterface.Triggers.ContainsKey(defaultBinding.InterfaceTriggerName))
                    {
                        Logger.Error("Cannot find interface trigger " + defaultBinding.InterfaceTriggerName);
                        continue;
                    }

                    Logger.Debug("Auto binding trigger " + defaultBinding.InterfaceTriggerName + " to " + defaultBinding.ChildName + defaultBinding.DeviceActionName);
                    child.OutputBindings.Add(CreateNewBinding(_defaultInterface.Triggers[defaultBinding.InterfaceTriggerName],
                                                              child.Actions[defaultBinding.DeviceActionName]));
                }
                else
                {
                    if (!Triggers.ContainsKey(defaultBinding.DeviceTriggerName))
                    {
                        Logger.Error("Cannot find interface trigger " + defaultBinding.DeviceTriggerName);
                        continue;
                    }

                    Logger.Debug("Auto binding trigger " + defaultBinding.DeviceTriggerName + " to " + defaultBinding.ChildName + defaultBinding.DeviceActionName);
                    child.OutputBindings.Add(CreateNewBinding(Triggers[defaultBinding.DeviceTriggerName],
                                                              child.Actions[defaultBinding.DeviceActionName], defaultBinding.DeviceTriggerBindingValue));
                }

                //child.OutputBindings.Add(
                //    new HeliosBinding(_defaultInterface.Triggers[defaultBinding.InterfaceTriggerName],
                //        child.Actions[defaultBinding.DeviceActionName]));
            }

            // now looping for all default output bindings to assign the value
            foreach (DefaultOutputBinding defaultBinding in _defaultOutputBindings)
            {
                if (!Children.ContainsKey(defaultBinding.ChildName))
                {
                    Logger.Error("Cannot find child " + defaultBinding.ChildName);
                    continue;
                }
                HeliosVisual child = Children[defaultBinding.ChildName];
                if (!child.Triggers.ContainsKey(defaultBinding.DeviceTriggerName))
                {
                    Logger.Error("Cannot find trigger " + defaultBinding.DeviceTriggerName);
                    continue;
                }
                if (!_defaultInterface.Actions.ContainsKey(defaultBinding.InterfaceActionName))
                {
                    Logger.Error("Cannot find action " + defaultBinding.InterfaceActionName);
                    continue;
                }
                Logger.Debug("Child Output binding trigger " + defaultBinding.DeviceTriggerName + " to " + defaultBinding.InterfaceActionName);
                child.OutputBindings.Add(CreateNewBinding(child.Triggers[defaultBinding.DeviceTriggerName],
                                                          _defaultInterface.Actions[defaultBinding.InterfaceActionName]));

                //            child.OutputBindings.Add(
                //new HeliosBinding(child.Triggers[defaultBinding.DeviceTriggerName],
                //                  _defaultInterface.Actions[defaultBinding.InterfaceActionName]));
            }
        }
Example #43
0
        public void SerializeControl(HeliosVisual control, XmlWriter xmlWriter)
        {
            TypeConverter boolConverter = TypeDescriptor.GetConverter(typeof(bool));

            xmlWriter.WriteStartElement("Control");
            xmlWriter.WriteAttributeString("TypeIdentifier", control.TypeIdentifier);
            xmlWriter.WriteAttributeString("Name", control.Name);
            xmlWriter.WriteAttributeString("SnapTarget", boolConverter.ConvertToInvariantString(control.IsSnapTarget));
            xmlWriter.WriteAttributeString("Locked", boolConverter.ConvertToInvariantString(control.IsLocked));
            control.WriteXml(xmlWriter);
            if (control.PersistChildren)
            {
                SerializeControls(control.Children, xmlWriter);
            }
            else
            {
                xmlWriter.WriteStartElement("Children");
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();
        }