public MailMonitorPrompter(IMailClient mailClient) { _mailClient = mailClient; Receive <CheckForMail>(_ => { Task.Run(() => _mailClient.ReadMessages()) .ContinueWith(readTask => new MailArrived(readTask.Result)) .PipeTo(Self); }); Receive <MailArrived>(message => { ScheduleNextMailCheck(); foreach (var mailObserver in _mailObservers) { foreach (var mail in message.Messages) { mailObserver.Tell(new MailReceived(mail.Attachments)); } } }); Receive <StartObserving>(_ => _mailObservers.Add(Sender)); Receive <StopObserving>(_ => _mailObservers.Remove(Sender)); }
public void Process(IMailClient mailClient, IOpticalCharacterRecognizer ocr, IClaimScanner claimScanner, IClaimManagementSystem claimManagement) { var emails = mailClient.ReadMessages(); foreach (var emailMessage in emails) { var recognizedAttachmentsContents = new List<string>(); foreach (var attachment in emailMessage.Attachments) { try { recognizedAttachmentsContents.Add(ocr.Scan(attachment.Path)); } catch (Exception e) { ProcessFailedAttachment(attachment, e); } } var claims = new List<Claim>(); foreach (var recognizedAttachmentsContent in recognizedAttachmentsContents) { try { var scanResult = claimScanner.Scan(recognizedAttachmentsContent); if (scanResult.Success) claims.Add(scanResult.Claim); else throw new Exception("Unable to find claim in attachment"); } catch (Exception e) { ProcessFailedClaim(recognizedAttachmentsContent, e); } } foreach (var claim in claims) { int retryCount = 3; while (true) { try { claimManagement.Upload(claim); } catch (Exception) { retryCount--; if (retryCount < 0) throw; else Thread.Sleep(5000); } } } } }
public MailMonitorPrompter(IMailClient mailClient) { _mailClient = mailClient; Receive<CheckForMail>(_ => { Task.Run(() => _mailClient.ReadMessages()) .ContinueWith(readTask => new MailArrived(readTask.Result)) .PipeTo(Self); }); Receive<MailArrived>(message => { ScheduleNextMailCheck(); foreach (var mailObserver in _mailObservers) foreach (var mail in message.Messages) mailObserver.Tell(new MailReceived(mail.Attachments)); }); Receive<StartObserving>(_ => _mailObservers.Add(Sender)); Receive<StopObserving>(_ => _mailObservers.Remove(Sender)); }
public void Process(IMailClient mailClient, IOpticalCharacterRecognizer ocr, IClaimScanner claimScanner, IClaimManagementSystem claimManagement) { var emails = mailClient.ReadMessages(); foreach (var emailMessage in emails) { var recognizedAttachmentsContents = new List <string>(); foreach (var attachment in emailMessage.Attachments) { try { recognizedAttachmentsContents.Add(ocr.Scan(attachment.Path)); } catch (Exception e) { ProcessFailedAttachment(attachment, e); } } var claims = new List <Claim>(); foreach (var recognizedAttachmentsContent in recognizedAttachmentsContents) { try { var scanResult = claimScanner.Scan(recognizedAttachmentsContent); if (scanResult.Success) { claims.Add(scanResult.Claim); } else { throw new Exception("Unable to find claim in attachment"); } } catch (Exception e) { ProcessFailedClaim(recognizedAttachmentsContent, e); } } foreach (var claim in claims) { int retryCount = 3; while (true) { try { claimManagement.Upload(claim); } catch (Exception) { retryCount--; if (retryCount < 0) { throw; } else { Thread.Sleep(5000); } } } } } }