Exemple #1
0
        public WhatIfResult OnComplete(ProjectItem projectItem, DateTime completedDate, bool addNewPeriodics)
        {
            Assertion.Require(projectItem, "projectItem");

            this.whatIfResult = new WhatIfResult(projectItem, ProjectItemOperation.Complete);

            // Add root state change
            var stateChange = new ProjectItemStateChange(projectItem, ProjectItemOperation.Complete)
            {
                ActualEndDate = completedDate
            };

            whatIfResult.AddStateChange(stateChange);

            // Update related
            UpdateRelatedProjectItemsDeadlines(projectItem, completedDate);


            if (addNewPeriodics)
            {
                var newPeriodicResult = ModelingServices.TryGetNextPeriodic(projectItem, completedDate);

                if (newPeriodicResult != null)
                {
                    this.whatIfResult.AddStateChanges(newPeriodicResult.StateChanges);
                }
            }

            return(this.whatIfResult);
        }
Exemple #2
0
        public WhatIfResult OnUpdateDeadlines()
        {
            WhatIfResult current = GetWhatIfResultWithRootProjectItemBranch();

            foreach (var item in current.StateChanges)
            {
                item.ProcessMatchResult = ProjectItemProcessMatchResult.MatchedEqual;

                if (!item.ProjectItem.HasTemplate)
                {
                    continue;
                }

                ActivityModel template = item.ProjectItem.GetTemplate().Template;

                if (template.IsPeriodic)
                {
                    item.ProcessMatchResult = ProjectItemProcessMatchResult.NoProgrammingRule;
                }
            }

            UpdateDeadlinesForUncompletedActivities(current);

            UpdateDeadlinesForCurrentCompletedActivities(current);
            return(current);
        }
Exemple #3
0
        static private void StoreChanges(WhatIfResult result)
        {
            foreach (var stateChange in result.StateChanges)
            {
                switch (stateChange.Operation)
                {
                case ProjectItemOperation.Complete:
                    stateChange.ProjectItem.Complete(stateChange.ActualEndDate);
                    break;

                case ProjectItemOperation.UpdateDeadline:
                    stateChange.ProjectItem.SetDeadline(stateChange.Deadline);
                    stateChange.ProjectItem.Save();
                    break;

                case ProjectItemOperation.CreateFromTemplate:
                    stateChange.ProjectItem = CreateFromTemplate(stateChange);
                    break;

                case ProjectItemOperation.Reactivate:
                    stateChange.ProjectItem.Reactivate();
                    break;

                default:
                    throw Assertion.EnsureNoReachThisCode($"Unrecognized WhatIfResult operation {stateChange.Operation}");
                } // switch
            }     // foreach
        }
Exemple #4
0
        private void AddNewModelActivitiesToCurrentResult(WhatIfResult current,
                                                          WhatIfResult newModelResult)
        {
            return;

            //try {
            //  var notIncludedList = newModelResult.StateChanges.FindAll(x => !current.StateChanges.Contains(y => y.Template == x.Template));

            //  foreach (var notIncluded in notIncludedList) {
            //    notIncluded.ProcessMatchResult = ProjectItemProcessMatchResult.OnlyInProcess;

            //    notIncluded.ProcessID = this.RootProjectItem.ProcessID;
            //    notIncluded.SubprocessID = this.RootProjectItem.SubprocessID;

            //    int index = SetNewActivityInsertionRule(notIncluded, current, newModelResult);

            //    if (index >= 0) {
            //      current.InsertStateChange(index, notIncluded);
            //    } else {
            //      current.AddStateChange(notIncluded);
            //    }
            //  }
            //} catch (Exception e) {
            //  EmpiriaLog.Error(e);
            //  throw e;
            //}
        }
Exemple #5
0
        static public FixedList <ProjectItem> Complete(ProjectItem projectItem, DateTime completedDate)
        {
            Assertion.Require(projectItem, "projectItem");

            WhatIfResult result = ModelingServices.WhatIfCompleted(projectItem, completedDate, false);

            if (result.HasErrors)
            {
                throw result.GetException();
            }

            if (!String.IsNullOrWhiteSpace(projectItem.ProcessID))
            {
                ProjectItemData.ResetSubprocessID(projectItem.ProcessID);
            }

            StoreChanges(result);

            CreateNextPeriodicIfNecessary(projectItem, completedDate);
            ProjectItemData.ClearProcessID();

            projectItem.Project.Refresh();


            return(projectItem.Project.GetItems());
        }
