Ejemplo n.º 1
0
 public void AddActivitiesUpdateIsAuto(WfActivity wfAct)
 {
     ActivitiesUpdateIsAuto[wfAct.WfaId.Value] = new WfActivityUpdate()
     {
         WfaId = wfAct.WfaId, IsAuto = wfAct.IsAuto, IsValid = wfAct.IsValid
     };
 }
Ejemplo n.º 2
0
 public void AddActivityDecision(WfActivity wfAct, WfDecision wfDecision)
 {
     ActivitiesDecisions.Add(new WfActivityDecision()
     {
         Activity = wfAct, Decision = wfDecision
     });
 }
Ejemplo n.º 3
0
        public void AutoValidateNextActivities(WfWorkflow wfWorkflow, int wfActivityDefinitionId)
        {
            WfActivityDefinition activityDefinition = _workflowStorePlugin.ReadActivityDefinition(wfActivityDefinitionId);

            object obj = _itemStorePlugin.ReadItem((int)wfWorkflow.ItemId);
            int?   wfCurrentActivityDefinitionId = null;

            while (CanAutoValidateActivity(activityDefinition, obj))
            {
                WfActivity wfActivityCurrent = AutoValidateActivity(activityDefinition);
                wfCurrentActivityDefinitionId = wfActivityCurrent.WfadId;
                if (_workflowStorePlugin.HasNextActivity(wfActivityCurrent) == false)
                {
                    break;
                }
                activityDefinition = _workflowStorePlugin.FindNextActivity(wfActivityCurrent);
            }

            // Remove this workflow update ?
            if (wfCurrentActivityDefinitionId != null)
            {
                wfWorkflow.WfaId2 = wfCurrentActivityDefinitionId;
                _workflowStorePlugin.UpdateWorkflowInstance(wfWorkflow);
            }
        }
Ejemplo n.º 4
0
        public void CreateActivity(WfActivity wfActivity)
        {
            int generatedId = Interlocked.Increment(ref memoryActivitySequenceGenerator);

            wfActivity.WfaId = generatedId;
            inMemoryActivityStore[generatedId] = wfActivity;
        }
Ejemplo n.º 5
0
        public IList <WfDecision> FindAllDecisionByActivity(WfActivity wfActivity)
        {
            IList <WfDecision> ret;
            FilterCriteria     filterCriteria = new FilterCriteria();

            filterCriteria.Equals(WfDecision.Cols.WFA_ID, wfActivity.WfaId);
            ret = new List <WfDecision>(BrokerManager.GetBroker <WfDecision>().GetAllByCriteria(filterCriteria));
            return(ret);
        }
Ejemplo n.º 6
0
        public void SaveDecision(WfWorkflow wfWorkflow, WfDecision wfDecision)
        {
            Debug.Assert(WfCodeStatusWorkflow.Sta.ToString().Equals(wfWorkflow.WfsCode), "A workflow must be started before saving decision");
            //---
            WfActivity currentActivity = _workflowStorePlugin.ReadActivity((int)wfWorkflow.WfaId2);

            // Attach decision to the activity
            wfDecision.WfaId = (int)currentActivity.WfaId;
            _workflowStorePlugin.CreateDecision(wfDecision);
        }
Ejemplo n.º 7
0
        public WfActivityDefinition FindNextActivity(WfActivity activity, string transitionName)
        {
            FilterCriteria filterCriteria = new FilterCriteria();

            filterCriteria.Equals(WfTransitionDefinition.Cols.WFAD_ID_FROM, activity.WfadId);
            filterCriteria.Equals(WfTransitionDefinition.Cols.NAME, transitionName);
            WfTransitionDefinition transition = BrokerManager.GetBroker <WfTransitionDefinition>().GetByCriteria(filterCriteria);

            return(BrokerManager.GetBroker <WfActivityDefinition>().Get(transition.WfadIdTo));
        }
Ejemplo n.º 8
0
        public bool HasNextActivity(WfActivity activity, string transitionName)
        {
            var cmd = GetSqlServerCommand("HasNextTransition.sql");

            cmd.Parameters.AddWithValue(WfTransitionDefinition.Cols.WFAD_ID_FROM, activity.WfadId);
            cmd.Parameters.AddWithValue(WfTransitionDefinition.Cols.NAME, transitionName);

            bool hasNext = cmd.ReadScalar <int>() == 1;

            return(hasNext);
        }
