Exemplo n.º 1
0
        private SpotterBase CreateNextSpotter(string contentType)
        {
            if (this._capacity != 0 && this._total >= this._capacity)
            {
                throw new Exception("Out of pool capacity.");
            }

            var i = SpotterFactory.GetSpotter(contentType);

            this._total++;
            this._inUse.Add(i);
            return(i);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates new spotter pool with selected capacity.
        /// </summary>
        /// <param name="capacity">Pool capacity.</param>
        public SpotterPool(int capacity)
        {
            this._capacity = capacity;
            this._total    = 0;

            /* initialize with spotters of all kind if capacity is not limitless */
            if (capacity > 0)
            {
                foreach (var contentType in SpotterFactory.SupportedContent)
                {
                    SpotterBase i = null;
                    // have to create multipart spotter manualy because it has to be initialized with this pool but it is yet uninitialized in SpotterFactory
                    i = contentType.StartsWith("multipart/form-data")? new SpotterMultipart(this) : SpotterFactory.GetSpotter(contentType);
                    this._total++;
                    this._free.Add(new KeyValuePair <Type, SpotterBase>(i.GetType(), i));
                }
            }
        }