private MakabaEntityTree GetEntityTree(BoardEntity2 data)
 {
     var entity = new MakabaEntityTree()
     {
         Board = data.Board,
         BoardBannerImage = data.BoardBannerImage,
         BoardBannerLink = data.BoardBannerLink,
         BoardName = data.BoardName,
         BoardSpeed = string.IsNullOrWhiteSpace(data.BoardSpeed) ? "" : $"{data.BoardSpeed} п./час",
         CurrentPage = data.CurrentPage.TryParseWithDefault(),
         CurrentThread = data.CurrentThread.TryParseWithDefault(),
         Icons = data.Icons != null
             ? data.Icons.Select(i => new MakabaIconReference()
             {
                 Name = i.Name,
                 Number = i.NumberInt,
                 Url = i.Url
             }).OrderBy(i => i.Number).ToList()
             : null,
         Pages =
             data.Pages != null
                 ? data.Pages.Select(s => s.TryParseWithDefault(-1))
                     .Where(i => i >= 0)
                     .Distinct()
                     .OrderBy(i => i)
                     .ToList()
                 : null,
         IsBoard = data.IsBoard.TryParseWithDefault() != 0,
         IsIndex = data.IsIndex.TryParseWithDefault() != 0,
         ThreadTags = data.Tags != null ? data.Tags.Select(t => new ThreadTagLink()
         {
             Engine = CoreConstants.Engine.Makaba,
             Board = data.Board,
             Tag = t
         }).Where(t => t.Tag != null).OfType<BoardLinkBase>().ToList() : null
     };
     return entity;
 }
 /// <summary>
 /// Парсить данные треда.
 /// </summary>
 /// <param name="data">Данные.</param>
 /// <param name="link">Ссылка.</param>
 /// <returns>Результат.</returns>
 public ThreadTree ParseThread(BoardEntity2 data, ThreadLink link)
 {
     var entity = GetEntityTree(data);
     var result = new ThreadTree()
     {
         Link = link,
         ParentLink = new BoardLink()
         {
             Engine = CoreConstants.Engine.Makaba,
             Board = link.Board,
         },
         Extensions = new List<PostTreeCollectionExtension>(),
         Posts = data.Threads.SelectMany(p => p.Posts).OrderBy(p => p.Number.TryParseWithDefault()).Select(p => Parse(p, link, false)).ToList(),                
     };
     result.Extensions.Add(new MakabaCollectionExtension() { Entity = entity });
     for (int i = 0; i < result.Posts.Count; i++)
     {
         result.Posts[i].Counter = i + 1;
     }
     return result;
 }
 /// <summary>
 /// Парсить данные страницы борды.
 /// </summary>
 /// <param name="data">Данные.</param>
 /// <param name="link">Ссылка.</param>
 /// <returns>Результат.</returns>
 public BoardPageTree ParseBoardPage(BoardEntity2 data, BoardPageLink link)
 {
     var entity = GetEntityTree(data);
     var result = new BoardPageTree()
     {
         Extensions = new List<BoardPageTreeExtension>(),
         LastModified = null,
         Link = link,
         ParentLink = new RootLink()
         {
             Engine = CoreConstants.Engine.Makaba
         },
         PageNumber = link.Page,
         Threads = new List<ThreadPreviewTree>(),
         MaxPage = entity.Pages != null ? entity.Pages.OrderByDescending(p => p).Select(p => (int?)p).FirstOrDefault() : null,
     };
     result.Extensions.Add(new MakabaBoardPageExtension()
     {
         Entity = entity
     });
     if (data.Threads != null)
     {
         foreach (var t in data.Threads)
         {
             var posts = t.Posts.OrderBy(p => p.Number.TryParseWithDefault()).ToArray();
             var tnum = posts.First().Number.TryParseWithDefault();
             var tlink = new ThreadLink()
             {
                 Engine = CoreConstants.Engine.Makaba,
                 Board = link.Board,
                 Thread = tnum,
             };
             var thread = new ThreadPreviewTree()
             {
                 Extensions = new List<PostTreeCollectionExtension>(),
                 Link = tlink,
                 ParentLink = link,
                 ImageCount =
                     t.ImagesCount.TryParseWithDefault() +
                     posts.Sum(p => (p.Files ?? new BoardPostFile2[0]).Length),
                 Omit = t.PostsCount.TryParseWithDefault(),
                 OmitImages = t.ImagesCount.TryParseWithDefault(),
                 ReplyCount = Math.Max(t.PostsCount.TryParseWithDefault() + posts.Count(), 0),
                 Posts = posts.Select(p => Parse(p, tlink, true)).ToList(),
             };
             for (var i = 0; i < thread.Posts.Count; i++)
             {
                 thread.Posts[i].Flags |= PostFlags.ThreadPreview;
                 if (i == 0)
                 {
                     thread.Posts[i].Counter = 1;
                     thread.Posts[i].Flags |= PostFlags.ThreadPreviewOpPost;
                 }
                 else
                 {
                     var ni = thread.Posts.Count - i;
                     thread.Posts[i].Counter = thread.ReplyCount - ni;
                 }
             }
             result.Threads.Add(thread);
         }
     }
     return result;
 }