public async Task <FlowResult <FlowState> > CreateFlowStateAsync(InitFlowStateModel model) { var set = StateManager.GetFlowSet <FlowState>(); var typeSet = StateManager.GetFlowSet <FlowType>(); var type = await typeSet.GetByIdAsync(model.TypeId); if (type == null) { return(FlowResult <FlowState> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(type)))); } var entity = FlowEntity.InitializeType(new FlowState() { Name = model.Name, Title = model.Title, StateType = (byte)model.StateType, TypeId = type.Id, Tag = model.Tag, }); var result = await set.CreateAsync(entity); return(FlowResult <FlowState> .Successful(result)); }
public async Task <FlowResult <FlowTransition> > CreateFlowTransitionAsync(InitFlowTransitionModel model) { var set = StateManager.GetFlowSet <FlowTransition>(); var stateSet = StateManager.GetFlowSet <FlowState>(); var source = await stateSet.GetByIdAsync(model.SourceId); if (source == null) { return(FlowResult <FlowTransition> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(source)))); } var destination = await stateSet.GetByIdAsync(model.DestinationId); if (destination == null) { return(FlowResult <FlowTransition> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(destination)))); } var entity = FlowEntity.InitializeType(new FlowTransition() { Name = model.Name, Title = model.Title, SourceId = source.Id, DestinationId = destination.Id, TransitionType = model.TransitionType, TypeId = source.TypeId, }); var result = await set.CreateAsync(entity); return(FlowResult <FlowTransition> .Successful(result)); }
public async Task <FlowResult <FlowInstance> > CreateFlowInstanceAsync(InitFlowModel model) { var set = StateManager.GetFlowSet <FlowInstance>(); var typeSet = StateManager.GetFlowSet <FlowType>(); var type = await typeSet.GetByIdAsync(model.TypeId); if (type == null) { return(FlowResult <FlowInstance> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(type)))); } var entity = FlowEntity.InitializeType(new FlowInstance() { Title = model.Title, Payload = model.Payload, TypeId = type.Id, InitializerId = model.InitializerId, AccessPhrase = model.AccessPhrase, }); var result = await set.CreateAsync(entity); return(FlowResult <FlowInstance> .Successful(result)); }
public async Task <FlowResult <FlowType> > CreateFlowTypeAsync(InitFlowTypeModel initModel) { var set = StateManager.GetFlowSet <FlowType>(); var entity = FlowEntity.InitializeType(new FlowType() { EntityType = initModel.EntityType.FullName, EntityPayloadType = initModel.EntityPayloadType.FullName, Name = initModel.Name, }); var resultTask = await set.CreateAsync(entity); return(FlowResult <FlowType> .Successful(resultTask)); }
public async Task <FlowResult <IEnumerable <FlowTransition> > > GetSourceTransitionsAsync(Guid sourceId) { //Get current instance if (sourceId.GuidIsEmpty()) { throw new ArgumentNullException(nameof(sourceId)); } var stateSet = StateManager.GetFlowSet <FlowState>(); var targetSource = await stateSet .FirstOrDefaultAsync(x => x.Id.Equals(sourceId)); if (targetSource == null) { return(FlowResult <IEnumerable <FlowTransition> > .Failed(new FlowError(FlowErrors.ItemNotFound, args : nameof(FlowState)))); } var transitionSet = StateManager.GetFlowSet <FlowTransition>(); var typeSet = StateManager.GetFlowSet <FlowType>(); var reasonSet = StateManager.GetFlowSet <FlowTransitionReason>(); var query = from transition in transitionSet.GetAll() join type in typeSet.GetAll() on transition.TypeId equals type.Id join source in stateSet.GetAll() on transition.SourceId equals source.Id join destination in stateSet.GetAll() on transition.DestinationId equals destination.Id where transition.SourceId == sourceId select new FlowTransition() { Id = transition.Id, Type = type, CreatedAt = transition.CreatedAt, ModifiedAt = transition.ModifiedAt, Deleted = transition.Deleted, TypeId = transition.TypeId, Name = transition.Name, SourceId = transition.SourceId, DestinationId = transition.DestinationId, Destination = destination, IsAutomatic = transition.IsAutomatic, Source = source, Title = transition.Title, TransitionType = transition.TransitionType }; var transitions = await transitionSet.ToListAsync(query); return(FlowResult <IEnumerable <FlowTransition> > .Successful(transitions)); }
public async Task <FlowResult <FlowStep> > CreateFlowStepAsync(MoveModel model) { var set = StateManager.GetFlowSet <FlowStep>(); var instanceSet = StateManager.GetFlowSet <FlowInstance>(); var transitionSet = StateManager.GetFlowSet <FlowTransition>(); var stateSet = StateManager.GetFlowSet <FlowState>(); var instance = await instanceSet.GetByIdAsync(model.InstanceId); if (instance == null) { return(FlowResult <FlowStep> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(instance)))); } var transition = await transitionSet.GetByIdAsync(model.TransitionId); if (transition == null) { return(FlowResult <FlowStep> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(transition)))); } var state = await stateSet.GetByIdAsync(transition.DestinationId); if (state == null) { return(FlowResult <FlowStep> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(state)))); } var entity = FlowEntity.InitializeType(new FlowStep() { InstanceId = instance.Id, IsCurrent = true, TransitionId = transition.Id, Payload = model.Payload, Comment = model.Comment, CurrentStateName = state.Name, CurrentStateTitle = state.Title, CurrentStateType = state.StateType, }); var result = await set.CreateAsync(entity); return(FlowResult <FlowStep> .Successful(result)); }
public async Task <FlowResult <IEnumerable <FlowTransition> > > GetInstanceTransitionsAsync(Guid instanceId) { //Get current instance if (instanceId.GuidIsEmpty()) { throw new ArgumentNullException(nameof(instanceId)); } var instanceSet = StateManager.GetFlowSet <FlowInstance>(); var targetInstance = await instanceSet.FirstOrDefaultAsync(x => x.Id.Equals(instanceId)); if (targetInstance == null) { return(FlowResult <IEnumerable <FlowTransition> > .Failed(new FlowError(FlowErrors.ItemNotFound, args : nameof(FlowInstance)))); } //Get current instance state var stepSet = StateManager.GetFlowSet <FlowStep>(); var currentStep = await stepSet .FirstOrDefaultAsync(x => x.InstanceId.Equals(targetInstance.Id) && x.IsCurrent); if (currentStep == null) { return(FlowResult <IEnumerable <FlowTransition> > .Failed(new FlowError(FlowErrors.InstanceHasnostep))); } //Get current step transition var transitionSet = StateManager.GetFlowSet <FlowTransition>(); var currentTransition = await transitionSet .FirstOrDefaultAsync(x => x.Id.Equals(currentStep.TransitionId)); //Get current state var stateSet = StateManager.GetFlowSet <FlowState>(); var currentState = await stateSet.FirstOrDefaultAsync(x => x.Id.Equals(currentTransition.DestinationId)); //Get current state transitions var transitions = await transitionSet.GetAllAsync(x => x.SourceId.Equals(currentState.Id)); return(FlowResult <IEnumerable <FlowTransition> > .Successful(transitions)); }
public async Task <FlowResult <FlowStep> > DisableCurrentStepAsync(Guid instanceId) { var set = StateManager.GetFlowSet <FlowStep>(); var instanceSet = StateManager.GetFlowSet <FlowInstance>(); var instance = await instanceSet.GetByIdAsync(instanceId); if (instance == null) { return(FlowResult <FlowStep> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(instance)))); } var currentStep = await set.FirstOrDefaultAsync(x => x.InstanceId.Equals(instanceId) && x.IsCurrent); currentStep.IsCurrent = false; var updateResult = await set.UpdateAsync(currentStep); return(FlowResult <FlowStep> .Successful(updateResult)); }
public async Task <FlowResult <IEnumerable <FlowStep> > > GetInstanceStepsAsync(Guid instanceId) { //Get current instance if (instanceId.GuidIsEmpty()) { throw new ArgumentNullException(nameof(instanceId)); } var instanceSet = StateManager.GetFlowSet <FlowInstance>(); var targetInstance = await instanceSet.FirstOrDefaultAsync(x => x.Id.Equals(instanceId)); if (targetInstance == null) { return(FlowResult <IEnumerable <FlowStep> > .Failed(new FlowError(FlowErrors.ItemNotFound, args : nameof(FlowInstance)))); } //Get all steps var stepSet = StateManager.GetFlowSet <FlowStep>(); var steps = await stepSet.GetAllAsync(x => x.InstanceId.Equals(targetInstance.Id)); return(FlowResult <IEnumerable <FlowStep> > .Successful(steps)); }