private IDictionary <string, string> RpcSetConfiguration(string uuid, IDictionary <string, object> config) { // Make sure the object ID is valid IUserObject instance = m_mot.GetInstance(Guid.Parse(uuid)); if (instance == null) { throw new ArgumentException("No such object."); } // Make sure it is an object and it is configurable if (instance.ObjectType.IsFactory() || !(instance is IConfigurable)) { throw new ArgumentException("Cannot apply configuration to this type of object."); } // Get the matching configuration description IConfigurationDescription desc = m_mot.GetConfigurationDescription(instance.UUID); if (desc == null) { throw new ArgumentException("No configuration description available for object."); } // Verify the configuration Dictionary <string, string> failures = new Dictionary <string, string>(); config = desc.Verify(config, failures); if (config != null) { IConfigurable configurable = instance as IConfigurable; if (configurable.ValidateConfiguration(desc, config, failures)) { configurable.ApplyConfiguration(desc, config); } } return(failures); }
/// <summary> /// Enable the plugin /// </summary> /// <returns></returns> public bool EnablePlugin() { // Add the plugin to the MOT on the assumption it will work MasterObjectTable mot = Locator.Current.GetService <MasterObjectTable>(); mot.AddInstance(m_plugin); // If the plugin supports configuration we need to give it one before // initialisation IConfigurable configurable = m_plugin as IConfigurable; if (configurable != null) { IConfigurationDescription description = mot.GetConfigurationDescription(m_plugin.UUID); IDictionary <string, object> values = mot.GetConfiguration(m_plugin.UUID); Dictionary <string, string> failures = new Dictionary <string, string>(); if (!configurable.ValidateConfiguration(description, values, failures)) { StringBuilder sb = new StringBuilder(); string separator = ""; foreach (KeyValuePair <string, string> message in failures) { sb.Append(separator); separator = ", "; sb.Append(String.Format("'{0}' - {1}", message.Key, message.Value)); } this.Log().Error("One or more configuration values are not applicable - " + sb.ToString()); mot.RemoveInstance(m_plugin.UUID); return(false); } try { configurable.ApplyConfiguration(description, values); } catch (Exception ex) { this.Log().Error("Unable to apply configuration to plugin - {0}.", ex.ToString()); mot.RemoveInstance(m_plugin.UUID); return(false); } } // Now try and initialise it bool initialised = false; try { initialised = m_plugin.Initialise(this); if (initialised) { this.Log().Info("Initialised plugin"); } else { this.Log().Error("Failed to initialise plugin."); } } catch (Exception ex) { this.Log().Error("Failed to initialise plugin - {0}", ex.Message); } if (!initialised) { mot.RemoveInstance(m_plugin.UUID); } return(initialised); }