Exemple #6
0
        static private void StoreChanges(WhatIfResult result)
        {
            foreach (var stateChange in result.StateChanges)
            {
                ProjectItem projectItem = stateChange.ProjectItem;

                switch (stateChange.ProcessMatchResult)
                {
                case ProjectItemProcessMatchResult.MatchedWithDataChanges:
                    // projectItem.SetData(stateChange);
                    projectItem.Save();
                    break;

                case ProjectItemProcessMatchResult.MatchedWithDeadlineAndDataChanges:
                    // projectItem.SetData(stateChange);
                    projectItem.SetDeadline(stateChange.Deadline);
                    projectItem.Save();
                    break;

                case ProjectItemProcessMatchResult.MatchedWithDeadlineChanges:
                    projectItem.SetDeadline(stateChange.Deadline);
                    projectItem.Save();
                    break;

                ////case ProjectItemProcessMatchResult.OnlyInProcess:
                ////  stateChange.ProjectItem = ProjectUpdater.CreateFromTemplate(stateChange,
                ////                                                              stateChange.InsertionPosition);
                ////  break;

                default:
                    break;
                } // switch
            }     // foreach
        }
        public WhatIfResult CreateFromEvent(Activity activityModel, DateTime eventDate)
        {
            Assertion.Require(activityModel, "activityModel");

            // Create root
            this.whatIfResult = new WhatIfResult(activityModel, ProjectItemOperation.CreateFromTemplate);

            this.CreateBranchFromTemplate(activityModel);

            // Set root dates;

            var stateChange = this.whatIfResult.StateChanges[0];

            stateChange.Deadline = eventDate;
            stateChange.Project  = this.targetProject;

            //// Append any other external dependencies of the activity model tree
            // var dependencies = this.whatIfResult.GetUncontainedModelDependencies(activityModel);

            // foreach (var dependency in dependencies) {
            //   this.CreateBranchFromTemplate(dependency);
            // }

            // ToDo: Change this by a recursive strategy
            for (int i = 0; i < 10; i++)
            {
                this.RecalculateDates();
            }

            this.CalculatePeriodicDates(eventDate);

            return(this.whatIfResult);
        }
Exemple #8
0
        static private void UpdateDeadlinesForCurrentCompletedActivities(WhatIfResult current)
        {
            var currentCompletedActivities =
                current.StateChanges.FindAll(x => x.ProjectItem.HasTemplate && x.ProjectItem.ActualEndDate != ExecutionServer.DateMaxValue &&
                                             x.ProjectItem.Status == StateEnums.ActivityStatus.Completed);

            foreach (var completedActivityStateChange in currentCompletedActivities)
            {
                UpdateRelatedProjectItemsDeadlines(current, completedActivityStateChange,
                                                   completedActivityStateChange.ProjectItem.ActualEndDate);
            } // foreach
        }
        static public WhatIfResult WhatIfReactivated(ProjectItem projectItem)
        {
            Assertion.Require(projectItem, "projectItem");

            var whatIfResult = new WhatIfResult(projectItem, ProjectItemOperation.Reactivate);

            var stateChange = new ProjectItemStateChange(projectItem, ProjectItemOperation.Reactivate);

            whatIfResult.AddStateChange(stateChange);

            return(whatIfResult);
        }
Exemple #10
0
        static public void Reactivate(ProjectItem projectItem)
        {
            Assertion.Require(projectItem, "projectItem");

            WhatIfResult result = ModelingServices.WhatIfReactivated(projectItem);

            if (result.HasErrors)
            {
                throw result.GetException();
            }

            StoreChanges(result);
        }
Exemple #11
0
 private void MoveProjectItemsAccordingToInsertionRules(WhatIfResult result)
 {
     foreach (var item in result.StateChanges)
     {
         if (item.HasInsertionRule)
         {
             if (item.ParentStateChange != null && item.InsertionPoint.IsEmptyInstance)
             {
                 item.InsertionPoint = item.ProjectItem;
             }
             this.Project.MoveTo(item.ProjectItem, item.InsertionRule, item.InsertionPoint, item.InsertionPosition);
         }
     }
 }
