コード例 #1
0
        protected void AttachListenToLocations(ConfigBase config)
        {
            ConfigSetting setting = config as ConfigSetting;

            if (setting == null)
            {
                return;
            }
            ConfigSettingMetadata csm = (ConfigSettingMetadata)setting.Metadata;

            if (csm.ListenTo == null)
            {
                return;
            }
            foreach (string listenToLocation in csm.ListenTo)
            {
                IConfigurationNode node;
                if (FindNode(listenToLocation, out node))
                {
                    if (node.ConfigObj is ConfigSetting)
                    {
                        setting.ListenTo((ConfigSetting)node.ConfigObj);
                    }
                    else
                    {
                        ServiceRegistration.Get <ILogger>().Warn("ConfigurationNode '{0}': Trying to listen to setting, but location '{1}' references a {2}",
                                                                 Location, listenToLocation, node.ConfigObj.GetType().Name);
                    }
                }
            }
        }
コード例 #2
0
        protected static ConfigSettingMetadata BuildCustomSetting(
            PluginItemMetadata itemData, PluginRuntime plugin)
        {
            string location  = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
            string text      = null;
            string sort      = null;
            string className = null;
            string helpText  = null;
            IDictionary <string, string> additionalData  = null;
            IDictionary <string, Type>   additionalTypes = null;
            ICollection <string>         listenTo        = null;

            foreach (KeyValuePair <string, string> attr in itemData.Attributes)
            {
                switch (attr.Key)
                {
                case "Text":
                    text = attr.Value;
                    break;

                case "Sort":
                    sort = attr.Value;
                    break;

                case "ClassName":
                    className = attr.Value;
                    break;

                case "HelpText":
                    helpText = attr.Value;
                    break;

                case "ListenTo":
                    listenTo = ParseListenTo(attr.Value);
                    break;

                case "AdditionalData":
                    additionalData = ParseAdditionalData(attr.Value);
                    break;

                case "AdditionalTypes":
                    additionalTypes = ParseAdditionalTypes(attr.Value, plugin);
                    break;

                default:
                    throw new ArgumentException("'ConfigSetting' builder doesn't define an attribute '" + attr.Key + "'");
                }
            }
            if (text == null)
            {
                throw new ArgumentException("'ConfigSetting' item needs an attribute 'Text'");
            }
            ConfigSettingMetadata result = new ConfigSettingMetadata(location, text, sort, className, helpText, listenTo)
            {
                AdditionalData  = additionalData,
                AdditionalTypes = additionalTypes
            };

            return(result);
        }
コード例 #3
0
        protected ConfigBase Instantiate(ConfigBaseMetadata metadata, PluginRuntime pluginRuntime)
        {
            ServiceRegistration.Get <ILogger>().Debug("ConfigurationNode: Loading configuration item '{0}'", metadata.Location);
            ConfigBase result;

            if (metadata.GetType() == typeof(ConfigGroupMetadata))
            {
                result = new ConfigGroup();
            }
            else if (metadata.GetType() == typeof(ConfigSectionMetadata))
            {
                result = new ConfigSection();
            }
            else if (metadata.GetType() == typeof(ConfigSettingMetadata))
            {
                ConfigSettingMetadata csm = (ConfigSettingMetadata)metadata;
                try
                {
                    ConfigSetting cs = (ConfigSetting)pluginRuntime.InstantiatePluginObject(csm.ClassName);
                    if (cs == null)
                    {
                        throw new ArgumentException(string.Format("Configuration class '{0}' not found", csm.ClassName));
                    }
                    cs.Load();
                    if (csm.ListenTo != null)
                    {
                        foreach (string listenToLocation in csm.ListenTo)
                        {
                            IConfigurationNode node;
                            if (FindNode(listenToLocation, out node))
                            {
                                if (node.ConfigObj is ConfigSetting)
                                {
                                    cs.ListenTo((ConfigSetting)node.ConfigObj);
                                }
                                else
                                {
                                    ServiceRegistration.Get <ILogger>().Warn("ConfigurationNode '{0}': Trying to listen to setting, but location '{1}' references a {2}",
                                                                             Location, listenToLocation, node.ConfigObj.GetType().Name);
                                }
                            }
                        }
                    }
                    result = cs;
                }
                catch (Exception ex)
                {
                    ServiceRegistration.Get <ILogger>().Error("Error loading configuration class '{0}'", ex, csm.ClassName);
                    return(null);
                }
            }
            else
            {
                throw new NotImplementedException(string.Format("Unknown child class '{0}' of '{1}'", metadata.GetType().FullName, typeof(ConfigBaseMetadata).FullName));
            }
            result.SetMetadata(metadata);
            return(result);
        }
