Skip to content

Instantly share code, notes, and snippets.

@brianium
Created March 16, 2012 21:01
Show Gist options
  • Save brianium/2052663 to your computer and use it in GitHub Desktop.
Save brianium/2052663 to your computer and use it in GitHub Desktop.
domain service
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