Exemple #1
0
        public bool isLastGeneratorState(int planningAppStateId)
        {
            if (this.CurrentPlanningStatus.Name != StatusList.AppInProgress)
            {
                return(false); //Only interested in live applications when adding generators
            }
            var r = OrderedPlanningAppStates.GetEnumerator();

            while (r.MoveNext())
            {
                PlanningAppState prev = r.Current;
                if (r.Current.Id == planningAppStateId)
                {
                    if (r.MoveNext())
                    {
                        if (r.Current.GeneratorOrder > prev.GeneratorOrder &&
                            !prev.Completed()) //Cannot add generator if completed last gen state
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #2
0
 private List <PlanningAppState> RollbackDueByDates(int daysDiff, PlanningAppState current)
 {
     return(PlanningAppStates
            .Where(s => s.DueByDate > current.DueByDate)
            .Select(c => { c.DueByDate = c.DueByDate.AddBusinessDays(-daysDiff); return c; })
            .ToList());
 }
Exemple #3
0
        public void generateDueByDates()
        {
            if (!Completed())
            {
                //Important - put states in order before processing!!
                PlanningAppStates = PlanningAppStates.OrderBy(s => s.state.OrderId).ToList();
                var prevState    = new PlanningAppState();
                var currState    = Current();
                var resetCurrent = Current();

                while (currState != null)
                {
                    if (!isFirstState(currState))
                    {
                        prevState = SeekPrev();
                        currState.AggregateDueByDate(prevState);
                    }
                    else
                    {
                        currState.SetDueByDate();
                    }

                    currState = Next(currState);
                }
                //Set original state
                SetCurrent(resetCurrent);
            }
        }
Exemple #4
0
 //Private Functions
 public void SetCurrent(PlanningAppState planningAppState)
 {
     foreach (var state  in OrderedPlanningAppStates)
     {
         state.CurrentState = false;
     }
     OrderedPlanningAppStates[OrderedPlanningAppStates.IndexOf(planningAppState)].CurrentState = true;
 }
Exemple #5
0
 private void RollForwardDueByDates(int daysDiff, PlanningAppState prevState)
 {
     if (!Completed())
     {
         PlanningAppStates
         .Where(s => s.DueByDate > prevState.DueByDate)
         .Select(c => { c.DueByDate = c.DueByDate.AddBusinessDays(daysDiff); return(c); })
         .ToList();
     }
 }
Exemple #6
0
 public PlanningAppState SeekPrev(PlanningAppState planningAppState) //Get previous state based on specified State
 {
     if (!Completed() && !isFirstState(planningAppState))
     {
         return(OrderedPlanningAppStates[OrderedPlanningAppStates.IndexOf(planningAppState) - 1]);
     }
     else
     {
         return(null);
     }
 }
Exemple #7
0
 public bool canRemoveGenerator(PlanningAppState planningAppState)
 {
     if (!this.Completed())
     {
         if (isLastGeneratorState(planningAppState.Id))
         {
             var curr = this.Current();
             if (planningAppState.GeneratorOrder > curr.GeneratorOrder)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #8
0
        public PlanningAppState Next(PlanningAppState planningAppState)
        {
            PlanningAppState nextState = new PlanningAppState();

            if (!isLastState(planningAppState))
            {
                nextState = OrderedPlanningAppStates[OrderedPlanningAppStates.IndexOf(planningAppState) + 1];
                planningAppState.CurrentState = false;
                nextState.CurrentState        = true;
                return(nextState);
            }
            else
            {
                return(null);
            }
        }
Exemple #9
0
        public PlanningApp GeneratePlanningStates(List <StateInitialiserState> stateInitialisers,
                                                  IEnumerable <StateStatus> stateStatus)
        {
            var currentDate = SystemDate.Instance.date;

            foreach (var stateInialiser in stateInitialisers)
            {
                PlanningAppState newPlanningAppState = new PlanningAppState();
                newPlanningAppState.state = stateInialiser;

                PlanningAppState prevState;
                var stateCount = PlanningAppStates.Count;
                if (stateCount > 0)
                {
                    prevState = PlanningAppStates[stateCount - 1];
                    newPlanningAppState.DueByDate = prevState.DueByDate.AddBusinessDays(stateInialiser.CompletionTime);
                }
                else
                {
                    newPlanningAppState.DueByDate = currentDate.AddBusinessDays(stateInialiser.CompletionTime);
                }

                newPlanningAppState.StateStatus = stateStatus.Where(s => s.Name == StatusList.OnTime).SingleOrDefault();
                //Add custom fields to state if exist
                foreach (var stateInitialiserStateCustomField in newPlanningAppState.state.StateInitialiserStateCustomFields)
                {
                    newPlanningAppState.customFields
                    .Add(new PlanningAppStateCustomField {
                        StateInitialiserStateCustomFieldId = stateInitialiserStateCustomField.StateInitialiserCustomFieldId
                    });
                }
                PlanningAppStates.Add(newPlanningAppState);
            }
            //set first state to current state
            if (PlanningAppStates.Count > 0)
            {
                PlanningAppStates[0].CurrentState = true;
            }

            //Set overall Status to InProgress
            CurrentPlanningStatus = stateStatus.Where(s => s.Name == StatusList.AppInProgress).SingleOrDefault();

            return(this);
        }
Exemple #10
0
        public void updateDueByDates()  //Called when inserting a new state to an existing planning app
        {
            if (!Completed())
            {
                //Important - put states in order before processing!!
                PlanningAppStates = PlanningAppStates.OrderBy(s => s.state.OrderId).ToList();
                var prevState    = new PlanningAppState();
                var currState    = Current();
                var resetCurrent = Current();

                while (currState != null)
                {
                    if (!isFirstState(currState))
                    {
                        prevState = SeekPrev();
                        currState.AggregateDueByDate(prevState);
                    }
                    currState = Next(currState);
                }
                //Set original state
                SetCurrent(resetCurrent);
            }
        }
Exemple #11
0
        public PlanningApp InsertNewPlanningState(StateInitialiserState newStateInitialiser, IEnumerable <StateStatus> stateStatus)
        {
            if (!Completed())
            {
                var currentState = Current();

                if (newStateInitialiser.OrderId > currentState.state.OrderId)
                {
                    //Remove states after current state
                    var states = this.PlanningAppStates.ToList();

                    PlanningAppState newState = new PlanningAppState();
                    newState.state          = newStateInitialiser;
                    newState.CurrentState   = false;
                    newState.StateStatus    = stateStatus.Where(s => s.Name == StatusList.OnTime).SingleOrDefault();
                    newState.CompletionDate = null;
                    newState.DueByDate      = DateTime.Now;
                    PlanningAppStates.Add(newState);

                    updateDueByDates();
                }
            }
            return(this);
        }
Exemple #12
0
 private PlanningAppState FirstState(PlanningAppState planningAppState)
 {
     return(OrderedPlanningAppStates.Count() > 0 ? OrderedPlanningAppStates[0] : null);
 }
Exemple #13
0
 public bool isFirstState(PlanningAppState planningAppState)
 {
     return(OrderedPlanningAppStates.IndexOf(planningAppState) == 0);
 }
Exemple #14
0
 public bool isLastState(PlanningAppState planningAppState)
 {
     return(OrderedPlanningAppStates.Count() == (OrderedPlanningAppStates.IndexOf(planningAppState) + 1));
 }
 public void AggregateDueByDate(PlanningAppState planningAppState)
 {
     this.DueByDate = planningAppState.DueByDate.AddBusinessDays(this.CompletionTime());
 }