Exemple #12
0
        public FixedList <ProjectItem> UpdateDeadlines()
        {
            WhatIfResult result = OnUpdateDeadlines();

            if (result.HasErrors)
            {
                throw result.GetException();
            }

            StoreChanges(result);

            return(result.StateChanges.ConvertAll(x => x.ProjectItem)
                   .ToFixedList());
        }
Exemple #13
0
        private WhatIfResult GetWhatIfResultWithRootProjectItemBranch()
        {
            WhatIfResult result = new WhatIfResult(this.RootProjectItem, ProjectItemOperation.UpdateProcessChanges);

            FixedList <ProjectItem> currentActivities = this.RootProjectItem.GetBranch();

            foreach (var projectItem in currentActivities)
            {
                var stateChange = new ProjectItemStateChange(projectItem, ProjectItemOperation.UpdateProcessChanges);

                result.AddStateChange(stateChange);
            }

            return(result);
        }
Exemple #14
0
        public FixedList <ProjectItem> UpdateWithLastProcessChanges()
        {
            WhatIfResult result = this.OnUpdateWithLastProcessChanges();

            if (result.HasErrors)
            {
                throw result.GetException();
            }

            StoreChanges(result);

            MoveProjectItemsAccordingToInsertionRules(result);

            return(result.StateChanges.ConvertAll(x => x.ProjectItem)
                   .ToFixedList());
        }
Exemple #15
0
        public WhatIfResult OnUpdateWithLastProcessChanges()
        {
            WhatIfResult current = GetWhatIfResultWithRootProjectItemBranch();

            WhatIfResult newModelResult = GetNewModelResult();

            WhatIfResult merged = GetMergeWhatIfResult(current.StateChanges, newModelResult.StateChanges);

            AddNewModelActivitiesToCurrentResult(merged, newModelResult);

            UpdateDeadlinesForCurrentCompletedActivities(merged);

            UpdateDeadlinesForUncompletedActivities(merged);

            return(merged);
        }
Exemple #16
0
        private WhatIfResult GetMergeWhatIfResult(FixedList <ProjectItemStateChange> current,
                                                  FixedList <ProjectItemStateChange> newModel)
        {
            WhatIfResult merge = new WhatIfResult(this.RootProjectItem, ProjectItemOperation.UpdateProcessChanges);

            merge.AddStateChanges(current);

            foreach (var item in merge.StateChanges)
            {
                if (item.ProjectItem.HasTemplate)
                {
                    TryMatch(item, newModel);
                }
                else
                {
                    item.ProcessMatchResult = ProjectItemProcessMatchResult.OnlyInProject;
                }
            }

            return(merge);
        }
Exemple #17
0
        static private void UpdateRelatedProjectItemsDeadlines(WhatIfResult current,
                                                               ProjectItemStateChange stateChange,
                                                               DateTime completedDate)
        {
            var projectItem = stateChange.ProjectItem;

            FixedList <ProjectItemStateChange> relatedStateChangesList = current.GetRelatedStateChanges(stateChange);

            foreach (var relatedStateChange in relatedStateChangesList)
            {
                var model = ((Activity)relatedStateChange.Template).Template;

                DateTime?updatedDeadline = UtilityMethods.CalculateNewDeadline(model, completedDate);

                if (!updatedDeadline.HasValue)
                {
                    continue;
                }

                if (relatedStateChange == null)
                {
                    continue;
                }

                if (updatedDeadline.Value != relatedStateChange.ProjectItem.Deadline)
                {
                    relatedStateChange.Deadline           = updatedDeadline.Value;
                    relatedStateChange.ProcessMatchResult = AddDeadlineChangeToMatchResult(relatedStateChange.ProcessMatchResult);
                }
                else
                {
                    relatedStateChange.Deadline           = ExecutionServer.DateMaxValue;
                    relatedStateChange.ProcessMatchResult = RemoveDeadlineChangeFromMatchResult(relatedStateChange.ProcessMatchResult);
                }

                // Recursive call
                UpdateRelatedProjectItemsDeadlines(current, relatedStateChange, updatedDeadline.Value);
            }
        }
