コード例 #1
0
        /// <summary>
        /// Extension on <see cref="SqlServerStreamConfig"/> to build a <see cref="SqlStream"/>.
        /// </summary>
        /// <param name="streamConfig">The stream configuration object.</param>
        /// <param name="serializerFactory">The serializer factory.</param>
        /// <returns>A <see cref="SqlStream"/>.</returns>
        public static SqlStream ToStream(
            this SqlServerStreamConfig streamConfig,
            ISerializerFactory serializerFactory)
        {
            streamConfig.MustForArg(nameof(streamConfig)).NotBeNull();
            serializerFactory.MustForArg(nameof(serializerFactory)).NotBeNull();

            if (streamConfig.AllLocators.Count != 1)
            {
                throw new NotSupportedException(Invariant($"One single resource locators are currently supported and '{streamConfig.AllLocators.Count}' were provided."));
            }

            var resourceLocatorProtocol = new SingleResourceLocatorProtocols(streamConfig.AllLocators.Single());

            var result = new SqlStream(
                streamConfig.Name,
                streamConfig.DefaultConnectionTimeout,
                streamConfig.DefaultCommandTimeout,
                streamConfig.DefaultSerializerRepresentation,
                streamConfig.DefaultSerializationFormat,
                serializerFactory,
                resourceLocatorProtocol);

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlStream"/> class.
        /// </summary>
        /// <param name="name">The name of the stream.</param>
        /// <param name="defaultConnectionTimeout">The default connection timeout.</param>
        /// <param name="defaultCommandTimeout">The default command timeout.</param>
        /// <param name="defaultSerializerRepresentation">Default serializer description to use.</param>
        /// <param name="defaultSerializationFormat">Default serializer format.</param>
        /// <param name="serializerFactory">The factory to get a serializer to use for objects.</param>
        /// <param name="resourceLocatorProtocol">The protocols for getting locators.</param>
        public SqlStream(
            string name,
            TimeSpan defaultConnectionTimeout,
            TimeSpan defaultCommandTimeout,
            SerializerRepresentation defaultSerializerRepresentation,
            SerializationFormat defaultSerializationFormat,
            ISerializerFactory serializerFactory,
            IResourceLocatorProtocols resourceLocatorProtocol)
            : base(name, serializerFactory, defaultSerializerRepresentation, defaultSerializationFormat, resourceLocatorProtocol)
        {
            name.MustForArg(nameof(name)).NotBeNullNorWhiteSpace();
            defaultSerializerRepresentation.MustForArg(nameof(defaultSerializerRepresentation)).NotBeNull();
            serializerFactory.MustForArg(nameof(serializerFactory)).NotBeNull();
            resourceLocatorProtocol.MustForArg(nameof(resourceLocatorProtocol)).NotBeNull();

            this.StreamRepresentation     = new StreamRepresentation(this.Name);
            this.DefaultConnectionTimeout = defaultConnectionTimeout;
            this.DefaultCommandTimeout    = defaultCommandTimeout;

            var allLocators = this.ResourceLocatorProtocols.Execute(new GetAllResourceLocatorsOp());

            this.singleLocator = allLocators.Count == 1 ? allLocators.Single().ConfirmAndConvert <SqlServerLocator>() : null;
        }