Skip to content

Instantly share code, notes, and snippets.

View odeheurles's full-sized avatar

Olivier Deheurles odeheurles

View GitHub Profile
@odeheurles
odeheurles / StronglyTypedEvent
Created June 21, 2014 07:50
Defining a strongly typed event
_rfqEventServerSendsQuote = _stateMachine.SetTriggerParameters<IQuote>(RfqEvent.ServerNewQuote);
@odeheurles
odeheurles / RFQTransitions
Created June 21, 2014 07:51
Defining RFQ Transitions
_stateMachine.Configure(RfqState.Input)
.Permit(RfqEvent.UserRequests, RfqState.Requesting);
_stateMachine.Configure(RfqState.Requesting)
.Permit(RfqEvent.ServerNewQuote, RfqState.Quoted)
.Permit(RfqEvent.UserCancels, RfqState.Cancelling)
.Permit(RfqEvent.InternalError, RfqState.Error);
_stateMachine.Configure(RfqState.Quoted)
.PermitReentry(RfqEvent.ServerNewQuote)
@odeheurles
odeheurles / FireEvent
Created June 25, 2014 10:45
Fire an event to the state machine
// for an event without parameters
_stateMachine.Fire(RfqEvent.ServerQuoteStreamComplete)
// for a strongly typed event
_stateMachine.Fire(_rfqEventServerSendsExecutionReport, executionReport)
@odeheurles
odeheurles / DefiningActions
Created June 25, 2014 10:47
Defining actions
_stateMachine.Configure(RfqState.Requesting)
.OnEntry(LogTransition)
.OnEntryFrom(_rfqEventUserRequests, OnEntryRequesting)
.Permit(RfqEvent.ServerNewQuote, RfqState.Quoted)
.Permit(RfqEvent.UserCancels, RfqState.Cancelling)
.Permit(RfqEvent.InternalError, RfqState.Error);
private void OnEntryRequesting(IQuoteRequest quoteRequest)
{
// here goes the code to send a quote request to the server
@odeheurles
odeheurles / ErrorHandling
Created June 25, 2014 10:48
Error handling
_stateMachine.OnUnhandledTrigger(OnUnhandledTrigger);
private void OnUnhandledTrigger(RfqState state, RfqEvent trigger)
{
var message = string.Format("State machine received an invalid trigger '{0}' in state '{1}'", trigger, state);
Console.WriteLine(message);
_rfqUpdateSubject.OnError(new ApplicationException(message));
}
public interface IRfq : IDisposable
{
void RequestQuote(IQuoteRequest quoteRequest);
void Cancel(long rfqId);
void Execute(IExecutionRequest quote);
IObservable<RfqUpdate> Updates { get; }
}