Esempio n. 1
0
        // TODO: allow third party interface loading from external assembly dll
        //          eg. AddInterface(string domain, string assemblyName)
        public MIGInterface AddInterface(string domain, string assemblyName)
        {
            MIGInterface migInterface = null;

            if (!Interfaces.ContainsKey(domain))
            {
                try
                {
                    var type = Type.GetType("MIG.Interfaces." + domain + (String.IsNullOrWhiteSpace(assemblyName) ? "" : ", " + assemblyName));
                    migInterface         = (MIGInterface)Activator.CreateInstance(type);
                    migInterface.Options = configuration.GetInterface(domain).Options;
                }
                catch (Exception e)
                {
                    // TODO: add error logging
                    Console.WriteLine("MIG ERROR: could not load interface '" + domain + "': " + e.Message);
                }
                if (migInterface != null)
                {
                    Interfaces.Add(domain, migInterface);
                    migInterface.InterfaceModulesChangedAction  += MigService_InterfaceModulesChanged;
                    migInterface.InterfacePropertyChangedAction += MigService_InterfacePropertyChanged;
                }
            }
            else
            {
                migInterface = Interfaces[domain];
            }
            return(migInterface);
        }
Esempio n. 2
0
        // TODO: allow third party interface loading from external assembly dll
        //          eg. AddInterface(string domain, string assemblyFileName)
        public MIGInterface AddInterface(string domain)
        {
            MIGInterface migInterface = null;

            if (!Interfaces.ContainsKey(domain))
            {
                try
                {
                    var type = Type.GetType("MIG.Interfaces." + domain);
                    migInterface         = (MIGInterface)Activator.CreateInstance(type);
                    migInterface.Options = configuration.GetInterface(domain).Options;
                }
                catch
                {
                    // TODO: add error logging
                }
                if (migInterface != null)
                {
                    Interfaces.Add(domain, migInterface);
                    migInterface.InterfaceModulesChangedAction  += MigService_InterfaceModulesChanged;
                    migInterface.InterfacePropertyChangedAction += MigService_InterfacePropertyChanged;
                }
            }
            else
            {
                migInterface = Interfaces[domain];
            }
            return(migInterface);
        }
Esempio n. 3
0
 public void DisableInterface(string domain)
 {
     if (Interfaces.ContainsKey(domain))
     {
         MIGInterface migInterface = Interfaces[domain];
         migInterface.Disconnect();
     }
 }
Esempio n. 4
0
 public static MIGServiceConfiguration.Interface.Option GetOption(this MIGInterface iface, string option)
 {
     if (iface.Options != null)
     {
         return(iface.Options.Find(o => o.Name == option));
     }
     return(null);
 }
Esempio n. 5
0
 public void EnableInterface(string domain)
 {
     if (Interfaces.ContainsKey(domain))
     {
         MIGInterface migInterface = Interfaces[domain];
         migInterface.Options = configuration.GetInterface(domain).Options;
         migInterface.Connect();
     }
 }
Esempio n. 6
0
        public static void SetOption(this MIGInterface iface, string option, string value)
        {
            var opt = iface.GetOption(option);

            if (opt != null)
            {
                iface.Disconnect();
                opt.Value = value;
                iface.Connect();
            }
        }
Esempio n. 7
0
        public void AddInterface(string intfdomain)
        {
            MIGInterface migintf = null;
            Type         type    = Type.GetType("MIG.Interfaces." + intfdomain);

            migintf = (MIGInterface)Activator.CreateInstance(type);
            Interfaces.Add(intfdomain, migintf);
            migintf.InterfacePropertyChangedAction += new Action <InterfacePropertyChangedAction>(MIGService_InterfacePropertyChanged);
            //TODO: implement eventually a RemoveInterface method containing code:
            //			mif.InterfacePropertyChangedAction -= MIGService_InterfacePropertyChangedAction;
        }
Esempio n. 8
0
        public MIGInterface DisableInterface(string domain)
        {
            MIGInterface migInterface = null;

            if (Interfaces.ContainsKey(domain))
            {
                migInterface           = Interfaces[domain];
                migInterface.IsEnabled = false;
                migInterface.Disconnect();
            }
            return(migInterface);
        }
Esempio n. 9
0
        public MIGInterface EnableInterface(string domain)
        {
            MIGInterface migInterface = null;

            if (Interfaces.ContainsKey(domain))
            {
                migInterface           = Interfaces[domain];
                migInterface.Options   = configuration.GetInterface(domain).Options;
                migInterface.IsEnabled = true;
                migInterface.Connect();
            }
            return(migInterface);
        }
