Zetbox.Client.Presentables.Calendar.FetchCache.FetchEventsAsync C# (CSharp) Method

FetchEventsAsync() public method

public FetchEventsAsync ( System.DateTime from, System.DateTime to ) : ZbTask>
from System.DateTime
to System.DateTime
return ZbTask>
        public ZbTask<IEnumerable<EventViewModel>> FetchEventsAsync(DateTime from, DateTime to)
        {
            if (_calendars.Count == 0) return new ZbTask<IEnumerable<EventViewModel>>(ZbTask.Synchron, () => new List<EventViewModel>());

            // first -> the recurrence cache
            if (_recurrenceCache == null)
            {
                _recurrenceCache = MakeFetchTask(DateTime.MinValue, DateTime.MinValue);
            }

            // make primary task first
            var result = MakeFetchTask(from, to);
            result.OnResult(t =>
            {
                var range = (to - from);
                MakeFetchTask(from - range, to - range);
                MakeFetchTask(from + range, to + range);
            })
            .OnResult(t =>
            {
                t.Result = t.Result.Union(_recurrenceCache.Result);
            });

            return result;
        }