feat : add version 0.24.27.47 , complete site-maps , complete slugs

release
Amir Hossein Khademi 2024-04-23 23:57:52 +03:30
parent 4e2aec8e2c
commit 8679140b4b
19 changed files with 614 additions and 365 deletions

View File

@ -1 +1 @@
0.23.26.46
0.24.27.47

View File

@ -17,7 +17,7 @@
"TaxesFee": 9
},
"SiteSettings": {
"BaseUrl": "https://api.hamyan.visabartar.com",
"BaseUrl": "http://192.168.1.12:32770",
"WebSiteUrl": "https://hamyan.visabartar.com",
"AdminPanelBaseUrl": "https://admin.hamyan.visabartar.com",
"StorageBaseUrl": "https://storage.visabartar.com",

View File

@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"PostgresServer": "Host=185.220.227.88;Username=vesmmehAgent;Password=g05CTjK358Vx3Eoc9satsWyVwo+15UmsA2dnCrZRUYh1pLTe;Database=NetinaShopDB;Application Name=NetinaShopApi",
"PostgresServer": "Host=185.220.227.107;Username=vesmmehAgent;Password=g05CTjK358Vx3Eoc9satsWyVwo+15UmsA2dnCrZRUYh1pLTe;Database=NetinaShopDB;Application Name=NetinaShopApi",
"Postgres": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=NetinaShopDB;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS",
"MartenDB": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=NetinaShopMartenDB;"
},

View File

@ -17,7 +17,7 @@ public class HealthController : ICarterModule
public async Task<IResult> GetHealth([FromServices]ISiteMapService siteMapService)
{
//await siteMapService.CreateSiteMapAsync();
await siteMapService.CreateSiteMapAsync();
var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
var check = new HealthCheck
{

View File

@ -34,7 +34,7 @@ public class SeedController : ICarterModule
.WithDisplayName("SeedBlogsAsync")
.HasApiVersion(1.0);
group.MapPost("blog/categories", SeedBlogCategoriesSlugAsync)
group.MapPost("blog/categories", SeedBlogCategoriesAsync)
.WithDisplayName("SeedBlogCategoriesAsync")
.HasApiVersion(1.0);
}
@ -147,28 +147,6 @@ public class SeedController : ICarterModule
categories.Add(requestDto.BaseCategoryId, ent.Id);
}
return TypedResults.Ok(categories);
}
public async Task<IResult> SeedBlogCategoriesSlugAsync([FromBody] List<SeedBlogCategoryRequestDto> request, [FromQuery] string key, [FromServices] IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
{
if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==")
throw new AppException("Key is not valid", ApiResultStatusCode.UnAuthorized);
Dictionary<int, Guid> categories = new Dictionary<int, Guid>();
foreach (var requestDto in request)
{
var ent = await repositoryWrapper.SetRepository<BlogCategory>()
.TableNoTracking
.FirstOrDefaultAsync(bc=>bc.Name==requestDto.Name,cancellationToken);
if (ent == null)
continue;
ent.Slug = requestDto.Slug;
repositoryWrapper.SetRepository<BlogCategory>().Update(ent);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
categories.Add(requestDto.BaseCategoryId, ent.Id);
}
return TypedResults.Ok(categories);
}
}

View File

@ -6,8 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<AssemblyVersion>0.23.26.46</AssemblyVersion>
<FileVersion>0.23.26.46</FileVersion>
<AssemblyVersion>0.24.27.47</AssemblyVersion>
<FileVersion>0.24.27.47</FileVersion>
</PropertyGroup>
<ItemGroup>

View File

