Пример #1
0
        public async Task ReminderDeliveryAsync(string userId, ReminderDelivery reminderDelivery)
        {
            if (!reminderDelivery.Removed)
            {
                await logger.LogForUser(userId, $"Received reminder for {reminderDelivery.Event.Subject}");
            }
            else
            {
                await logger.LogForUser(userId, $"Received reminder removed");
            }
            var syncResult = await focusCalendarSyncService.SyncAsync(userId, DateTimeOffset.Now,
                                                                      DateTimeOffset.Now + FocusConstants.FocusScanTime + FocusConstants.CalendarServiceInacurracy);

            var lastLocation = await locationService.GetLastLocationAsync(userId);

            var res = await focusUpdateService.Update(userId, new FocusUpdateRequest()
            {
                ItemSyncResult = syncResult,
                Location       = lastLocation
            });

            // for now request anyway, there item might be unchanged due to planner
            await locationService.RequestLocationAsync(userId, DateTimeOffset.Now, res);
        }
Пример #2
0
        public async Task<Plan> GetPlan(string userId, DateTimeOffset from, DateTimeOffset to)
        {

            string start = "#home";

            var syncResult = await _focusCalendarSyncService.SyncAsync(userId, from, to);
            var items = (await _focusStore.GetTimeRangeAsync(userId, from, to)).OrderBy(d => d.Start);
            var directionsList = new List<DirectionsResult>();
            var focusItemsList = new List<FocusItem>();
            DateTimeOffset? getup = null;
            bool first = true;
            foreach (var e in items)
            {
                var calendarItem = syncResult.Events.Where(c => c.Id == e.CalendarEventId && c.FeedId == e.CalendarEventFeedId).SingleOrDefault();
                if (null != calendarItem)
                {
                    if (first)
                    {

                    }
                    focusItemsList.Add(e);
                    var address = calendarItem.GetFormattedAddress();
                    if (!string.IsNullOrEmpty(address))
                    {
                        var directions = await _travelServiceClient.Users[userId]
                            .Directions.Transit.Get(start, address, calendarItem.Start);
                        var route = DirectionUtils.SelectRoute(directions);
                        if (null == directions.NotFound)
                        {
                            if (first)
                            {
                                getup = route.DepatureTime - TimeSpan.FromHours(1);
                            }
                            directionsList.Add(directions);
                            await _focusStore.UpdateDirections(e.Id, directions, 0);
                            await _focusStore.UpdateIndicateTime(e.Id, route.DepatureTime);
                            e.IndicateTime = route.DepatureTime;
                            e.DirectionsMetadata = new DirectionsMetadata()
                            {
                                Error = directions.NotFound?.Reason,
                                Key = directions.CacheKey,
                                PeferredRoute = 0,
                                TravelStatus = TravelStatus.UnStarted
                            };
                        }
                        else
                        {
                            await _focusStore.UpdateDirections(e.Id, directions, null);
                            e.DirectionsMetadata = new DirectionsMetadata()
                            {
                                Error = directions.NotFound?.Reason,
                                Key = directions.CacheKey,
                                PeferredRoute = 0,
                                TravelStatus = TravelStatus.UnStarted
                            };
                        }
                        start = address;
                    }
                    first = false;
                }
            }
            var plan = new Plan()
            {
                Events = syncResult.Events,
                Directions = directionsList.ToArray(),
                FocusItems = items.ToArray(),
                GetUp = getup
            };
            return plan;
        }