Esempio n. 1
0
 private async Task OnExecuteToggleTimeSlot(ActivityTimeSlot timeSlot)
 {
     if (timeSlot.IsRunning)
     {
         await timeSlot.StopAsync();
     }
     else
     {
         await timeSlot.StartAsync();
     }
 }
Esempio n. 2
0
        public static List <ActivityTimeSlot> TryFindTimeForActivityAndTravel(ActivityPoint activityPoint, TimeWindow freeTimeWindow)
        {
            var activityPointAndTravel = new List <ActivityTimeSlot>();
            var drivingTimeToActivity  =
                CalcDrivingTime(freeTimeWindow.ActivityBefore?.Activity?.Location, activityPoint.Location);
            var drivingTimeFromActivity = CalcDrivingTime(activityPoint.Location, freeTimeWindow.ActivityAfter?.Activity?.Location);
            var duration = (int)activityPoint.AvgSpendingTimeInHours + drivingTimeToActivity + drivingTimeFromActivity;
            ActivityTimeSlot activityTimeSlot = null;

            if (duration > freeTimeWindow.TimeSlot.EndTime - freeTimeWindow.TimeSlot.StartTime)
            {
                return(null);
            }

            if (activityPoint.OpeningTime < freeTimeWindow.TimeSlot.StartTime && freeTimeWindow.TimeSlot.StartTime + duration <= activityPoint.ClosingTime)
            {
                activityTimeSlot = new ActivityTimeSlot(new TimeSlot(freeTimeWindow.TimeSlot.StartTime + drivingTimeToActivity, freeTimeWindow.TimeSlot.StartTime + activityPoint.AvgSpendingTimeInHours + drivingTimeToActivity), activityPoint);
            }

            if (activityPoint.ClosingTime > freeTimeWindow.TimeSlot.EndTime && freeTimeWindow.TimeSlot.EndTime - duration >= activityPoint.OpeningTime)
            {
                activityTimeSlot = new ActivityTimeSlot(new TimeSlot(freeTimeWindow.TimeSlot.EndTime - activityPoint.AvgSpendingTimeInHours - drivingTimeFromActivity, freeTimeWindow.TimeSlot.EndTime - drivingTimeFromActivity), activityPoint);
            }

            if (activityPoint.OpeningTime >= freeTimeWindow.TimeSlot.StartTime && activityPoint.OpeningTime + duration <= freeTimeWindow.TimeSlot.EndTime)
            {
                activityTimeSlot = new ActivityTimeSlot(new TimeSlot(activityPoint.OpeningTime + drivingTimeToActivity, activityPoint.OpeningTime + activityPoint.AvgSpendingTimeInHours + drivingTimeToActivity), activityPoint);
            }

            if (activityTimeSlot == null)
            {
                return(null);
            }

            var startTime = activityTimeSlot.TimeSlot.StartTime;
            var endTime   = activityTimeSlot.TimeSlot.EndTime;

            if (drivingTimeToActivity > 0)
            {
                activityPointAndTravel.Add(new ActivityTimeSlot(new TimeSlot(startTime - drivingTimeToActivity, startTime), null, true));
            }

            activityPointAndTravel.Add(activityTimeSlot);

            if (drivingTimeFromActivity > 0)
            {
                activityPointAndTravel.Add(new ActivityTimeSlot(new TimeSlot(endTime, endTime + drivingTimeFromActivity), null, true));
            }

            return(activityPointAndTravel);
        }
Esempio n. 3
0
 private void TimeSlotContextMenuOpened(object sender, RoutedEventArgs e)
 {
     _currentTimeSlot = ((sender as ContextMenu)?.PlacementTarget as FrameworkElement)?.Tag as ActivityTimeSlot;
 }