Exemple #1
0
        /// <summary>
        /// Adds the interface.
        /// </summary>
        /// <returns>The interface.</returns>
        /// <param name="domain">Domain.</param>
        /// <param name="assemblyName">Assembly name.</param>
        public MigInterface AddInterface(string domain, string assemblyName = "")
        {
            MigInterface migInterface = GetInterface(domain);

            if (migInterface == null)
            {
                Type type = null;
                try
                {
                    type = TypeLookup("MIG.Interfaces." + domain, assemblyName);
                    if (type == null)
                    {
                        Log.Error("Can't find type for Mig Interface with domain {0} (assemblyName={1})", domain, assemblyName);
                        return(null);
                    }
                    migInterface = (MigInterface)Activator.CreateInstance(type);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
                if (migInterface != null)
                {
                    var interfaceVersion = VersionLookup(type.Assembly);
                    Log.Debug("Adding Interface {0} Version: {1}", migInterface.GetDomain(), interfaceVersion);
                    Interfaces.Add(migInterface);
                    migInterface.InterfaceModulesChanged  += MigService_InterfaceModulesChanged;
                    migInterface.InterfacePropertyChanged += MigService_InterfacePropertyChanged;
                }
            }

            // Try loading interface settings from MIG configuration
            var config = configuration.GetInterface(domain);

            if (config == null)
            {
                config = new Interface {
                    Domain = domain
                };
                if (config.Options == null)
                {
                    config.Options = new List <Option>();
                }
                configuration.Interfaces.Add(config);
            }
            if (migInterface != null)
            {
                Log.Debug("Setting Interface options");
                migInterface.Options = config.Options;
                foreach (var opt in config.Options)
                {
                    migInterface.SetOption(opt.Name, opt.Value);
                }
            }
            return(migInterface);
        }
        public static void SetOption(this MigInterface iface, string option, string value)
        {
            MigService.Log.Trace("{0}: {1}={2}", iface.GetDomain(), option, value);
            var opt = iface.GetOption(option);

            if (opt == null)
            {
                opt = new Option(option);
                iface.Options.Add(opt);
            }
            opt.Value = value;
            iface.OnSetOption(opt);
        }
Exemple #3
0
        /// <summary>
        /// Adds the interface.
        /// </summary>
        /// <returns>The interface.</returns>
        /// <param name="domain">Domain.</param>
        /// <param name="assemblyName">Assembly name.</param>
        public MigInterface AddInterface(string domain, string assemblyName = "")
        {
            MigInterface migInterface = GetInterface(domain);

            if (migInterface == null)
            {
                try
                {
                    var type = TypeLookup("MIG.Interfaces." + domain, assemblyName);
                    migInterface = (MigInterface)Activator.CreateInstance(type);
                }
                catch (Exception e)
                {
                    MigService.Log.Error(e);
                }
                if (migInterface != null)
                {
                    Log.Debug("Adding Interface {0}", migInterface.GetDomain());
                    Interfaces.Add(migInterface);
                    migInterface.InterfaceModulesChanged  += MigService_InterfaceModulesChanged;
                    migInterface.InterfacePropertyChanged += MigService_InterfacePropertyChanged;
                }
            }
            // Try loading interface settings from MIG configuration
            var config = configuration.GetInterface(domain);

            if (config == null)
            {
                config        = new Interface();
                config.Domain = domain;
                if (config.Options == null)
                {
                    config.Options = new List <Option>();
                }
                configuration.Interfaces.Add(config);
            }
            if (migInterface != null)
            {
                Log.Debug("Setting Interface options");
                migInterface.Options = config.Options;
                foreach (var opt in config.Options)
                {
                    migInterface.SetOption(opt.Name, opt.Value);
                }
            }
            return(migInterface);
        }
Exemple #4
0
 private void modules_RefreshInterface(MigInterface iface)
 {
     if (migService.Configuration.GetInterface(iface.GetDomain()).IsEnabled)
     {
         var interfaceModules = iface.GetModules();
         if (interfaceModules.Count > 0)
         {
             // delete removed modules
             var deleted = systemModules.FindAll(m => m.Domain == iface.GetDomain() && (interfaceModules.Find(m1 => m1.Address == m.Address && m1.Domain == m.Domain) == null));
             foreach (var mod in deleted)
             {
                 // only "real" modules defined by mig interfaces are considered
                 var virtualParam = Utility.ModuleParameterGet(mod, Properties.VirtualModuleParentId);
                 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.GetDomain());
         foreach (var mod in deleted)
         {
             var virtualParam = Utility.ModuleParameterGet(mod, Properties.VirtualModuleParentId);
             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);
             }
         }
     }
 }