Exemple #1
0
 public virtual IOrderedEnumerable <Term> GetDeletableCoveredTerms(Term source)
 {
     return(TermSet.Retrieve <Term>(source.Start, source.End)
            .Where(t => t.Level > source.Level)
            .WhereDeletableTerms(source)
            .WhereFamilyTerms(source)
            .OrderByStartAndLevel());
 }
Exemple #2
0
        public virtual IEnumerable <Term> GetCoveredTermsWithAbsent(Term source)
        {
            var results = TermSet.Retrieve <Term>(source.Start, source.End)
                          .Where(t => !ReferenceEquals(source, t) && t.Level > source.Level && source.EnclosedWithTypeVerification(t))
                          .WhereFamilyTerms(source);

            return(results);
        }
Exemple #3
0
        public virtual IEnumerable <Term> GetCoveredTerms(Term source)
        {
            Func <Term, bool> excludeAbesent = t => !(t is AbsentEvent);

            var results = TermSet.Retrieve <Term>(source.Start, source.End).Where(t => !ReferenceEquals(source, t) && excludeAbesent(t) && source.EnclosedWithTypeVerification(t))
                          .WhereFamilyTerms(source);

            return(results);
        }
Exemple #4
0
        //public virtual void CreateOffWork(Term newTerm, Action<ITerm, bool> callback)
        //{
        //    var foundTerms = TermSet.Retrieve<Term>(newTerm.Start, newTerm.End, o => o.Is<IIndependenceTerm>());
        //    var filteredTerms = foundTerms.Where(t => t.IsCoverd(newTerm.Start, newTerm.End)).OrderBy(o=> o.Start);

        //    var success = CreateValidations[newTerm.GetType()].Invoke(this, newTerm, filteredTerms);
        //    if (success)
        //    {
        //        _termSet.Add(newTerm);
        //        newTerm.UpdateLevel();
        //        newTerm.SetEmployeeId(Id);
        //    }

        //    callback(newTerm, success);
        //}

        public virtual void Create(Term newTerm, Action <ITerm, bool> callback, bool withRplaceDayOff)
        {
            //var success = false;

            //var closestBottomTerm = GetOrderedBottoms(newTerm).FirstOrDefault();
            //if (closestBottomTerm == null || !closestBottomTerm.Locked)
            //{
            //TODO: reconsider OrderBy clause

            var foundTerms    = TermSet.Retrieve <Term>(newTerm.Start, newTerm.End, o => o.IsNot <IImmutableTerm>());
            var filteredTerms = foundTerms.Where(t => t.IsCoverd(newTerm.Start, newTerm.End)).OrderByDescending(o => o.Level);

            var success = CreateValidations[newTerm.GetType()].Invoke(this, newTerm, filteredTerms);

            //set up belongToPrev
            //xnewTerm.RectifyAttribution(Boundary, newTerm.Start);

            //temporary remark with IsOutOfBoundary limit
            //if (success && newTerm.IsNot<IOffWork>())
            //{
            //    var lowestTerm = newTerm.GetLowestTerm();
            //    success = !lowestTerm.IsOutOfBoundary(lowestTerm.Start, this);
            //}

            if (!success && newTerm.Exception != null && withRplaceDayOff && newTerm.Exception.CauseTarget is DayOff)
            {
                success = Delete(newTerm.Exception.CauseTarget, false);
            }

            if (success)
            {
                _termSet.Add(newTerm);
                newTerm.UpdateLevel();
                newTerm.SetEmployeeId(Id);
                //xnewTerm.ForceAssignSeat(foundTerms, true);

                Reporting(newTerm);
                //xEmptySeatArrangment<AbsentEvent>(newTerm);
            }

            callback(newTerm, success);
        }
Exemple #5
0
        /// <summary>
        /// Get bottoms order by Level DESC
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public virtual IOrderedEnumerable <Term> GetOrderedBottoms(Term source)
        {
            var results = TermSet.Retrieve <Term>(source.Start, source.End).Where(o => !ReferenceEquals(source, o) && source.IsInTheRange(o.Start, o.End)).OrderByDescending(o => o.Level);

            return(results);
        }
Exemple #6
0
 /// <summary>
 /// In Boundary terms
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public virtual IEnumerable <T> GetAllTermWithoutOffWork <T>(DateTime start, DateTime end, Predicate <Term> predicate)
 {
     return(TermSet.Retrieve <Term>(start, end)
            .Where(o => o.IsNot <IOffWork>() && predicate(o) && o.IsCoverd(Boundary.Start, Boundary.End))
            .OfType <T>());
 }
Exemple #7
0
 /// <summary>
 /// In Boundary terms
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public virtual IEnumerable <T> GetAllTerm <T>(DateTime start, DateTime end)
 {
     return(TermSet.Retrieve <Term>(start, end)
            .Where(o => o.IsCoverd(Boundary.Start, Boundary.End))
            .OfType <T>());
 }
