// 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); }
// 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); }
public void DisableInterface(string domain) { if (Interfaces.ContainsKey(domain)) { MIGInterface migInterface = Interfaces[domain]; migInterface.Disconnect(); } }
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); }
public void EnableInterface(string domain) { if (Interfaces.ContainsKey(domain)) { MIGInterface migInterface = Interfaces[domain]; migInterface.Options = configuration.GetInterface(domain).Options; migInterface.Connect(); } }
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(); } }
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; }
public MIGInterface DisableInterface(string domain) { MIGInterface migInterface = null; if (Interfaces.ContainsKey(domain)) { migInterface = Interfaces[domain]; migInterface.IsEnabled = false; migInterface.Disconnect(); } return(migInterface); }
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); }
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); }
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; }
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(); }
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); } } } }