@ -3,6 +3,7 @@ using System.Web;
using System.Xml;
using Netina.Core.Models;
using Netina.Domain.Entities.Blogs;
using Netina.Domain.Entities.Brands;
using Netina.Domain.Entities.ProductCategories;
using Netina.Domain.Entities.Products;
@ -36,7 +37,11 @@ public class SiteMapService : ISiteMapService
doc.AppendChild(root);
var categories = await _repositoryWrapper.SetRepository<ProductCategory>()
var productCategories = await _repositoryWrapper.SetRepository<ProductCategory>()
.TableNoTracking
.ToListAsync();
var blogCategories= await _repositoryWrapper.SetRepository<BlogCategory>()
.TableNoTracking
.ToListAsync();
@ -54,14 +59,29 @@ public class SiteMapService : ISiteMapService
siteMapElement.AppendChild(lastmod);
}
foreach (var category in categories)
foreach (var blogCategory in blogCategories)
{
XmlElement siteMapElement = doc.CreateElement("sitemap", doc.DocumentElement?.NamespaceURI);
root.AppendChild(siteMapElement);
XmlElement id = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
id.InnerText = Path.Combine(_siteSetting.StorageBaseUrl, "site-maps", $"{category.Id.ToString().ToUpper()}.gz");
id.InnerText = Path.Combine(_siteSetting.StorageBaseUrl, "site-maps", $"{blogCategory.Id.ToString().ToUpper()}.gz");
siteMapElement.AppendChild(id);
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
lastmod.InnerText = DateTime.Today.ToString("yyyy-MM-dd");
siteMapElement.AppendChild(lastmod);
}
foreach (var productCategory in productCategories)
{
XmlElement siteMapElement = doc.CreateElement("sitemap", doc.DocumentElement?.NamespaceURI);
root.AppendChild(siteMapElement);
XmlElement id = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
id.InnerText = Path.Combine(_siteSetting.StorageBaseUrl, "site-maps", $"{productCategory.Id.ToString().ToUpper()}.gz");
siteMapElement.AppendChild(id);
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
@ -86,10 +106,81 @@ public class SiteMapService : ISiteMapService
await CreateCategoriesSiteMapsAsync();
await CreateProductsSiteMapsAsync();
await CreateBlogsSiteMapsAsync();
await CreateBrandsSiteMapsAsync();
await CreateBlogCategoriesSiteMapsAsync();
}
private async Task CreateBrandsSiteMapsAsync()
{
var siteMapsUId = SiteMapUIds.Brands;
var brands = await _repositoryWrapper.SetRepository<Brand>()
.TableNoTracking
.ToListAsync();
XmlDocument doc = new XmlDocument();
XmlDeclaration documentType = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(documentType);
//XmlNode declaration = doc.CreateNode(XmlNodeType.XmlDeclaration, "sitemap.xml", null);
//doc.AppendChild(declaration);
XmlElement root = doc.CreateElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
root.SetAttribute("xmlns:image", "http://www.google.com/schemas/sitemap-image/1.1");
doc.AppendChild(root);
foreach (var brand in brands)
{
var productUrl = $"{_siteSetting.WebSiteUrl}/brands/{brand.Id}/{brand.Slug}";
XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI);
root.AppendChild(urlElement);
XmlElement loc = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
loc.InnerText = Path.Combine(productUrl);
urlElement.AppendChild(loc);
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
lastmod.InnerText = brand.ModifiedAt == DateTime.MinValue ? brand.CreatedAt.ToString("yyyy-MM-dd") : brand.ModifiedAt.ToString("yyyy-MM-dd");
urlElement.AppendChild(lastmod);
XmlElement changeFeq = doc.CreateElement("changefreq", doc.DocumentElement?.NamespaceURI);
changeFeq.InnerText = "daily";
urlElement.AppendChild(changeFeq);
XmlElement priority = doc.CreateElement("priority", doc.DocumentElement?.NamespaceURI);
priority.InnerText = "0.9";
urlElement.AppendChild(priority);
}
using var siteMapStream = new MemoryStream();
await using var siteMapWriter = new XmlTextWriter(siteMapStream, Encoding.UTF8);
doc.WriteTo(siteMapWriter);
siteMapWriter.Flush();
byte[] unZipBytes = siteMapStream.ToArray();
using (var compressedStream = new MemoryStream())
await using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress))
{
zipStream.Write(unZipBytes, 0, unZipBytes.Length);
zipStream.Close();
var siteMapArray = compressedStream.ToArray();
await _uploadFileService.UploadFileByteAsync(new FileUploadRequest
{
FileBytes = siteMapArray,
ContentType = "text/plain",
FileName = $"{siteMapsUId}.gz",
FileUploadType = FileUploadType.SiteMap,
});
}
}
private async Task CreateCategoriesSiteMapsAsync()
{
var siteMapsUId = SiteMapUIds.Categories;
@ -111,12 +202,12 @@ public class SiteMapService : ISiteMapService
foreach (var productCategory in categories)
{
var productUrl = $"{_siteSetting.WebSiteUrl}/categories/{productCategory.Id}/{HttpUtility.UrlEncode(productCategory.Name.Replace(' ', '-'))}";
var productUrl = $"{_siteSetting.WebSiteUrl}/categories/{productCategory.Id}/{productCategory.Slug}";
XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI);
root.AppendChild(urlElement);
XmlElement loc = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
loc.InnerText = Path.Combine(productCategory.Name);
loc.InnerText = Path.Combine(productUrl);
urlElement.AppendChild(loc);
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
@ -254,13 +345,139 @@ public class SiteMapService : ISiteMapService
private async Task CreateBlogsSiteMapsAsync()
{
var siteMapsUId = SiteMapUIds.Blogs;
var blogs = await _repositoryWrapper.SetRepository<Blog>()
.TableNoTracking
.Select(BlogMapper.ProjectToSDto)
.ToListAsync();
var groupedProducts = blogs.GroupBy(p => p.CategoryId);
foreach (var group in groupedProducts)
{
XmlDocument doc = new XmlDocument();
XmlDeclaration documentType = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(documentType);
//XmlNode declaration = doc.CreateNode(XmlNodeType.XmlDeclaration, "sitemap.xml", null);
//doc.AppendChild(declaration);
XmlElement root = doc.CreateElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
root.SetAttribute("xmlns:image", "http://www.google.com/schemas/sitemap-image/1.1");
//root.SetAttribute("xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9");
doc.AppendChild(root);
foreach (var blog in group)
{
XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI);
root.AppendChild(urlElement);
XmlElement loc = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
loc.InnerText = Path.Combine($"{_siteSetting.WebSiteUrl}/blogs/{blog.Id}/{blog.Slug}");
urlElement.AppendChild(loc);
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
lastmod.InnerText = blog.ModifiedAt == DateTime.MinValue
? blog.CreatedAt.ToString("yyyy-MM-dd")
: blog.ModifiedAt.ToString("yyyy-MM-dd");
urlElement.AppendChild(lastmod);
XmlElement changeFeq = doc.CreateElement("changefreq", doc.DocumentElement?.NamespaceURI);
changeFeq.InnerText = "daily";
urlElement.AppendChild(changeFeq);
XmlElement priority = doc.CreateElement("priority", doc.DocumentElement?.NamespaceURI);
priority.InnerText = "0.9";
urlElement.AppendChild(priority);
//Image
if (blog.MainImage != string.Empty)
{
XmlElement image =
doc.CreateElement("image:image", "http://www.google.com/schemas/sitemap-image/1.1");
urlElement.AppendChild(image);
XmlElement imageLoc =
doc.CreateElement("image:loc", "http://www.google.com/schemas/sitemap-image/1.1");
imageLoc.InnerText = $"{_siteSetting.StorageBaseUrl}/{blog.MainImage.Replace("Med", "Thumb")}";
image.AppendChild(imageLoc);
XmlElement imageCaption = doc.CreateElement("image:caption",
"http://www.google.com/schemas/sitemap-image/1.1");
imageCaption.InnerText = blog.Title;
image.AppendChild(imageCaption);
}
////News
//XmlElement news = doc.CreateElement("news:news", "http://www.google.com/schemas/sitemap-news/0.9");
//urlElement.AppendChild(news);
//XmlElement newTitle = doc.CreateElement("news:title", "http://www.google.com/schemas/sitemap-news/0.9");
//newTitle.InnerText = blog.Title;
//news.AppendChild(newTitle);
//XmlElement newPublificationDate = doc.CreateElement("news:publication_date", "http://www.google.com/schemas/sitemap-news/0.9");
//newPublificationDate.InnerText = blog.CreatedAt.ToString("yyyy-MM-dd");
//news.AppendChild(newPublificationDate);
//XmlElement newsPublification = doc.CreateElement("news:publication", "http://www.google.com/schemas/sitemap-news/0.9");
//news.AppendChild(newsPublification);
//XmlElement newsPublicationName = doc.CreateElement("news:name", "http://www.google.com/schemas/sitemap-news/0.9");
//newsPublicationName.InnerText = blog.Title;
//newsPublification.AppendChild(newsPublicationName);
//XmlElement newsPublicationLanq = doc.CreateElement("news:language", "http://www.google.com/schemas/sitemap-news/0.9");
//newsPublicationLanq.InnerText = blog.CreatedAt.ToString("yyyy-MM-dd");
//newsPublification.AppendChild(newsPublicationLanq);
}
using var siteMapStream = new MemoryStream();
await using var siteMapWriter = new XmlTextWriter(siteMapStream, Encoding.UTF8);
doc.WriteTo(siteMapWriter);
siteMapWriter.Flush();
byte[] unZipBytes = siteMapStream.ToArray();
using (var compressedStream = new MemoryStream())
await using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress))
{
zipStream.Write(unZipBytes, 0, unZipBytes.Length);
zipStream.Close();
var siteMapArray = compressedStream.ToArray();
await _uploadFileService.UploadFileByteAsync(new FileUploadRequest
{
FileBytes = siteMapArray,
ContentType = "text/plain",
FileName = $"{group.Key.ToString().ToUpper()}.gz",
FileUploadType = FileUploadType.SiteMap,
});
}
}
}
private async Task CreateBlogCategoriesSiteMapsAsync()
{
var siteMapsUId = SiteMapUIds.BlogCategories;
var blogCategories = await _repositoryWrapper.SetRepository<BlogCategory>()
.TableNoTracking
.ToListAsync();
XmlDocument doc = new XmlDocument();
XmlDeclaration documentType = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(documentType);
@ -273,17 +490,17 @@ public class SiteMapService : ISiteMapService
root.SetAttribute("xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9");
doc.AppendChild(root);
foreach (var blog in blogs)
foreach (var blogCategory in blogCategories)
{
XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI);
root.AppendChild(urlElement);
XmlElement loc = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
loc.InnerText = Path.Combine($"{_siteSetting.WebSiteUrl}/blogs/{blog.Id}/{blog.Slug}");
loc.InnerText = Path.Combine($"{_siteSetting.WebSiteUrl}/blogs/{blogCategory.Id}/{blogCategory.Slug}");
urlElement.AppendChild(loc);
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
lastmod.InnerText = blog.ModifiedAt == DateTime.MinValue ? blog.CreatedAt.ToString("yyyy-MM-dd") : blog.ModifiedAt.ToString("yyyy-MM-dd");
lastmod.InnerText = blogCategory.ModifiedAt == DateTime.MinValue ? blogCategory.CreatedAt.ToString("yyyy-MM-dd") : blogCategory.ModifiedAt.ToString("yyyy-MM-dd");
urlElement.AppendChild(lastmod);
@ -296,47 +513,6 @@ public class SiteMapService : ISiteMapService
priority.InnerText = "0.9";
urlElement.AppendChild(priority);
//Image
XmlElement image = doc.CreateElement("image:image", "http://www.google.com/schemas/sitemap-image/1.1");
urlElement.AppendChild(image);
XmlElement imageLoc = doc.CreateElement("image:loc", "http://www.google.com/schemas/sitemap-image/1.1");
imageLoc.InnerText = $"{_siteSetting.StorageBaseUrl}/{blog.MainImage.Replace("Med", "Thumb")}";
image.AppendChild(imageLoc);
XmlElement imageCaption = doc.CreateElement("image:caption", "http://www.google.com/schemas/sitemap-image/1.1");
imageCaption.InnerText = blog.Title;
image.AppendChild(imageCaption);
////News
//XmlElement news = doc.CreateElement("news:news", "http://www.google.com/schemas/sitemap-news/0.9");
//urlElement.AppendChild(news);
//XmlElement newTitle = doc.CreateElement("news:title", "http://www.google.com/schemas/sitemap-news/0.9");
//newTitle.InnerText = blog.Title;
//news.AppendChild(newTitle);
//XmlElement newPublificationDate = doc.CreateElement("news:publication_date", "http://www.google.com/schemas/sitemap-news/0.9");
//newPublificationDate.InnerText = blog.CreatedAt.ToString("yyyy-MM-dd");
//news.AppendChild(newPublificationDate);
//XmlElement newsPublification = doc.CreateElement("news:publication", "http://www.google.com/schemas/sitemap-news/0.9");
//news.AppendChild(newsPublification);
//XmlElement newsPublicationName = doc.CreateElement("news:name", "http://www.google.com/schemas/sitemap-news/0.9");
//newsPublicationName.InnerText = blog.Title;
//newsPublification.AppendChild(newsPublicationName);
//XmlElement newsPublicationLanq = doc.CreateElement("news:language", "http://www.google.com/schemas/sitemap-news/0.9");
//newsPublicationLanq.InnerText = blog.CreatedAt.ToString("yyyy-MM-dd");
//newsPublification.AppendChild(newsPublicationLanq);
}
using var siteMapStream = new MemoryStream();

