Ejemplo n.º 1
0
        private HeliosProfile LoadProfile(string path, Dispatcher dispatcher, out IEnumerable <string> loadingWork)
        {
            if (ConfigManager.ImageManager is IImageManager2 imageManager2)
            {
                imageManager2.ClearFailureTracking();
            }

            if (!File.Exists(path))
            {
                loadingWork = new string[0];
                return(null);
            }

            HeliosProfile profile = new HeliosProfile(false)
            {
                Path    = path,
                Name    = Path.GetFileNameWithoutExtension(path),
                IsDirty = false,
                // ReSharper disable once AssignNullToNotNullAttribute file exists asserted above
                LoadTime = Directory.GetLastWriteTime(path)
            };

            loadingWork = LoadingWork(profile, dispatcher);
            return(profile);
        }
        public override List<HeliosInterface> GetInterfaceInstances(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            List<HeliosInterface> interfaces = new List<HeliosInterface>();

            if (descriptor == null)
            {
                ConfigManager.LogManager.LogWarning("Descriptor is null passed into UniqueHeliosInterfaceFactory.GetInterfaceInstances.");
            }
            else
            {
                if (IsUnique(descriptor, profile))
                {
                    HeliosInterface newInterface = (HeliosInterface)Activator.CreateInstance(descriptor.InterfaceType);
                    if (newInterface == null)
                    {
                        ConfigManager.LogManager.LogWarning("New interface is null.");
                    }
                    interfaces.Add(newInterface);
                }
                else
                {
                    ConfigManager.LogManager.LogInfo("Unique interface already exists in profile " + descriptor.Name);
                }
            }

            return interfaces;
        }
