Esempio n. 1
0
 internal Queue(string formatName, QueueAccessMode accessMode, QueueShareReceive shareMode)
 {
     Contract.Requires(formatName != null);
     AccessMode = accessMode;
     ShareMode  = shareMode;
     FormatName = formatName;
 }
Esempio n. 2
0
        /// <summary>
        /// Get the existing Queue or open a new Queue using the factory method.
        /// </summary>
        public T Open(string formatName, QueueAccessMode mode, QueueShareReceive share = QueueShareReceive.Shared)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(formatName));
            var key = new Key(formatName, mode, share);

            lock (_cache.SyncRoot)
            {
                T queue = _cache[key];
                if (queue == null || queue.IsClosed)
                {
                    _cache[key] = queue = _factory(formatName, mode, share);
                }
                return(queue);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Takes the existing <see cref="Queue"/> or open a new Queue using the factory method.  Removes the queue from the cache.
        /// After you have finished with the borrowed queue call <see cref="Return(T)"/>
        /// </summary>
        public T Borrow(string formatName, QueueAccessMode mode, QueueShareReceive share = QueueShareReceive.Shared)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(formatName));
            T   queue;
            var key = new Key(formatName, mode, share);

            lock (_cache.SyncRoot)
            {
                queue = _cache[key];
                if (queue != null)
                {
                    _cache.Remove(key); // take it out of the cache
                }
            }

            return(queue == null || queue.IsClosed ? _factory(formatName, mode, share) : queue);
        }
Esempio n. 4
0
 /// <summary>Opens a queue using a <paramref name="formatName"/>.  Use <see cref="Queues.PathToFormatName(string)"/> to get the <paramref name="formatName"/> for a queue path.</summary>
 public QueueReader(string formatName, QueueReaderMode readerMode = QueueReaderMode.Receive, QueueShareReceive share = QueueShareReceive.Shared)
     : base(formatName, (QueueAccessMode)readerMode, share)
 {
     Open();
 }
Esempio n. 5
0
        /// <summary>Opens a queue using a <paramref name="formatName"/>.  Use <see cref="Queues.PathToFormatName(string)"/> to get the <paramref name="formatName"/> for a queue path.</summary>
        public SubQueue(string formatName, QueueReaderMode mode = QueueReaderMode.Receive, QueueShareReceive share = QueueShareReceive.Shared)
            : base(formatName, mode, share)
        {
            Contract.Requires(formatName.IndexOf(';') > 0, "formatName is not a subqueue");

            int res = Native.OpenQueue(FormatName, QueueAccessMode.Move, QueueShareReceive.Shared, out _moveHandle);

            if (res != 0)
            {
                throw new QueueException(res);
            }
        }
Esempio n. 6
0
 public Key(string formatName, QueueAccessMode mode, QueueShareReceive share)
 {
     this.formatName = formatName;
     this.mode       = mode;
     this.share      = share;
 }
Esempio n. 7
0
 public static extern int OpenQueue(string formatName, QueueAccessMode access, QueueShareReceive shareMode, out QueueHandle handle);