Exemple #18
0
        static public FixedList <ProjectItem> CreateActivitiesFromModel(Activity activityModel,
                                                                        Project project,
                                                                        DateTime eventDate,
                                                                        ProjectItem insertionPoint,
                                                                        TreeItemInsertionRule insertionRule)
        {
            Assertion.Require(activityModel, "activityModel");
            Assertion.Require(project, "project");
            Assertion.Require(insertionPoint, "insertionPoint");

            WhatIfResult result = ModelingServices.WhatIfCreatedFromEvent(activityModel, project, eventDate);

            if (result.HasErrors)
            {
                throw result.GetException();
            }

            ProjectItemData.ResetProcessID();

            StoreChanges(result);

            ProjectItemData.ClearProcessID();

            if (result.StateChanges.Count > 0)
            {
                if (!insertionPoint.IsEmptyInstance && insertionRule != TreeItemInsertionRule.AsTreeRootAtEnd)
                {
                    project.MoveTo(result.StateChanges[0].ProjectItem, insertionRule, insertionPoint);
                }
                else if (insertionPoint.IsEmptyInstance && (insertionRule == TreeItemInsertionRule.AsTreeRootAtStart ||
                                                            insertionRule == TreeItemInsertionRule.AsTreeRootAtEnd))
                {
                    project.MoveTo(result.StateChanges[0].ProjectItem, insertionRule, insertionPoint);
                }
            }
            return(project.GetItems());
        }
Exemple #19
0
        static private int SetNewActivityInsertionRule(ProjectItemStateChange toInsertActivity,
                                                       WhatIfResult current, WhatIfResult newModelResult)
        {
            int position = -1;

            var parent = current.StateChanges.Find(x => !x.ProjectItem.IsEmptyInstance &&
                                                   x.Template.UID == toInsertActivity.Template.Parent.UID);

            if (parent != null)
            {
                var newSiblings = current.StateChanges.FindAll(x => x.ProjectItem.IsEmptyInstance &&
                                                               x.ParentStateChange.UID == parent.UID);

                var parentIndex = current.StateChanges.IndexOf(parent);

                var currentSiblings = current.StateChanges.FindAll(x => !x.ProjectItem.IsEmptyInstance &&
                                                                   x.ProjectItem.Parent.UID == parent.ProjectItem.UID);

                if (currentSiblings.Count != 0)
                {
                    toInsertActivity.InsertionPoint = parent.ProjectItem;
                    toInsertActivity.InsertionRule  = TreeItemInsertionRule.AsChildAsLastNode;

                    position = parentIndex + currentSiblings.Count + newSiblings.Count + 1;

                    EmpiriaLog.Trace($"Rule 0: {toInsertActivity.Template.Name} at position {position}.");
                }
                else
                {
                    toInsertActivity.ParentStateChange = parent;

                    toInsertActivity.InsertionPoint = parent.ProjectItem;
                    toInsertActivity.InsertionRule  = TreeItemInsertionRule.AsChildAsLastNode;

                    position = parentIndex + newSiblings.Count + 1;

                    EmpiriaLog.Trace($"Rule 1: {toInsertActivity.Template.Name} at position {position}.");
                }
            }
            else
            {
                Assertion.Require(toInsertActivity.ParentStateChange, nameof(toInsertActivity.ParentStateChange));

                var newParent = current.StateChanges.Find(x => x.UID == toInsertActivity.ParentStateChange.UID);

                var newParentIdx = current.StateChanges.IndexOf(newParent);

                var currentSiblings = current.StateChanges.FindAll(x => x.ParentStateChange != null &&
                                                                   x.ParentStateChange.UID == toInsertActivity.ParentStateChange.UID);

                toInsertActivity.ParentStateChange = newParent;

                toInsertActivity.InsertionPoint = ProjectItem.Empty;
                toInsertActivity.InsertionRule  = TreeItemInsertionRule.AsChildAsLastNode;

                position = newParentIdx + currentSiblings.Count + 1;

                EmpiriaLog.Trace($"Rule 2: {toInsertActivity.Template.Name} at position {position}.");
            }

            return(position);
        }