Exemple #1
0
        public WorkflowContext(string persistenceContext, string machineContext, string initialState, string repositoryKey)
        {
            _persistenceContext = persistenceContext;
            _machineContext     = machineContext;
            _cachedState        = initialState;

            _machineStateData = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowMachineState>()
                                .ConfiguredResolve <IDataRepositoryService <WorkflowMachineState,
                                                                            WorkflowMachineState,
                                                                            DataEnvelope <WorkflowMachineState, NoMetadata>,
                                                                            NoMetadata,
                                                                            DatumEnvelope <WorkflowMachineState, NoMetadata>,
                                                                            NoMetadata> >
                                    (repositoryKey);

            WorkflowMachineState current = null;

            var qs = new QuerySpecification
            {
                BookMark = new GenericPageBookmark {
                    PageSize = 100
                },
                Where = new Filter
                {
                    PredicateJoin = PredicateJoin.And,
                    Rules         = new Comparison[]
                    {
                        new Comparison
                        {
                            Data  = _persistenceContext,
                            Field = "Parent",
                            Test  = Test.Equal
                        },
                        new Comparison
                        {
                            Data  = _machineContext,
                            Field = "StateMachine",
                            Test  = Test.Equal
                        }
                    }
                }
            };

            var queryResult = _machineStateData.Query(qs).Items.EmptyIfNull();

            current = queryResult.FirstOrDefault();

            if (null != current)
            {
                _cachedState = current.State;
                _cachedId    = current.Id;
            }
            else
            {
                _cachedId = string.Format("MS{0}-{1}", _persistenceContext, _machineContext);
                ChangeState(_cachedState);
            }
        }
Exemple #2
0
        public void ChangeState(string st)
        {
            _cachedState = st;
            var update = new WorkflowMachineState
            {
                Id               = _cachedId,
                Parent           = _persistenceContext,
                StateMachine     = _machineContext,
                State            = _cachedState,
                LastStateChanged = DateTime.UtcNow
            };

            _machineStateData.Store(update);
        }