Exemple #8
0
        public virtual void SetTime(ITerm term, DateTime unCheckedstart, DateTime uncheckedEnd, Action <ITerm, bool> callback, bool withRplaceDayOff)
        {
            var start = unCheckedstart.TurnToMultiplesOf5();
            var end   = uncheckedEnd.TurnToMultiplesOf5();

            var result = false;
            var source = (Term)term;

            var value = new DateRange(start, end);

            if (start >= end)
            {
                source.Exception = new TermException(source, "InvalidTimeValue");
                callback(source, false);
                return;
            }


            bool?childIsInsideOfParent = null;

            source.Bottom.SaftyInvoke(o => childIsInsideOfParent = value.IsInTheRange(o));

            //var assignmentIsOutOfBoundary = source.GetLowestTerm().IsOutOfBoundary(start, this);
            //if(assignmentIsOutOfBoundary)
            //    source.Exception = new TermException(source, "IsOutOfBoundary");
            if (childIsInsideOfParent == false)
            {
                source.Exception = new TermException(source, "BreakAwayFromParent");
            }

            if ((!source.Locked) && childIsInsideOfParent != false) // ((!source.Locked) && !assignmentIsOutOfBoundary && childIsInsideOfParent != false)
            {
                var coverage       = source.MeasureCoverage(value.Start, value.End);
                var coverdTerms    = TermSet.Retrieve <Term>(coverage.Start, coverage.End, o => !ReferenceEquals(o, source) && o.IsNot <IImmutableTerm>()).ToList(); //range filter
                var overlappedTerm = coverdTerms.FirstOrDefault(o => o.Level == source.Level && o.IsCoverd(value));                                                  //same level have any covered term
                var relatedTerms   = coverdTerms.WhereFamilyTerms(source).ToList();                                                                                  //relation filter, the real child in the parent

                if (overlappedTerm == null || (withRplaceDayOff && overlappedTerm is DayOff))
                {
                    if (source.IsNot <AbsentEvent>())
                    {
                        overlappedTerm.SaftyInvoke <DayOff>(o =>
                        {
                            _termSet.Remove(o);
                            overlappedTerm = null;
                        });

                        var notMoving = !source.CanCauseMoved(start, end);
                        var offset    = new { L = value.Start.Subtract(source.Start), R = value.End.Subtract(source.End) };

                        var    verifiedTerms = relatedTerms.Where(o => o.IsInTheRange(source.Start, source.End)).OrderByDescending(o => o.Level);
                        var    lockedTerms   = relatedTerms.Where(o => o.Locked && o.IsInTheRange(source.Start, source.End));
                        Action applyDelegate = () => { };

                        foreach (var o in verifiedTerms)
                        {
                            var newTime = new DateRange(o.Is <AbsentEvent>() || o.Locked || notMoving ? o.Start : o.Start.Add(offset.L), o.Is <AbsentEvent>() || o.Locked || notMoving ? o.End : o.End.Add(offset.R));
                            if (o.Level < source.Level ? !value.IsInTheRange(newTime) : !newTime.IsInTheRange(value) && o.IsNot <AbsentEvent>())
                            {
                                overlappedTerm = o;
                                break;
                            }

                            if (o.Is <AbsentEvent>() && !o.IsInTheRange(o.ParentTerm == term ? start : o.ParentTerm.Start, o.ParentTerm == term ? end : o.ParentTerm.End))
                            {
                                overlappedTerm = o;
                                break;
                            }

                            if (notMoving || o.Is <AbsentEvent>())
                            {
                                continue;
                            }
                            var current = o;
                            var verifyLockedTermIsNotInTheRange = new Func <Term, bool>(lockedTerm =>
                            {
                                if (lockedTerm.Bottom != current)
                                {
                                    return(false);
                                }
                                if (!lockedTerm.IsInTheRange(newTime.Start, newTime.End))
                                {
                                    overlappedTerm = lockedTerm;
                                }
                                return(true);
                            });

                            if (lockedTerms.Any(verifyLockedTermIsNotInTheRange))
                            {
                                continue;
                            }

                            overlappedTerm = lockedTerms.FirstOrDefault(locked => !ReferenceEquals(current, locked) && ((locked.Level == current.Level && locked.IsCoverd(newTime))));
                            if (overlappedTerm == null && !o.Locked && !o.BottomIsLocked())
                            {
                                applyDelegate += () =>
                                {
                                    current.Snapshot();
                                    current.Start = newTime.Start;
                                    current.End   = newTime.End;
                                };
                                current.ForceAssignSeat(coverdTerms, false);
                            }
                            if (overlappedTerm != null)
                            {
                                break;
                            }
                        }
                        if (overlappedTerm == null)
                        {
                            applyDelegate();
                        }
                    }

                    if (overlappedTerm == null)
                    {
                        source.Snapshot();
                        source.RectifyAttribution(Boundary, value.Start);
                        source.Start = value.Start;
                        source.End   = value.End;
                        result       = true;
                        TermSet.Rebuild <Term>();
                        Reporting(source);
                        EmptySeatArrangment <AbsentEvent>(source);
                        source.ForceAssignSeat(coverdTerms, false);
                        source.TryReplaceSeat();
                    }
                }
                if (overlappedTerm != null)
                {
                    source.Exception = new TermException(overlappedTerm, "Covered");
                }
            }

            callback(source, result);
        }