Ejemplo n.º 1
0
        /// <summary>
        /// Prints the activity tree, starting from the top or optionally from a given origin.
        ///
        /// Call this method from any place that's called during a tick, such as the Tick() method itself or
        /// the Before(First|Last)Run() methods. The origin activity will be marked in the output.
        /// </summary>
        /// <param name="self">The actor performing this activity.</param>
        /// <param name="origin">Activity from which to start traversing, and which to mark. If null, mark the calling activity, and start traversal from the top.</param>
        /// <param name="level">Initial level of indentation.</param>
        protected void PrintActivityTree(Actor self, Activity origin = null, int level = 0)
        {
            if (origin == null)
            {
                self.CurrentActivity.PrintActivityTree(self, this);
            }
            else
            {
                Console.Write(new string(' ', level * 2));
                if (origin == this)
                {
                    Console.Write("*");
                }

                Console.WriteLine(GetType().ToString().Split('.').Last());

                if (ChildActivity != null)
                {
                    ChildActivity.PrintActivityTree(self, origin, level + 1);
                }

                if (NextActivity != null)
                {
                    NextActivity.PrintActivityTree(self, origin, level);
                }
            }
        }
Ejemplo n.º 2
0
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = 1561563491;

                hashCode = (hashCode * 157) + Id.GetHashCode();
                hashCode = (hashCode * 157) + WorkflowID.GetHashCode();
                hashCode = (hashCode * 157) + ExecutionID.GetHashCode();
                hashCode = (hashCode * 157) + ExecutionOrigin.GetHashCode();
                hashCode = (hashCode * 157) + IsSubExecution.GetHashCode();
                hashCode = (hashCode * 157) + IsRemoteWorkflow.GetHashCode();
                hashCode = (hashCode * 157) + WorkflowName.GetHashCode();
                hashCode = (hashCode * 157) + AuditType.GetHashCode();
                hashCode = (hashCode * 157) + PreviousActivity.GetHashCode();
                hashCode = (hashCode * 157) + PreviousActivityType.GetHashCode();
                hashCode = (hashCode * 157) + PreviousActivityId.GetHashCode();
                hashCode = (hashCode * 157) + NextActivity.GetHashCode();
                hashCode = (hashCode * 157) + NextActivityType.GetHashCode();
                hashCode = (hashCode * 157) + NextActivityId.GetHashCode();
                hashCode = (hashCode * 157) + ServerID.GetHashCode();
                hashCode = (hashCode * 157) + ParentID.GetHashCode();
                hashCode = (hashCode * 157) + ExecutingUser.GetHashCode();
                hashCode = (hashCode * 157) + ExecutionOriginDescription.GetHashCode();
                hashCode = (hashCode * 157) + ExecutionToken.GetHashCode();
                hashCode = (hashCode * 157) + AdditionalDetail.GetHashCode();
                hashCode = (hashCode * 157) + Environment.GetHashCode();
                hashCode = (hashCode * 157) + AuditDate.GetHashCode();

                return(hashCode);
            }
        }
Ejemplo n.º 3
0
 public void Queue(Activity activity)
 {
     if (NextActivity != null)
     {
         NextActivity.Queue(activity);
     }
     else
     {
         NextActivity = activity;
     }
 }
Ejemplo n.º 4
0
 public virtual void Queue(Actor self, Activity activity)
 {
     if (NextActivity != null)
     {
         NextActivity.Queue(self, activity);
     }
     else
     {
         NextActivity = activity;
     }
 }
Ejemplo n.º 5
0
        public IEnumerable <T> ActivitiesImplementing <T>(bool includeChildren = true) where T : IActivityInterface
        {
            if (includeChildren && ChildActivity != null)
            {
                foreach (var a in ChildActivity.ActivitiesImplementing <T>())
                {
                    yield return(a);
                }
            }

            if (this is T)
            {
                yield return((T)(object)this);
            }

            if (NextActivity != null)
            {
                foreach (var a in NextActivity.ActivitiesImplementing <T>())
                {
                    yield return(a);
                }
            }
        }
