Skip to content

Instantly share code, notes, and snippets.

@bwatts
Created January 5, 2013 10:38
Show Gist options
  • Save bwatts/4460937 to your computer and use it in GitHub Desktop.
Save bwatts/4460937 to your computer and use it in GitHub Desktop.
public class WorkItem : Aggregate
{
public WorkItem(EntityId id, string description, TimeSpan retryInterval)
{
Announce(new WorkItemCreatedEvent(id, description, retryInterval));
}
public string Description { get; private set; }
public Progress Progress { get; private set; }
public TimeSpan RetryInterval { get; private set; }
public Uri ResultLocation { get; private set; }
private void Handle(ReportProgressCommand command)
{
Announce(command.Progress == Progress.Complete
? new ProgressReportedEvent(Id, Progress, command.ResultLocation)
: new ProgressReportedEvent(Id, Progress, command.Progress));
}
private void Observe(WorkItemCreatedEvent e)
{
OnCreated(e.WorkItemId, e.When);
Description = e.Description;
RetryInterval = e.RetryInterval;
Progress = Progress.Accepted;
}
private void Observe(ProgressReportedEvent e)
{
OnModified(e.When);
Progress = e.NewProgress;
ResultLocation = e.ResultLocation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment