public void Serialize(StateMap sd, SerializationHelper helper) { sd.Set("IsSuccessfullyCompleted", IsSuccessfullyCompleted); sd.Set("Exception", _thrownException.GetOr(default(Exception))); sd.Set(nameof(_awaiters), _awaiters); }
public void Serialize(StateMap sd, SerializationHelper helper) { sd.Set(nameof(_handler), _handler); sd.Set(nameof(_value), _value); }
public QueuePendingState(IDelayQueueContext context, StateMap stateMap) : base(context, stateMap) { }
public ClientConnectedState(TcpClientConnection context, StateMap stateMap) : base(context, stateMap, BinaryConnectionState.Connected) { }
/// <summary> /// Create a state machine of the given base type and will set it on the given context /// Will internally called by the <see cref="StateMachine"/> wrapper class /// </summary> internal static void Create <TStateBase>(IStateContext context, int?initialKey) where TStateBase : StateBase { var stateBaseType = typeof(TStateBase); // Check the base type if (!stateBaseType.IsAbstract) { throw new ArgumentException("The state base class must be abstract!"); } // Load all fields // 1. Get all fields which are static constant with the attribute // 2. let attribute and create an anonymous array var definedStates = (from stateField in GetStateFields(stateBaseType) let att = stateField.GetCustomAttribute <StateDefinitionAttribute>() select new { Key = (int)stateField.GetValue(null), att.IsInitial, att.Type }).ToArray(); if (definedStates.Length == 0) { throw new InvalidOperationException("There was no state constant defined in the given base type." + $"There musst be at least one constant integer attributed with the {nameof(StateDefinitionAttribute)}."); } // If a initial key is set, we check if it exists if (initialKey.HasValue && definedStates.All(s => s.Key != initialKey.Value)) { throw new InvalidOperationException($"There was no state defined with key: {initialKey}"); } // Group by type to find multiple defined state types var duplicates = definedStates.GroupBy(state => state.Type).Where(g => g.Count() > 1).Select(g => g.Key).ToArray(); if (duplicates.Any()) { var typeNames = string.Join(", ", duplicates.Select(type => type.Name)); throw new InvalidOperationException($"State types are only allowed once: {typeNames}"); } var stateMap = new StateMap(); StateBase initialState = null; foreach (var definedState in definedStates) { var instance = (StateBase)Activator.CreateInstance(definedState.Type, context, stateMap); instance.Key = definedState.Key; if (initialKey.HasValue && initialKey.Value == definedState.Key) { initialState = instance; } else if (definedState.IsInitial && initialState == null) { initialState = instance; } else if (definedState.IsInitial && initialState != null) { throw new InvalidOperationException("At least one state must be flagged as '" + $"{nameof(StateDefinitionAttribute.IsInitial)} = true'."); } stateMap.Add(definedState.Key, instance); } if (initialState == null) { throw new InvalidOperationException("There is no state flagged with " + $"'{nameof(StateDefinitionAttribute.IsInitial)} = true'."); } context.SetState(initialState); initialState.OnEnter(); }
public void Serialize(StateMap sd, SerializationHelper helper) { sd.Set(nameof(_any), _any); sd.Set(nameof(_currentMax), _currentMax); }
public override void Serialize(StateMap sd, SerializationHelper helper) => sd.Set(nameof(_inner), _inner);
public ReadyState(WorkflowEngine context, StateMap stateMap) : base(context, stateMap) { }
public void Serialize(StateMap sd, SerializationHelper helper) => sd.Set(nameof(Value), Value);
public override void Serialize(StateMap sd, SerializationHelper helper) { sd.Set(nameof(_isCompletedSuccessfully), _isCompletedSuccessfully); sd.Set(nameof(_thrownException), _thrownException.GetOr(default(Exception))); sd.Set(nameof(_continuation), _continuation); }
public void Serialize(StateMap sd, SerializationHelper helper) { sd[nameof(Messages)] = Messages; sd[nameof(Network)] = Network; }
public override void Serialize(StateMap sd, SerializationHelper helper) => sd.Set("Exception", _thrownException);
public override void Serialize(StateMap stateToSerialize, SerializationHelper helper) { }
public abstract void Serialize(StateMap stateToSerialize, SerializationHelper helper);
public void Serialize(StateMap sd, SerializationHelper helper) { sd.Set(nameof(_curr), _curr); sd.Set(nameof(_folder), _folder); }
public RunningState(WorkflowEngine context, StateMap stateMap) : base(context, stateMap) { }
public void Serialize(StateMap sd, SerializationHelper helper) { }
protected ClientStateBase(TcpClientConnection context, StateMap stateMap, BinaryConnectionState connectionState) : base(context, stateMap) { Current = connectionState; }
public void Serialize(StateMap sd, SerializationHelper helper) => sd.Set(nameof(_count), _count);
private State FindStateNamed(string stateName, StateMap stateMap) => stateMap.OrderedStates.Single(s => s.Name == stateName);
public void Serialize(StateMap sd, SerializationHelper helper) { sd.Set(nameof(Name), Name); sd.Set(nameof(Child), Child); }
public void Serialize(StateMap sd, SerializationHelper helper) { sd.Set(nameof(ThrownException), ThrownException); sd.Set(nameof(Source), Source); }
/// <summary> /// Executes the behavior for this instance. /// </summary> /// <param name="container"> </param> /// <param name="stateMap"> </param> public void Execute(IContainer container, StateMap stateMap) { _action.Invoke( ); }
public void Serialize(StateMap sd, SerializationHelper helper) { sd.Set(nameof(Messages), Messages); sd.Set(nameof(Count), Count); }
/// <summary> /// Initializes a new instance of the <see cref="StateBase"/> class. /// </summary> /// <param name="context">Context of the state machine</param> /// <param name="stateMap">Map of states to objects</param> protected StateBase(IStateContext context, StateMap stateMap) { Map = stateMap; Context = context; }
/// <summary> /// constructor /// </summary> public StartedState(ResourceWrapper context, StateMap stateMap) : base(context, stateMap) { }
/// <summary> /// constructor /// </summary> protected ResourceStateBase(ResourceWrapper context, StateMap stateMap) : base(context, stateMap) { }
protected EngineState(WorkflowEngine context, StateMap stateMap) : base(context, stateMap) { }
public static void SerializeReferencesUsingReflectionInto(this object instance, StateMap sd, SerializationHelper helper) { var instanceType = instance.GetType(); var fields = instanceType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var fieldValues = fields .Select(f => new { Field = f, Value = f.GetValue(instance) }) .Where(a => a.Value == null || a.Field.FieldType.IsPrimitive || a.Field.FieldType == typeof(DateTime) || a.Field.FieldType == typeof(string) || a.Value is IPersistable || a.Value is IPropertyPersistable || a.Value.GetType().IsDisplayClass() || a.Value is Delegate ) .Select(a => new FieldNameAndValue(a.Field.Name, a.Value)); foreach (var fieldAndValue in fieldValues) { sd.Set(fieldAndValue.Name, helper.GetReference(fieldAndValue.Value)); } }
public void Begin() { Push(); m_Map = new StateMap(); }