Ejemplo n.º 6
0
        public override bool Tick(Actor self)
        {
            returnToBase = false;

            // Refuse to take off if it would land immediately again.
            if (aircraft.ForceLanding)
            {
                Cancel(self);
            }

            if (IsCanceling)
            {
                return(true);
            }

            // Check that AttackFollow hasn't cancelled the target by modifying attack.Target
            // Having both this and AttackFollow modify that field is a horrible hack.
            if (hasTicked && attackAircraft.RequestedTarget.Type == TargetType.Invalid)
            {
                return(true);
            }

            if (attackAircraft.IsTraitPaused)
            {
                return(false);
            }

            target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
            attackAircraft.SetRequestedTarget(self, target, forceAttack);
            hasTicked = true;

            if (!targetIsHiddenActor && target.Type == TargetType.Actor)
            {
                lastVisibleTarget       = Target.FromTargetPositions(target);
                lastVisibleMaximumRange = attackAircraft.GetMaximumRangeVersusTarget(target);
                lastVisibleOwner        = target.Actor.Owner;
                lastVisibleTargetTypes  = target.Actor.GetEnabledTargetTypes();
            }

            // The target may become hidden in the same tick the FlyAttack constructor is called,
            // causing lastVisible* to remain uninitialized.
            // Fix the fallback values based on the frozen actor properties
            else if (target.Type == TargetType.FrozenActor && !lastVisibleTarget.IsValidFor(self))
            {
                lastVisibleTarget       = Target.FromTargetPositions(target);
                lastVisibleMaximumRange = attackAircraft.GetMaximumRangeVersusTarget(target);
                lastVisibleOwner        = target.FrozenActor.Owner;
                lastVisibleTargetTypes  = target.FrozenActor.TargetTypes;
            }

            useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);

            // Target is hidden or dead, and we don't have a fallback position to move towards
            if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
            {
                return(true);
            }

            // If all valid weapons have depleted their ammo and Rearmable trait exists, return to RearmActor to reload
            // and resume the activity after reloading if AbortOnResupply is set to 'false'
            if (rearmable != null && !useLastVisibleTarget && attackAircraft.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
            {
                // Attack moves never resupply
                if (source == AttackSource.AttackMove)
                {
                    return(true);
                }

                // AbortOnResupply cancels the current activity (after resupplying) plus any queued activities
                if (attackAircraft.Info.AbortOnResupply)
                {
                    NextActivity?.Cancel(self);
                }

                QueueChild(new ReturnToBase(self));
                returnToBase = true;
                return(attackAircraft.Info.AbortOnResupply);
            }

            var pos         = self.CenterPosition;
            var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;

            // We don't know where the target actually is, so move to where we last saw it
            if (useLastVisibleTarget)
            {
                // We've reached the assumed position but it is not there - give up
                if (checkTarget.IsInRange(pos, lastVisibleMaximumRange))
                {
                    return(true);
                }

                // Fly towards the last known position
                QueueChild(new Fly(self, target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red));
                return(false);
            }

            var delta         = attackAircraft.GetTargetPosition(pos, target) - pos;
            var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw : aircraft.Facing;

            QueueChild(new TakeOff(self));

            var minimumRange = attackAircraft.Info.AttackType == AirAttackType.Strafe ? WDist.Zero : attackAircraft.GetMinimumRangeVersusTarget(target);

            // Move into range of the target.
            if (!target.IsInRange(pos, lastVisibleMaximumRange) || target.IsInRange(pos, minimumRange))
            {
                QueueChild(aircraft.MoveWithinRange(target, minimumRange, lastVisibleMaximumRange, target.CenterPosition, Color.Red));
            }

            // The aircraft must keep moving forward even if it is already in an ideal position.
            else if (attackAircraft.Info.AttackType == AirAttackType.Strafe)
            {
                QueueChild(new StrafeAttackRun(self, attackAircraft, target, strafeDistance != WDist.Zero ? strafeDistance : lastVisibleMaximumRange));
            }
            else if (attackAircraft.Info.AttackType == AirAttackType.Default && !aircraft.Info.CanHover)
            {
                QueueChild(new FlyAttackRun(self, target, lastVisibleMaximumRange));
            }

            // Turn to face the target if required.
            else if (!attackAircraft.TargetInFiringArc(self, target, 4 * attackAircraft.Info.FacingTolerance))
            {
                aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed);
            }

            return(false);
        }
        /// <summary>
        /// 流程活动处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ResultMessage SubmitWorkitemInstance(RequestBySubmitWorkitem request)
        {
            ResultMessage rm = new ResultMessage()
            {
                State = true, Message = ""
            };

            WorkitemInstance wii = this.GetWorkitemInstance(request.WorkitemInstanceGuid);

            ///不在许可范围之内的,直接返回失败
            if (!this.IsEffective(wii))
            {
                return new ResultMessage()
                       {
                           State = false, Message = "不在许可操作范围内!"
                       }
            }
            ;

            wii.AduitContent = request.AduitContent;
            wii.AduitSign    = request.AduitSign;

            wii.SelectVoteItem       = request.SelectVoteItem;
            wii.OtherVoteItemContent = request.OtherVoteItemContent;
            wii.IsProxy = request.IsProxyUser;
            if (wii.IsProxy)
            {
                wii.ProxyUser = this.Context.CurUser;
            }
            else
            {
                wii.User = this.Context.CurUser;
            }
            //wii.SetDataEntity(request.DataEntity);

            switch (request.State)
            {
                #region Running 挂起流程操作
            case eWorkitemState.Running:
            {
                wii.Hung();
                wii.Save();
            }
            break;
                #endregion

                #region Abort 退出流程处理,中止流程
            case eWorkitemState.Abort:
            {
                #region 条件判断
                bool b = false;
                ///是否大管理员
                if (this.Context.CurUser.IsAdministrator())
                {
                    b = true;
                }
                ///是否流程模型管理员
                if (wii.GetWorkflowInstance().GetWorkflow().Administrators.Contains(this.Context.CurUser, _uc))
                {
                    b = true;
                }
                ///是否是流程发起人
                if (_uc.Equals(this.Context.CurUser, wii.GetWorkflowInstance().Author))
                {
                    b = true;
                }
                if (!b)
                {
                    rm.State   = false;
                    rm.Message = "你不具体中止流程的权限。只有管理员和发起人才可以中止流程!";
                    break;
                }
                #endregion

                wii.Abort();
                wii.Save();
                wii.GetWorkflowInstance().Save();
                break;
            }
                #endregion

                #region Completed 正常完成流程处理
            case eWorkitemState.Completed:
            {
                wii.GetWorkflowInstance().SetDataEntity(request.DataEntity);

                #region 创建后继流程活动工作项
                IList <NextActivity> tmp = new List <NextActivity>();
                foreach (var na in request.NextActivities)
                {
                    foreach (var o in na.Operaters)
                    {
                        var x = new NextActivity()
                        {
                            WorkitemInstanceGuid = System.Guid.NewGuid().ToString(),
                            ActivityGuid         = na.Activity,
                            ActivityByname       = na.ActivityName,
                            User = this.GetUser(o),
                        };

                        #region 创建后继流程活动工作项
                        WorkitemInstance xwii = new WorkitemInstance(wii.GetWorkflowInstance().Guid,
                                                                     wii.GetWorkflow().GetActivity(na.Activity, eDaoItem.Guid))
                        {
                            ActivityGuid   = x.ActivityGuid,
                            AduitContent   = "",
                            ReadTime       = null,
                            NextActivities = null,
                            EndTime        = null,
                            User           = x.User,
                            ProxyUser      = null,
                            //WorkitemInstanceState = eWorkitemState.Ready,
                            IsProxy = false,
                            FromWorkitemInstanceGuid = wii.Guid,
                            AttachmentTrainsitions   = null,
                        };
                        xwii.SetContext(this.Context);
                        ///取流程实例数据到流程实例活动
                        xwii.Start();
                        //xwii.BeforeTrigger();
                        xwii.Save();
                        #endregion
                        tmp.Add(x);
                    }
                }
                wii.NextActivities = tmp;
                #endregion

                ///完成流程实例活动
                wii.AfterTrigger();
                wii.Save();
                wii.GetWorkflowInstance().Save();
                break;
            }
                #endregion

                #region Other
            case eWorkitemState.Ready:
            case eWorkitemState.ExclusionCompleted:
            default:
            {
                break;
            }
                #endregion
            }
            ///解锁
            this.DecodeLock(wii);
            if (!rm.State)
            {
                return(rm);
            }

            return(rm);
        }
    }