Exemplo n.º 1
0
        void ProgressGroupFinished(object sender, EventArgs e)
        {
            ProgressGroup group = (ProgressGroup)sender;

            lock (_SyncLock)
                ProgressGroups.Remove(group);

            OnPropertyChanged("HasRunning");
        }
Exemplo n.º 2
0
        public void Add(ProgressGroup group)
        {
            group.IsRegistered = true;
            group.Completed += ProgressGroupFinished;

            lock (_SyncLock)
                ProgressGroups.Add(group);

            OnPropertyChanged("HasRunning");
        }
Exemplo n.º 3
0
        public void Add(ProgressGroup group)
        {
            group.IsRegistered = true;
            group.Completed   += ProgressGroupFinished;

            lock (_SyncLock)
                ProgressGroups.Add(group);

            OnPropertyChanged("HasRunning");
        }
Exemplo n.º 4
0
        public void Register(ProgressGroup group)
        {
            bool contains;

            lock (_SyncLock)
                contains = ProgressGroups.Contains(group);

            if (!contains)
            {
                group.IsRegistered = true;
                group.Completed   += ProgressGroupFinished;

                lock (_SyncLock)
                    ProgressGroups.Add(group);

                OnPropertyChanged("HasRunning");
            }
        }
Exemplo n.º 5
0
        public void Register(ProgressGroup group)
        {
            bool contains;

            lock (_SyncLock)
                contains = ProgressGroups.Contains(group);

            if (!contains)
            {
                group.IsRegistered = true;
                group.Completed += ProgressGroupFinished;

                lock (_SyncLock)
                    ProgressGroups.Add(group);

                OnPropertyChanged("HasRunning");
            }
        }
Exemplo n.º 6
0
        protected override void ExecuteCore()
        {
            var access = new ClientMessageAccess(message);
            var group = new ProgressGroup { Status = Strings.SendingMessage };

            ProgressManager.Current.Register(group);

            var msg = message.DuckCopy<ChannelMessage>();

            try
            {
                msg.BodyText = access.BodyText.ToStream();
                msg.BodyHtml = access.BodyHtml.ToStream();

                // Handle attachments
                foreach (var document in message.Documents)
                {
                    var attachment = new ChannelAttachment
                        {
                            Filename = document.Filename,
                            ContentType = document.ContentType,
                            ContentStream = new MemoryStream()
                        };

                    attachment.ContentStream = File.OpenRead(
                        ClientState.Current.Storage.ResolvePhysicalFilename(".", document.StreamName));

                    msg.Attachments.Add(attachment);
                }

                Logger.Debug("Message has {0} attachments", LogSource.BackgroundTask, msg.Attachments.Count);

                var recipients = BuildRecipients();

                try
                {
                    group.SourceChannelId = message.TargetChannelId;

                    var channel = ChannelsManager.GetChannelObject(message.TargetChannelId);

                    // The messageid itself is not used by the send channel, so inject our friendlyrowkey into that field.
                    // The field is added to the headers collection which in turn is used again to determine if its a sent
                    // item that is allready in your inbox2 sent items folder.
                    msg.MessageIdentifier = message.MessageKey;
                    msg.ConversationId = message.ConversationIdentifier;

                    // Filter only the recipients that belong to this channel
                    msg.To = recipients[message.TargetChannelId].To;
                    msg.CC = recipients[message.TargetChannelId].CC;
                    msg.BCC = recipients[message.TargetChannelId].BCC;

                    Logger.Debug("Sending message. Channel = {0}", LogSource.BackgroundTask, channel.Configuration.DisplayName);

                    if (channel.Configuration.IsConnected)
                        SendCloudMessage(channel.Configuration, msg);
                    else
                        channel.OutputChannel.Send(msg);

                    Logger.Debug("Send was successfull. Channel = {0}", LogSource.BackgroundTask, channel.Configuration.DisplayName);
                }
                catch (Exception ex)
                {
                    ClientState.Current.ShowMessage(
                        new AppMessage(String.Concat(Strings.UnableToSendMessage, ", ",
                            String.Format(Strings.ServerSaid, ex.Message)))
                            {
                                SourceChannelId = message.TargetChannelId
                            }, MessageType.Error);

                    throw;
                }

                EventBroker.Publish(AppEvents.SendMessageFinished);

                Thread.CurrentThread.ExecuteOnUIThread(() =>
                    ClientState.Current.ShowMessage(
                        new AppMessage(Strings.MessageSentSuccessfully)
                        {
                            EntityId = message.MessageId.Value,
                            EntityType = EntityType.Message
                        }, MessageType.Success));
            }
            finally
            {
                if (msg.BodyText != null)
                    msg.BodyText.Dispose();

                if (msg.BodyHtml != null)
                    msg.BodyHtml.Dispose();

                group.IsCompleted = true;

                // Close attachment streams
                foreach (var channelAttachment in msg.Attachments)
                {
                    channelAttachment.ContentStream.Dispose();
                    channelAttachment.ContentStream = null;
                }
            }
        }
        protected override void ExecuteCore()
        {
            var group = new ProgressGroup { Status = Strings.UpdatingStatus };

            ProgressManager.Current.Register(group);

            try
            {
                foreach (var config in status.TargetChannels)
                {
                    var channel = ChannelsManager.GetChannelObject(config.ChannelId);

                    try
                    {
                        group.SourceChannelId = config.ChannelId;

                        ChannelContext.Current.ClientContext = new ChannelClientContext(ClientState.Current.Context, config);

                        Logger.Debug("Updating status. Channel = {0}", LogSource.BackgroundTask, config.DisplayName);

                        if (config.IsConnected)
                        {
                            var data = String.Format("wrap_access_token={0}&channels={1}&inreplyto={2}&body={3}",
                                CloudApi.AccessToken, config.ChannelKey, status.InReplyTo, HttpUtility.UrlEncode(status.Status));

                            HttpServiceRequest.Post(String.Concat(CloudApi.ApiBaseUrl, "send/statusupdate"), data, true);

                        }
                        else
                        {
                            channel.StatusUpdatesChannel.UpdateMyStatus(status.DuckCopy<ChannelStatusUpdate>());
                        }
                    }
                    catch (Exception ex)
                    {
                        ClientState.Current.ShowMessage(
                            new AppMessage(
                                String.Concat(
                                    String.Format(Strings.ErrorOccuredDuringStatusUpdate, channel.Configuration.DisplayName),
                                    String.Format(Strings.ServerSaid, ex.Message)))
                            {
                                SourceChannelId = config.ChannelId
                            }, MessageType.Error);

                        throw;
                    }
                }

                Thread.CurrentThread.ExecuteOnUIThread(() =>
                    ClientState.Current.ShowMessage(
                        new AppMessage(Strings.StatusUpdatedSuccessfully)
                            {
                                EntityId = status.StatusId,
                                EntityType = EntityType.UserStatus
                            }, MessageType.Success));
            }
            finally
            {
                group.IsCompleted = true;
            }
        }