Ejemplo n.º 3
0
        private IEnumerable <string> LoadingWork(HeliosProfile profile, Dispatcher dispatcher)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments   = true;
            settings.IgnoreWhitespace = true;

            TextReader reader    = new StreamReader(profile.Path);
            XmlReader  xmlReader = XmlReader.Create(reader, settings);

            HeliosSerializer deserializer = new HeliosSerializer(dispatcher);
            int profileVersion            = deserializer.GetProfileVersion(xmlReader);

            if (profileVersion != 3)
            {
                profile.IsInvalidVersion = true;
            }
            else
            {
                foreach (string progress in deserializer.DeserializeProfile(profile, xmlReader))
                {
                    yield return(progress);
                }
            }

            xmlReader.Close();
            reader.Close();
        }
        private bool IsUnique(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            foreach (HeliosInterface heliosInterface in profile.Interfaces)
            {
                if (descriptor.InterfaceType.BaseType.Name != "BaseUDPInterface")
                {
                    HeliosInterfaceDescriptor interfaceDescriptor = ConfigManager.ModuleManager.InterfaceDescriptors[heliosInterface.GetType()];
                    if (interfaceDescriptor.TypeIdentifier.Equals(descriptor.TypeIdentifier))
                    {
                        // If any existing interfaces in the profile have the same type identifier do not add them.
                        return(false);
                    }
                }
                else
                {
                    string _a = heliosInterface.TypeIdentifier;
                    string _b = heliosInterface.BaseTypeIdentifier;
                    HeliosInterfaceDescriptor interfaceDescriptor = ConfigManager.ModuleManager.InterfaceDescriptors[heliosInterface.GetType()];
                    if (interfaceDescriptor.TypeIdentifier.Equals(descriptor.TypeIdentifier) || heliosInterface.BaseTypeIdentifier == "BaseUDPInterface")
                    {
                        // If any existing interfaces in the profile have the same type identifier do not add them.
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
 protected override void OnProfileChanged(HeliosProfile oldProfile)
 {
     base.OnProfileChanged(oldProfile);
     foreach (HeliosVisual child in Children)
     {
         child.Profile = Profile;
     }
 }
Ejemplo n.º 6
0
        public virtual List<HeliosInterface> GetInterfaceInstances(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            List<HeliosInterface> interfaces = new List<HeliosInterface>();

            if (descriptor != null)
            {
                interfaces.Add((HeliosInterface)Activator.CreateInstance(descriptor.InterfaceType));
            }

            return interfaces;
        }
        public override List<HeliosInterface> GetAutoAddInterfaces(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            List<HeliosInterface> interfaces = new List<HeliosInterface>();

            if (descriptor != null && descriptor.AutoAdd && IsUnique(descriptor, profile))
            {
                interfaces.Add((HeliosInterface)Activator.CreateInstance(descriptor.InterfaceType));
            }

            return interfaces;
        }
Ejemplo n.º 8
0
        public bool SaveProfile(HeliosProfile profile)
        {
            try
            {
                string tempPath   = Path.ChangeExtension(profile.Path, "tmp");
                string backupPath = Path.ChangeExtension(profile.Path, "bak");

                // Delete tmp file if exists
                if (File.Exists(tempPath))
                {
                    File.Delete(tempPath);
                }

                TextWriter    writer        = new StreamWriter(tempPath, false);
                TypeConverter boolConverter = TypeDescriptor.GetConverter(typeof(bool));

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;

                XmlWriter xmlWriter = XmlWriter.Create(writer, settings);
                HeliosBindingCollection bindings = new HeliosBindingCollection();

                HeliosSerializer serializer = new HeliosSerializer(null);
                serializer.SerializeProfile(profile, xmlWriter);

                profile.IsDirty = false;
                xmlWriter.Close();
                writer.Close();

                // Delete existing backup
                if (File.Exists(backupPath))
                {
                    File.Delete(backupPath);
                }

                // backup existing file
                if (File.Exists(profile.Path))
                {
                    File.Move(profile.Path, backupPath);
                }

                // Rename .tmp to actual
                File.Move(tempPath, profile.Path);

                profile.LoadTime = Directory.GetLastWriteTime(profile.Path);

                return(true);
            }
            catch (Exception e)
            {
                Logger.Error(e, "Error saving profile");
                return(false);
            }
        }
Ejemplo n.º 9
0
        public HeliosProfile LoadProfile(string path, Dispatcher dispatcher)
        {
            HeliosProfile profile = null;

            try
            {
                if (File.Exists(path))
                {
                    bool rewrite = false;

                    profile      = new HeliosProfile(false);
                    profile.Path = path;
                    profile.Name = Path.GetFileNameWithoutExtension(path);

                    XmlReaderSettings settings = new XmlReaderSettings();
                    settings.IgnoreComments   = true;
                    settings.IgnoreWhitespace = true;

                    TextReader reader    = new StreamReader(path);
                    XmlReader  xmlReader = XmlReader.Create(reader, settings);

                    HeliosSerializer deserializer = new HeliosSerializer(dispatcher);
                    int profileVersion            = deserializer.GetProfileVersion(xmlReader);

                    if (profileVersion != 3)
                    {
                        profile.IsInvalidVersion = true;
                    }
                    else
                    {
                        deserializer.DeserializeProfile(profile, xmlReader);
                    }

                    xmlReader.Close();
                    reader.Close();

                    profile.IsDirty  = false;
                    profile.LoadTime = Directory.GetLastWriteTime(path);

                    if (rewrite)
                    {
                        SaveProfile(profile);
                    }
                }
            }
            catch (Exception e)
            {
                ConfigManager.LogManager.LogError("Error loading profile " + path, e);
                profile = null;
            }

            return(profile);
        }
Ejemplo n.º 10
0
        protected override void OnProfileChanged(HeliosProfile oldProfile)
        {
            base.OnProfileChanged(oldProfile);

            if (oldProfile != null)
            {
                DetachFromProfileOnMainThread(oldProfile);
            }

            if (Profile != null)
            {
                AttachToProfileOnMainThread();
            }
        }
Ejemplo n.º 11
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);
        }
        private bool IsUnique(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            foreach (HeliosInterface heliosInterface in profile.Interfaces)
            {
                HeliosInterfaceDescriptor interfaceDescriptor = ConfigManager.ModuleManager.InterfaceDescriptors[heliosInterface.GetType()];
                if (interfaceDescriptor.TypeIdentifier.Equals(descriptor.TypeIdentifier))
                {
                    // If any existing interfaces in the profile have the same type identifier do not add them.
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 public HeliosInterfaceEditor CreateInterfaceEditor(HeliosInterface item, HeliosProfile profile)
 {
     HeliosInterfaceEditor editor = null;
     if (item != null)
     {
         HeliosInterfaceDescriptor descriptor = _interfaceDescriptors[item.GetType()];
         if (descriptor != null && descriptor.InterfaceEditorType != null)
         {
             editor = (HeliosInterfaceEditor)Activator.CreateInstance(descriptor.InterfaceEditorType);
             editor.Interface = item;
             editor.Profile = profile;
         }
     }
     return editor;
 }
Ejemplo n.º 15
0
        public void DeserializeProfile(HeliosProfile profile, XmlReader xmlReader)
        {
            profile.Monitors.Clear();
            DeserializeMonitors(profile.Monitors, xmlReader);

            profile.Interfaces.Clear();
            DeserializeInterfaces(profile.Interfaces, xmlReader);

            foreach (HeliosBinding binding in DeserializeBindings(profile, new List <HeliosVisual>(), xmlReader))
            {
                binding.Trigger.Source.OutputBindings.Add(binding);
                binding.Action.Target.InputBindings.Add(binding);
            }

            xmlReader.ReadEndElement();
        }
Ejemplo n.º 16
0
        public HeliosInterfaceEditor CreateInterfaceEditor(HeliosInterface item, HeliosProfile profile)
        {
            HeliosInterfaceEditor editor = null;

            if (item != null)
            {
                HeliosInterfaceDescriptor descriptor = _interfaceDescriptors[item.GetType()];
                if (descriptor != null && descriptor.InterfaceEditorType != null)
                {
                    editor           = (HeliosInterfaceEditor)Activator.CreateInstance(descriptor.InterfaceEditorType);
                    editor.Interface = item;
                    editor.Profile   = profile;
                }
            }
            return(editor);
        }
Ejemplo n.º 17
0
 public HeliosProfile LoadProfile(string path)
 {
     try
     {
         HeliosProfile profile = LoadProfile(path, null, out IEnumerable <string> loadingWork);
         foreach (string progress in loadingWork)
         {
             Logger.Debug(progress);
         }
         return(profile);
     }
     catch (Exception e)
     {
         Logger.Error(e, "Error loading profile " + path);
         return(null);
     }
 }
Ejemplo n.º 18
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();
     }
 }
Ejemplo n.º 19
0
        private bool IsUnique(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            foreach (HeliosInterface heliosInterface in profile.Interfaces)
            {
                HeliosInterfaceDescriptor interfaceDescriptor = ConfigManager.ModuleManager.InterfaceDescriptors[heliosInterface.GetType()];
                if (interfaceDescriptor.TypeIdentifier.Equals(descriptor.TypeIdentifier))
                {
                    // If any existing interfaces in the profile have the same type identifier do not add them.
                    return(false);
                }

                // XXX this hack is going away in helios17 and interface2 branches
                if (_udpInterfaceTypes.Contains(descriptor.InterfaceType.BaseType.Name) &&
                    _udpInterfaceTypes.Contains(heliosInterface.GetType().BaseType.Name))
                {
                    // don't add descendants of BaseUDPInterface
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 20
0
        public void SerializeProfile(HeliosProfile profile, XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("HeliosProfile");
            xmlWriter.WriteElementString("Version", "3");

            SerializeMonitors(profile.Monitors, xmlWriter);

            SerializeInterfaces(profile.Interfaces, xmlWriter);

            xmlWriter.WriteStartElement("Bindings");
            foreach (HeliosInterface heliosInterface in profile.Interfaces)
            {
                SerializeBindings(heliosInterface.OutputBindings, xmlWriter);
            }

            foreach (HeliosVisual visual in profile.Monitors)
            {
                SerializeBindings(visual, xmlWriter);
            }

            xmlWriter.WriteEndElement(); // Bindings

            xmlWriter.WriteEndElement(); // HeliosProfile
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 22
0
 protected override void OnProfileChanged(HeliosProfile oldProfile)
 {
     base.OnProfileChanged(oldProfile);
     foreach (HeliosVisual child in Children)
     {
         child.Profile = Profile;
     }
 }
Ejemplo n.º 23
0
 public HeliosBindingCollection DeserializeBindings(HeliosProfile profile, List<HeliosVisual> localObjects, XmlReader xmlReader)
 {
     return DeserializeBindings(profile, null, null, localObjects, xmlReader);
 }
Ejemplo n.º 24
0
 public static HeliosObject ResolveReferenceName(HeliosProfile profile, string reference)
 {
     return ResolveReferenceName(profile, null, null, EMPTYLOCALS, reference);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Notification method for profile changes.
 /// </summary>
 protected virtual void OnProfileChanged(HeliosProfile oldProfile)
 {
 }
Ejemplo n.º 26
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;
        }
Ejemplo n.º 27
0
 public List<HeliosInterface> GetAutoAddInstances(HeliosProfile profile)
 {
     return Factory.GetAutoAddInterfaces(this, profile);
 }
Ejemplo n.º 28
0
        public override List <HeliosInterface> GetAutoAddInterfaces(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            List <HeliosInterface> interfaces = new List <HeliosInterface>();

            if (descriptor != null && descriptor.AutoAdd && IsUnique(descriptor, profile))
            {
                interfaces.Add((HeliosInterface)Activator.CreateInstance(descriptor.InterfaceType));
            }

            return(interfaces);
        }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
0
        public void SerializeProfile(HeliosProfile profile, XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("HeliosProfile");
            xmlWriter.WriteElementString("Version", "3");

            SerializeMonitors(profile.Monitors, xmlWriter);

            SerializeInterfaces(profile.Interfaces, xmlWriter);

            xmlWriter.WriteStartElement("Bindings");
            foreach (HeliosInterface heliosInterface in profile.Interfaces)
            {
                SerializeBindings(heliosInterface.OutputBindings, xmlWriter);
            }

            foreach (HeliosVisual visual in profile.Monitors)
            {
                SerializeBindings(visual, xmlWriter);
            }

            xmlWriter.WriteEndElement();  // Bindings

            xmlWriter.WriteEndElement(); // HeliosProfile
        }
Ejemplo n.º 31
0
        public void DeserializeProfile(HeliosProfile profile, XmlReader xmlReader)
        {

            profile.Monitors.Clear();
            DeserializeMonitors(profile.Monitors, xmlReader);

            profile.Interfaces.Clear();
            DeserializeInterfaces(profile.Interfaces, xmlReader);

            foreach (HeliosBinding binding in DeserializeBindings(profile, new List<HeliosVisual>(), xmlReader))
            {
                binding.Trigger.Source.OutputBindings.Add(binding);
                binding.Action.Target.InputBindings.Add(binding);
            }

            xmlReader.ReadEndElement();
        }
Ejemplo n.º 32
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]));
            }
        }
Ejemplo n.º 33
0
 public List <HeliosInterface> GetAutoAddInstances(HeliosProfile profile)
 {
     return(Factory.GetAutoAddInterfaces(this, profile));
 }
Ejemplo n.º 34
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]));
            }
        }
