Example #1
0
        private async Task <ActivitySchedule> RetrieveActivityScheduleFromCache(string babyId)
        {
            ActivitySchedule activitySchedule = null;
            var cache = await activityScheduleCache.Value;

            cache.TryGetValue(babyId, out activitySchedule);
            return(activitySchedule);
        }
Example #2
0
        private async Task SaveActivityScheduleToCache(ActivitySchedule schedule, string babyId)
        {
            var cache = await activityScheduleCache.Value;

            cache[babyId] = schedule;
            var cacheFile = await activityScheduleCacheFile.Value;
            await activityScheduleSemaphore.WaitAsync();

            try
            {
                await cacheFile.WriteJsonToFile(typeof(Dictionary <string, ActivitySchedule>),
                                                cache);
            }
            finally
            {
                activityScheduleSemaphore.Release();
            }
        }
 private bool AnyActivityHasExpired(ActivitySchedule activitySchedule)
 {
     return(activitySchedule.NextChangeDueAt <= DateTimeOffset.Now ||
            activitySchedule.NextFeedDueAt <= DateTimeOffset.Now ||
            activitySchedule.NextSleepDueAt <= DateTimeOffset.Now);
 }
Example #4
0
 public IAsyncAction SaveActivitySchedule(ActivitySchedule schedule, string babyId)
 {
     return(SaveActivityScheduleToCache(schedule, babyId).AsAsyncAction());
 }