public static IList <Term> NewAssignmentWithEvents <T>(DateTime startDate, TermStyle termStyle , IEnumerable <SubEventInsertRule> rules) where T : Term { var newTerm = New <T>(startDate, termStyle); var terms = new List <Term>(rules.Count() + 1) { newTerm }; foreach (var rule in rules) { DateTime startTime; // Whole SubEvent should be inside the range of StartValue~EndValue var amountOfAvailableOccurPoints = rule.GetAmountOfAvailableOccurPoints(); if (amountOfAvailableOccurPoints == 1) { // SubEvent can only occur at the begin of range startTime = newTerm.Start.AddMinutes(rule.TimeRange.StartValue); } else { var randomOffset = TermExt.ArrangeSubEventRandom.Next(0, amountOfAvailableOccurPoints); startTime = newTerm.Start.AddMinutes(rule.TimeRange.StartValue + (randomOffset * rule.OccurScale)); } var newSubEvent = New(startTime, rule.SubEvent, rule.SubEventLength); if (newSubEvent.IsInTheRange(newTerm.Start, newTerm.End)) { terms.Add(newSubEvent); } } return(terms); }
public VisibleSubEventTerm(TermStyle source, TimeValueRange timeValueRange, DateTime start) { _source = source; TimeRange = timeValueRange; Background = _source.Background; Start = start; }
public static T New <T>(DateTime uncheckedStart, TermStyle termStyle) where T : Term { var start = uncheckedStart.TurnToMultiplesOf5(); DateTime startTime; if (termStyle is AssignmentType) { startTime = start.Date.AddMinutes(termStyle.TimeRange.StartValue); } else { startTime = start; } var length = TimeSpan.FromMinutes(termStyle.TimeRange.Length); var ci = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, CallingConventions.HasThis, new[] { typeof(DateTime), typeof(TimeSpan) }, null); var obj = (T)ci.Invoke(new object[] { startTime, length }); obj.MAssign(new { termStyle.Background, Text = termStyle.Name, termStyle.OnService, termStyle.AsARest, TermStyleId = termStyle.Id }); obj.IsNeedSeat = termStyle.Occupied; return(obj); }
/// <summary> /// New Term /// </summary> /// <param name="startDate">Can't be 00:00</param> /// <param name="termStyle"></param> /// <param name="lenghtOfMinutes"></param> /// <returns></returns> public static Term New(DateTime startDate, TermStyle termStyle, int lenghtOfMinutes) { if (termStyle == null) { throw new ArgumentNullException("termStyle"); } var startTime = startDate; if (termStyle is AssignmentType) { //用途不明却,需注意旧版使用情境 var startValue = startDate.Hour * 60 + startDate.Minute; if (startValue == termStyle.TimeRange.StartValue) { startTime = startDate.Date.AddMinutes(termStyle.TimeRange.StartValue); } } var length = TimeSpan.FromMinutes(lenghtOfMinutes); var ci = termStyle.Type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, CallingConventions.HasThis, new[] { typeof(DateTime), typeof(TimeSpan) }, null); var obj = ci.Invoke(new object[] { startTime, length }); obj.MAssign(new { termStyle.Background, Text = termStyle.Name, termStyle.OnService, termStyle.AsARest, TermStyleId = termStyle.Id }); obj.SaftyInvoke <Term>(t => t.IsNeedSeat = termStyle.Occupied); obj.SaftyInvoke <IAssignment>(t => { t.HrDate = startDate.Date; }); if (termStyle is AssignmentType) { var type = termStyle.As <AssignmentType>(); obj.MAssign(new { type.AsAWork, type.IgnoreAdherence, type.GapGuaranteed }); } return(obj as Term); }
public VisibleSubEventTerm(TermStyle source, DateTime start) : this(source, source.TimeRange, start) { }
public static bool IsSubEventKind(this TermStyle obj) { return(SubEventKinds.Contains(obj.Type)); }
public static Term New(DateTime start, TermStyle termStyle) { return(New(start, termStyle, termStyle.TimeRange.Length)); }
public static Term NewAssignment(DateTime unCheckedstart, DateTime uncheckedEnd, TermStyle termStyle) { var start = unCheckedstart.TurnToMultiplesOf5(); var end = uncheckedEnd.TurnToMultiplesOf5(); if (termStyle.Type.FullName != null) { if (termStyle as BasicAssignmentType == null && termStyle.Type.FullName.Contains("Event")) { throw new ArgumentNullException("termStyle"); } } if (end < start) { end = end.AddDays(1); } var length = end.Subtract(start); var ci = termStyle.Type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, CallingConventions.HasThis, new[] { typeof(DateTime), typeof(TimeSpan) }, null); var obj = ci.Invoke(new object[] { start, length }); var type = termStyle.As <BasicAssignmentType>(); obj.MAssign(new { type.Background, Text = type.Name, type.OnService, IsNeedSeat = type.Occupied, type.AsAWork, type.AsARest, type.IgnoreAdherence, type.GapGuaranteed, TermStyleId = type.Id }); return(obj as Term); }
public AbsentEvent(DateTime start, TimeSpan length, TermStyle style) : base(start, length) { _level = 3; this.MAssign(new { style.Background, Text = style.Name, IsNeedSeat = style.Occupied }); }