private bool ValidateProducerType(string producer, string producerType, out IDcaSettingsValidator customValidator)
        {
            customValidator = null;

            string assemblyName;
            string typeName;

            if (DcaStandardPluginValidators.ProducerValidators.ContainsKey(producerType))
            {
                assemblyName = DcaStandardPluginValidators.ProducerValidators[producerType].AssemblyName;
                typeName     = DcaStandardPluginValidators.ProducerValidators[producerType].TypeName;
            }
            else
            {
                WriteError(
                    FabricValidatorUtility.TraceTag,
                    "Producer type '{0}' specified in section '{1}', parameter '{2}' is not supported.",
                    producerType,
                    producer,
                    FabricValidatorConstants.ParameterNames.ProducerType);
                return(false);
            }

            object producerObject = CreatePluginObject(producer, assemblyName, typeName);

            if (null == producerObject)
            {
                return(false);
            }

            customValidator = producerObject as IDcaSettingsValidator;
            if (null == customValidator)
            {
                WriteError(
                    FabricValidatorUtility.TraceTag,
                    "Object of type {0} in assembly {1} does not implement the IDcaSettingsValidator interface.",
                    typeName,
                    assemblyName);
                return(false);
            }

            PluginInfo pluginInfo = new PluginInfo();

            pluginInfo.Instance     = producer;
            pluginInfo.AssemblyName = assemblyName;
            pluginInfo.TypeName     = typeName;
            pluginInfo.Validator    = customValidator;
            this.producerList.Add(pluginInfo);
            this.producerInstanceToType[producer] = producerType;
            return(true);
        }
        private bool ValidateCustomParameters(string sectionName, string[] standardParameters, IDcaSettingsValidator validator)
        {
            Dictionary <string, SettingsOverridesTypeSectionParameter> section = this.settingsMap[sectionName];
            Dictionary <string, string>       parameters          = new Dictionary <string, string>();
            Dictionary <string, SecureString> encryptedParameters = new Dictionary <string, SecureString>();

            foreach (string paramName in section.Keys)
            {
                if (null != Array.Find(standardParameters, paramName.Equals))
                {
                    continue;
                }
                else if (section[paramName].IsEncrypted)
                {
                    encryptedParameters[paramName] = section[paramName].GetSecureValue(this.storeName);
                }
                else
                {
                    parameters[paramName] = section[paramName].Value;
                }
            }

            bool success = validator.Validate((ITraceWriter)this, sectionName, parameters, encryptedParameters);

            this.atLeastOnePluginEnabled = this.atLeastOnePluginEnabled || validator.Enabled;
            return(success);
        }
        private bool ValidateConsumerType(string consumer, string consumerType, out IDcaSettingsValidator customValidator)
        {
            customValidator = null;
            string assemblyName;
            string typeName;
            bool   success = true;

            if (DcaStandardPluginValidators.ConsumerValidators.ContainsKey(consumerType))
            {
                assemblyName = DcaStandardPluginValidators.ConsumerValidators[consumerType].AssemblyName;
                typeName     = DcaStandardPluginValidators.ConsumerValidators[consumerType].TypeName;
            }
            else
            {
                if (this.configurations.ContainsKey(consumerType))
                {
                    WriteError(
                        FabricValidatorUtility.TraceTag,
                        "Consumer type {0} referenced in section '{1}', parameter '{2}' conflicts with a well-known section name.",
                        consumerType,
                        consumer,
                        FabricValidatorConstants.ParameterNames.ConsumerType);
                    return(false);
                }

                if (!this.settingsMap.ContainsKey(consumerType))
                {
                    WriteError(
                        FabricValidatorUtility.TraceTag,
                        "Consumer type {0} referenced in section '{1}', parameter '{2}' is not recognized.",
                        consumerType,
                        consumer,
                        FabricValidatorConstants.ParameterNames.ConsumerType);
                    return(false);
                }

                try
                {
                    success = ValidateAllParameterNames(consumerType, consumerTypeSectionParameters) && success;

                    if (!ValidateRequiredParametersPresent(consumerType, consumerTypeSectionParameters))
                    {
                        return(false);
                    }

                    assemblyName = this.settingsMap[consumerType][FabricValidatorConstants.ParameterNames.PluginValidationAssembly].Value;
                    assemblyName = assemblyName.Trim();
                    if (!assemblyName.Equals(Path.GetFileName(assemblyName)))
                    {
                        WriteError(
                            FabricValidatorUtility.TraceTag,
                            "Assembly name '{0}' in section '{1}' is not in the correct format. The assembly name should not include the path.",
                            assemblyName,
                            consumerType);
                        return(false);
                    }

                    typeName = this.settingsMap[consumerType][FabricValidatorConstants.ParameterNames.PluginValidationType].Value;
                    typeName = typeName.Trim();
                }
                finally
                {
                    if (null == this.standardConsumerTypes.Find(consumerType.Equals))
                    {
                        // Add this section to the consumer types list. Later, we'll
                        // remove each member of the list from the settings map because
                        // standard validation rules do not apply to it and custom
                        // validation has already been performed.
                        // We don't want to remove it from the settings map right now
                        // because other consumer instances might be of the same consumer
                        // type, so we may still come across more sections that refer to
                        // this consumer type section.
                        this.standardConsumerTypes.Add(consumerType);
                    }
                }
            }

            object consumerObject = CreatePluginObject(consumer, assemblyName, typeName);

            if (null == consumerObject)
            {
                return(false);
            }

            customValidator = consumerObject as IDcaSettingsValidator;
            if (null == customValidator)
            {
                WriteError(
                    FabricValidatorUtility.TraceTag,
                    "Object of type {0} in assembly {1} does not implement the IDcaSettingsValidator interface.",
                    typeName,
                    assemblyName);
                return(false);
            }

            if (success)
            {
                PluginInfo pluginInfo = new PluginInfo();
                pluginInfo.Instance     = consumer;
                pluginInfo.AssemblyName = assemblyName;
                pluginInfo.TypeName     = typeName;
                pluginInfo.Validator    = customValidator;
                this.ConsumerList.Add(pluginInfo);
            }

            return(success);
        }