Пример #1
0
 void Postdicate(ProcessContext processContext, ITransaction trans = null)
 {
     // 已处理,且状态有变化的才能执行结束检查
     if (this.Status != ActivityStates.Dealed || !this.statesChanged || results == null)
     {
         return;
     }
     if (!this.Action.Postdicate(this, processContext))
     {
         return;
     }
     this.Status          = ActivityStates.Done;
     this.Entity.DoneTime = DateTime.Now;
     if (this.Graph.Exports != null && this.Graph.Exports.Count > 0)
     {
         var parent       = this.Parent as Activity;
         var parentStates = parent.States as JObject;
         foreach (var pair in this.Graph.Exports)
         {
             var value = JSON.GetPathValue(this.states, pair.Key);
             JSON.SetPathValue(parentStates, pair.Value, value);
             parent.statesChanged = true;
         }
         parent.SaveChanges(trans);
         this.Todo(parent, null);
     }
     this.SaveChanges(trans);
 }
Пример #2
0
 void Postdicate(IActivity activity, object results, Context context)
 {
     // 已处理,且状态有变化的才能执行结束检查
     if (this.Status != ActivityStates.Dealed || !this.statesChanged || results == null)
     {
         return;
     }
     if (!activity.Postdicate(results, this, context))
     {
         return;
     }
     this.Status = ActivityStates.Done;
     if (this.Graph.Exports != null && this.Graph.Exports.Count > 0)
     {
         var parent       = this.Parent;
         var parentStates = parent.States as JObject;
         foreach (var pair in this.Graph.Exports)
         {
             var value = JSON.GetPathValue(this.states, pair.Key);
             JSON.SetPathValue(parentStates, pair.Value, value);
             parent.statesChanged = true;
         }
         parent.SaveChanges();
         this.DelayExecute((context) => {
             parent.Deal(null, context.Dealer, context);
         });
     }
     this.SaveChanges();
 }
Пример #3
0
        public virtual NavigateResults Navigate(IActivity activity, IAssociation assoc, object executeResults, ProcessContext processContext)
        {
            //未指定Key,看是否已经完成
            if (string.IsNullOrEmpty(assoc.Key))
            {
                // 未完成,不能进行下一步
                if (activity.Status != ActivityStates.Done)
                {
                    return(null);
                }
            }
            // 看是状态是否满足
            else
            {
                if (activity.State <string>(assoc.Key) != assoc.Value)
                {
                    return(null);
                }
            }
            var nextDealerIdPath = assoc.NextDealerIdPath;

            if (string.IsNullOrEmpty(nextDealerIdPath))
            {
                nextDealerIdPath = processContext.Engine.DefaultNextDealerIdPath;
            }
            var nextDealerNamePath = assoc.NextDealerNamePath;

            if (string.IsNullOrEmpty(nextDealerNamePath))
            {
                nextDealerNamePath = processContext.Engine.DefaultNextDealerNamePath;
            }
            var nextDealerId = activity.State <string>(nextDealerIdPath);

            if (string.IsNullOrEmpty(nextDealerId))
            {
                throw new Exception(string.Format("活动对象{0}在执行导航{1}时,已经通过,但未能找到下一处理人", activity.Id, assoc.Name));
            }
            var nextDealer = new User(nextDealerId, activity.State <string>(nextDealerNamePath));

            object nextInputs;

            if (assoc.NextInputsMaps != null)
            {
                var jObj = new JObject();
                foreach (var pair in assoc.NextInputsMaps)
                {
                    var value = activity.State(pair.Key);
                    JSON.SetPathValue(jObj, pair.Value, value);
                }
                nextInputs = jObj;
            }
            else
            {
                nextInputs = executeResults;
            }
            return(new NavigateResults(nextDealer, nextInputs));
        }
Пример #4
0
 public Activity State(string key, JToken value)
 {
     if (this.states == null)
     {
         if (!string.IsNullOrWhiteSpace(this.Entity.States))
         {
             this.states = JObject.Parse(this.Entity.States);
         }
         if (this.states == null)
         {
             this.states = new JObject();
         }
     }
     JSON.SetPathValue(this.states, key, value);
     this.statesChanged = true;
     return(this);
 }
Пример #5
0
        public Activity(Engine engine, Activity parent, INode node, string version, object inputs, IUser creator, IUser owner, ProcessContext processContext)
        {
            this.Engine = engine;
            this.graph  = node;
            this.parent = parent;


            #region init entity
            var entity = new ActivityEntity()
            {
                Id          = Guid.NewGuid(),
                NodeName    = node.Name,
                NodePath    = parent == null ? node.Name : parent.NodePath + "/" + node.Name,
                Status      = ActivityStates.Creating,
                Version     = version ?? parent?.Version,
                Domain      = engine.Name,
                ActionType  = node.InstanceType ?? engine.DefaultActionType,
                Graph       = JSON.Stringify(node),
                HasChildren = node.Nodes != null && node.Nodes.Count > 0,
                Inputs      = JSON.Stringify(inputs),
                CreateTime  = DateTime.Now,
                CreatorId   = creator.Id,
                CreatorName = creator.Name
            };

            this.entity = entity;
            this.Owner  = owner;
            #endregion

            if (parent != null)
            {
                this.FlowRepository = parent.FlowRepository;
                this.AddChild(this);
            }
            else
            {
                this.FlowRepository = engine.ResolveFlowRepository(processContext);
            }

            #region init states
            var states = new JObject();
            var metas  = (node as Node).Metas;
            if (metas != null)
            {
                foreach (var pair in metas)
                {
                    states.Add(pair.Key, pair.Value.DeepClone());
                }
            }
            if (parent != null && node.Imports != null)
            {
                var pStates = parent.States as JObject;
                foreach (var pair in node.Imports)
                {
                    var value = JSON.GetPathValue(pStates, pair.Value);
                    JSON.SetPathValue(states, pair.Key, value);
                }
            }

            this.entity.States = states.ToString();
            this.states        = states;
            #endregion
        }
Пример #6
0
        public Action(Engine engine, Action parent, Node node, string version, object inputs, IUser creator, IUser dealer = null)
        {
            this.Engine = engine;
            this.graph  = node;
            this.parent = parent;

            #region init entity
            var entity = new ActivityEntity()
            {
                Id           = Guid.NewGuid(),
                NodeName     = node.Name,
                NodePath     = parent == null?node.Name:parent.NodePath + "/" + node.Name,
                Status       = ActivityStates.Created,
                Version      = version ?? parent?.Version,
                Domain       = engine.Name,
                ActivityType = node.InstanceType ?? engine.DefaultActivityInstanceType,
                Graph        = JSON.Stringify(node),
                HasChildren  = node.Nodes != null && node.Nodes.Count > 0,
                Inputs       = JSON.Stringify(inputs),
                CreateTime   = DateTime.Now,
                CreatorId    = creator.Id,
                CreatorName  = creator.Name
            };

            this.entity = entity;
            if (dealer != null)
            {
                this.dealer       = dealer;
                entity.DealerId   = dealer.Id;
                entity.DealerName = dealer.Name;
            }
            #endregion
            #region init states
            var states = new JObject();
            if (node.Meta != null)
            {
                foreach (var pair in node.Meta)
                {
                    states.Add(pair.Key, pair.Value.DeepClone());
                }
            }
            if (parent != null && node.Imports != null)
            {
                var pStates = parent.States as JObject;
                foreach (var pair in node.Imports)
                {
                    var value = JSON.GetPathValue(pStates, pair.Value);
                    JSON.SetPathValue(states, pair.Key, value);
                }
            }
            if (inputs != null)
            {
                var inputObj = JObject.FromObject(inputs);
                foreach (var pair in inputObj)
                {
                    states[pair.Key] = pair.Value;
                }
            }
            this.entity.States = states.ToString();
            this.states        = states;
            #endregion
        }