Created
March 16, 2012 21:01
-
-
Save brianium/2052663 to your computer and use it in GitHub Desktop.
domain service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace DMSSubscriberUpdate.Domain.Services | |
{ | |
class SubscriberProcessor | |
{ | |
protected Subscriber Subscriber { get; set; } | |
public SubscriberProcessor(Subscriber subscriber) | |
{ | |
Subscriber = subscriber; | |
} | |
public Subscriber Process() | |
{ | |
//the first attempt | |
var skip = 0; | |
Attempt attempt = null; | |
while (skip != Subscriber.Attempts.Count) | |
{ | |
Attempt next = Subscriber.Attempts.Skip(skip).Take(1).First(); | |
if (attempt == null) | |
{ | |
next.Succeed(); | |
} | |
else | |
{ | |
if (next.ChannelID == attempt.ChannelID && next.Confirmed == attempt.Confirmed) | |
{ | |
next.Fail(); | |
} | |
else if (next.ChannelID == attempt.ChannelID && next.Confirmed != attempt.Confirmed) | |
{ | |
next.Succeed(); | |
} | |
else if (next.ChannelID != attempt.ChannelID) | |
{ | |
//first attempt in new channel | |
next.Succeed(); | |
} | |
} | |
skip++; | |
attempt = next; | |
} | |
return Subscriber; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment