Skip to content

Commit

Permalink
switch failure events to fail calls
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullin committed Aug 28, 2012
1 parent da2e4da commit df03162
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions E004-event-sourcing-basics/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,39 +106,31 @@ public class FactoryImplementation3
public void AssignEmployeeToFactory(string employeeName)
{
Print("?> Command: Assign employee {0} to factory", employeeName);
// CheckIfEmployeeCanBeAssignedToFactory(employeeName);

if (_ourListOfEmployeeNames.Contains(employeeName))
{
// yes, this is really weird check, but this factory has really strict rules.
// manager should've remembered that
RecordThat(new EmployeeKickedOutOfFactory()
{
EmployeeName = employeeName,
Reason = string.Format("the name of '{0}' only one employee can have", employeeName)
});
Fail(":> the name of '{0}' only one employee can have", employeeName);

return;
}

if (employeeName == "bender")
{
RecordThat(new EmployeeKickedOutOfFactory()
{
EmployeeName = employeeName,
Reason = "Guys with name 'bender' are trouble."
});
Fail(":> Guys with name 'bender' are trouble.");
return;
}

DoPaperWork("Assign employee to the factory");

RecordThat(new EmployeeAssignedToFactory()
RecordThat(new EmployeeAssignedToFactory
{
EmployeeName = employeeName
});
// DoPaperWork();
// RecordThatEmployeeAssignedToFactory(employeeName);
}



void DoPaperWork(string workName)
{
Print(" > Work: papers... {0}... ", workName);
Expand All @@ -159,17 +151,10 @@ void RecordThat(IEvent e)
}





void AnnounceInsideFactory(EmployeeAssignedToFactory e)
{
_ourListOfEmployeeNames.Add(e.EmployeeName);
}
void AnnounceInsideFactory(EmployeeKickedOutOfFactory e)
{
// this is a trick. Don't care about it for now
}
}

public class EmployeeAssignedToFactory : IEvent
Expand All @@ -181,16 +166,7 @@ public override string ToString()
return string.Format("new worker joins our forces: '{0}'", EmployeeName);
}
}
public class EmployeeKickedOutOfFactory : IEvent
{
public string EmployeeName;
public string Reason;

public override string ToString()
{
return string.Format("'{0}' is not allowed, because '{1}'", EmployeeName, Reason);
}
}

// let's run this implementation
public static void RunFactoryImplementation3()
Expand Down Expand Up @@ -228,6 +204,12 @@ static void Print(string format, params object[] args)
else Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(format, args);
}

static void Fail(string format, params object[] args)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(format, args);
}
}

public interface IEvent
Expand Down

0 comments on commit df03162

Please sign in to comment.