public static IEnumerable <Term> RetriveTerms(this TimeBox timeBox, DateTime start, DateTime end) { var terms = timeBox.GetAllTerm <Term>(start, end).ToList(); terms.RemoveAll(o => o.IsInTheRange(start, end)); return(terms); }
public Agent(TimeBox timeBox, Attendance attendance, DateRange enquiryRange) { timeBox.Boundary = new DateRange(attendance.Start, attendance.End); _dailyContainer = new Dictionary <DateTime, HeaderContainer <DateTime, IAssignment, int> >(Convert.ToInt32(timeBox.Boundary.Duration.TotalDays)); Schedule = timeBox; _laborRule = attendance; _enquiryRange = enquiryRange; }
/// <summary> /// 排班秘书使用 /// </summary> /// <param name="timeBox"></param> /// <param name="attendance"></param> /// <param name="enquiryRange"></param> public PlanningAgent(TimeBox timeBox, Attendance attendance, DateRange enquiryRange) : this(timeBox, attendance) { _enquiryRange = enquiryRange; var enquiryDays = (int)_enquiryRange.Duration.TotalDays; _dailyContainer = new Dictionary <int, HeaderContainer <DateTime, IIndependenceTerm, int> >(enquiryDays); // 重要逻辑控制 _dailyRecords = new Dictionary <DateTime, DateTerm>(enquiryDays); _timeBox.Boundary = new DateRange(_enquiryRange.Start.AddDays(-Global.HeadDayAmount), _enquiryRange.End); // 重要逻辑控制 BuildOnlines(); }
/// <summary> /// Get Assignment DNA /// </summary> /// <param name="timeBox"></param> /// <param name="source">Should be assignment type</param> /// <returns></returns> public static string GetShiftprint(this TimeBox timeBox, Term source) { var summary = new StringBuilder(string.Format("{0:yyyy/MM/dd HH:mm}%{1:yyyy/MM/dd HH:mm}#{2}", source.Start, source.End, source.Id)); foreach (var item in timeBox.GetCoveredTermsWithAbsent(source)) { summary.Append(string.Format("{0:yyyy/MM/dd HH:mm}%{1:yyyy/MM/dd HH:mm}#{2}", item.Start, item.End, item.Id)); } var m = new MD5CryptoServiceProvider(); byte[] s = m.ComputeHash(Encoding.UTF8.GetBytes(summary.ToString())); return(BitConverter.ToString(s)); }
public static void Reset(this Term source, TimeBox timeBox, Func <Term, bool> isNeedReset) { //TODO:Fix it for better performance //var results = timeBox.GetCoveredTermsWithAbsent(source); foreach (var term in timeBox.TermSet) { if (isNeedReset(term)) { term.Reset(); } } source.Reset(); }
private static bool AbsentEventCreation(TimeBox sender, Term absent, IOrderedEnumerable<Term> orderedTerms) { if (orderedTerms.Any(t => t.CanNotOverlapWithAbsent && t.OverlapNotEnclosed(absent))) return false; var exists = orderedTerms.Where(absent.NeedRelyOn) .Any(t => { if (t.EnclosedWithTypeVerification(absent)) { absent.Bottom = t.GetLowestTerm() as Term; //if (absent.IsNeedSeat != t.IsNeedSeat && t is AssignmentBase) // ((AssignmentBase)t).CancelSeatArrangement(absent); return true; } return false; }); return exists; }
public static bool VerifyAnyOverlap(this Term source, TimeBox timeBox) { var lowestTerm = source.GetLowestTerm() as Term; var convertTerms = timeBox.GetCoveredTermsWithAbsent(lowestTerm).ToArray(); if (lowestTerm == source) { return(timeBox.TermSet.Where(o => o != source && o.Level == source.Level).Any(o => { var overlap = source.AnyOverlap(o); return overlap; })); } var closestBottomTerm = timeBox.GetClosestBottom(source); if (closestBottomTerm != source.Bottom) { return(true); } return(convertTerms.Where(o => o != source || o.Id != source.Id).OrderBy(o => o.Start).Any(o => o.Id != source.Id && o.Level > source.Level ? source.OverlapNotEnclosed(o) : o.OverlapNotEnclosed(source))); }
private static bool DependencyTermCreation(TimeBox sender, Term other, IOrderedEnumerable <Term> orderedTerms) { var newTermType = other.GetType(); var closestBottom = sender.GetClosestBottom(other); var overlapping = false; var canLandingOn = false; foreach (var t in orderedTerms) { var insiede = other.IsInTheRange(t.Start, t.End); overlapping = t.AnyOverlap(other) && !insiede; //oh! No~ if (overlapping) { other.Exception = new TermException(t, "AnyOverlap"); break; } canLandingOn = t.CanBeOverlap(newTermType); if (!canLandingOn && insiede) { other.Exception = new TermException(t, "RelationIncorrect"); break; }// find right position but no right relation if (canLandingOn && insiede) { other.Bottom = closestBottom; break; } } return(overlapping == false && canLandingOn); }
private static bool DependencyTermCreation(TimeBox sender, Term other, IOrderedEnumerable<Term> orderedTerms) { var newTermType = other.GetType(); var closestBottom = sender.GetClosestBottom(other); var overlapping = false; var canLandingOn = false; foreach (var t in orderedTerms) { var insiede = other.IsInTheRange(t.Start, t.End); overlapping = t.AnyOverlap(other) && !insiede; //oh! No~ if (overlapping) { other.Exception = new TermException(t, "AnyOverlap"); break; } canLandingOn = t.CanBeOverlap(newTermType); if (!canLandingOn && insiede) { other.Exception = new TermException(t, "RelationIncorrect"); break; }// find right position but no right relation if (canLandingOn && insiede) { other.Bottom = closestBottom; break; } } return overlapping == false && canLandingOn; }
private static bool IndependenceTermCreation(TimeBox sender, Term other, IOrderedEnumerable<Term> orderedTerms) { //bugs might be here var result = !orderedTerms.Any(t => { var found = false; if (t.Level > other.Level) { found = other.OverlapNotEnclosed(t); other.Exception = new TermException(t, "OverlapNotEnclosed"); }//upper term if (t.Level == other.Level && !(t is IOffWork || other is IOffWork) && t.HrDateEq(other)) // 只有非IOffWork不可相交 { found = t.IsCoverd(other); other.Exception = new TermException(t, "IsCoverd"); }// same level term return found; }); return result; }
private static bool AbsentEventCreation(TimeBox sender, Term absent, IOrderedEnumerable <Term> orderedTerms) { if (orderedTerms.Any(t => t.CanNotOverlapWithAbsent && t.OverlapNotEnclosed(absent))) { return(false); } var exists = orderedTerms.Where(absent.NeedRelyOn) .Any(t => { if (t.EnclosedWithTypeVerification(absent)) { absent.Bottom = t.GetLowestTerm() as Term; //if (absent.IsNeedSeat != t.IsNeedSeat && t is AssignmentBase) // ((AssignmentBase)t).CancelSeatArrangement(absent); return(true); } return(false); }); return(exists); }
private static bool IndependenceTermCreation(TimeBox sender, Term other, IOrderedEnumerable <Term> orderedTerms) { //bugs might be here var result = !orderedTerms.Any(t => { var found = false; if (t.Level > other.Level) { found = other.OverlapNotEnclosed(t); other.Exception = new TermException(t, "OverlapNotEnclosed"); }//upper term if (t.Level == other.Level && !(t is IOffWork || other is IOffWork) && t.HrDateEq(other)) // 只有非IOffWork不可相交 { found = t.IsCoverd(other); other.Exception = new TermException(t, "IsCoverd"); }// same level term return(found); }); return(result); }
/// <summary> /// 取范围碰到的 /// </summary> public static IEnumerable <Term> CollideTerms(this TimeBox timeBox, DateRange range) { return(timeBox.TermSet.CollideTerms(range)); }
/// <summary> /// 取范围之内的 /// </summary> public static IEnumerable <Term> CenterTerms(this TimeBox timeBox, Term source) { return(timeBox.CenterTerms(new DateRange(source.Start, source.End))); }
public static bool IsOutOfBoundary(this Term term, Action <IIndependenceTerm> lowestTermDetection, TimeBox timeBox) { var lowestTerm = term.GetLowestTerm(); lowestTermDetection(lowestTerm); //var compareTime = (lowestTerm as Term ?? term).Start; //if (compareTime < timeBox.Boundary.Start) // return true; //if (compareTime >= timeBox.Boundary.End && !lowestTerm.BelongToPrv) // return true; return(lowestTerm.IsOutOfBoundary(lowestTerm.Start, timeBox)); }
//为了 hibernate hql new 语法支持, 重新读取 ReloadAgent用 public PlanningAgent(TimeBox timeBox, Attendance attendance) : this(timeBox) { _laborRule = attendance; }
private static bool HolidayTermCreation(TimeBox sender, Term other, IOrderedEnumerable <Term> orderedTerms) { return(!orderedTerms.OfType <IIndependenceTerm>().Any(o => other.HrDateEq(o))); }
private static bool HolidayTermCreation(TimeBox sender, Term other, IOrderedEnumerable<Term> orderedTerms) { return !orderedTerms.OfType<IIndependenceTerm>().Any(o => other.HrDateEq(o)); }
/// <summary> /// 特定类型的 /// </summary> public static IEnumerable <Term> SpecificTerm <T>(this TimeBox timeBox) where T : Term { return(timeBox.TermSet.SpecificTerm <T>()); }
public static Term FindOne(this TimeBox timeBox, Type type, DateTime start) { return(timeBox.TermSet.Retrieve <Term>(start, start).SingleOrDefault(t => t.Start == start && t.GetType() == type)); }
public Agent(TimeBox timeBox) { Schedule = timeBox; }
//public static bool IsOutOfBoundary(this Term term, DateTime checkPoint, DateRange boundary) //{ // var lowestTerm = term.GetLowestTerm(); // var isDayOffOrTimeOff = term is DayOff || term is TimeOff; // var compareTime = lowestTerm == term || isDayOffOrTimeOff ? checkPoint : lowestTerm.Start; // if (compareTime < boundary.Start) // return true; // if (compareTime >= boundary.End && !lowestTerm.BelongToPrv) // return true; // return false; //} public static bool IsOutOfBoundary(this IIndependenceTerm lowestTerm, DateTime compareTime, TimeBox timeBox) { var originalStartTime = lowestTerm.Start; var insideTimeBox = originalStartTime.IsInTheRange(timeBox.Boundary.Start, timeBox.Boundary.End); if (insideTimeBox == false && lowestTerm.BelongToPrv == false) { return(true); } if (insideTimeBox && lowestTerm.BelongToPrv == true) { return(true); } var distanceBetweenCompareTimeAndBoundaryEnd = compareTime.Subtract(timeBox.Boundary.End); if (insideTimeBox == false && compareTime.IsInTheRange(timeBox.Boundary.Start, timeBox.Boundary.End) && lowestTerm.BelongToPrv == true) { return(false); } if (distanceBetweenCompareTimeAndBoundaryEnd > TimeSpan.FromHours(12)) { return(true); } if (compareTime < timeBox.Boundary.Start) { return(true); } //if (compareTime >= timeBox.Boundary.End && !lowestTerm.BelongToPrv) // return true; return(false); }
//为了 hibernate hql new 语法支持 protected PlanningAgent(TimeBox timeBox) { _timeBox = timeBox; }