Ejemplo n.º 35
0
        public override List <HeliosInterface> GetInterfaceInstances(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            List <HeliosInterface> interfaces = new List <HeliosInterface>();

            if (descriptor == null)
            {
                Logger.Warn("Descriptor is null passed into UniqueHeliosInterfaceFactory.GetInterfaceInstances.");
            }
            else
            {
                if (IsUnique(descriptor, profile))
                {
                    HeliosInterface newInterface = (HeliosInterface)Activator.CreateInstance(descriptor.InterfaceType);
                    if (newInterface == null)
                    {
                        Logger.Warn("New interface is null.");
                    }
                    interfaces.Add(newInterface);
                }
                else
                {
                    Logger.Debug("Unique interface already exists in profile " + descriptor.Name + ". Type: " + descriptor.InterfaceType.BaseType.Name);
                }
            }

            return(interfaces);
        }
Ejemplo n.º 36
0
 public HeliosBindingCollection DeserializeBindings(HeliosProfile profile, List <HeliosVisual> localObjects, XmlReader xmlReader)
 {
     return(DeserializeBindings(profile, null, null, localObjects, xmlReader));
 }
Ejemplo n.º 37
0
 public IEnumerable <HeliosBinding> DeserializeBindings(HeliosProfile profile, List <HeliosVisual> localObjects, XmlReader xmlReader)
 {
     return(DeserializeBindings(profile, null, null, localObjects, xmlReader));
 }
