示例#1
0
        void ReceiveFoldersTask_FinishedSuccess(ReceiveFoldersTask foldersTask, ChannelConfiguration config, IClientInputChannel inputChannel)
        {
            var gate    = new ConcurrencyGate(config.InputChannel.MaxConcurrentConnections);
            var folders = foldersTask.Folders.OrderByDescending(f => (int)f.FolderType);
            var changed = new List <Message>();

            // Folders are pushed by descending order into concurrency gate and then popped again,
            // this way the Inbox folder is processed before the sent items folder etc.
            foreach (var folder in folders)
            {
                if (folder.FolderType == ChannelFolderType.Inbox ||
                    folder.FolderType == ChannelFolderType.SentItems)
                {
                    gate.Add(new ReceiveMessagesTask(config, inputChannel.Clone(), folder, range));
                }
                else if (folder.FolderType == ChannelFolderType.Trash || folder.FolderType == ChannelFolderType.Spam)
                {
                    gate.Add(new EnumerateMessagesFolderTask(config, inputChannel.Clone(), folder, range));
                }
                else if (folder.FolderType == ChannelFolderType.Label)
                {
                    if (config.Charasteristics.SupportsLabels)
                    {
                        gate.Add(new EnumerateLabelsFolderTask(changed, config, inputChannel.Clone(), folder, range));
                    }
                }
            }

            gate.Execute();

            // Process any labels that we might have received
            if (config.Charasteristics.SupportsLabels)
            {
                new ProcessLabelsTask(changed, config).Execute();
            }

            if (inputChannel is IPoolableChannel)
            {
                ((IPoolableChannel)inputChannel).FreeAllConnections();
            }
        }
示例#2
0
        protected override void ExecuteCore()
        {
            ClientState.Current.Messages.Errors.Clear();

            var channels = dataService.SelectAll <ChannelConfig>()
                           .Select(ChannelFactory.Create)
                           .Select(s => new ChannelInstance(s))
                           .Where(c => !c.Configuration.IsConnected)
                           .ToList();

            if (channels.Count == 0)
            {
                return;
            }

            var gate = new ConcurrencyGate(2);

            foreach (var channelInstance in channels)
            {
                var inputChannel = channelInstance.InputChannel;
                var config       = channelInstance.Configuration;

                var foldersTask = new ReceiveFoldersTask(channelInstance.Configuration, inputChannel.Clone());

                foldersTask.FinishedSuccess += ((sender, e) =>
                                                ReceiveFoldersTask_FinishedSuccess((ReceiveFoldersTask)sender, config, inputChannel));

                gate.Add(foldersTask);
            }

            // Wait for all receive tasks to complete, keeping the queue filled for the ReceiveTask.
            // This prevents any new receive task from getting enqueued.
            gate.Execute();

            // Clean up connection scavangers
            ConnectionPoolScavenger.Shutdown();

            GC.Collect(GC.MaxGeneration);
        }
示例#3
0
        protected override void ExecuteCore()
        {
            ClientState.Current.Messages.Errors.Clear();

            var channels = dataService.SelectAll<ChannelConfig>()
                .Select(ChannelFactory.Create)
                .Select(s => new ChannelInstance(s))
                .Where(c => !c.Configuration.IsConnected)
                .ToList();

            if (channels.Count == 0)
                return;

            var gate = new ConcurrencyGate(2);

            foreach (var channelInstance in channels)
            {
                var inputChannel = channelInstance.InputChannel;
                var config = channelInstance.Configuration;

                var foldersTask = new ReceiveFoldersTask(channelInstance.Configuration, inputChannel.Clone());

                foldersTask.FinishedSuccess += ((sender, e) =>
                    ReceiveFoldersTask_FinishedSuccess((ReceiveFoldersTask)sender, config, inputChannel));

                gate.Add(foldersTask);
            }

            // Wait for all receive tasks to complete, keeping the queue filled for the ReceiveTask.
            // This prevents any new receive task from getting enqueued.
            gate.Execute();

            // Clean up connection scavangers
            ConnectionPoolScavenger.Shutdown();

            GC.Collect(GC.MaxGeneration);
        }
示例#4
0
        void ReceiveFoldersTask_FinishedSuccess(ReceiveFoldersTask foldersTask, ChannelConfiguration config, IClientInputChannel inputChannel)
        {
            var gate = new ConcurrencyGate(config.InputChannel.MaxConcurrentConnections);
            var folders = foldersTask.Folders.OrderByDescending(f => (int) f.FolderType);
            var changed = new List<Message>();

            // Folders are pushed by descending order into concurrency gate and then popped again,
            // this way the Inbox folder is processed before the sent items folder etc.
            foreach (var folder in folders)
            {
                if (folder.FolderType == ChannelFolderType.Inbox
                    || folder.FolderType == ChannelFolderType.SentItems)
                {
                    gate.Add(new ReceiveMessagesTask(config, inputChannel.Clone(), folder, range));
                }
                else if (folder.FolderType == ChannelFolderType.Trash || folder.FolderType == ChannelFolderType.Spam)
                {
                    gate.Add(new EnumerateMessagesFolderTask(config, inputChannel.Clone(), folder, range));
                }
                else if (folder.FolderType == ChannelFolderType.Label)
                {
                    if (config.Charasteristics.SupportsLabels)
                        gate.Add(new EnumerateLabelsFolderTask(changed, config, inputChannel.Clone(), folder, range));
                }
            }

            gate.Execute();

            // Process any labels that we might have received
            if (config.Charasteristics.SupportsLabels)
                new ProcessLabelsTask(changed, config).Execute();

            if (inputChannel is IPoolableChannel)
                ((IPoolableChannel)inputChannel).FreeAllConnections();
        }