private static void AddCalendarEventsToMatrix(Calendar cal, Color color,
                                                      ref CalendarDayEntity[,] calendarMatrix)
        {
            var firstMonday = DateTime.Today.AddDays(-7).StartOfWeek(DayOfWeek.Monday);

            for (var deltaDay = 0; deltaDay < 5 * 7; deltaDay++)
            {
                var day           = firstMonday.AddDays(deltaDay);
                var eventEntities = cal.Events
                                    .Where(x => x.DtStart.Date == day.Date)
                                    .Select(x => new CalendarEventEntity
                {
                    Color = color,
                    Date  = x.DtStart.AsSystemLocal,
                    Name  = x.Name,
                    Place = x.Location
                })
                                    .OrderBy(x => x.Date)
                                    .ToList();


                if (calendarMatrix[deltaDay / 7, deltaDay % 7] == null)
                {
                    calendarMatrix[deltaDay / 7, deltaDay % 7] = new CalendarDayEntity
                    {
                        Date   = day,
                        Events = new List <CalendarEventEntity>()
                    }
                }
                ;

                calendarMatrix[deltaDay / 7, deltaDay % 7].Events.AddRange(eventEntities);
            }
        }
    }
        private CalendarDayEntity[,] GetCalendarMatrix()
        {
            var calendarMatrix = new CalendarDayEntity[5, 7];

            List <(Task <Calendar>, Color)> tasks = new List <(Task <Calendar>, Color)>();

            foreach (var(_, color, link) in CalendarSources.Sources)
            {
                var task = Task.Run(() =>
                {
                    Calendar calendar;
                    if (link == string.Empty)
                    {
                        calendar = new RaspTruIcalConverter(HttpClient)
                                   .GetByLink(EliteRoomUrl, 1, 3);
                    }
                    else
                    {
                        var iCalendarString = HttpClient.GetStringAsync(link).Result;
                        calendar            = Calendar.Load(iCalendarString);
                    }

                    return(calendar);
                });

                tasks.Add((task, color));
            }

            Task.WaitAll(tasks.Select(x => x.Item1).ToArray <Task>());
            foreach (var(task, color) in tasks)
            {
                AddCalendarEventsToMatrix(task.Result, color, ref calendarMatrix);
            }

            return(calendarMatrix);
        }