コード例 #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);
        }
コード例 #2
0
        private void CreateBranchFromTemplate(Activity activityModel)
        {
            var modelBranch = activityModel.GetBranch();

            foreach (var modelItem in modelBranch)
            {
                var stateChange = new ProjectItemStateChange(modelItem, ProjectItemOperation.CreateFromTemplate);

                stateChange.Project = this.targetProject;

                if (this.whatIfResult.StateChanges.Count != 0)
                {
                    var parent = this.whatIfResult.StateChanges.Find(x => x.Template.Id == modelItem.Parent.Id);

                    if (parent != null)
                    {
                        stateChange.ParentStateChange = parent;
                    }
                    else
                    {
                        stateChange.ParentStateChange = this.whatIfResult.StateChanges[0];
                    }
                } // if

                this.whatIfResult.AddStateChange(stateChange);
            } // foreach
        }
コード例 #3
0
        private void AddUpdateDeadlineStateChange(ProjectItem projectItem,
                                                  DateTime updatedDeadline)
        {
            var stateChange = new ProjectItemStateChange(projectItem, ProjectItemOperation.UpdateDeadline)
            {
                Deadline = updatedDeadline
            };

            this.whatIfResult.AddStateChange(stateChange);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        private static bool IsFirstPeriodic(ProjectItemStateChange currentItem)
        {
            var parent     = currentItem.ProjectItem.Parent;
            var templateId = currentItem.ProjectItem.TemplateId;
            var position   = currentItem.ProjectItem.Position;

            var items        = currentItem.Project.GetItems();
            var isSubsequent = items.Contains(x => x.Parent.Id == parent.Id &&
                                              x.TemplateId == templateId && x.Position < position);

            return(!isSubsequent);
        }
コード例 #6
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);
        }
コード例 #7
0
        static private bool HasProgrammingRule(ProjectItemStateChange currentItem,
                                               ProjectItemStateChange matchedInNewModel)
        {
            ActivityModel template = ((Activity)matchedInNewModel.Template).Template;

            if (template.IsPeriodic && DeadlineChanged(currentItem, matchedInNewModel))
            {
                if (IsFirstPeriodic(currentItem))
                {
                    return(true);
                }
                return(false);
            }

            return(true);
        }
コード例 #8
0
        static private bool DeadlineChanged(ProjectItemStateChange currentItem,
                                            ProjectItemStateChange matchedInNewModel)
        {
            ProjectItem projectItem = currentItem.ProjectItem;

            if (matchedInNewModel.Deadline == ExecutionServer.DateMaxValue)
            {
                return(false);
            }

            if (projectItem.Deadline == matchedInNewModel.Deadline)
            {
                return(false);
            }

            return(true);
        }
コード例 #9
0
        static public Activity CreateFromTemplate(ProjectItemStateChange stateChange, int position = -1)
        {
            Assertion.Require(stateChange, "stateChange");
            Assertion.Require(stateChange.Project, "stateChange.Project");
            Assertion.Require(stateChange.Template, "stateChange.Template");

            var json = new JsonObject();

            json.Add("name", stateChange.Template.Name);
            json.Add("notes", stateChange.Template.Notes);

            json.Add("foreignLang", stateChange.Template.ForeignLanguageData.ToJson());

            json.Add("deadline", stateChange.Deadline);
            json.Add("plannedEndDate", stateChange.PlannedEndDate);

            json.Add("templateId", stateChange.Template.Id);

            json.Add("processID", stateChange.ProcessID);
            json.Add("subProcessID", stateChange.SubprocessID);

            Activity activity = null;


            if (position == -1)
            {
                activity = stateChange.Project.AddActivity(json);
            }
            else
            {
                activity = stateChange.Project.InsertActivity(json, position);
            }

            if (stateChange.Replaces != null)
            {
                activity.SetParentAndPosition(stateChange.Replaces.Parent,
                                              stateChange.Replaces.Position);
            }
            else if (stateChange.ParentStateChange != null &&
                     !stateChange.ParentStateChange.ProjectItem.IsEmptyInstance)
            {
                activity.SetAndSaveParent(stateChange.ParentStateChange.ProjectItem);
            }

            return(activity);
        }
コード例 #10
0
        static private void SetUpdatedData(ProjectItemStateChange currentItem,
                                           ProjectItemStateChange matchedInNewModel)
        {
            ProjectItem projectItem = currentItem.ProjectItem;

            if (projectItem.Name != matchedInNewModel.Template.Name)
            {
                currentItem.Name = matchedInNewModel.Template.Name;
            }

            if (projectItem.Notes != matchedInNewModel.Template.Notes)
            {
                currentItem.Notes = matchedInNewModel.Template.Notes;
            }

            if (projectItem.Theme != matchedInNewModel.Template.Theme)
            {
                currentItem.Theme = matchedInNewModel.Template.Theme;
            }
        }