View File

@ -2,11 +2,15 @@
public static class SiteMapUIds
{
public const string Categories = "5709ACC29A4D42E5B6F2DFFAD2FB0018";
public const string Brands = "662AF2DC6A2746FA88191F1F3DA94164";
public const string Blogs = "4C2F0C2A7A3E41268702D12FDDDB837F";
public const string BlogCategories = "B5FF333DC4FF4BB4A309CE3AA32CE45A";
public static List<string> AllSiteMapsUIds => new List<string>
{
BlogCategories,
Categories,
Blogs
Blogs,
Brands
};
}

View File

@ -8,6 +8,7 @@ public class BlogLDto : BaseDto<BlogLDto , Blog>
public string Slug { get; set; } = string.Empty;
public int ReadingTime { get; set; }
public string Summery { get; set; } = string.Empty;
public string MainImage { get; set; } = string.Empty;
public bool IsSuggested { get; set; }
public Guid CategoryId { get; set; }
public string CategoryName { get; set; } = string.Empty;

View File

@ -24,7 +24,7 @@ public partial class Blog : ApiEntity
}
public string Title { get; internal set; } = string.Empty;
public string Content { get; internal set; } = string.Empty;
public string Slug { get; set; } = string.Empty;
public string Slug { get; internal set; } = string.Empty;
public string Tags { get; internal set; } = string.Empty;
public int ReadingTime { get; internal set; }
public string Summery { get; internal set; } = string.Empty;