Ejemplo n.º 9
0
 public void UnsetCurrentActivity(WfActivityDefinition wfActivityDefinition)
 {
     foreach (WfWorkflow wf in inMemoryWorkflowInstanceStore.Values)
     {
         WfActivity currentActivity = ReadActivity(wf.WfaId2.Value);
         if (wf.WfaId2.Equals(currentActivity.WfaId) && wfActivityDefinition.WfadId.Equals(currentActivity.WfadId))
         {
             wf.WfaId2 = null;
         }
     }
 }
Ejemplo n.º 10
0
        public bool HasNextActivity(WfActivity activity, string transitionName)
        {
            //TODO: remove this method and use FindNextActivity
            FilterCriteria filterCriteria = new FilterCriteria();

            filterCriteria.Equals(WfTransitionDefinition.Cols.WFAD_ID_FROM, activity.WfadId);
            filterCriteria.Equals(WfTransitionDefinition.Cols.NAME, transitionName);
            WfTransitionDefinition transition = BrokerManager.GetBroker <WfTransitionDefinition>().GetByCriteria(filterCriteria);

            return(transition != null);
        }
        private WfActivity GetNewActivity(WfActivityDefinition activityDefinition, WfWorkflow wfWorkflow, bool isAuto, bool isValid)
        {
            WfActivity wfActivity = new WfActivity();

            wfActivity.CreationDate = DateTime.Now;
            wfActivity.WfadId       = activityDefinition.WfadId.Value;
            wfActivity.WfwId        = wfWorkflow.WfwId.Value;
            wfActivity.IsAuto       = isAuto;
            wfActivity.IsValid      = isValid;
            return(wfActivity);
        }
Ejemplo n.º 12
0
        public IList <WfDecision> FindAllDecisionByActivity(WfActivity wfActivity)
        {
            Debug.Assert(wfActivity != null);
            Debug.Assert(wfActivity.WfaId != null);
            //---
            IList <WfDecision> wfDecisions = new List <WfDecision>();

            foreach (WfDecision wfDecision in inMemoryDecisionStore.Values)
            {
                if (wfActivity.WfaId.Equals(wfDecision.WfaId))
                {
                    wfDecisions.Add(wfDecision);
                }
            }

            return(wfDecisions);
        }
Ejemplo n.º 13
0
        private WfActivity AutoValidateActivity(WfActivityDefinition wfNextActivityDefinition)
        {
            //Automatic validation of this activity
            DateTime now = new DateTime();

            WfActivity wfActivityCurrent = new WfActivity();

            wfActivityCurrent.CreationDate = now;
            wfActivityCurrent.WfadId       = (int)wfNextActivityDefinition.WfadId;

            _workflowStorePlugin.CreateActivity(wfActivityCurrent);

            WfDecision decision = new WfDecision();

            decision.User         = USER_AUTO;
            decision.DecisionDate = now;

            return(wfActivityCurrent);
        }
Ejemplo n.º 14
0
        public void StartInstance(WfWorkflow wfWorkflow)
        {
            Debug.Assert(wfWorkflow == null);
            Debug.Assert(WfCodeStatusWorkflow.Sta.ToString().Equals(wfWorkflow.WfsCode), "A workflow must be started before pausing");
            //---
            wfWorkflow.WfsCode = WfCodeStatusWorkflow.Sta.ToString();

            WfWorkflowDefinition wfWorkflowDefinition = _workflowStorePlugin.ReadWorkflowDefinition((int)wfWorkflow.WfwdId);

            WfActivity wfActivityCurrent = new WfActivity();

            wfActivityCurrent.CreationDate = new DateTime();
            wfActivityCurrent.WfadId       = (int)wfWorkflowDefinition.WfadId;
            _workflowStorePlugin.CreateActivity(wfActivityCurrent);
            wfWorkflow.WfaId2 = wfActivityCurrent.WfaId;
            _workflowStorePlugin.UpdateWorkflowInstance(wfWorkflow);

            AutoValidateNextActivities(wfWorkflow, (int)wfWorkflowDefinition.WfadId);
        }
Ejemplo n.º 15
0
        public void CreateActivity(WfActivity wfActivity)
        {
            int id = (int)BrokerManager.GetBroker <WfActivity>().Save(wfActivity);

            wfActivity.WfaId = id;
        }
