Ejemplo n.º 1
0
        public async Task <Response> Handle(Request message)
        {
            var repository = new ExchangeRepository(this.inboxConfig);

            var data = await repository.Read(message.EmailPaginator);

            var emails = data.Transform(t => new EmailItem
            {
                From       = t.From.Address,
                ReceivedOn = t.DateTimeReceived,
                Subject    = t.Subject
            });

            return(new Response
            {
                Emails = emails
            });
        }
Ejemplo n.º 2
0
        public async Task <Response> Handle(Request message)
        {
            var folder = await this.context.LinkedFolders
                         .Include(t => t.Inbox)
                         .SingleOrExceptionAsync(t => t.Id == message.LinkedFolderId);

            var repository = new ExchangeRepository(folder.Inbox.Email);

            await repository.Initialize(folder.NewItemsFolder, folder.ProcessedItemsFolder);

            var result = await repository.Read(new Paginator
            {
                PageSize  = int.MaxValue,
                PageIndex = 1
            });

            foreach (var item in result.Results)
            {
                var email = new ImportedEmail(folder, item);

                var alreadyAdded = this.context.ImportedEmails.Any(t =>
                                                                   t.LinkedFolderId == folder.Id &&
                                                                   t.MessageId == email.MessageId);

                if (!alreadyAdded)
                {
                    this.context.ImportedEmails.Add(email);
                }
            }

            await this.context.SaveChangesAsync();

            await repository.MoveItemsToProcessedFolder(result.Results.Select(t => t.Id).ToList());

            return(new Response());
        }