View File

@ -17,7 +17,7 @@ public partial class BlogCategory : ApiEntity
Description = description;
}
public string Name { get; internal set; } = string.Empty;
public string Slug { get; set; } = string.Empty;
public string Slug { get; internal set; } = string.Empty;
public string Description { get; internal set; } = string.Empty;
public List<Blog> Blogs { get; internal set; } = new();
}

View File

@ -23,7 +23,7 @@ public partial class Brand : ApiEntity
}
public string PersianName { get; internal set; } = string.Empty;
public string EnglishName { get; internal set; } = string.Empty;
public string Slug { get; set; } = string.Empty;
public string Slug { get; internal set; } = string.Empty;
public string Description { get; internal set; } = string.Empty;
public bool HasSpecialPage { get; internal set; }
public string PageUrl { get; internal set; } = string.Empty;

View File

@ -19,7 +19,7 @@ public partial class ProductCategory : ApiEntity
IsMain = isMain;
}
public string Name { get; internal set; } = string.Empty;
public string Slug { get; set; } = string.Empty;
public string Slug { get; internal set; } = string.Empty;
public string Description { get; internal set; } = string.Empty;
public bool IsMain { get; set; }

View File

@ -49,7 +49,7 @@ public partial class Product : ApiEntity
}
public string PersianName { get; internal set; } = string.Empty;
public string EnglishName { get; internal set; } = string.Empty;
public string Slug { get; set; } = string.Empty;
public string Slug { get; internal set; } = string.Empty;
public string Summery { get; internal set; } = string.Empty;
public string ExpertCheck { get; internal set; } = string.Empty;
public string Tags { get; internal set; } = string.Empty;

View File

