示例#1
0
        /// <summary>
        /// Ensures that the specified items are cached for the specified messages.
        /// </summary>
        /// <param name="pMessages"></param>
        /// <param name="pItems"></param>
        /// <param name="pConfiguration">Operation specific timeout, cancellation token and progress callbacks.</param>
        /// <returns>A list of messages where something went wrong and the cache was not populated.</returns>
        /// <remarks>
        /// <note type="note"><see cref="cMessageCacheItems"/> has implicit conversions from other types including <see cref="fMessageProperties"/>. This means that you can use values of those types as arguments to this method.</note>
        /// </remarks>
        public List <cMessage> Fetch(IEnumerable <cMessage> pMessages, cMessageCacheItems pItems, cCacheItemFetchConfiguration pConfiguration)
        {
            var lContext = mRootContext.NewMethodV(true, nameof(cIMAPClient), nameof(Fetch), 3);

            if (pMessages == null)
            {
                throw new ArgumentNullException(nameof(pMessages));
            }
            if (pItems == null)
            {
                throw new ArgumentNullException(nameof(pItems));
            }

            var lMessageHandles = cMessageHandleList.FromMessages(pMessages);

            if (lMessageHandles.All(h => h.Contains(pItems)))
            {
                return(new List <cMessage>());
            }

            var lTask = ZFetchCacheItemsAsync(lMessageHandles, pItems, pConfiguration, lContext);

            mSynchroniser.Wait(lTask, lContext);

            return(new List <cMessage>(from m in pMessages where !m.MessageHandle.Contains(pItems) select m));
        }
示例#2
0
        private async Task <List <cMessage> > ZUIDFetchCacheItemsAsync(iMailboxHandle pMailboxHandle, cUIDList pUIDs, cMessageCacheItems pItems, cCacheItemFetchConfiguration pConfiguration, cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZUIDFetchCacheItemsAsync), pMailboxHandle, pUIDs, pItems);

            if (mDisposed)
            {
                throw new ObjectDisposedException(nameof(cIMAPClient));
            }

            var lSession = mSession;

            if (lSession == null || lSession.ConnectionState != eConnectionState.selected)
            {
                throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotSelected);
            }

            if (pMailboxHandle == null)
            {
                throw new ArgumentNullException(nameof(pMailboxHandle));
            }
            if (pUIDs == null)
            {
                throw new ArgumentNullException(nameof(pUIDs));
            }
            if (pItems == null)
            {
                throw new ArgumentNullException(nameof(pItems));
            }

            if (pUIDs.Count == 0)
            {
                return(new List <cMessage>());
            }
            if (pItems.IsEmpty)
            {
                throw new ArgumentOutOfRangeException(nameof(pItems));
            }

            cMessageHandleList lMessageHandles;

            if (pConfiguration == null)
            {
                using (var lToken = mCancellationManager.GetToken(lContext))
                {
                    var lMC       = new cMethodControl(mTimeout, lToken.CancellationToken);
                    var lProgress = new cProgress();
                    lMessageHandles = await lSession.UIDFetchCacheItemsAsync(lMC, pMailboxHandle, pUIDs, pItems, lProgress, lContext).ConfigureAwait(false);
                }
            }
            else
            {
                var lMC       = new cMethodControl(pConfiguration.Timeout, pConfiguration.CancellationToken);
                var lProgress = new cProgress(mSynchroniser, pConfiguration.Increment);
                lMessageHandles = await lSession.UIDFetchCacheItemsAsync(lMC, pMailboxHandle, pUIDs, pItems, lProgress, lContext).ConfigureAwait(false);
            }

            List <cMessage> lMessages = new List <cMessage>(lMessageHandles.Count);

            foreach (var lMessageHandle in lMessageHandles)
            {
                lMessages.Add(new cMessage(this, lMessageHandle));
            }
            return(lMessages);
        }
示例#3
0
        private async Task ZFetchCacheItemsAsync(cMessageHandleList pMessageHandles, cMessageCacheItems pItems, cCacheItemFetchConfiguration pConfiguration, cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZFetchCacheItemsAsync), pMessageHandles, pItems);

            if (mDisposed)
            {
                throw new ObjectDisposedException(nameof(cIMAPClient));
            }

            var lSession = mSession;

            if (lSession == null || lSession.ConnectionState != eConnectionState.selected)
            {
                throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotSelected);
            }

            if (pMessageHandles == null)
            {
                throw new ArgumentNullException(nameof(pMessageHandles));
            }
            if (pItems == null)
            {
                throw new ArgumentNullException(nameof(pItems));
            }

            if (pMessageHandles.Count == 0)
            {
                return;
            }
            if (pItems.IsEmpty)
            {
                return;
            }

            if (pConfiguration == null)
            {
                using (var lToken = mCancellationManager.GetToken(lContext))
                {
                    var lMC       = new cMethodControl(mTimeout, lToken.CancellationToken);
                    var lProgress = new cProgress();
                    await lSession.FetchCacheItemsAsync(lMC, pMessageHandles, pItems, lProgress, lContext).ConfigureAwait(false);
                }
            }
            else
            {
                var lMC       = new cMethodControl(pConfiguration.Timeout, pConfiguration.CancellationToken);
                var lProgress = new cProgress(mSynchroniser, pConfiguration.Increment);
                await lSession.FetchCacheItemsAsync(lMC, pMessageHandles, pItems, lProgress, lContext).ConfigureAwait(false);
            }
        }
示例#4
0
        internal async Task <cMessageHandleList> FetchAsync(IEnumerable <iMessageHandle> pMessageHandles, cMessageCacheItems pItems, cCacheItemFetchConfiguration pConfiguration)
        {
            var lContext = mRootContext.NewMethodV(true, nameof(cIMAPClient), nameof(FetchAsync), 2);

            if (pMessageHandles == null)
            {
                throw new ArgumentNullException(nameof(pMessageHandles));
            }
            if (pItems == null)
            {
                throw new ArgumentNullException(nameof(pItems));
            }

            var lMessageHandles = cMessageHandleList.FromMessageHandles(pMessageHandles);

            if (lMessageHandles.All(h => h.Contains(pItems)))
            {
                return(new cMessageHandleList());
            }

            await ZFetchCacheItemsAsync(lMessageHandles, pItems, pConfiguration, lContext).ConfigureAwait(false);

            return(new cMessageHandleList(from h in lMessageHandles where !h.Contains(pItems) select h));
        }
示例#5
0
        internal Task <List <cMessage> > MessagesAsync(iMailboxHandle pMailboxHandle, IEnumerable <cUID> pUIDs, cMessageCacheItems pItems, cCacheItemFetchConfiguration pConfiguration)
        {
            var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(MessagesAsync));

            return(ZUIDFetchCacheItemsAsync(pMailboxHandle, cUIDList.FromUIDs(pUIDs), pItems, pConfiguration, lContext));
        }
示例#6
0
        internal List <cMessage> Messages(iMailboxHandle pMailboxHandle, IEnumerable <cUID> pUIDs, cMessageCacheItems pItems, cCacheItemFetchConfiguration pConfiguration)
        {
            var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(Messages));
            var lTask    = ZUIDFetchCacheItemsAsync(pMailboxHandle, cUIDList.FromUIDs(pUIDs), pItems, pConfiguration, lContext);

            mSynchroniser.Wait(lTask, lContext);
            return(lTask.Result);
        }