private HashSet <ArticleBlock> CreateBlocks(long articleId) { HashSet <ArticleBlock> result = new HashSet <ArticleBlock>(); TextBlock textBlock = new TextBlock(); textBlock.Text = "Some Text for " + articleId; textBlock.SortIndex = 0; result.Add(textBlock); ImageBlock imageBlock = new ImageBlock(); imageBlock.Image = CreateImage(1L); textBlock.SortIndex = 1; result.Add(imageBlock); TextBlock secondTextBlock = new TextBlock(); secondTextBlock.Text = "Second Text for " + articleId; secondTextBlock.SortIndex = 2; result.Add(secondTextBlock); GalleryBlock galleryBlock = new GalleryBlock(); secondTextBlock.SortIndex = 3; List <Image> galleryImages = new List <Image>(); galleryImages.Add(CreateImage(2L)); galleryImages.Add(CreateImage(3L)); galleryBlock.Images = galleryImages; result.Add(galleryBlock); TextBlock thirdTextBlock = new TextBlock(); thirdTextBlock.Text = "Third Text for " + articleId; thirdTextBlock.SortIndex = 4; result.Add(thirdTextBlock); VideoBlock videoBlock = new VideoBlock(); videoBlock.Type = VideoBlockType.YOUTUBE; videoBlock.Url = "https://youtu.be/myvideo"; videoBlock.SortIndex = 5; result.Add(videoBlock); return(result); }
private async Task ImportGalleryAsync(Export data, Site site, List <Post <string> > posts) { foreach (var cat in data.GalleryCats) { var textParts = new List <string>(); var current = cat; while (current != null) { textParts.Add(current.Title); if (current.CatId > 0) { current = data.GalleryCats.FirstOrDefault(c => c.Id == current.CatId); } else { current = null; } } textParts.Reverse(); var tags = new List <Tag>(); foreach (var text in textParts) { var tag = GetTag(text); tags.Add(tag); } var pics = data.GalleryPics.Where(p => p.CatId == cat.Id); foreach (var picsGroup in pics.GroupBy(p => p.Date.Date)) { var url = $"gallery_{picsGroup.First().Id.ToString()}"; var post = new Post <string> { Id = Guid.NewGuid(), Url = url, Title = cat.Title, DateAdded = picsGroup.First().Date, DateUpdated = picsGroup.First().Date, DatePublished = picsGroup.First().Date, IsPublished = true, AuthorId = picsGroup.First().AuthorId.ToString(), Blocks = new List <ContentBlock>() }; foreach (var galleryPicExport in picsGroup) { var pictures = new List <StorageItem>(); foreach (var picFile in galleryPicExport.Files) { var pic = await _filesUploader.UploadFromUrlAsync(picFile.Url, $"posts/{post.DateAdded.Year.ToString()}/{post.DateAdded.Month.ToString()}", picFile.FileName); if (pic != null) { pictures.Add(pic); } } if (pictures.Count == 1) { var block = new PictureBlock { Id = Guid.NewGuid(), Position = 1, Data = new PictureBlockData() }; var picFile = pictures[0]; var pic = await _filesUploader.UploadFromUrlAsync(picFile.PublicUri.ToString(), $"posts/{post.DateAdded.Year.ToString()}/{post.DateAdded.Month.ToString()}", picFile.FileName); if (pic != null) { block.Data.Picture = pic; post.Blocks.Add(block); } } else { var block = new GalleryBlock { Id = Guid.NewGuid(), Position = 1, Data = new GalleryBlockData() }; block.Data.Pictures = pictures.ToArray(); post.Blocks.Add(block); } if (!string.IsNullOrEmpty(galleryPicExport.Desc)) { post.Blocks.Add(new TextBlock { Id = Guid.NewGuid(), Position = 0, Data = new TextBlockData { Text = galleryPicExport.Desc } }); } } post.TagIds = tags.Select(t => t.Id).ToArray(); if (cat.GameId > 0) { var game = data.Games.FirstOrDefault(g => g.Id == cat.GameId); if (game != null) { post.SectionIds = new[] { _gamesMap[game.Id].Id }; post.SiteIds = _gamesMap[game.Id].SiteIds; } } if (cat.DeveloperId > 0) { var developer = data.Developers.FirstOrDefault(g => g.Id == cat.DeveloperId); if (developer != null) { post.SectionIds = new[] { _developersMap[developer.Id].Id }; post.SiteIds = _developersMap[developer.Id].SiteIds; } } if (cat.TopicId > 0) { var topic = data.Topics.FirstOrDefault(g => g.Id == cat.TopicId); if (topic != null) { post.SectionIds = new[] { _topicsMap[topic.Id].Id }; post.SiteIds = _topicsMap[topic.Id].SiteIds; } } posts.Add(post); RegisterRedirect(cat.FullUrl, _linkGenerator.GeneratePublicUrl(post, site).ToString()); } } }