private static void FillPlanFinishDate(ActivityInfoCollection activities)
        {
            double   avgDurations = double.MinValue;
            DateTime dateTimeNow  = DataContext.Current.CurrentUserTimeZone.ToLocalTime(DateTime.UtcNow);

            for (int index = 0; index < activities.Count; index++)
            {
                ActivityInfo activity = activities[index];

                if (activity.State == AssignmentState.Pending && activity.PlanFinishDate == null)
                {
                    if (activity.Parent != null)
                    {
                        activity.PlanStartDate  = activity.Parent.PlanStartDate;
                        activity.PlanFinishDate = activity.Parent.PlanFinishDate;
                    }
                    else
                    {
                        activity.PlanStartDate = activities[index - 1].PlanFinishDate;

                        int elementWidth = activity.Type == ActivityType.Assignment?
                                           (activity.Activities.Count == 0 ? 1 : activity.Activities.Count) : (activity.Activities.Count);

                        if (avgDurations == double.MinValue)
                        {
                            if (elementWidth == 0)
                            {
                                avgDurations = 0;
                            }
                            else
                            {
                                int belowCount = activity.GetActivitiesBelowCount();
                                avgDurations = (activity.BusinessProcess.PlanFinishDate.Value - activity.PlanStartDate.Value).TotalMinutes / (belowCount + elementWidth);
                            }
                        }

                        activity.PlanFinishDate = activity.PlanStartDate.Value.AddMinutes(elementWidth * avgDurations);
                    }

                    if (activity.PlanStartDate.HasValue &&
                        activity.PlanStartDate.Value < dateTimeNow)
                    {
                        activity.TimeStatus = AssignmentTimeStatus.OverStart;
                    }

                    if (activity.PlanFinishDate.HasValue &&
                        activity.PlanFinishDate.Value < dateTimeNow)
                    {
                        activity.TimeStatus = AssignmentTimeStatus.OverDue;
                    }
                }

                if (activity.Activities.Count > 0)
                {
                    FillPlanFinishDate(activity.Activities);
                }
            }
        }
        /// <summary>
        /// Creates the business process activity info.
        /// </summary>
        /// <param name="businessProcess">The business process.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="parentActivity">The parent activity.</param>
        /// <param name="activityInfoItems">The activity info items.</param>
        private static void CreateBusinessProcessActivityInfo(BusinessProcessInfo businessProcess, WorkflowChangesScope scope, EntityObject[] assignments, CompositeActivity parentActivity, ActivityInfoCollection activityInfoItems)
        {
            foreach (Activity activity in parentActivity.Activities)
            {
                if (activity is CreateAssignmentAndWaitResultActivity)
                {
                    CreateAssignmentAndWaitResultActivity asgActivity = (CreateAssignmentAndWaitResultActivity)activity;
                    PropertyValueCollection properties = asgActivity.AssignmentProperties;

                    ActivityInfo activityInfo = new ActivityInfo();
                    activityInfoItems.Add(activityInfo);

                    activityInfo.Name = activity.Name;
                    activityInfo.Type = ActivityType.Assignment;

                    AssignmentEntity assignment = FindAssignmentByActivityName(assignments, activity.Name);

                    if (assignment != null)
                    {
                        activityInfo.State   = (AssignmentState)assignment.State;
                        activityInfo.Subject = assignment.Subject;

                        activityInfo.TimeStatus = (AssignmentTimeStatus?)assignment.TimeStatus;

                        activityInfo.PlanStartDate  = assignment.ActualStartDate;
                        activityInfo.PlanFinishDate = assignment.PlanFinishDate;

                        activityInfo.ActualStartDate  = assignment.ActualStartDate;
                        activityInfo.ActualFinishDate = assignment.ActualFinishDate;
                        activityInfo.Comment          = assignment.Comment;

                        activityInfo.UserId = assignment.UserId;

                        activityInfo.ClosedBy = assignment.ClosedBy;

                        activityInfo.ExecutionResult = (AssignmentExecutionResult?)assignment.ExecutionResult;
                    }
                    else
                    {
                        activityInfo.State = businessProcess.State == BusinessProcessState.Closed?
                                             AssignmentState.Closed:
                                             AssignmentState.Pending;

                        if (asgActivity.AssignmentProperties.Contains(AssignmentEntity.FieldSubject))
                        {
                            activityInfo.Subject = (string)asgActivity.AssignmentProperties[AssignmentEntity.FieldSubject];
                        }

                        if (asgActivity.AssignmentProperties.Contains(AssignmentEntity.FieldUserId))
                        {
                            activityInfo.UserId = (int?)asgActivity.AssignmentProperties[AssignmentEntity.FieldUserId];
                        }

                        // Resolve Plan Time
                        //if (activityInfo.State == AssignmentState.Pending &&
                        //    businessProcess.State == BusinessProcessState.Active &&
                        //    businessProcess.PlanFinishDate.HasValue)
                        //{
                        //    //CalculatePlanFinishDate(businessProcess, parentActivity, activity, activityInfo);
                        //}

                        //if (activityInfo.PlanStartDate.HasValue &&
                        //    activityInfo.PlanStartDate.Value < DateTime.Now)
                        //    activityInfo.TimeStatus = AssignmentTimeStatus.OverStart;

                        //if (activityInfo.PlanFinishDate.HasValue &&
                        //    activityInfo.PlanFinishDate.Value < DateTime.Now)
                        //    activityInfo.TimeStatus = AssignmentTimeStatus.OverDue;
                    }


                    // 2008-07-07 Added Assignment Properties
                    activityInfo.AssignmentProperties.AddRange(asgActivity.AssignmentProperties);
                    //
                }
                else if (activity is BlockActivity)
                {
                    // Create Block Info
                    ActivityInfo blockInfo = new ActivityInfo();
                    activityInfoItems.Add(blockInfo);

                    blockInfo.Name = activity.Name;
                    blockInfo.Type = ActivityType.Block;

                    blockInfo.State = businessProcess.State == BusinessProcessState.Closed ?
                                      AssignmentState.Closed :
                                      AssignmentState.Pending;

                    CreateBusinessProcessActivityInfo(businessProcess, scope, assignments, (BlockActivity)activity, blockInfo.Activities);

                    if (blockInfo.State == AssignmentState.Pending)
                    {
                        if (blockInfo.Activities.Count > 0)
                        {
                            foreach (ActivityInfo childActivitiInfo in blockInfo.Activities)
                            {
                                if (childActivitiInfo.State == AssignmentState.Active)
                                {
                                    blockInfo.State = AssignmentState.Active;
                                    break;
                                }
                                else if (childActivitiInfo.State == AssignmentState.Closed)
                                {
                                    blockInfo.State = AssignmentState.Closed;
                                }
                            }
                        }
                        else
                        {
                            int blockIndex = activityInfoItems.IndexOf(blockInfo);

                            if (blockIndex == 0)
                            {
                                blockInfo.State = AssignmentState.Closed;
                            }
                            else
                            {
                                blockInfo.State = activityInfoItems[blockIndex - 1].State == AssignmentState.Active? AssignmentState.Pending:
                                                  activityInfoItems[blockIndex - 1].State;
                            }
                        }
                    }

                    if (blockInfo.Activities.Count > 0 &&
                        (blockInfo.State == AssignmentState.Active ||
                         blockInfo.State == AssignmentState.Closed))
                    {
                        blockInfo.PlanStartDate  = blockInfo.Activities[0].PlanStartDate;
                        blockInfo.PlanFinishDate = blockInfo.Activities[0].PlanFinishDate;
                    }
                }
            }
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusinessProcessInfo"/> class.
 /// </summary>
 public BusinessProcessInfo()
 {
     this.Activities = new ActivityInfoCollection(this);
 }