Exemple #1
0
        /// <summary>
        /// Parse the supplied XmlElement and populate the supplied ObjectDefinitionBuilder as required.
        /// </summary>
        /// <remarks>
        /// The default implementation delegates to the
        /// <code>
        /// DoParse
        /// </code>
        ///  version without
        ///             ParameterContext argument.
        /// </remarks>
        /// <param name="element">The element.</param><param name="parserContext">The parser context.</param><param name="builder">The builder used to define the
        /// <code>
        /// IObjectDefinition
        /// </code>
        /// .</param>
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            if (element.HasAttribute(ConnectionStringAttribute))
            {
                if (element.Attributes.Cast <XmlAttribute>().Any(a => a.Name != ConnectionStringAttribute && a.Name != "id"))
                {
                    parserContext.ReaderContext.ReportFatalException(element, "If the connectionString attribute is used, then other connection attributes should not be specified");
                }
                else
                {
                    NamespaceUtils.AddConstructorArgValueIfAttributeDefined(builder, element, ConnectionStringAttribute);
                    return;
                }
            }

            //if connectionString attribute was not specified than servers should be specified.
            if (!element.HasAttribute(Endpoints))
            {
                parserContext.ReaderContext.ReportFatalException(element, "Either the connection string containing the endpoints or the Endpoints attribute is required.");
            }

            //to rely on the out-of-the-box ability provided by ConfiguratioOptions.Parse(connectionString) method,
            //we'll now read all of the attributes and form a connection string.

            var connectionString = new StringBuilder();

            connectionString.Append(element.GetAttribute(Endpoints));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(AbortOnConnectFail));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(AllowAdmin));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(ChannelPrefix));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(ConnectRetry));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(ConnectTimeout));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(ConfigChannel));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(DefaultDatabase));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(KeepAlive));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(Password));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(Proxy));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(ResolveDns));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(Ssl));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(SslHost));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(SyncTimeout));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(TieBreaker));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(Version));
            connectionString.Append(element.ToKeyValuePairAttributeStringIfDefined(WriteBufferSize));

            builder.AddConstructorArg(new TypedStringValue(connectionString.ToString()));
        }
 /// <summary>
 /// Parse the supplied XmlElement and populate the supplied ObjectDefinitionBuilder as required.
 /// </summary>
 /// <remarks>
 /// The default implementation delegates to the
 /// <code>
 /// DoParse
 /// </code>
 ///  version without
 ///             ParameterContext argument.
 /// </remarks>
 /// <param name="element">The element.</param><param name="parserContext">The parser context.</param><param name="builder">The builder used to define the
 /// <code>
 /// IObjectDefinition
 /// </code>
 /// .</param>
 protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
 {
     NamespaceUtils.AddConstructorArgRefIfAttributeDefined(builder, element, nameof(RedisQueueSentinel.Connection).ToCamelCase());
     NamespaceUtils.AddConstructorArgValueIfAttributeDefined(builder, element, nameof(RedisQueueSentinel.MessageTimeout).ToCamelCase());
     NamespaceUtils.AddConstructorArgValueIfAttributeDefined(builder, element, nameof(RedisQueueSentinel.Interval).ToCamelCase());
 }