public SecurableClassDefinition CreateAndCommitSecurableClassDefinitionWithAccessControlLists(int accessControlLists, ClientTransaction transaction) { CreateEmptyDomain(); using (transaction.EnterNonDiscardingScope()) { SecurableClassDefinition classDefinition = CreateOrderSecurableClassDefinition(); StatelessAccessControlList statelessAccessControlList = StatelessAccessControlList.NewObject(); classDefinition.StatelessAccessControlList = statelessAccessControlList; var stateProperty = StatePropertyDefinition.NewObject(Guid.NewGuid(), "Property"); classDefinition.AddStateProperty(stateProperty); for (int i = 1; i < accessControlLists; i++) { StatefulAccessControlList statefulAccessControlList = StatefulAccessControlList.NewObject(); classDefinition.StatefulAccessControlLists.Add(statefulAccessControlList); statefulAccessControlList.CreateAccessControlEntry(); CreateStateCombination(statefulAccessControlList, stateProperty, StateDefinition.NewObject(string.Format("Value {0}", i), i)); } ClientTransactionScope.CurrentTransaction.Commit(); return(classDefinition); } }
public void StateDefinitionTestSimplePasses() { DummyClass dc = new DummyClass(); DummyClass copy = new DummyClass(); dc.i = 1; dc.f = 2f; dc.d = 3d; dc.l = 4L; dc.v = new Vector3(1, 2, 3); dc.q = Quaternion.Euler(30f, 45f, 15f); dc.notRecorded = 1; StateDefinition sd = StateDefinitionFactory.CreateDefinition(typeof(DummyClass), "i", "f"); byte[] bytes = sd.GetState(dc); Debug.Log("State of data container: " + System.BitConverter.ToString(bytes)); sd.SetState(copy, bytes); Assert.AreEqual(dc.i, copy.i); Assert.AreEqual(dc.f, copy.f); Assert.AreEqual(dc.d, copy.d); Assert.AreEqual(dc.l, copy.l); Assert.AreNotEqual(dc.notRecorded, copy.notRecorded); }
/// <summary> /// Create a new LogDownloader /// </summary> /// <param name="isAsyncTransfer">Determines if this machine will be set up asyncronus transfers.</param> /// <param name="threadName">The name to report in closing operations for this binary socket.</param> /// <param name="closingWorker">The closing worker to add this binary socket too.</param> protected ThreadedTransferMachine(bool isAsyncTransfer, string threadName, ClosingWorker closingWorker) : base(threadName) { // add thread to the closing worker closingWorker?.AddThread(this); // initialize the StateMachine WorkerState = new StateDefinition(); if (isAsyncTransfer) { MachineFunctions.InitializeStates(WorkerStateMachine = new StepDefinition(threadName, true, WorkerState) { #region StateMachine SubSteps = new List <StepDefinition> { new StepDefinition("Transfer Packet") { Delegate = StateMachine_TransferPacket, DelayTimeMs = 500 }, new StepDefinition("Packet Timeout") { Delegate = StateMachine_PacketTimeout, DelayTimeMs = 0 }, new StepDefinition("Complete") { Delegate = StateMachine_Complete, DelayTimeMs = 200 } } #endregion // StateMachine }); } else { MachineFunctions.InitializeStates(WorkerStateMachine = new StepDefinition(threadName, true, WorkerState) { #region StateMachine SubSteps = new List <StepDefinition> { new StepDefinition("Transfer Packet") { Delegate = StateMachine_TransferPacket, DelayTimeMs = 0 }, new StepDefinition("Complete") { Delegate = StateMachine_Complete, DelayTimeMs = 200 } } #endregion // StateMachine }); } // start the StateMachine in the Complete state MachineFunctions.JumpToLast(WorkerStateMachine); // initialize ThreadingBase WorkerThreads = new List <ThreadInfo> { new ThreadInfo(new Thread(Worker), "State Machine", threadName, WorkerStateMachine) }; }
void ImportMecanimLayer(StateDefinition def, AC ac, int layer) { string name = "MecanimLayer_" + layer + "_Weight"; PropertyDefinition pdef = def.Properties.FirstOrDefault(x => x.StateAssetSettings.MecanimLayer == layer && x.StateAssetSettings.MecanimMode == MecanimMode.LayerWeight); if (pdef == null) { pdef = CreateProperty(new PropertyStateSettings()); pdef.PropertyType = new PropertyTypeFloat() { Compression = new FloatCompression { Accuracy = 0.01f, MinValue = 0, MaxValue = 1, Enabled = true } }; pdef.Name = name; pdef.StateAssetSettings.MecanimLayer = layer; pdef.StateAssetSettings.MecanimMode = MecanimMode.LayerWeight; pdef.StateAssetSettings.MecanimDirection = MecanimDirection.UsingAnimatorMethods; Debug.Log(string.Format("Imported Mecanim Layer: {0}", pdef.Name)); def.Properties.Add(pdef); } else if (!(pdef.PropertyType is PropertyTypeFloat)) { pdef.PropertyType = new PropertyTypeFloat() { Compression = new FloatCompression { Accuracy = 0.01f, MinValue = 0, MaxValue = 1, Enabled = true } }; Debug.Log(string.Format("Updated Mecanim Layer: {0}", pdef.Name)); } }
/// <inheritdoc/> public virtual IWorkflowBuilder EndsWith(Func <IStateBuilderFactory, IStateBuilder> stateSetup) { StateDefinition state = this.AddState(stateSetup); state.End = new EndDefinition(); return(this.Workflow); }
/// <summary> /// Registers the given object. /// Returns true if it was registered, false if it was already registered. /// </summary> /// <param name="o"></param> /// <returns></returns> public bool Register(object o) { if (o == null) { throw new ArgumentException("Object given is null."); } if (!registeredObjects.ContainsKey(o)) { // Create a definition for this type, if it doesn't exist. if (!definitions.ContainsKey(o.GetType())) { StateDefinition sd = StateDefinitionFactory.CreateDefinition(o.GetType()); definitions.Add(o.GetType(), sd); } registeredObjects.Add(o, new RecordableMetadata(nextObjID, TimeState.NOMINAL)); nextObjID++; //print("Registered object " + o.ToString() + ". Hashcode: " + o.GetHashCode()); return(true); } else { print("Dictionary contains key " + o + ": " + registeredObjects.ContainsKey(o)); } return(false); }
/// <inheritdoc/> public virtual IWorkflowExecutionTimeoutBuilder Run(StateDefinition state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } return(this.Run(this.Pipeline.AddState(state).Name)); }
public void AttachState(StateDefinition state) { ArgumentUtility.CheckNotNull("state", state); StateUsage stateUsage = StateUsage.NewObject(); stateUsage.StateDefinition = state; StateUsages.Add(stateUsage); }
public static void GetName(StateDefinition obj, MethodReturnEventArgs <string> e) { e.Result = obj.Module != null? string.Format("Workflow.StateDefinitions.{0}.{1}.{2}", obj.WFDefinition.Module.Namespace, Regex.Replace(obj.WFDefinition.Name, "\\W", "_"), Regex.Replace(obj.Name, "\\W", "_")) : null; }
private StateDefinition CreateState(string name, int value) { StateDefinition state = StateDefinition.NewObject(name, value); state.Index = value; return(state); }
public StateBuilder( TState stateId, IImplicitAddIfNotAvailableStateDefinitionDictionary <TState, TEvent> stateDefinitionDictionary, IFactory <TState, TEvent> factory) { this.stateDefinitionDictionary = stateDefinitionDictionary; this.factory = factory; this.stateDefinition = this.stateDefinitionDictionary[stateId]; }
/// <inheritdoc/> public virtual IPipelineBuilder Then(Func <IStateBuilderFactory, IStateBuilder> stateSetup) { if (stateSetup == null) { throw new ArgumentNullException(nameof(stateSetup)); } this.CurrentState = this.AddState(stateSetup); return(this); }
/// <inheritdoc/> public virtual StateDefinition AddState(StateDefinition state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } this.States.Add(state); return(state); }
public HierarchyBuilderTest() { this.superState = new StateDefinition <string, int>(SuperState); this.states = A.Fake <IImplicitAddIfNotAvailableStateDefinitionDictionary <string, int> >(); A.CallTo(() => this.states[SuperState]).Returns(this.superState); this.initiallyLastActiveStates = A.Fake <IDictionary <string, string> >(); this.testee = new HierarchyBuilder <string, int>(SuperState, this.states, this.initiallyLastActiveStates); }
// We remember the parents for States separately from the State object itself // to make it easier to deal with deserialized states (which lack the parent structure) /// <summary> /// Add a new state definition /// </summary> public static State AddState(string name, Func <TStateMachine, TEvent, State, TContext, Task>?entryAction = null, Func <TStateMachine, State, TEvent, TContext, Task>?exitAction = null, State?parent = null) { var stateDefinition = new StateDefinition(name, entryAction, exitAction, parent); definitions.Add(name, stateDefinition); return(stateDefinition.GetState()); }
/// <inheritdoc/> public virtual IStateBuilder <TState> CompensateWith(StateDefinition state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } state.UsedForCompensation = true; this.State.CompensatedBy = this.Pipeline.AddState(state).Name; return(this); }
/// <summary> /// Add a state, mapped to a type, to this reference definition. /// </summary> /// <param name="type">Type of state to add</param> /// <param name="def">State definition to add.</param> public void AddState(StateType type, StateDefinition def) { // Enforce only 1 of each type, except for Generic, which can have as many as it wants. if (m_StatesPresent.Contains(type) && type != StateType.Generic) { return; } m_StatesPresent.Add(type); m_StateDefinition.Add(def); }
public void GetState_ValidValue() { StatePropertyDefinition stateProperty = _testHelper.CreateConfidentialityProperty(0); StateDefinition actualState = stateProperty.GetState(MetadataTestHelper.Confidentiality_PrivateValue); StateDefinition expectedState = _testHelper.CreatePrivateState(); MetadataObjectAssert.AreEqual(expectedState, actualState, "Private state"); }
public void Indexer_ValidName() { StatePropertyDefinition stateProperty = _testHelper.CreateConfidentialityProperty(0); StateDefinition actualState = stateProperty[MetadataTestHelper.Confidentiality_ConfidentialName]; StateDefinition expectedState = _testHelper.CreateConfidentialState(); MetadataObjectAssert.AreEqual(expectedState, actualState, "Confidential state"); }
public StateDefinition CreateState(string name, int value) { using (_transaction.EnterNonDiscardingScope()) { StateDefinition state = StateDefinition.NewObject(name, value); state.Index = value; return(state); } }
/// <inheritdoc/> public virtual void TransitionTo(Func <IStateBuilderFactory, IStateBuilder> stateSetup) { //TODO: configure transition StateDefinition state = this.Pipeline.AddState(stateSetup); this.Outcome = new TransitionDefinition() { NextState = state.Name }; }
/// <inheritdoc/> public virtual IPipelineBuilder StartsWith(StateDefinition state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } this.Pipeline.AddState(state); this.Workflow.StartStateName = state.Name; return(this.Pipeline); }
/// <inheritdoc/> public virtual IPipelineBuilder StartsWith(Func <IStateBuilderFactory, IStateBuilder> stateSetup) { if (stateSetup == null) { throw new ArgumentNullException(nameof(stateSetup)); } StateDefinition state = this.Pipeline.AddState(stateSetup); this.Workflow.StartStateName = state.Name; return(this.Pipeline); }
/// <summary> /// Adds a definition for a type, defining which properties will be recorded. /// </summary> /// <param name="s"></param> public void AddDefinition(StateDefinition s) { if (!definitions.ContainsKey(s.Type)) { definitions.Add(s.Type, s); } else { throw new InvalidOperationException("Cannot add new definition for type '" + s.Type + "', as it already exists."); } }
public HierarchyBuilder( TState superStateId, IImplicitAddIfNotAvailableStateDefinitionDictionary <TState, TEvent> stateDefinitions, IDictionary <TState, IStateDefinition <TState, TEvent> > initiallyLastActiveStates) { Guard.AgainstNullArgument("states", stateDefinitions); this.stateDefinitions = stateDefinitions; this.initiallyLastActiveStates = initiallyLastActiveStates; this.superState = this.stateDefinitions[superStateId]; }
public void StateEngineTest() { { var orderState = new StateDefinition<Order, OrderState>( x => x.State, new StateTransitionDefinition<Order, OrderState>(OrderState.Init, OrderState.Confirmed), new StateTransitionDefinition<Order, OrderState>(OrderState.Confirmed, OrderState.Processing), new StateTransitionDefinition<Order, OrderState>(OrderState.Processing, OrderState.Done) { Expect = (entity, o) => entity.Delivery.State == DeliveryState.Done } ); var deliveryState = new StateDefinition<Delivery, DeliveryState>( x => x.State, new StateTransitionDefinition<Delivery, DeliveryState>(DeliveryState.Init, DeliveryState.Prepare) { Expect = (entity, o) => entity.Order.State == OrderState.Processing }, new StateTransitionDefinition<Delivery, DeliveryState>(DeliveryState.Prepare, DeliveryState.Sent) { Expect = (entity, o) => entity.Order.State == OrderState.Processing }, new StateTransitionDefinition<Delivery, DeliveryState>(DeliveryState.Sent, DeliveryState.Done) { PostAction = (container, entity, arg3) => container.StateEngine.Execute(entity.Order, OrderState.Done) } ); StateEngine.Add(orderState); StateEngine.Add(deliveryState); } { var order = new Order(); var delivery = new Delivery {Order = order}; order.Delivery = delivery; using (var uow = new DummyUnitOfWorkContainer()) { Assert.Throws<StateTransitionNotAllowedException>(() => uow.StateEngine.Execute(delivery, DeliveryState.Prepare)); uow.StateEngine.Execute(order, OrderState.Confirmed); Assert.Throws<StateTransitionNotAllowedException>(() => uow.StateEngine.Execute(delivery, DeliveryState.Prepare)); uow.StateEngine.Execute(order, OrderState.Processing); Assert.Throws<StateTransitionNotAllowedException>(() => uow.StateEngine.Execute(order, OrderState.Done)); uow.StateEngine.Execute(delivery, DeliveryState.Prepare); Assert.Throws<StateTransitionNotAllowedException>(() => uow.StateEngine.Execute(order, OrderState.Done)); uow.StateEngine.Execute(delivery, DeliveryState.Sent); Assert.Throws<StateTransitionNotAllowedException>(() => uow.StateEngine.Execute(order, OrderState.Done)); uow.StateEngine.Execute(delivery, DeliveryState.Done); Assert.Equal(OrderState.Done, order.State); } } }
public void HierarchyWhenDefiningAStateAsItsOwnInitialSubStateThenAnExceptionIsThrown() { var testee = new StateDefinition <States, Events>(States.A); Action action = () => testee.InitialStateModifiable = testee; action .Should() .Throw <ArgumentException>() .WithMessage(StatesExceptionMessages.StateCannotBeTheInitialSubStateToItself(testee.ToString())); }
private void CheckThatStateHasNotAlreadyASuperState(StateDefinition <TState, TEvent> subState) { Guard.AgainstNullArgument("subState", subState); if (subState.SuperState != null) { throw new InvalidOperationException( ExceptionMessages.CannotSetStateAsASuperStateBecauseASuperStateIsAlreadySet( this.superState.Id, subState)); } }
public void GetStates_OneState() { SecurableClassDefinition classDefinition = _testHelper.CreateOrderClassDefinition(); StatePropertyDefinition property = _testHelper.CreatePaymentStateProperty(classDefinition); StateDefinition state = property.DefinedStates[1]; StateCombination combination = _testHelper.CreateStateCombination(classDefinition, state); StateDefinition[] states = combination.GetStates(); Assert.That(states.Length, Is.EqualTo(1)); Assert.That(states[0], Is.SameAs(state)); }
/// <inheritdoc/> public virtual IStateBuilder <TState> CompensateWith(Func <IStateBuilderFactory, IStateBuilder> stateSetup) { if (stateSetup == null) { throw new ArgumentNullException(nameof(stateSetup)); } StateDefinition compensatedBy = this.Pipeline.AddState(stateSetup); compensatedBy.UsedForCompensation = true; this.State.CompensatedBy = compensatedBy.Name; return(this); }
/// <inheritdoc/> public virtual IPipelineBuilder Then(Func <IStateBuilderFactory, IStateBuilder> stateSetup) { if (stateSetup == null) { throw new ArgumentNullException(nameof(stateSetup)); } var nextState = this.AddState(stateSetup); this.CurrentState.TransitionToStateName = nextState.Name; this.CurrentState = nextState; return(this); }
public void StateEngineTest() { var stateDefinition = new StateDefinition<TestEntity, TestStatus>( x => x.Status, new StateTransitionDefinition<TestEntity, TestStatus>(TestStatus.Status1, TestStatus.Status2), new StateTransitionDefinition<TestEntity, TestStatus>(TestStatus.Status2, TestStatus.Status3) { ExpectParameterType = typeof (StateChangeArgument), Expect = (entity, o) => entity.Allow, PreAction = (container, entity, arg) => { /* do something before action */ }, PostAction = (container, entity, arg) => { entity.Date = arg.Date; //container.OnCommitAction(() => // { // // Code to send // }); container.StateEngine.Execute(entity, TestStatus.Status4); } }, new StateTransitionDefinition<TestEntity, TestStatus>(TestStatus.Status3, TestStatus.Status4), new StateTransitionDefinition<TestEntity, TestStatus>(TestStatus.Status4, TestStatus.Status5), new StateTransitionDefinition<TestEntity, TestStatus>(TestStatus.Status4, TestStatus.Status6)); var testEntity = new TestEntity(); var stateChangeArgument = new StateChangeArgument {Date = DateTime.Now.AddDays(1)}; using (var uow = new DummyUnitOfWorkContainer()) { Assert.Equal(TestStatus.Status1, testEntity.Status); // state is not added and should throw state not found Assert.Throws<StateNotFoundForEntityException>(() => uow.StateEngine.Execute(testEntity, TestStatus.Status2)); } // Add state definition to the static collection StateEngine.Add(stateDefinition); using (var uow = new DummyUnitOfWorkContainer()) { Assert.Equal(TestStatus.Status1, testEntity.Status); var allowedStates = uow.StateEngine.GetAvailableTransitions<TestEntity, TestStatus>(testEntity); Assert.Equal(new HashSet<TestStatus>(new[] {TestStatus.Status2}), allowedStates); Assert.Throws<StateTransitionArgumentException>(() => uow.StateEngine.Execute(testEntity, TestStatus.Status2, stateChangeArgument)); Assert.Equal(TestStatus.Status1, testEntity.Status); uow.StateEngine.Execute(testEntity, TestStatus.Status2); Assert.Equal(TestStatus.Status2, testEntity.Status); allowedStates = uow.StateEngine.GetAvailableTransitions<TestEntity, TestStatus>(testEntity); Assert.Equal(new HashSet<TestStatus>(new[] {TestStatus.Status3}), allowedStates); Assert.Throws<StateTransitionArgumentException>(() => uow.StateEngine.Execute(testEntity, TestStatus.Status3)); Assert.Throws<StateTransitionNotAllowedException>(() => uow.StateEngine.Execute(testEntity, TestStatus.Status3, stateChangeArgument)); Assert.Equal(TestStatus.Status2, testEntity.Status); testEntity.Allow = true; Assert.Throws<StateTransitionArgumentException>(() => uow.StateEngine.Execute(testEntity, TestStatus.Status3)); Assert.Equal(TestStatus.Status2, testEntity.Status); uow.StateEngine.Execute(testEntity, TestStatus.Status3, stateChangeArgument); Assert.Equal(stateChangeArgument.Date, testEntity.Date); // Post action move status one more step so the status should be Status4 Assert.Equal(TestStatus.Status4, testEntity.Status); allowedStates = uow.StateEngine.GetAvailableTransitions<TestEntity, TestStatus>(testEntity); Assert.Equal(new HashSet<TestStatus>(new[] {TestStatus.Status5, TestStatus.Status6}), allowedStates); Assert.Throws<StateTransitionNotAllowedException>(() => uow.StateEngine.Execute(testEntity, TestStatus.Status1)); Assert.Throws<StateTransitionNotAllowedException>(() => uow.StateEngine.Execute(testEntity, TestStatus.Status2)); } }