Example #1
0
        private async Task UpdateTaskCacheForListId(string listId, DateTime?lastSync, DateTime currentSync, bool includeCompletedTasks)
        {
            var response = await _taskApiClient.GetTasksByListIdAsync(listId, lastSync, includeCompletedTasks).ConfigureAwait(false);

            var tasks = _responseParser.GetTasks(response);

            if (lastSync != null)
            {
                await _taskCache.AddOrReplaceAsync(listId, tasks).ConfigureAwait(false);

                var deletedTasks = _responseParser.GetDeletedTasks(response);
                await _taskCache.RemoveAsync(deletedTasks).ConfigureAwait(false);
            }
            else
            {
                await _taskCache.AddOrReplaceAsync(listId, tasks, true).ConfigureAwait(false);
            }

            _syncTracker.SetLastSync(listId, currentSync);

            foreach (var task in tasks)
            {
                if (!task.ListId.Equals(listId))
                {
                    // The current list is not this task's master list.  We'll need to ensure that the master list is also synchronized so that we have
                    // all subtask information.
                    var masterListLastSync = _syncTracker.GetLastSync(task.ListId);
                    if (masterListLastSync == null || masterListLastSync.Value < currentSync)
                    {
                        await UpdateTaskCacheForListId(task.ListId, masterListLastSync, currentSync, includeCompletedTasks).ConfigureAwait(false);
                    }
                }
            }
        }