Ejemplo n.º 16
0
 public void UpdateActivity(WfActivity wfActivity)
 {
     BrokerManager.GetBroker <WfActivity>().Save(wfActivity);
 }
Ejemplo n.º 17
0
 public bool HasNextActivity(WfActivity activity)
 {
     return(HasNextActivity(activity, WfCodeTransition.Default.ToString()));
 }
Ejemplo n.º 18
0
 public void AddActivitiesCreate(WfActivity wfAct)
 {
     ActivitiesCreate[wfAct.WfadId + "|" + wfAct.WfwId] = wfAct;
 }
        public void CustomRecalculation(IList <WfActivityDefinition> activityDefinitions, RuleConstants ruleConstants, WfWorkflow wf, IDictionary <int, List <RuleDefinition> > dicRules, IDictionary <int, List <RuleConditionDefinition> > dicConditions, IDictionary <int, List <SelectorDefinition> > dicSelectors, IDictionary <int, List <RuleFilterDefinition> > dicFilters, IDictionary <int, List <WfActivity> > dicActivities, IDictionary <int, List <WfDecision> > dicDecision, IDictionary <int, object> dicObjects, WfRecalculationOutput output)
        {
            object obj;

            dicObjects.TryGetValue(wf.ItemId.Value, out obj);

            if (obj == null)
            {
                // No item associated to this workflow.
                return;
            }

            List <WfActivity> allActivities;

            dicActivities.TryGetValue(wf.WfwId.Value, out allActivities);

            if (allActivities == null)
            {
                // No activity for this workflow.
                allActivities = new List <WfActivity>();
            }

            IDictionary <int, WfActivity> activities = allActivities.ToDictionary(a => a.WfadId);

            WfActivity currentActivity = allActivities.Where(a => a.WfaId.Equals(wf.WfaId2.Value)).FirstOrDefault();
            IList <WfActivityDefinition> nextActivityDefinitions;

            if (currentActivity != null)
            {
                nextActivityDefinitions = activityDefinitions.SkipWhile(ad => ad.WfadId.Equals(currentActivity.WfadId) == false).ToList();
            }
            else
            {
                nextActivityDefinitions = activityDefinitions;
            }

            RuleContext ruleContext = new RuleContext(obj, ruleConstants);

            foreach (WfActivityDefinition ad in nextActivityDefinitions)
            {
                WfActivity activity;
                activities.TryGetValue(ad.WfadId.Value, out activity);
                int actDefId = ad.WfadId.Value;

                bool isManual = _ruleManager.IsRuleValid(actDefId, ruleContext, dicRules, dicConditions);

                if (isManual)
                {
                    IList <AccountUser> accounts = _ruleManager.SelectAccounts(actDefId, ruleContext, dicSelectors, dicFilters);
                    isManual = accounts.Count > 0;
                }

                if (isManual)
                {
                    if (activity == null)
                    {
                        WfActivity wfActivity = GetNewActivity(ad, wf, false, false);
                        output.AddActivitiesCreateUpdateCurrentActivity(wfActivity);
                        break;
                    }

                    if (activity.IsValid == false)
                    {
                        wf.WfaId2 = activity.WfaId;
                        output.AddWorkflowsUpdateCurrentActivity(wf);
                        break;
                    }
                }
                else
                {
                    if (activity == null)
                    {
                        WfActivity wfActivity = GetNewActivity(ad, wf, true, false);
                        output.AddActivitiesCreate(wfActivity);
                    }
                    else
                    {
                        activity.IsAuto = true;
                        output.AddActivitiesUpdateIsAuto(activity);
                    }
                }
            }
        }
Ejemplo n.º 20
0
 public void UpdateActivity(WfActivity wfActivity)
 {
     inMemoryActivityStore[wfActivity.WfaId] = wfActivity;
 }
Ejemplo n.º 21
0
 public bool HasNextActivity(WfActivity activity, string transitionName)
 {
     return(transitionsNext.ContainsKey(activity.WfadId + "|" + transitionName));
 }
Ejemplo n.º 22
0
 public void DeleteActivity(WfActivity wfActivity)
 {
     BrokerManager.GetBroker <WfWorkflow>().Delete(wfActivity);
 }