Exemplo n.º 8
0
        protected override void ExecuteChannelCore()
        {
            ProgressGroup = new ProgressGroup { SourceChannelId = config.ChannelId };

            ExecuteOnUIThread(() => ProgressManager.Current.Register(ProgressGroup));

            ProgressGroup.Status = "Connecting...";

            var result = channel.Connect();

            try
            {
                if (result == ConnectResult.Success)
                {
                    ProgressGroup.Status = "Retreiving folders...";

                    var cf = channel.GetFolders().ToList();
                    folders.AddRange(cf.Where(f => !f.Name.ToLower().StartsWithAny(ignore)));

                    foreach (var folder in folders)
                        Logger.Debug("Folder: {0} {1}", LogSource.Receive, folder.FolderId, folder.FolderType);

                    if (Channel is IReadStateChannel)
                    {
                        List<Message> messages;

                        // Get dirty messages
                        using (mailbox.Messages.ReaderLock)
                            messages = mailbox.Messages
                                .Where(m => m.TargetChannel == config || m.SourceChannelId == config.ChannelId)
                                .Where(m => m.TargetMessageState.HasValue)
                                .Union(mailbox.Messages
                                    .Where(m => m.TargetChannel == config || m.SourceChannelId == config.ChannelId)
                                    .Where(m => m.PostLabels.Any()))
                                .ToList();

                        if (messages.Count > 0)
                        {
                            ProgressGroup.Status = "Syncing readstates...";

                            foreach (var message in messages)
                            {
                                try
                                {
                                    new UpdateMessageStateTask(config, (IReadStateChannel)Channel, folders, message).Execute();
                                }
                                catch (Exception ex)
                                {
                                    Logger.Error("An error has occured while trying to update message state. Message = {0}, Exception = {1}", LogSource.BackgroundTask, message, ex);
                                }
                                finally
                                {
                                    message.TargetMessageState = null;

                                    ClientState.Current.DataService.Update(message);
                                }
                            }
                        }
                    }
                }
                else
                {
                    ShowChannelError(result, false);
                }
            }
            catch (Exception)
            {
                ShowChannelError(result, true);

                throw;
            }
            finally
            {
                ProgressGroup.IsCompleted = true;
            }
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
        protected override void ExecuteChannelCore()
        {
            if (ProgressGroup == null)
                ProgressGroup = new ProgressGroup { SourceChannelId = config.ChannelId };

            ExecuteOnUIThread(() => ProgressManager.Current.Register(ProgressGroup));

            try
            {
                PreProcess();

                channel.SelectFolder(folder);

                SetSelectionRange();

                var headers = channel.GetHeaders().ToList();

                // Channel returned oldest first, turn around and use newest first
                if (Channel is IReversePagableChannel)
                    headers.Reverse();

                var headersToDownload = GetHeadersToDownload(headers);

                if (headersToDownload != null)
                {
                    Logger.Debug("Got {0} headers from {1}", LogSource.Receive, headersToDownload.Count, config.DisplayName);

                    if (headersToDownload.Count > 0)
                    {
                        ProgressGroup.Status = String.Format("Downloading {0}...", LocalizedFolderNames.GetName(folder.ToStorageFolder()));
                        ProgressGroup.SetMaximum(headersToDownload.Count);

                        // Download details for each header
                        headersToDownload.ForEach(DownloadHeader);
                    }
                }

                EventBroker.Publish(AppEvents.ReceiveMessagesFinished);
            }
            finally
            {
                PostProcess();
            }
        }