@ -23,6 +23,11 @@ namespace Netina.Domain.Mappers
Summery = p1.Summery,
IsSuggested = p1.IsSuggested,
CategoryId = p1.CategoryId,
Category = new BlogCategory()
{
Name = p1.CategoryName,
Id = p1.CategoryId
},
Files = funcMain1(p1.Files),
Id = p1.Id,
CreatedAt = p1.CreatedAt
@ -44,199 +49,208 @@ namespace Netina.Domain.Mappers
result.Summery = p3.Summery;
result.IsSuggested = p3.IsSuggested;
result.CategoryId = p3.CategoryId;
result.Files = funcMain2(p3.Files, result.Files);
result.Category = funcMain2(new Never(), result.Category, p3);
result.Files = funcMain3(p3.Files, result.Files);
result.Id = p3.Id;
result.CreatedAt = p3.CreatedAt;
return result;
}
public static Expression<Func<BlogLDto, Blog>> ProjectToBlog => p7 => new Blog()
public static Expression<Func<BlogLDto, Blog>> ProjectToBlog => p9 => new Blog()
{
Title = p7.Title,
Content = p7.Content,
Slug = p7.Slug,
Tags = p7.Tags,
ReadingTime = p7.ReadingTime,
Summery = p7.Summery,
IsSuggested = p7.IsSuggested,
CategoryId = p7.CategoryId,
Files = p7.Files.Select<StorageFileSDto, BlogStorageFile>(p8 => new BlogStorageFile()
Title = p9.Title,
Content = p9.Content,
Slug = p9.Slug,
Tags = p9.Tags,
ReadingTime = p9.ReadingTime,
Summery = p9.Summery,
IsSuggested = p9.IsSuggested,
CategoryId = p9.CategoryId,
Category = new BlogCategory()
{
Name = p8.Name,
FileLocation = p8.FileLocation,
FileName = p8.FileName,
IsHeader = p8.IsHeader,
IsPrimary = p8.IsPrimary,
FileType = p8.FileType,
Id = p8.Id,
CreatedAt = p8.CreatedAt
Name = p9.CategoryName,
Id = p9.CategoryId
},
Files = p9.Files.Select<StorageFileSDto, BlogStorageFile>(p10 => new BlogStorageFile()
{
Name = p10.Name,
FileLocation = p10.FileLocation,
FileName = p10.FileName,
IsHeader = p10.IsHeader,
IsPrimary = p10.IsPrimary,
FileType = p10.FileType,
Id = p10.Id,
CreatedAt = p10.CreatedAt
}).ToList<BlogStorageFile>(),
Id = p7.Id,
CreatedAt = p7.CreatedAt
Id = p9.Id,
CreatedAt = p9.CreatedAt
};
public static BlogLDto AdaptToLDto(this Blog p9)
public static BlogLDto AdaptToLDto(this Blog p11)
{
return p9 == null ? null : new BlogLDto()
return p11 == null ? null : new BlogLDto()
{
Title = p9.Title,
Content = p9.Content,
Tags = p9.Tags,
Slug = p9.Slug,
ReadingTime = p9.ReadingTime,
Summery = p9.Summery,
IsSuggested = p9.IsSuggested,
CategoryId = p9.CategoryId,
CategoryName = p9.Category == null ? null : p9.Category.Name,
Files = funcMain3(p9.Files),
Id = p9.Id,
CreatedAt = p9.CreatedAt
Title = p11.Title,
Content = p11.Content,
Tags = p11.Tags,
Slug = p11.Slug,
ReadingTime = p11.ReadingTime,
Summery = p11.Summery,
MainImage = p11.Files.Count > 0 && p11.Files.Any<BlogStorageFile>(funcMain4) ? p11.Files.FirstOrDefault<BlogStorageFile>(funcMain5).FileName : string.Empty,
IsSuggested = p11.IsSuggested,
CategoryId = p11.CategoryId,
CategoryName = p11.Category == null ? null : p11.Category.Name,
Files = funcMain6(p11.Files),
Id = p11.Id,
CreatedAt = p11.CreatedAt
};
}
public static BlogLDto AdaptTo(this Blog p11, BlogLDto p12)
public static BlogLDto AdaptTo(this Blog p13, BlogLDto p14)
{
if (p11 == null)
if (p13 == null)
{
return null;
}
BlogLDto result = p12 ?? new BlogLDto();
BlogLDto result = p14 ?? new BlogLDto();
result.Title = p11.Title;
result.Content = p11.Content;
result.Tags = p11.Tags;
result.Slug = p11.Slug;
result.ReadingTime = p11.ReadingTime;
result.Summery = p11.Summery;
result.IsSuggested = p11.IsSuggested;
result.CategoryId = p11.CategoryId;
result.CategoryName = p11.Category == null ? null : p11.Category.Name;
result.Files = funcMain4(p11.Files, result.Files);
result.Id = p11.Id;
result.CreatedAt = p11.CreatedAt;
result.Title = p13.Title;
result.Content = p13.Content;
result.Tags = p13.Tags;
result.Slug = p13.Slug;
result.ReadingTime = p13.ReadingTime;
result.Summery = p13.Summery;
result.MainImage = p13.Files.Count > 0 && p13.Files.Any<BlogStorageFile>(funcMain4) ? p13.Files.FirstOrDefault<BlogStorageFile>(funcMain5).FileName : string.Empty;
result.IsSuggested = p13.IsSuggested;
result.CategoryId = p13.CategoryId;
result.CategoryName = p13.Category == null ? null : p13.Category.Name;
result.Files = funcMain7(p13.Files, result.Files);
result.Id = p13.Id;
result.CreatedAt = p13.CreatedAt;
return result;
}
public static Expression<Func<Blog, BlogLDto>> ProjectToLDto => p15 => new BlogLDto()
public static Expression<Func<Blog, BlogLDto>> ProjectToLDto => p17 => new BlogLDto()
{
Title = p15.Title,
Content = p15.Content,
Tags = p15.Tags,
Slug = p15.Slug,
ReadingTime = p15.ReadingTime,
Summery = p15.Summery,
IsSuggested = p15.IsSuggested,
CategoryId = p15.CategoryId,
CategoryName = p15.Category.Name,
Files = p15.Files.Select<BlogStorageFile, StorageFileSDto>(p16 => new StorageFileSDto()
Title = p17.Title,
Content = p17.Content,
Tags = p17.Tags,
Slug = p17.Slug,
ReadingTime = p17.ReadingTime,
Summery = p17.Summery,
MainImage = p17.Files.Count > 0 && p17.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p17.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
IsSuggested = p17.IsSuggested,
CategoryId = p17.CategoryId,
CategoryName = p17.Category.Name,
Files = p17.Files.Select<BlogStorageFile, StorageFileSDto>(p18 => new StorageFileSDto()
{
Name = p16.Name,
FileLocation = p16.FileLocation,
FileName = p16.FileName,
IsHeader = p16.IsHeader,
IsPrimary = p16.IsPrimary,
FileType = p16.FileType,
Id = p16.Id
Name = p18.Name,
FileLocation = p18.FileLocation,
FileName = p18.FileName,
IsHeader = p18.IsHeader,
IsPrimary = p18.IsPrimary,
FileType = p18.FileType,
Id = p18.Id
}).ToList<StorageFileSDto>(),
Id = p15.Id,
CreatedAt = p15.CreatedAt
Id = p17.Id,
CreatedAt = p17.CreatedAt
};
public static Blog AdaptToBlog(this BlogSDto p17)
public static Blog AdaptToBlog(this BlogSDto p19)
{
return p17 == null ? null : new Blog()
return p19 == null ? null : new Blog()
{
Title = p17.Title,
Slug = p17.Slug,
Tags = p17.Tags,
ReadingTime = p17.ReadingTime,
Summery = p17.Summery,
IsSuggested = p17.IsSuggested,
CategoryId = p17.CategoryId,
Title = p19.Title,
Slug = p19.Slug,
Tags = p19.Tags,
ReadingTime = p19.ReadingTime,
Summery = p19.Summery,
IsSuggested = p19.IsSuggested,
CategoryId = p19.CategoryId,
Category = new BlogCategory()
{
Name = p17.CategoryName,
Id = p17.CategoryId
Name = p19.CategoryName,
Id = p19.CategoryId
},
Id = p17.Id,
CreatedAt = p17.CreatedAt,
ModifiedAt = p17.ModifiedAt
Id = p19.Id,
CreatedAt = p19.CreatedAt,
ModifiedAt = p19.ModifiedAt
};
}
public static Blog AdaptTo(this BlogSDto p18, Blog p19)
public static Blog AdaptTo(this BlogSDto p20, Blog p21)
{
if (p18 == null)
if (p20 == null)
{
return null;
}
Blog result = p19 ?? new Blog();
Blog result = p21 ?? new Blog();
result.Title = p18.Title;
result.Slug = p18.Slug;
result.Tags = p18.Tags;
result.ReadingTime = p18.ReadingTime;
result.Summery = p18.Summery;
result.IsSuggested = p18.IsSuggested;
result.CategoryId = p18.CategoryId;
result.Category = funcMain5(new Never(), result.Category, p18);
result.Id = p18.Id;
result.CreatedAt = p18.CreatedAt;
result.ModifiedAt = p18.ModifiedAt;
result.Title = p20.Title;
result.Slug = p20.Slug;
result.Tags = p20.Tags;
result.ReadingTime = p20.ReadingTime;
result.Summery = p20.Summery;
result.IsSuggested = p20.IsSuggested;
result.CategoryId = p20.CategoryId;
result.Category = funcMain8(new Never(), result.Category, p20);
result.Id = p20.Id;
result.CreatedAt = p20.CreatedAt;
result.ModifiedAt = p20.ModifiedAt;
return result;
}
public static BlogSDto AdaptToSDto(this Blog p22)
public static BlogSDto AdaptToSDto(this Blog p24)
{
return p22 == null ? null : new BlogSDto()
return p24 == null ? null : new BlogSDto()
{
Title = p22.Title,
Slug = p22.Slug,
Tags = p22.Tags,
ReadingTime = p22.ReadingTime,
Summery = p22.Summery,
IsSuggested = p22.IsSuggested,
CategoryId = p22.CategoryId,
CategoryName = p22.Category == null ? null : p22.Category.Name,
MainImage = p22.Files.Count > 0 && p22.Files.Any<BlogStorageFile>(funcMain6) ? p22.Files.FirstOrDefault<BlogStorageFile>(funcMain7).FileName : string.Empty,
ModifiedAt = p22.ModifiedAt,
Id = p22.Id,
CreatedAt = p22.CreatedAt
Title = p24.Title,
Slug = p24.Slug,
Tags = p24.Tags,
ReadingTime = p24.ReadingTime,
Summery = p24.Summery,
IsSuggested = p24.IsSuggested,
CategoryId = p24.CategoryId,
CategoryName = p24.Category == null ? null : p24.Category.Name,
MainImage = p24.Files.Count > 0 && p24.Files.Any<BlogStorageFile>(funcMain9) ? p24.Files.FirstOrDefault<BlogStorageFile>(funcMain10).FileName : string.Empty,
ModifiedAt = p24.ModifiedAt,
Id = p24.Id,
CreatedAt = p24.CreatedAt
};
}
public static BlogSDto AdaptTo(this Blog p23, BlogSDto p24)
public static BlogSDto AdaptTo(this Blog p25, BlogSDto p26)
{
if (p23 == null)
if (p25 == null)
{
return null;
}
BlogSDto result = p24 ?? new BlogSDto();
BlogSDto result = p26 ?? new BlogSDto();
result.Title = p23.Title;
result.Slug = p23.Slug;
result.Tags = p23.Tags;
result.ReadingTime = p23.ReadingTime;
result.Summery = p23.Summery;
result.IsSuggested = p23.IsSuggested;
result.CategoryId = p23.CategoryId;
result.CategoryName = p23.Category == null ? null : p23.Category.Name;
result.MainImage = p23.Files.Count > 0 && p23.Files.Any<BlogStorageFile>(funcMain6) ? p23.Files.FirstOrDefault<BlogStorageFile>(funcMain7).FileName : string.Empty;
result.ModifiedAt = p23.ModifiedAt;
result.Id = p23.Id;
result.CreatedAt = p23.CreatedAt;
result.Title = p25.Title;
result.Slug = p25.Slug;
result.Tags = p25.Tags;
result.ReadingTime = p25.ReadingTime;
result.Summery = p25.Summery;
result.IsSuggested = p25.IsSuggested;
result.CategoryId = p25.CategoryId;
result.CategoryName = p25.Category == null ? null : p25.Category.Name;
result.MainImage = p25.Files.Count > 0 && p25.Files.Any<BlogStorageFile>(funcMain9) ? p25.Files.FirstOrDefault<BlogStorageFile>(funcMain10).FileName : string.Empty;
result.ModifiedAt = p25.ModifiedAt;
result.Id = p25.Id;
result.CreatedAt = p25.CreatedAt;
return result;
}
public static Expression<Func<Blog, BlogSDto>> ProjectToSDto => p25 => new BlogSDto()
public static Expression<Func<Blog, BlogSDto>> ProjectToSDto => p27 => new BlogSDto()
{
Title = p25.Title,
Slug = p25.Slug,
Tags = p25.Tags,
ReadingTime = p25.ReadingTime,
Summery = p25.Summery,
IsSuggested = p25.IsSuggested,
CategoryId = p25.CategoryId,
CategoryName = p25.Category.Name,
MainImage = p25.Files.Count > 0 && p25.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p25.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
ModifiedAt = p25.ModifiedAt,
Id = p25.Id,
CreatedAt = p25.CreatedAt
Title = p27.Title,
Slug = p27.Slug,
Tags = p27.Tags,
ReadingTime = p27.ReadingTime,
Summery = p27.Summery,
IsSuggested = p27.IsSuggested,
CategoryId = p27.CategoryId,
CategoryName = p27.Category.Name,
MainImage = p27.Files.Count > 0 && p27.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p27.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
ModifiedAt = p27.ModifiedAt,
Id = p27.Id,
CreatedAt = p27.CreatedAt
};
private static List<BlogStorageFile> funcMain1(List<StorageFileSDto> p2)
@ -270,20 +284,30 @@ namespace Netina.Domain.Mappers
}
private static List<BlogStorageFile> funcMain2(List<StorageFileSDto> p5, List<BlogStorageFile> p6)
private static BlogCategory funcMain2(Never p5, BlogCategory p6, BlogLDto p3)
{
if (p5 == null)
BlogCategory result = p6 ?? new BlogCategory();
result.Name = p3.CategoryName;
result.Id = p3.CategoryId;
return result;
}
private static List<BlogStorageFile> funcMain3(List<StorageFileSDto> p7, List<BlogStorageFile> p8)
{
if (p7 == null)
{
return null;
}
List<BlogStorageFile> result = new List<BlogStorageFile>(p5.Count);
List<BlogStorageFile> result = new List<BlogStorageFile>(p7.Count);
int i = 0;
int len = p5.Count;
int len = p7.Count;
while (i < len)
{
StorageFileSDto item = p5[i];
StorageFileSDto item = p7[i];
result.Add(item == null ? null : new BlogStorageFile()
{
Name = item.Name,
@ -301,82 +325,92 @@ namespace Netina.Domain.Mappers
}
private static List<StorageFileSDto> funcMain3(List<BlogStorageFile> p10)
{
if (p10 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p10.Count);
int i = 0;
int len = p10.Count;
while (i < len)
{
BlogStorageFile item = p10[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static List<StorageFileSDto> funcMain4(List<BlogStorageFile> p13, List<StorageFileSDto> p14)
{
if (p13 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p13.Count);
int i = 0;
int len = p13.Count;
while (i < len)
{
BlogStorageFile item = p13[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static BlogCategory funcMain5(Never p20, BlogCategory p21, BlogSDto p18)
{
BlogCategory result = p21 ?? new BlogCategory();
result.Name = p18.CategoryName;
result.Id = p18.CategoryId;
return result;
}
private static bool funcMain6(BlogStorageFile f)
private static bool funcMain4(BlogStorageFile f)
{
return f.IsPrimary;
}
private static bool funcMain7(BlogStorageFile f)
private static bool funcMain5(BlogStorageFile f)
{
return f.IsPrimary;
}
private static List<StorageFileSDto> funcMain6(List<BlogStorageFile> p12)
{
if (p12 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p12.Count);
int i = 0;
int len = p12.Count;
while (i < len)
{
BlogStorageFile item = p12[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static List<StorageFileSDto> funcMain7(List<BlogStorageFile> p15, List<StorageFileSDto> p16)
{
if (p15 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p15.Count);
int i = 0;
int len = p15.Count;
while (i < len)
{
BlogStorageFile item = p15[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static BlogCategory funcMain8(Never p22, BlogCategory p23, BlogSDto p20)
{
BlogCategory result = p23 ?? new BlogCategory();
result.Name = p20.CategoryName;
result.Id = p20.CategoryId;
return result;
}
private static bool funcMain9(BlogStorageFile f)
{
return f.IsPrimary;
}
private static bool funcMain10(BlogStorageFile f)
{
return f.IsPrimary;
}

View File

@ -10,6 +10,10 @@ public class MapsterRegister : IRegister
.Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f=>f.IsPrimary) ? o.Files.FirstOrDefault(f=>f.IsPrimary)!.FileName : string.Empty)
.TwoWays();
config.NewConfig<Blog, BlogLDto>()
.Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f => f.IsPrimary) ? o.Files.FirstOrDefault(f => f.IsPrimary)!.FileName : string.Empty)
.TwoWays();
config.NewConfig<BlogCategory, BlogCategorySDto>()
.Map("BlogCount", o => o.Blogs.Count)
.TwoWays();

View File

@ -190,7 +190,7 @@ public class DbInitializerService : IDbInitializerService
{
//var noSlugProducts = await _repositoryWrapper.SetRepository<Product>()
// .TableNoTracking
// .Where(p => p.Slug==string.Empty)
// .Where(p => p.Slug == string.Empty)
// .ToListAsync();
//if (noSlugProducts.Count > 0)
@ -207,7 +207,7 @@ public class DbInitializerService : IDbInitializerService
//var noSlugProductCategories = await _repositoryWrapper.SetRepository<ProductCategory>()
// .TableNoTracking
// .Where(pc=>pc.Slug == string.Empty)
// .Where(pc => pc.Slug == string.Empty)
// .ToListAsync();
//if (noSlugProductCategories.Count > 0)
//{

View File

@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.60" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.0.0" />

View File

@ -9,6 +9,9 @@ using Netina.Domain.Enums;
using Netina.WordPressDBConverter.Services.RestServices;
using Refit;
using System.Reflection.Metadata;
using HtmlAgilityPack;
using System.Net.Http;
using System.Text.RegularExpressions;
var postMetaReader = new StreamReader("F:\\wp_postmeta.json");
@ -48,9 +51,6 @@ var posts = JsonConvert.DeserializeObject<List<WordPressPostDto>>(json);
if (posts == null)
throw new Exception("Posts is null");
//CREATE CATEGORY PART
List<SeedBlogCategoryRequestDto> categories = new List<SeedBlogCategoryRequestDto>();
List<WordPressPostTagDto> tags = new List<WordPressPostTagDto>();
@ -82,86 +82,137 @@ foreach (var taxonomy in termTaxonomies)
}
var categoriesRest = new Dictionary<int, Guid>();
categoriesRest = await RestWrapper.Instance.SeedRestApi.SeedBlogCategoriesAsync(categories, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
//categoriesRest = await RestWrapper.Instance.SeedRestApi.SeedBlogCategoriesAsync(categories, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
Console.WriteLine($"{categories.Count} BlogCategory Added Success !");
//CREATE BLOG PART
List<SeedBlogRequestDto> blogs = new List<SeedBlogRequestDto>();
var random = new Random(1532);
int thumbCounter = 0;
int postedCounter = 0;
int postCounter = 0;
foreach (var wordPressPostDto in posts.Where(p => p.post_type == "page"))
int uploadedCounter = 0;
var wpPosts = posts.Where(p => p.post_type is "page" or "post").Skip(336).ToList();
foreach (var wordPressPostDto in wpPosts)
{
SeedBlogRequestDto blog;
Guid categoryId = default;
string postTags = string.Empty;
var postTermRelations = termRelationships.Where(p => p.object_id == wordPressPostDto.ID).ToList();
foreach (var postTermRelation in postTermRelations)
try
{
var taxanomy = termTaxonomies.FirstOrDefault(f => f.term_taxonomy_id == postTermRelation.term_taxonomy_id);
if (taxanomy != null)
SeedBlogRequestDto blog;
Guid categoryId = default;
string postTags = string.Empty;
var postTermRelations = termRelationships.Where(p => p.object_id == wordPressPostDto.ID).ToList();
foreach (var postTermRelation in postTermRelations)
{
if (taxanomy.taxonomy == "category")
categoryId = categoriesRest.FirstOrDefault(c => c.Key == taxanomy.term_id.ToInt()).Value;
if (taxanomy.taxonomy == "post_tag")
postTags += tags.FirstOrDefault(t => t.TermId == taxanomy.term_id.ToInt())?.Tag + " , ";
var taxanomy = termTaxonomies.FirstOrDefault(f => f.term_taxonomy_id == postTermRelation.term_taxonomy_id);
if (taxanomy != null)
{
if (taxanomy.taxonomy == "category")
categoryId = categoriesRest.FirstOrDefault(c => c.Key == taxanomy.term_id.ToInt()).Value;
if (taxanomy.taxonomy == "post_tag")
postTags += tags.FirstOrDefault(t => t.TermId == taxanomy.term_id.ToInt())?.Tag + " , ";
}
}
}
if (categoryId == default)
categoryId = categoriesRest.FirstOrDefault(c => c.Key == 0).Value;
if (categoryId == default)
categoryId = categoriesRest.FirstOrDefault(c => c.Key == 0).Value;
var files = new List<StorageFileSDto>();
string pattern = "<img\\s+[^>]*>";
var files = new List<StorageFileSDto>();
var thumbnailMeta = postMetas.FirstOrDefault(pm => pm.post_id == wordPressPostDto.ID && pm.meta_key == "_thumbnail_id");
if (thumbnailMeta != null)
{
var thumbnail = posts.FirstOrDefault(p => p.ID.ToInt() == thumbnailMeta.meta_value.ToInt());
if (thumbnail != null)
// Use Regex to match the pattern in the HTML content
MatchCollection matches = Regex.Matches(wordPressPostDto.post_content, pattern);
if (matches.Count > 0)
{
using var httpClient = new HttpClient();
var imageBytes = await httpClient.GetByteArrayAsync(thumbnail.guid);
var uploadFile = new FileUploadRequest
foreach (Match match in matches)
{
ContentType = thumbnail.post_mime_type,
FileName = $"{StringExtensions.GetId(10)}.jpeg",
FileUploadType = FileUploadType.Image,
StringBaseFile = Convert.ToBase64String(imageBytes),
};
var fileRest = await RestWrapper.Instance.UploadRestApi.UploadAsync(uploadFile);
try
{
Console.WriteLine(match.Value);
files.Add(new StorageFileSDto
{
FileLocation = fileRest.FileLocation,
FileName = fileRest.FileName,
Name = fileRest.FileName,
FileType = StorageFileType.Image
});
Console.WriteLine($"Thumbnail uploaded : {thumbCounter++}");
// Extract 'src' attribute value from the <img> tag (using another regex)
string srcPattern = "src\\s*=\\s*\"([^\"]+)\"";
Match srcMatch = Regex.Match(match.Value, srcPattern);
if (srcMatch.Success)
{
string oldSrc = srcMatch.Groups[1].Value;
using var httpClient = new HttpClient();
var imageBytes = await httpClient.GetByteArrayAsync(oldSrc);
var uploadFile = new FileUploadRequest
{
ContentType = "image/jpeg",
FileName = $"{StringExtensions.GetId(10)}.jpg",
FileUploadType = FileUploadType.Image,
StringBaseFile = Convert.ToBase64String(imageBytes),
};
var fileRest = await RestWrapper.Instance.UploadRestApi.UploadAsync(uploadFile);
string newSrc = $"https://storage.hamyanedalat.com/{fileRest.FileLocation}";
wordPressPostDto.post_content = wordPressPostDto.post_content.Replace(oldSrc, newSrc);
uploadedCounter++;
Console.WriteLine($"{uploadedCounter} File Uploaded Success !");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
continue;
}
}
}
//var thumbnailMeta = postMetas.FirstOrDefault(pm => pm.post_id == wordPressPostDto.ID && pm.meta_key == "_thumbnail_id");
//if (thumbnailMeta != null)
//{
// var thumbnail = posts.FirstOrDefault(p => p.ID.ToInt() == thumbnailMeta.meta_value.ToInt());
// if (thumbnail != null)
// {
// using var httpClient = new HttpClient();
// var imageBytes = await httpClient.GetByteArrayAsync(thumbnail.guid);
// var uploadFile = new FileUploadRequest
// {
// ContentType = thumbnail.post_mime_type,
// FileName = $"{StringExtensions.GetId(10)}.jpeg",
// FileUploadType = FileUploadType.Image,
// StringBaseFile = Convert.ToBase64String(imageBytes),
// };
// var fileRest = await RestWrapper.Instance.UploadRestApi.UploadAsync(uploadFile);
// files.Add(new StorageFileSDto
// {
// FileLocation = fileRest.FileLocation,
// FileName = fileRest.FileName,
// Name = fileRest.FileName,
// FileType = StorageFileType.Image
// });
// Console.WriteLine($"Thumbnail uploaded : {thumbCounter++}");
// }
//}
blog = new SeedBlogRequestDto
{
CategoryId = categoryId,
Content = wordPressPostDto.post_content,
IsSuggested = false,
ReadingTime = random.Next(1, 15),
Title = wordPressPostDto.post_title,
Files = files,
Slug = wordPressPostDto.post_name
};
blogs.Add(blog);
await RestWrapper.Instance.SeedRestApi.SeedBlogsAsync(new List<SeedBlogRequestDto> { blog },
"kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
Console.WriteLine($"{postCounter++} / {wpPosts.Count()} Blog Added Success !");
}
blog = new SeedBlogRequestDto
catch (Exception e)
{
CategoryId = categoryId,
Content = wordPressPostDto.post_content,
IsSuggested = false,
ReadingTime = random.Next(1, 15),
Title = wordPressPostDto.post_title,
Files = files,
Slug = wordPressPostDto.post_name
};
blogs.Add(blog);
await RestWrapper.Instance.SeedRestApi.SeedBlogsAsync(new List<SeedBlogRequestDto> { blog }, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
Console.WriteLine($"{postCounter++} / {blogs.Count} Blog Added Success !");
continue;
}
}
Console.ReadKey();