Ejemplo n.º 23
0
        public void SaveDecisionAndGoToNextActivity(WfWorkflow wfWorkflow, string transitionName, WfDecision wfDecision)
        {
            Debug.Assert(WfCodeStatusWorkflow.Sta.ToString().Equals(wfWorkflow.WfsCode), "A workflow must be started before saving decision");
            //---
            WfActivity currentActivity = _workflowStorePlugin.ReadActivity((int)wfWorkflow.WfaId2);

            // Updating the decision
            SaveDecision(wfWorkflow, wfDecision);

            WfActivityDefinition currentActivityDefinition = _workflowStorePlugin.ReadActivityDefinition(currentActivity.WfadId);

            WfCodeMultiplicityDefinition wfCodeMultiplicityDefinition = (WfCodeMultiplicityDefinition)Enum.Parse(typeof(WfCodeMultiplicityDefinition), currentActivityDefinition.WfmdCode);

            bool canGoToNextActivity = false;

            if (wfCodeMultiplicityDefinition == WfCodeMultiplicityDefinition.Mul)
            {
                IList <WfDecision>  wfDecisions   = _workflowStorePlugin.FindAllDecisionByActivity(currentActivity);
                object              obj           = _itemStorePlugin.ReadItem((int)wfWorkflow.ItemId);
                RuleConstants       ruleConstants = _ruleManager.GetConstants((int)wfWorkflow.WfwdId);
                IList <AccountUser> accounts      = _ruleManager.SelectAccounts(currentActivity.WfadId, obj, ruleConstants);

                //TODO : better impl than O(n²)
                int match = 0;
                foreach (AccountUser account in accounts)
                {
                    foreach (WfDecision decision in wfDecisions)
                    {
                        if (account.Id.Equals(decision.User))
                        {
                            match++;
                            break;
                        }
                    }
                }

                if (match == accounts.Count)
                {
                    canGoToNextActivity = true;
                }
            }
            else
            {
                canGoToNextActivity = true;
            }

            if (canGoToNextActivity)
            {
                if (_workflowStorePlugin.HasNextActivity(currentActivity, transitionName))
                {
                    WfActivityDefinition nextActivityDefinition = _workflowStorePlugin.FindNextActivity(currentActivity, transitionName);

                    //Autovalidating next activities
                    AutoValidateNextActivities(wfWorkflow, (int)nextActivityDefinition.WfadId);

                    WfActivity           lastAutoValidateActivity      = _workflowStorePlugin.ReadActivity((int)wfWorkflow.WfaId2);
                    WfActivityDefinition nextActivityDefinitionPrepare = _workflowStorePlugin.FindNextActivity(lastAutoValidateActivity);

                    DateTime now = new DateTime();
                    // Creating the next activity to validate.
                    WfActivity nextActivity = new WfActivity();
                    nextActivity.CreationDate = now;
                    nextActivity.WfadId       = (int)nextActivityDefinitionPrepare.WfadId;
                    nextActivity.WfwId        = (int)wfWorkflow.WfwId;
                    _workflowStorePlugin.CreateActivity(nextActivity);

                    wfWorkflow.WfaId2 = nextActivity.WfaId;
                    _workflowStorePlugin.UpdateWorkflowInstance(wfWorkflow);
                }
                else
                {
                    // No next activity to go. Ending the workflow
                    wfWorkflow.WfsCode = WfCodeStatusWorkflow.End.ToString();
                    _workflowStorePlugin.UpdateWorkflowInstance(wfWorkflow);
                }
            }
        }
        public WfActivityDefinition FindNextActivity(WfActivity activity, string transitionName)
        {
            WfTransitionDefinition transitionNext = transitionsNext[activity.WfaId + "|" + transitionName];

            return(inMemoryActivityDefinitionStore[transitionNext.WfadIdTo]);
        }
Ejemplo n.º 25
0
 public WfActivityDefinition FindNextActivity(WfActivity activity)
 {
     return(FindNextActivity(activity, WfCodeTransition.Default.ToString()));
 }
Ejemplo n.º 26
0
 public void AddActivitiesCreateUpdateCurrentActivity(WfActivity wfAct)
 {
     ActivitiesCreateUpdateCurrentActivity[wfAct.WfadId + "|" + wfAct.WfwId] = wfAct;
 }
Ejemplo n.º 27
0
 public void DeleteActivity(WfActivity wfActivity)
 {
     inMemoryActivityStore.Remove(wfActivity.WfaId);
 }