Ejemplo n.º 1
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 instance in channels)
            {
                if (instance.ContactsChannel != null)
                    gate.Add(new SyncContactsTask(instance.Configuration, instance.ContactsChannel.Clone()) { OverrideCanExecute = OverrideCanExecute });

                if (instance.StatusUpdatesChannel != null)
                    gate.Add(new SyncStatusUpdatesTask(instance.Configuration, instance.StatusUpdatesChannel.Clone()) { OverrideCanExecute = OverrideCanExecute });

                //if (instance.CalendarChannel != null)
                //    new SyncCalendarTask(instance.Configuration, instance.CalendarChannel) { OverrideCanExecute = OverrideCanExecute }.ExecuteAsync();
            }

            gate.Add(new SyncSearchStreamTask { OverrideCanExecute = OverrideCanExecute });

            gate.Execute();

            EventBroker.Publish(AppEvents.SyncFinished);
        }
Ejemplo n.º 2
0
        protected override void ExecuteCore()
        {
            ClientState.Current.Messages.Errors.Clear();

            if (ChannelsManager.Channels.Count == 0)
                return;

            var gate = new ConcurrencyGate(2);
            var channels = ListOrSingle<ChannelInstance>.Get(channel, ChannelsManager.Channels);

            foreach (var instance in channels.Where(c => !c.Configuration.IsConnected))
            {
                if (instance.ContactsChannel != null)
                    gate.Add(new SyncContactsTask(instance.Configuration, instance.ContactsChannel.Clone()) { OverrideCanExecute = OverrideCanExecute });

                if (instance.StatusUpdatesChannel != null)
                    gate.Add(new SyncStatusUpdatesTask(instance.Configuration, instance.StatusUpdatesChannel.Clone()) { OverrideCanExecute = OverrideCanExecute });

                //if (instance.CalendarChannel != null)
                //    new SyncCalendarTask(instance.Configuration, instance.CalendarChannel) { OverrideCanExecute = OverrideCanExecute }.ExecuteAsync();
            }

            if (channel == null)
                gate.Add(new SyncSearchStreamTask { OverrideCanExecute = OverrideCanExecute });

            gate.Execute();

            EventBroker.Publish(AppEvents.SyncFinished);
        }
Ejemplo n.º 3
0
        protected override void ExecuteCore()
        {
            ClientState.Current.Messages.Errors.Clear();

            if (ChannelsManager.Channels.Count == 0)
                return;

            var channels = ListOrSingle<ChannelInstance>.Get(channel, ChannelsManager.Channels);
            var gate = new ConcurrencyGate(2);

            foreach (var channelInstance in channels.Where(c => !c.Configuration.IsConnected))
            {
                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);
        }
Ejemplo n.º 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 group = new ProgressGroup { SourceChannelId = config.ChannelId };

            // 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) { ProgressGroup = group });
                }
                else if (folder.FolderType == ChannelFolderType.Label)
                {
                    if (config.Charasteristics.SupportsLabels)
                        gate.Add(new EnumerateLabelsFolderTask(config, inputChannel.Clone(), folder, range) { ProgressGroup = group });
                }
            }

            gate.Execute();
            group.IsCompleted = true;

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

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