Esempio n. 10
0
        public bool IsInterfacePresent(string domain)
        {
            bool         isPresent    = false;
            MIGInterface migInterface = null;

            try
            {
                var type = Type.GetType("MIG.Interfaces." + domain);
                migInterface = (MIGInterface)Activator.CreateInstance(type);
                isPresent    = migInterface.IsDevicePresent();
            }
            catch { }
            return(isPresent);
        }
Esempio n. 11
0
 public void AddInterface(string domain)
 {
     if (!Interfaces.ContainsKey(domain))
     {
         MIGInterface migInterface = null;
         var          type         = Type.GetType("MIG.Interfaces." + domain);
         migInterface         = (MIGInterface)Activator.CreateInstance(type);
         migInterface.Options = configuration.GetInterface(domain).Options;
         Interfaces.Add(domain, migInterface);
         migInterface.InterfaceModulesChangedAction  += MigService_InterfaceModulesChanged;
         migInterface.InterfacePropertyChangedAction += MigService_InterfacePropertyChanged;
     }
     //TODO: implement eventually a RemoveInterface method containing code:
     //          migInterface.ModulesChangedAction -= MigService_ModulesChanged;
     //			mif.InterfacePropertyChangedAction -= MIGService_InterfacePropertyChangedAction;
 }
Esempio n. 12
0
        public static void SetOption(this MIGInterface iface, string option, string value)
        {
            var opt = iface.GetOption(option);

            if (opt == null)
            {
                opt = new MIGServiceConfiguration.Interface.Option()
                {
                    Name = option
                };
                iface.Options.Add(opt);
            }
            iface.Disconnect();
            opt.Value = value;
            iface.Connect();
        }
Esempio n. 13
0
 private void modules_RefreshInterface(MIGInterface iface)
 {
     // TODO: read IsEnabled instead of IsConnected
     if (migService.Configuration.GetInterface(iface.Domain).IsEnabled)
     {
         var interfaceModules = iface.GetModules();
         if (interfaceModules.Count > 0)
         {
             // delete removed modules
             var deleted = systemModules.FindAll(m => m.Domain == iface.Domain && (interfaceModules.Find(m1 => m1.Address == m.Address && m1.Domain == m.Domain) == null));
             foreach (var mod in deleted)
             {
                 var virtualParam = Utility.ModuleParameterGet(mod, Properties.VIRTUALMODULE_PARENTID);
                 if (virtualParam == null || virtualParam.DecimalValue == 0)
                 {
                     Module garbaged = modulesGarbage.Find(m => m.Domain == mod.Domain && m.Address == mod.Address);
                     if (garbaged != null) modulesGarbage.Remove(garbaged);
                     modulesGarbage.Add(mod);
                     systemModules.Remove(mod);
                 }
             }
             //
             foreach (var migModule in interfaceModules)
             {
                 Module module = systemModules.Find(o => o.Domain == migModule.Domain && o.Address == migModule.Address);
                 if (module == null)
                 {
                     // try restoring from garbage
                     module = modulesGarbage.Find(o => o.Domain == migModule.Domain && o.Address == migModule.Address);
                     if (module != null)
                     {
                         systemModules.Add(module);
                     }
                     else
                     {
                         module = new Module();
                         module.Domain = migModule.Domain;
                         module.Address = migModule.Address;
                         systemModules.Add(module);
                     }
                 }
                 //
                 if (String.IsNullOrEmpty(module.Description))
                 {
                     module.Description = migModule.Description;
                 }
                 if (module.DeviceType == ModuleTypes.Generic)
                 {
                     module.DeviceType = migModule.ModuleType;
                 }
             }
         }
     }
     else
     {
         var deleted = systemModules.FindAll(m => m.Domain == iface.Domain);
         foreach (var mod in deleted)
         {
             var virtualParam = Utility.ModuleParameterGet(mod, Properties.VIRTUALMODULE_PARENTID);
             if (virtualParam == null || virtualParam.DecimalValue == 0)
             {
                 Module garbaged = modulesGarbage.Find(m => m.Domain == mod.Domain && m.Address == mod.Address);
                 if (garbaged != null) modulesGarbage.Remove(garbaged);
                 modulesGarbage.Add(mod);
                 systemModules.Remove(mod);
             }
         }
     }
 }