Пример #1
0
 /// <summary>
 /// Returns spotter to the pool. If Returning spotter that was not flaged as used exeption is raised.
 /// </summary>
 /// <param name="spotter">Returning spotter.</param>
 public void ReturningSpotter(SpotterBase spotter)
 {
     lock (this._lock)
     {
         if (!this._inUse.Contains(spotter))
         {
             throw new ArgumentException("Can not return spotter that is not in use.");
         }
         this._inUse.Remove(spotter);
         this._free.Add(new KeyValuePair <Type, SpotterBase>(spotter.GetType(), spotter));
         Monitor.Pulse(this._lock);
     }
 }
Пример #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));
                }
            }
        }
 public void UnloadPart(SpotterBase spotter)
 {
     this._spotterPool.ReturningSpotter(spotter);
 }