예제 #1
0
        public Error GetLayerStack(out ILayerStack stack)
        {
            Error error = null;

            if (cachedLayerStack != null)
            {
                stack = cachedLayerStack;
            }
            else
            {
                ILayer <TLayerData>[] layers;
                error = GetNewLayers(out layers);
                if (error == null)
                {
                    stack = new LayerStack <TLayerData>(logger, layers);
                }
                else
                {
                    stack = null;
                }
            }

            return(error);
        }
예제 #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;
            Error error = GetNewLayers(out layers);

            if (error == null)
            {
                bool stateless = layers.All(layer => layer is IStatelessLayer <TLayerData>);

                if (stateless)
                {
                    cachedLayerStack = new LayerStack <TLayerData>(logger, layers);
                }
            }
            else
            {
                throw new InvalidOperationException(error.message);
            }

            this.logger = logger;
        }