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);
        }
Beispiel #2
0
 /// <summary>
 ///     Конструктор.
 /// </summary>
 /// <param name="httpClient">Http-клиент.</param>
 /// <param name="memoryCache">Кэш.</param>
 public GetCalendarQuery(HttpClient httpClient, IMemoryCache memoryCache)
 {
     _memoryCache          = memoryCache;
     _raspTruIcalConverter = new RaspTruIcalConverter(httpClient, memoryCache, TimeSpan.FromHours(18));
 }