private List <FixedActivity> MergeItems(List <FixedActivity> resultList) { var mergedList = new List <FixedActivity>(); foreach (var currentActivity in resultList) { if (mergedList.Count == 0 || mergedList.Last().End < currentActivity.Start) { var latest = GetLongestIntersection(currentActivity, resultList); if (latest != null) { FixedActivity merged = currentActivity; merged.End = latest.End; mergedList.Add(merged); } else { if (mergedList.Count == 0 || !(Intersect(mergedList.Last(), currentActivity))) { mergedList.Add(currentActivity); } } } } return(mergedList); }
private void ManageSharingWithDefinedActivities(IDefinedActivity activity, List <Activity> activities) { if (activity.Repeat == null || activity.Repeat.RepeatPeriod == RepeatPeriod.Single) { return; } var days = (int)activity.Repeat.RepeatPeriod; var currentDay = activity.Start.Value.Date.AddDays(days); if (activity is FixedActivity) { var fixedActivity = activity as FixedActivity; while (currentDay <= fixedActivity.Repeat.EndDate && currentDay <= _rangeEnd) { var item = new FixedActivity(fixedActivity.Name, fixedActivity.Description, fixedActivity.Color, CreationType.ManuallyCreated, fixedActivity.Labels, fixedActivity.Category, fixedActivity.UserId, fixedActivity.Priority, currentDay + fixedActivity.Start.Value.TimeOfDay, currentDay + fixedActivity.End.TimeOfDay, false); currentDay = currentDay.AddDays(days); activities.Add(item); } } else { var unfixedActivity = activity as UnfixedActivity; while (currentDay <= unfixedActivity.Repeat.EndDate && currentDay <= _rangeEnd) { var item = new FixedActivity(unfixedActivity.Name, unfixedActivity.Description, unfixedActivity.Color, CreationType.ManuallyCreated, unfixedActivity.Labels, unfixedActivity.Category, unfixedActivity.UserId, unfixedActivity.Priority, currentDay + unfixedActivity.Start.Value.TimeOfDay, currentDay + unfixedActivity.End.Value.TimeOfDay, false); currentDay = currentDay.AddDays(days); activities.Add(item); } } }
private void CreateFixedActivities() { fixedActivity1 = new FixedActivity("FA1", "Fixed activity 1", Enums.Color.Black, Enums.CreationType.AutoGenerated, new List <Label>() { new Label("Label1", "1"), new Label("Label2", "1") }, new Category("CAT1", "Category 1", Enums.Color.Blue, 10, "1"), "1", 10, new DateTime(2020, 03, 29, 10, 0, 0), new DateTime(2020, 03, 29, 11, 0, 0), false); fixedActivity2 = new FixedActivity("FA2", "Fixed activity 2", Enums.Color.Red, Enums.CreationType.ManuallyCreated, new List <Label>() { new Label("Label1", "2"), new Label("Label2", "2") }, new Category("CAT1", "Category 1", Enums.Color.Green, 10, "2"), "2", 10, new DateTime(2020, 03, 29, 13, 0, 0), new DateTime(2020, 03, 29, 19, 0, 0), false); fixedActivity3 = new FixedActivity("FA3", "Fixed activity 3", Enums.Color.Gray, Enums.CreationType.ManuallyCreated, new List <Label>() { new Label("Label1", "3"), new Label("Label2", "3") }, new Category("CAT1", "Category 1", Enums.Color.Yellow, 10, "3"), "3", 10, new DateTime(2020, 03, 29, 10, 30, 0), new DateTime(2020, 03, 29, 18, 10, 0), false); }
private bool IsInFrame(FixedActivity activity) { if (activity.Start <= TimeFrameStart && activity.End >= TimeFrameEnd) { throw new ArgumentException(activity.Name); } return(!(activity.End <= TimeFrameStart || activity.Start >= TimeFrameEnd)); }
private void ManageSharingWithDeadlineActivities(DeadlineActivity activity, List <Activity> activities) { var itemStart = new FixedActivity(activity.Name, activity.Description, Color.Red, CreationType.ManuallyCreated, null, null, activity.UserId, 0, activity.Start, activity.Start.AddHours(1), false); var itemEnd = new FixedActivity(activity.Name, activity.Description, Color.Red, CreationType.ManuallyCreated, null, null, activity.UserId, 0, activity.End, activity.End.AddHours(1), false); activities.Add(itemStart); activities.Add(itemEnd); foreach (var milestone in activity.Milestones) { activities.Add(new FixedActivity(milestone.Name, "", Color.Red, CreationType.ManuallyCreated, null, null, activity.UserId, 0, milestone.Time, milestone.Time.AddHours(1), false)); } }
private FixedActivity GetLongestIntersection(FixedActivity fixedActivity, List <FixedActivity> list) { FixedActivity latest = null; foreach (var currentItem in list) { if (currentItem != fixedActivity && Intersect(fixedActivity, currentItem)) { if (latest == null) { latest = currentItem; } else { if (latest.End < currentItem.End) { latest = currentItem; } } } } if (latest != null && latest.End > fixedActivity.End) { var back = GetLongestIntersection(latest, list); if (back == null) { return(latest); } return(back); } else { return(null); } }
private bool Intersect(FixedActivity first, FixedActivity second) { return(!(first.End < second.Start)); }