Ejemplo n.º 1
0
        /// <summary>
        /// Construct a layer stack provider from a set of layer providers.
        /// </summary>
        /// <param name="layerProviders">Layer providers for this stack provider. Must be at least one and all must not be null.</param>
        public LayerStackProvider(params ILayerProvider <TLayerData>[] layerProviders)
        {
            if ((layerProviders == null) || (layerProviders.Length == 0))
            {
                throw new ArgumentException("At least one layer provider must be provided", nameof(layerProviders));
            }

            for (int i = 0; i < layerProviders.Length; i++)
            {
                if (layerProviders[i] == null)
                {
                    throw new ArgumentNullException($"Layer provider {i} was null");
                }
            }

            this.layerProviders = layerProviders;
            ILayer <TLayerData>[] layers = new ILayer <TLayerData> [layerProviders.Length];
            for (var i = 0; i < layerProviders.Length; i++)
            {
                layers[i] = layerProviders[i].GetLayer();
            }

            cachedLayerStack = new Lazy <LayerStack <TLayerData> >(() =>
            {
                bool stateless = layers.All(layer => layer is IStatelessLayer <TLayerData>);
                if (stateless)
                {
                    return(new LayerStack <TLayerData>(layers));
                }
                else
                {
                    return(null);
                }
            }, LazyThreadSafetyMode.ExecutionAndPublication);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Construct a layer stack provider from a set of layer providers.
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="layerProviders">Layer providers for this stack provider. Must be at least one and all must not be null.</param>
        public LayerStackProvider(Logger logger, params ILayerProvider <TLayerData>[] layerProviders)
        {
            if ((layerProviders == null) || (layerProviders.Length == 0))
            {
                throw new ArgumentException("At least one layer provider must be provided", nameof(layerProviders));
            }

            for (int i = 0; i < layerProviders.Length; i++)
            {
                if (layerProviders[i] == null)
                {
                    throw new ArgumentNullException($"Layer provider {i} was null");
                }
            }

            this.layerProviders = layerProviders;
            ILayer <TLayerData>[] layers = new ILayer <TLayerData> [layerProviders.Length];
            for (var i = 0; i < layerProviders.Length; i++)
            {
                layers[i] = layerProviders[i].GetLayer();
            }

            bool stateless = layers.All(layer => layer is IStatelessLayer <TLayerData>);

            if (stateless)
            {
                cachedLayerStack = new LayerStack <TLayerData>(logger, layers);
            }

            this.logger = logger;
        }