Exemplo n.º 1
0
        ///// <summary>
        ///// 添加或修改活动
        ///// </summary>
        ///// <param name="activity"></param>
        //public void SafeAddActivity(Activity activity)
        //{
        //    if (this.Activities == null)
        //    {
        //        this.Activities = new List<Activity>();
        //    }
        //    Activity old = Activities.FirstOrDefault(a => a.ID == activity.ID);
        //    if (old != null)
        //    {
        //        this.Activities.Remove(old);
        //    }
        //    //if (activity.Parent != this)
        //    //{
        //    //    activity.Parent = this;
        //    //}
        //    this.Activities.Add(activity);
        //    this.Transitions.ForEach(a =>
        //        {
        //            if (a.SrcActivity.ID == activity.ID)
        //            {
        //                a.SrcActivity = activity;
        //            }
        //            if (a.DestActivity.ID == activity.ID)
        //            {
        //                a.DestActivity = activity;
        //            }
        //        });
        //}
        /// <summary>
        /// 添加或修改活动
        /// </summary>
        /// <param name="oldActivityID"></param>
        /// <param name="activity"></param>
        public void SafeAddActivity(string oldActivityID, Activity activity)
        {
            if (this.Activities == null)
            {
                this.Activities = new List<Activity>();
            }

            ProcessDefine parent = activity.GetPropertyValue<ProcessDefine>("Parent");
            if (parent == null)
            {
                activity.SetPropertyValue("Parent", this);
            }

            this.Transitions.ForEach(a =>
            {
                if (a.SrcActivity == oldActivityID)
                {
                    a.SrcActivity = activity.ID;
                }
                if (a.DestActivity == oldActivityID)
                {
                    a.DestActivity = activity.ID;
                }
            });

            int index = -1;
            for (int i = 0; i < Activities.Count; i++)
            {
                if (Activities[i].ID == oldActivityID)
                {
                    index = i;
                    break;
                }
            }

            if (index != -1)
            {
                activity.Style = Activities[index].Style;
                Activities.RemoveAt(index);
                Activities.Insert(index, activity);
            }
            else
            {
                Activities.Add(activity);
            }
        }