in my .net domain object I track every state transition. This is done by putting the estate in a state history collection. Thus, later you can see a list sorted in order to find out what , the state has been changed in that .
So there is a way:
private void SetState(RequestState state)
{
var stateHistoryItem = new RequestStateHistoryItem(state, this);
stateHistoryItems.Add(stateHistoryItem);
}
When you create a new RequestStateHistoryItemcurrent date is automatically assigned. Like this:
protected IdentificationRequestStateHistoryItem()
{
timestamp = EntityTimestamp.New();
}
An object EntityTimestampis an object that contains a suitable user and is created and modified.
When listing state history, I do a decreasing order with Linq:
public virtual IEnumerable<RequestStateHistoryItem> StateHistoryItems
{
get { return stateHistoryItems.OrderByDescending(s => s.Timestamp.CreatedOn.Ticks); }
}
, Request, SetState(RequestState.Received) Received. , - , Started. ( db) Finished.
, , Received Started. System.Threading.Thread.Sleep(1000) Started .
, , Started CreatedOn - OLDER, Received ?!
TimeOfDay {17:04:42.9430318} FINSHED
Ticks 634019366829430318
TimeOfDay {17:04:39.5376207} RECEICED
Ticks 634019366795376207
TimeOfDay {17:04:39.5367815} STARTED
Ticks 634019366795367815
? , , , ?
new DateTimePrecise().Now, (. DateTimePrecise) . .
- , ?
public virtual bool Finish()
{
SetState(IdentificationRequestState.Received);
SetState(IdentificationRequestState.Finished);
SetState(IdentificationRequestState.Finished);
SetState(IdentificationRequestState.Received);
var match = ...
if (match != null)
{
...
}
else
{
...
}
}