コード例 #4
0
        public override bool IsSettingSupported(ConfigSetting setting)
        {
            if (!(setting is CustomConfigSetting))
            {
                return(false);
            }
            ConfigSettingMetadata metadata = (ConfigSettingMetadata)setting.Metadata;

            return(base.IsSettingSupported(setting) && metadata.AdditionalData.ContainsKey("WorkflowState"));
        }
コード例 #5
0
        /// <summary>
        /// Returns the configuration controller class which is responsible for the specified
        /// <paramref name="setting"/>.
        /// </summary>
        /// <param name="setting">The setting to check.</param>
        /// <returns>Configuration controller class which is responsible for the specified
        /// <paramref name="setting"/>, or <c>null</c>, if the setting is not supported.</returns>
        protected ConfigurationController FindConfigurationController(ConfigSetting setting)
        {
            if (setting == null)
            {
                return(null);
            }
            ConfigurationController result = null;
            // Check if a custom configuration controller is requested
            ConfigSettingMetadata metadata = (ConfigSettingMetadata)setting.Metadata;

            if (metadata.AdditionalTypes != null && metadata.AdditionalTypes.ContainsKey("CustomConfigController"))
            {
                Type controllerType = metadata.AdditionalTypes["CustomConfigController"];
                if (controllerType == null)
                {
                    ServiceRegistration.Get <ILogger>().Warn(
                        "ConfigurationModel: Custom configuration controller could not be loaded (config setting at location '{0}')",
                        metadata.Location);
                    return(null);
                }
                // Check if we already have the required controller available
                foreach (KeyValuePair <Type, ConfigurationController> registration in _registeredSettingTypes)
                {
                    if (registration.Value.GetType() == controllerType)
                    {
                        result = registration.Value;
                        break;
                    }
                }
                if (result == null)
                {
                    // FIXME Albert: Make configuration controllers to models; load them via the workflow manager.
                    // This will make configuration controllers be managed correctly
                    result = Activator.CreateInstance(controllerType) as ConfigurationController;
                    if (result != null)
                    {
                        // Lazily add the new controller type to our registered controllers
                        Register(result);
                    }
                }
                if (result != null)
                {
                    return(result);
                }
            }
            // Check if the workflow configuration controller can handle the setting
            if (_workflowConfigurationController.IsSettingSupported(setting))
            {
                return(_workflowConfigurationController);
            }
            // Else try a default configuration controller
            return(FindConfigurationController(setting.GetType()));
        }
コード例 #6
0
        public override void ExecuteConfiguration()
        {
            ConfigSettingMetadata metadata = (ConfigSettingMetadata)_setting.Metadata;

            if (metadata.AdditionalData.ContainsKey("WorkflowState"))
            { // Custom configuration workflow
                IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();
                workflowManager.NavigatePush(new Guid(metadata.AdditionalData["WorkflowState"]));
                // New configuration workflow has to take over the configuration "life cycle" for the
                // current config setting object (which can be accessed in this model via CurrentConfigSetting):
                // - Configure data (providing workflow states and screens for doing that, change the data, ...)
                // - Calling Save and Apply, or discard the setting by not saving it
                // The the sub workflow should step out again to give the control back to this model again.
            }
        }
コード例 #7
0
        protected ConfigBase Instantiate(ConfigBaseMetadata metadata, PluginRuntime pluginRuntime)
        {
            ServiceRegistration.Get <ILogger>().Debug("ConfigurationNode: Loading configuration item '{0}'", metadata.Location);
            ConfigBase result;

            if (metadata.GetType() == typeof(ConfigGroupMetadata))
            {
                result = new ConfigGroup();
            }
            else if (metadata.GetType() == typeof(ConfigSectionMetadata))
            {
                result = new ConfigSection();
            }
            else if (metadata.GetType() == typeof(ConfigSettingMetadata))
            {
                ConfigSettingMetadata csm = (ConfigSettingMetadata)metadata;
                try
                {
                    ConfigSetting cs = (ConfigSetting)pluginRuntime.InstantiatePluginObject(csm.ClassName);
                    if (cs == null)
                    {
                        throw new ArgumentException(string.Format("Configuration class '{0}' not found", csm.ClassName));
                    }
                    cs.Load();
                    result = cs;
                }
                catch (Exception ex)
                {
                    ServiceRegistration.Get <ILogger>().Error("Error loading configuration class '{0}'", ex, csm.ClassName);
                    return(null);
                }
            }
            else
            {
                throw new NotImplementedException(string.Format("Unknown child class '{0}' of '{1}'", metadata.GetType().FullName, typeof(ConfigBaseMetadata).FullName));
            }
            result.SetMetadata(metadata);
            return(result);
        }