Exemplo n.º 1
0
        public Stream GetStream(StreamType streamType, StreamParameters streamParameters)
        {
            LoadStreamFactories();

            if (_streamFactoriesHash.ContainsKey(streamType))
            {
                return _streamFactoriesHash[streamType].Create(streamParameters);
            }

            throw new ArgumentException(string.Format("No Factory defined for type {0}", streamType));
        }
        public Stream Create(StreamParameters streamParameters)
        {
            if(streamParameters != null)
            {
                var cryptoStreamParameters = streamParameters as CryptoStreamParameters;
                
                if(cryptoStreamParameters != null && cryptoStreamParameters.Stream != null && cryptoStreamParameters.CryptoTransform != null)
                {
                    return _cryptoStreamFactory.Create(cryptoStreamParameters.Stream, cryptoStreamParameters.CryptoTransform, cryptoStreamParameters.CryptoStreamMode);
                }

                throw new ArgumentException("StreamParameters must be of type CryptoStreamParameters with Stream and CryptoTransform, no default constructor exists!");
            }

            throw new ArgumentNullException("streamParameters");
        }
        public Stream Create(StreamParameters streamParameters)
        {
            if (streamParameters != null)
            {
                var memoryStreamParameters = streamParameters as MemoryStreamParameters;

                if (memoryStreamParameters != null)
                {
                    if (memoryStreamParameters.Buffer != null)
                    {
                        if (memoryStreamParameters.Writable.HasValue)
                        {
                            if (memoryStreamParameters.Index.HasValue && memoryStreamParameters.Count.HasValue)
                            {
                                if (memoryStreamParameters.PubliclyVisible.HasValue)
                                {
                                    return _memoryStreamFactory.Create(memoryStreamParameters.Buffer, memoryStreamParameters.Index.Value, memoryStreamParameters.Count.Value, memoryStreamParameters.Writable.Value, memoryStreamParameters.PubliclyVisible.Value);
                                }

                                return _memoryStreamFactory.Create(memoryStreamParameters.Buffer, memoryStreamParameters.Index.Value, memoryStreamParameters.Count.Value, memoryStreamParameters.Writable.Value);
                            }

                            return _memoryStreamFactory.Create(memoryStreamParameters.Buffer, memoryStreamParameters.Writable.Value);
                        }

                        if (memoryStreamParameters.Index.HasValue && memoryStreamParameters.Count.HasValue)
                        {
                            return _memoryStreamFactory.Create(memoryStreamParameters.Buffer, memoryStreamParameters.Index.Value, memoryStreamParameters.Count.Value);
                        }

                        return _memoryStreamFactory.Create(memoryStreamParameters.Buffer);
                    }

                    if (memoryStreamParameters.Capacity.HasValue)
                    {
                        return _memoryStreamFactory.Create(memoryStreamParameters.Capacity.Value);
                    }
                }
            }

            return _memoryStreamFactory.Create();
        }