コード例 #11
0
ファイル: WhatIfResult.cs プロジェクト: Ontica/Empiria.Steps
        internal FixedList <ProjectItemStateChange> GetRelatedStateChanges(ProjectItemStateChange stateChange)
        {
            if (stateChange.Template == null)
            {
                return(new FixedList <ProjectItemStateChange>());
            }

            Activity template = (Activity)stateChange.Template;

            FixedList <Activity> modelDependencies = this.GetContainedModelDependencies(template);

            List <ProjectItemStateChange> list = new List <ProjectItemStateChange>();

            foreach (var model in modelDependencies)
            {
                FixedList <ProjectItemStateChange> projectItems = this.StateChanges.FindAll(x => x.Template.Id == model.Id);

                list.AddRange(projectItems);
            }

            return(list.ToFixedList());
        }
コード例 #12
0
        static private bool DataChanged(ProjectItemStateChange currentItem,
                                        ProjectItemStateChange matchedInNewModel)
        {
            ProjectItem projectItem = currentItem.ProjectItem;

            if (projectItem.Status == StateEnums.ActivityStatus.Completed)
            {
                return(false);
            }

            // ToDo: Parametrize hardcoded constants
            if (projectItem.Name.Contains("Vista") || projectItem.Name.Contains("Jaguar"))
            {
                return(false);
            }

            // ToDo: Parametrize hardcoded constant
            if (projectItem.TemplateId == 109643)
            {
                return(false);
            }

            if (projectItem.Name != matchedInNewModel.Template.Name)
            {
                return(true);
            }

            if (projectItem.Notes != matchedInNewModel.Template.Notes)
            {
                return(true);
            }

            if (projectItem.Theme != matchedInNewModel.Template.Theme)
            {
                return(true);
            }

            return(false);
        }
コード例 #13
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);
            }
        }
コード例 #14
0
        static private void TryMatch(ProjectItemStateChange currentItem,
                                     FixedList <ProjectItemStateChange> newModel)
        {
            ProjectItem projectItem = currentItem.ProjectItem;

            var matchedInNewModel = newModel.Find(x => x.Template.Id == projectItem.TemplateId);

            if (matchedInNewModel == null)
            {
                if (projectItem.TemplateId != 0)
                {
                    currentItem.ProcessMatchResult = ProjectItemProcessMatchResult.OrphanInProject;
                }
                else
                {
                    currentItem.ProcessMatchResult = ProjectItemProcessMatchResult.OnlyInProject;
                }
                return;
            }

            bool hasProgrammingRule = HasProgrammingRule(currentItem, matchedInNewModel);
            bool dataChanged        = DataChanged(currentItem, matchedInNewModel);
            bool deadlineChanged    = DeadlineChanged(currentItem, matchedInNewModel);

            if (!hasProgrammingRule)
            {
                if (deadlineChanged)
                {
                    currentItem.Deadline = matchedInNewModel.Deadline;
                }

                currentItem.ProcessMatchResult = ProjectItemProcessMatchResult.NoProgrammingRule;
            }
            else if (deadlineChanged && dataChanged)
            {
                currentItem.Deadline = matchedInNewModel.Deadline;
                SetUpdatedData(currentItem, matchedInNewModel);

                currentItem.ProcessMatchResult = ProjectItemProcessMatchResult.MatchedWithDeadlineAndDataChanges;
            }
            else if (deadlineChanged && !dataChanged)
            {
                currentItem.Deadline = matchedInNewModel.Deadline;

                currentItem.ProcessMatchResult = ProjectItemProcessMatchResult.MatchedWithDeadlineChanges;
            }
            else if (!deadlineChanged && dataChanged)
            {
                SetUpdatedData(currentItem, matchedInNewModel);

                currentItem.ProcessMatchResult = ProjectItemProcessMatchResult.MatchedWithDataChanges;
            }
            else if (!deadlineChanged && !dataChanged)
            {
                currentItem.ProcessMatchResult = ProjectItemProcessMatchResult.MatchedEqual;
            }
            else
            {
                Assertion.EnsureNoReachThisCode("Should be impossible to reach this code.");
            }
        }
コード例 #15
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);
        }
コード例 #16
0
ファイル: WhatIfResult.cs プロジェクト: Ontica/Empiria.Steps
 internal void AddStateChange(ProjectItemStateChange stateChange)
 {
     this.stateChanges.Add(stateChange);
 }
コード例 #17
0
ファイル: WhatIfResult.cs プロジェクト: Ontica/Empiria.Steps
 internal void InsertStateChange(int index, ProjectItemStateChange stateChange)
 {
     this.stateChanges.Insert(index, stateChange);
 }