Ejemplo n.º 38
0
 public static HeliosObject ResolveReferenceName(HeliosProfile profile, string reference)
 {
     return(ResolveReferenceName(profile, null, null, EMPTYLOCALS, reference));
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 40
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;
 }
Ejemplo n.º 41
0
        public virtual List <HeliosInterface> GetInterfaceInstances(HeliosInterfaceDescriptor descriptor, HeliosProfile profile)
        {
            List <HeliosInterface> interfaces = new List <HeliosInterface>();

            if (descriptor != null)
            {
                interfaces.Add((HeliosInterface)Activator.CreateInstance(descriptor.InterfaceType));
            }

            return(interfaces);
        }
Ejemplo n.º 42
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;
        }
Ejemplo n.º 43
0
 /// <summary>
 /// Notification method for profile changes.
 /// </summary>
 protected virtual void OnProfileChanged(HeliosProfile oldProfile)
 {
 }
Ejemplo n.º 44
0
 /// <summary>
 /// called on the main thread when the interface is removed from a profile,
 /// usually due to deletion by the user
 ///
 /// shut down the interface and detach from all event handlers so the interface
 /// can be deallocated
 /// </summary>
 /// <param name="oldProfile"></param>
 protected virtual void DetachFromProfileOnMainThread(HeliosProfile oldProfile)
 {
     // no code in base
     _ = oldProfile;
 }