feat : add version 0.24.27.47 , complete site-maps , complete slugs
parent
4e2aec8e2c
commit
8679140b4b
|
@ -17,7 +17,7 @@
|
||||||
"TaxesFee": 9
|
"TaxesFee": 9
|
||||||
},
|
},
|
||||||
"SiteSettings": {
|
"SiteSettings": {
|
||||||
"BaseUrl": "https://api.hamyan.visabartar.com",
|
"BaseUrl": "http://192.168.1.12:32770",
|
||||||
"WebSiteUrl": "https://hamyan.visabartar.com",
|
"WebSiteUrl": "https://hamyan.visabartar.com",
|
||||||
"AdminPanelBaseUrl": "https://admin.hamyan.visabartar.com",
|
"AdminPanelBaseUrl": "https://admin.hamyan.visabartar.com",
|
||||||
"StorageBaseUrl": "https://storage.visabartar.com",
|
"StorageBaseUrl": "https://storage.visabartar.com",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"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",
|
"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;"
|
"MartenDB": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=NetinaShopMartenDB;"
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class HealthController : ICarterModule
|
||||||
|
|
||||||
public async Task<IResult> GetHealth([FromServices]ISiteMapService siteMapService)
|
public async Task<IResult> GetHealth([FromServices]ISiteMapService siteMapService)
|
||||||
{
|
{
|
||||||
//await siteMapService.CreateSiteMapAsync();
|
await siteMapService.CreateSiteMapAsync();
|
||||||
var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
|
var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
|
||||||
var check = new HealthCheck
|
var check = new HealthCheck
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class SeedController : ICarterModule
|
||||||
.WithDisplayName("SeedBlogsAsync")
|
.WithDisplayName("SeedBlogsAsync")
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
group.MapPost("blog/categories", SeedBlogCategoriesSlugAsync)
|
group.MapPost("blog/categories", SeedBlogCategoriesAsync)
|
||||||
.WithDisplayName("SeedBlogCategoriesAsync")
|
.WithDisplayName("SeedBlogCategoriesAsync")
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
}
|
}
|
||||||
|
@ -147,28 +147,6 @@ public class SeedController : ICarterModule
|
||||||
categories.Add(requestDto.BaseCategoryId, ent.Id);
|
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);
|
return TypedResults.Ok(categories);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,8 +6,8 @@
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<InvariantGlobalization>true</InvariantGlobalization>
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
<AssemblyVersion>0.23.26.46</AssemblyVersion>
|
<AssemblyVersion>0.24.27.47</AssemblyVersion>
|
||||||
<FileVersion>0.23.26.46</FileVersion>
|
<FileVersion>0.24.27.47</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Web;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Netina.Core.Models;
|
using Netina.Core.Models;
|
||||||
using Netina.Domain.Entities.Blogs;
|
using Netina.Domain.Entities.Blogs;
|
||||||
|
using Netina.Domain.Entities.Brands;
|
||||||
using Netina.Domain.Entities.ProductCategories;
|
using Netina.Domain.Entities.ProductCategories;
|
||||||
using Netina.Domain.Entities.Products;
|
using Netina.Domain.Entities.Products;
|
||||||
|
|
||||||
|
@ -36,7 +37,11 @@ public class SiteMapService : ISiteMapService
|
||||||
doc.AppendChild(root);
|
doc.AppendChild(root);
|
||||||
|
|
||||||
|
|
||||||
var categories = await _repositoryWrapper.SetRepository<ProductCategory>()
|
var productCategories = await _repositoryWrapper.SetRepository<ProductCategory>()
|
||||||
|
.TableNoTracking
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var blogCategories= await _repositoryWrapper.SetRepository<BlogCategory>()
|
||||||
.TableNoTracking
|
.TableNoTracking
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
@ -54,14 +59,29 @@ public class SiteMapService : ISiteMapService
|
||||||
siteMapElement.AppendChild(lastmod);
|
siteMapElement.AppendChild(lastmod);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var category in categories)
|
foreach (var blogCategory in blogCategories)
|
||||||
{
|
{
|
||||||
|
|
||||||
XmlElement siteMapElement = doc.CreateElement("sitemap", doc.DocumentElement?.NamespaceURI);
|
XmlElement siteMapElement = doc.CreateElement("sitemap", doc.DocumentElement?.NamespaceURI);
|
||||||
root.AppendChild(siteMapElement);
|
root.AppendChild(siteMapElement);
|
||||||
|
|
||||||
XmlElement id = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
|
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);
|
siteMapElement.AppendChild(id);
|
||||||
|
|
||||||
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
|
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
|
||||||
|
@ -86,10 +106,81 @@ public class SiteMapService : ISiteMapService
|
||||||
await CreateCategoriesSiteMapsAsync();
|
await CreateCategoriesSiteMapsAsync();
|
||||||
await CreateProductsSiteMapsAsync();
|
await CreateProductsSiteMapsAsync();
|
||||||
await CreateBlogsSiteMapsAsync();
|
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()
|
private async Task CreateCategoriesSiteMapsAsync()
|
||||||
{
|
{
|
||||||
var siteMapsUId = SiteMapUIds.Categories;
|
var siteMapsUId = SiteMapUIds.Categories;
|
||||||
|
@ -111,12 +202,12 @@ public class SiteMapService : ISiteMapService
|
||||||
|
|
||||||
foreach (var productCategory in categories)
|
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);
|
XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI);
|
||||||
root.AppendChild(urlElement);
|
root.AppendChild(urlElement);
|
||||||
|
|
||||||
XmlElement loc = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
|
XmlElement loc = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI);
|
||||||
loc.InnerText = Path.Combine(productCategory.Name);
|
loc.InnerText = Path.Combine(productUrl);
|
||||||
urlElement.AppendChild(loc);
|
urlElement.AppendChild(loc);
|
||||||
|
|
||||||
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
|
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
|
||||||
|
@ -254,13 +345,16 @@ public class SiteMapService : ISiteMapService
|
||||||
|
|
||||||
private async Task CreateBlogsSiteMapsAsync()
|
private async Task CreateBlogsSiteMapsAsync()
|
||||||
{
|
{
|
||||||
var siteMapsUId = SiteMapUIds.Blogs;
|
|
||||||
|
|
||||||
var blogs = await _repositoryWrapper.SetRepository<Blog>()
|
var blogs = await _repositoryWrapper.SetRepository<Blog>()
|
||||||
.TableNoTracking
|
.TableNoTracking
|
||||||
.Select(BlogMapper.ProjectToSDto)
|
.Select(BlogMapper.ProjectToSDto)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
var groupedProducts = blogs.GroupBy(p => p.CategoryId);
|
||||||
|
|
||||||
|
foreach (var group in groupedProducts)
|
||||||
|
{
|
||||||
XmlDocument doc = new XmlDocument();
|
XmlDocument doc = new XmlDocument();
|
||||||
XmlDeclaration documentType = doc.CreateXmlDeclaration("1.0", "utf-8", null);
|
XmlDeclaration documentType = doc.CreateXmlDeclaration("1.0", "utf-8", null);
|
||||||
doc.AppendChild(documentType);
|
doc.AppendChild(documentType);
|
||||||
|
@ -270,10 +364,10 @@ public class SiteMapService : ISiteMapService
|
||||||
|
|
||||||
XmlElement root = doc.CreateElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
|
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:image", "http://www.google.com/schemas/sitemap-image/1.1");
|
||||||
root.SetAttribute("xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9");
|
//root.SetAttribute("xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9");
|
||||||
doc.AppendChild(root);
|
doc.AppendChild(root);
|
||||||
|
|
||||||
foreach (var blog in blogs)
|
foreach (var blog in group)
|
||||||
{
|
{
|
||||||
XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI);
|
XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI);
|
||||||
root.AppendChild(urlElement);
|
root.AppendChild(urlElement);
|
||||||
|
@ -283,7 +377,9 @@ public class SiteMapService : ISiteMapService
|
||||||
urlElement.AppendChild(loc);
|
urlElement.AppendChild(loc);
|
||||||
|
|
||||||
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
|
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 = blog.ModifiedAt == DateTime.MinValue
|
||||||
|
? blog.CreatedAt.ToString("yyyy-MM-dd")
|
||||||
|
: blog.ModifiedAt.ToString("yyyy-MM-dd");
|
||||||
urlElement.AppendChild(lastmod);
|
urlElement.AppendChild(lastmod);
|
||||||
|
|
||||||
|
|
||||||
|
@ -298,18 +394,26 @@ public class SiteMapService : ISiteMapService
|
||||||
|
|
||||||
//Image
|
//Image
|
||||||
|
|
||||||
XmlElement image = doc.CreateElement("image:image", "http://www.google.com/schemas/sitemap-image/1.1");
|
|
||||||
|
|
||||||
|
if (blog.MainImage != string.Empty)
|
||||||
|
{
|
||||||
|
XmlElement image =
|
||||||
|
doc.CreateElement("image:image", "http://www.google.com/schemas/sitemap-image/1.1");
|
||||||
urlElement.AppendChild(image);
|
urlElement.AppendChild(image);
|
||||||
|
|
||||||
|
|
||||||
XmlElement imageLoc = doc.CreateElement("image:loc", "http://www.google.com/schemas/sitemap-image/1.1");
|
XmlElement imageLoc =
|
||||||
|
doc.CreateElement("image:loc", "http://www.google.com/schemas/sitemap-image/1.1");
|
||||||
imageLoc.InnerText = $"{_siteSetting.StorageBaseUrl}/{blog.MainImage.Replace("Med", "Thumb")}";
|
imageLoc.InnerText = $"{_siteSetting.StorageBaseUrl}/{blog.MainImage.Replace("Med", "Thumb")}";
|
||||||
image.AppendChild(imageLoc);
|
image.AppendChild(imageLoc);
|
||||||
|
|
||||||
|
|
||||||
XmlElement imageCaption = doc.CreateElement("image:caption", "http://www.google.com/schemas/sitemap-image/1.1");
|
XmlElement imageCaption = doc.CreateElement("image:caption",
|
||||||
|
"http://www.google.com/schemas/sitemap-image/1.1");
|
||||||
imageCaption.InnerText = blog.Title;
|
imageCaption.InnerText = blog.Title;
|
||||||
image.AppendChild(imageCaption);
|
image.AppendChild(imageCaption);
|
||||||
|
}
|
||||||
|
|
||||||
////News
|
////News
|
||||||
|
|
||||||
|
@ -345,6 +449,78 @@ public class SiteMapService : ISiteMapService
|
||||||
siteMapWriter.Flush();
|
siteMapWriter.Flush();
|
||||||
byte[] unZipBytes = siteMapStream.ToArray();
|
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);
|
||||||
|
|
||||||
|
//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 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/{blogCategory.Id}/{blogCategory.Slug}");
|
||||||
|
urlElement.AppendChild(loc);
|
||||||
|
|
||||||
|
XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);
|
||||||
|
lastmod.InnerText = blogCategory.ModifiedAt == DateTime.MinValue ? blogCategory.CreatedAt.ToString("yyyy-MM-dd") : blogCategory.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())
|
using (var compressedStream = new MemoryStream())
|
||||||
await using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress))
|
await using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress))
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,11 +2,15 @@
|
||||||
public static class SiteMapUIds
|
public static class SiteMapUIds
|
||||||
{
|
{
|
||||||
public const string Categories = "5709ACC29A4D42E5B6F2DFFAD2FB0018";
|
public const string Categories = "5709ACC29A4D42E5B6F2DFFAD2FB0018";
|
||||||
|
public const string Brands = "662AF2DC6A2746FA88191F1F3DA94164";
|
||||||
public const string Blogs = "4C2F0C2A7A3E41268702D12FDDDB837F";
|
public const string Blogs = "4C2F0C2A7A3E41268702D12FDDDB837F";
|
||||||
|
public const string BlogCategories = "B5FF333DC4FF4BB4A309CE3AA32CE45A";
|
||||||
|
|
||||||
public static List<string> AllSiteMapsUIds => new List<string>
|
public static List<string> AllSiteMapsUIds => new List<string>
|
||||||
{
|
{
|
||||||
|
BlogCategories,
|
||||||
Categories,
|
Categories,
|
||||||
Blogs
|
Blogs,
|
||||||
|
Brands
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ public class BlogLDto : BaseDto<BlogLDto , Blog>
|
||||||
public string Slug { get; set; } = string.Empty;
|
public string Slug { get; set; } = string.Empty;
|
||||||
public int ReadingTime { get; set; }
|
public int ReadingTime { get; set; }
|
||||||
public string Summery { get; set; } = string.Empty;
|
public string Summery { get; set; } = string.Empty;
|
||||||
|
public string MainImage { get; set; } = string.Empty;
|
||||||
public bool IsSuggested { get; set; }
|
public bool IsSuggested { get; set; }
|
||||||
public Guid CategoryId { get; set; }
|
public Guid CategoryId { get; set; }
|
||||||
public string CategoryName { get; set; } = string.Empty;
|
public string CategoryName { get; set; } = string.Empty;
|
||||||
|
|
|
@ -24,7 +24,7 @@ public partial class Blog : ApiEntity
|
||||||
}
|
}
|
||||||
public string Title { get; internal set; } = string.Empty;
|
public string Title { get; internal set; } = string.Empty;
|
||||||
public string Content { 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 string Tags { get; internal set; } = string.Empty;
|
||||||
public int ReadingTime { get; internal set; }
|
public int ReadingTime { get; internal set; }
|
||||||
public string Summery { get; internal set; } = string.Empty;
|
public string Summery { get; internal set; } = string.Empty;
|
||||||
|
|
|
@ -17,7 +17,7 @@ public partial class BlogCategory : ApiEntity
|
||||||
Description = description;
|
Description = description;
|
||||||
}
|
}
|
||||||
public string Name { get; internal set; } = string.Empty;
|
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 string Description { get; internal set; } = string.Empty;
|
||||||
public List<Blog> Blogs { get; internal set; } = new();
|
public List<Blog> Blogs { get; internal set; } = new();
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ public partial class Brand : ApiEntity
|
||||||
}
|
}
|
||||||
public string PersianName { get; internal set; } = string.Empty;
|
public string PersianName { get; internal set; } = string.Empty;
|
||||||
public string EnglishName { 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 string Description { get; internal set; } = string.Empty;
|
||||||
public bool HasSpecialPage { get; internal set; }
|
public bool HasSpecialPage { get; internal set; }
|
||||||
public string PageUrl { get; internal set; } = string.Empty;
|
public string PageUrl { get; internal set; } = string.Empty;
|
||||||
|
|
|
@ -19,7 +19,7 @@ public partial class ProductCategory : ApiEntity
|
||||||
IsMain = isMain;
|
IsMain = isMain;
|
||||||
}
|
}
|
||||||
public string Name { get; internal set; } = string.Empty;
|
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 string Description { get; internal set; } = string.Empty;
|
||||||
public bool IsMain { get; set; }
|
public bool IsMain { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public partial class Product : ApiEntity
|
||||||
}
|
}
|
||||||
public string PersianName { get; internal set; } = string.Empty;
|
public string PersianName { get; internal set; } = string.Empty;
|
||||||
public string EnglishName { 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 Summery { get; internal set; } = string.Empty;
|
||||||
public string ExpertCheck { get; internal set; } = string.Empty;
|
public string ExpertCheck { get; internal set; } = string.Empty;
|
||||||
public string Tags { get; internal set; } = string.Empty;
|
public string Tags { get; internal set; } = string.Empty;
|
||||||
|
|
|
@ -23,6 +23,11 @@ namespace Netina.Domain.Mappers
|
||||||
Summery = p1.Summery,
|
Summery = p1.Summery,
|
||||||
IsSuggested = p1.IsSuggested,
|
IsSuggested = p1.IsSuggested,
|
||||||
CategoryId = p1.CategoryId,
|
CategoryId = p1.CategoryId,
|
||||||
|
Category = new BlogCategory()
|
||||||
|
{
|
||||||
|
Name = p1.CategoryName,
|
||||||
|
Id = p1.CategoryId
|
||||||
|
},
|
||||||
Files = funcMain1(p1.Files),
|
Files = funcMain1(p1.Files),
|
||||||
Id = p1.Id,
|
Id = p1.Id,
|
||||||
CreatedAt = p1.CreatedAt
|
CreatedAt = p1.CreatedAt
|
||||||
|
@ -44,199 +49,208 @@ namespace Netina.Domain.Mappers
|
||||||
result.Summery = p3.Summery;
|
result.Summery = p3.Summery;
|
||||||
result.IsSuggested = p3.IsSuggested;
|
result.IsSuggested = p3.IsSuggested;
|
||||||
result.CategoryId = p3.CategoryId;
|
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.Id = p3.Id;
|
||||||
result.CreatedAt = p3.CreatedAt;
|
result.CreatedAt = p3.CreatedAt;
|
||||||
return result;
|
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()
|
|
||||||
{
|
|
||||||
Name = p8.Name,
|
|
||||||
FileLocation = p8.FileLocation,
|
|
||||||
FileName = p8.FileName,
|
|
||||||
IsHeader = p8.IsHeader,
|
|
||||||
IsPrimary = p8.IsPrimary,
|
|
||||||
FileType = p8.FileType,
|
|
||||||
Id = p8.Id,
|
|
||||||
CreatedAt = p8.CreatedAt
|
|
||||||
}).ToList<BlogStorageFile>(),
|
|
||||||
Id = p7.Id,
|
|
||||||
CreatedAt = p7.CreatedAt
|
|
||||||
};
|
|
||||||
public static BlogLDto AdaptToLDto(this Blog p9)
|
|
||||||
{
|
|
||||||
return p9 == null ? null : new BlogLDto()
|
|
||||||
{
|
{
|
||||||
Title = p9.Title,
|
Title = p9.Title,
|
||||||
Content = p9.Content,
|
Content = p9.Content,
|
||||||
Tags = p9.Tags,
|
|
||||||
Slug = p9.Slug,
|
Slug = p9.Slug,
|
||||||
|
Tags = p9.Tags,
|
||||||
ReadingTime = p9.ReadingTime,
|
ReadingTime = p9.ReadingTime,
|
||||||
Summery = p9.Summery,
|
Summery = p9.Summery,
|
||||||
IsSuggested = p9.IsSuggested,
|
IsSuggested = p9.IsSuggested,
|
||||||
CategoryId = p9.CategoryId,
|
CategoryId = p9.CategoryId,
|
||||||
CategoryName = p9.Category == null ? null : p9.Category.Name,
|
Category = new BlogCategory()
|
||||||
Files = funcMain3(p9.Files),
|
{
|
||||||
|
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 = p9.Id,
|
Id = p9.Id,
|
||||||
CreatedAt = p9.CreatedAt
|
CreatedAt = p9.CreatedAt
|
||||||
};
|
};
|
||||||
}
|
public static BlogLDto AdaptToLDto(this Blog p11)
|
||||||
public static BlogLDto AdaptTo(this Blog p11, BlogLDto p12)
|
|
||||||
{
|
{
|
||||||
if (p11 == null)
|
return p11 == null ? null : new BlogLDto()
|
||||||
|
{
|
||||||
|
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 p13, BlogLDto p14)
|
||||||
|
{
|
||||||
|
if (p13 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
BlogLDto result = p12 ?? new BlogLDto();
|
BlogLDto result = p14 ?? new BlogLDto();
|
||||||
|
|
||||||
result.Title = p11.Title;
|
result.Title = p13.Title;
|
||||||
result.Content = p11.Content;
|
result.Content = p13.Content;
|
||||||
result.Tags = p11.Tags;
|
result.Tags = p13.Tags;
|
||||||
result.Slug = p11.Slug;
|
result.Slug = p13.Slug;
|
||||||
result.ReadingTime = p11.ReadingTime;
|
result.ReadingTime = p13.ReadingTime;
|
||||||
result.Summery = p11.Summery;
|
result.Summery = p13.Summery;
|
||||||
result.IsSuggested = p11.IsSuggested;
|
result.MainImage = p13.Files.Count > 0 && p13.Files.Any<BlogStorageFile>(funcMain4) ? p13.Files.FirstOrDefault<BlogStorageFile>(funcMain5).FileName : string.Empty;
|
||||||
result.CategoryId = p11.CategoryId;
|
result.IsSuggested = p13.IsSuggested;
|
||||||
result.CategoryName = p11.Category == null ? null : p11.Category.Name;
|
result.CategoryId = p13.CategoryId;
|
||||||
result.Files = funcMain4(p11.Files, result.Files);
|
result.CategoryName = p13.Category == null ? null : p13.Category.Name;
|
||||||
result.Id = p11.Id;
|
result.Files = funcMain7(p13.Files, result.Files);
|
||||||
result.CreatedAt = p11.CreatedAt;
|
result.Id = p13.Id;
|
||||||
|
result.CreatedAt = p13.CreatedAt;
|
||||||
return result;
|
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()
|
|
||||||
{
|
|
||||||
Name = p16.Name,
|
|
||||||
FileLocation = p16.FileLocation,
|
|
||||||
FileName = p16.FileName,
|
|
||||||
IsHeader = p16.IsHeader,
|
|
||||||
IsPrimary = p16.IsPrimary,
|
|
||||||
FileType = p16.FileType,
|
|
||||||
Id = p16.Id
|
|
||||||
}).ToList<StorageFileSDto>(),
|
|
||||||
Id = p15.Id,
|
|
||||||
CreatedAt = p15.CreatedAt
|
|
||||||
};
|
|
||||||
public static Blog AdaptToBlog(this BlogSDto p17)
|
|
||||||
{
|
|
||||||
return p17 == null ? null : new Blog()
|
|
||||||
{
|
{
|
||||||
Title = p17.Title,
|
Title = p17.Title,
|
||||||
Slug = p17.Slug,
|
Content = p17.Content,
|
||||||
Tags = p17.Tags,
|
Tags = p17.Tags,
|
||||||
|
Slug = p17.Slug,
|
||||||
ReadingTime = p17.ReadingTime,
|
ReadingTime = p17.ReadingTime,
|
||||||
Summery = p17.Summery,
|
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,
|
IsSuggested = p17.IsSuggested,
|
||||||
CategoryId = p17.CategoryId,
|
CategoryId = p17.CategoryId,
|
||||||
|
CategoryName = p17.Category.Name,
|
||||||
|
Files = p17.Files.Select<BlogStorageFile, StorageFileSDto>(p18 => new StorageFileSDto()
|
||||||
|
{
|
||||||
|
Name = p18.Name,
|
||||||
|
FileLocation = p18.FileLocation,
|
||||||
|
FileName = p18.FileName,
|
||||||
|
IsHeader = p18.IsHeader,
|
||||||
|
IsPrimary = p18.IsPrimary,
|
||||||
|
FileType = p18.FileType,
|
||||||
|
Id = p18.Id
|
||||||
|
}).ToList<StorageFileSDto>(),
|
||||||
|
Id = p17.Id,
|
||||||
|
CreatedAt = p17.CreatedAt
|
||||||
|
};
|
||||||
|
public static Blog AdaptToBlog(this BlogSDto p19)
|
||||||
|
{
|
||||||
|
return p19 == null ? null : new Blog()
|
||||||
|
{
|
||||||
|
Title = p19.Title,
|
||||||
|
Slug = p19.Slug,
|
||||||
|
Tags = p19.Tags,
|
||||||
|
ReadingTime = p19.ReadingTime,
|
||||||
|
Summery = p19.Summery,
|
||||||
|
IsSuggested = p19.IsSuggested,
|
||||||
|
CategoryId = p19.CategoryId,
|
||||||
Category = new BlogCategory()
|
Category = new BlogCategory()
|
||||||
{
|
{
|
||||||
Name = p17.CategoryName,
|
Name = p19.CategoryName,
|
||||||
Id = p17.CategoryId
|
Id = p19.CategoryId
|
||||||
},
|
},
|
||||||
Id = p17.Id,
|
Id = p19.Id,
|
||||||
CreatedAt = p17.CreatedAt,
|
CreatedAt = p19.CreatedAt,
|
||||||
ModifiedAt = p17.ModifiedAt
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
Blog result = p19 ?? new Blog();
|
Blog result = p21 ?? new Blog();
|
||||||
|
|
||||||
result.Title = p18.Title;
|
result.Title = p20.Title;
|
||||||
result.Slug = p18.Slug;
|
result.Slug = p20.Slug;
|
||||||
result.Tags = p18.Tags;
|
result.Tags = p20.Tags;
|
||||||
result.ReadingTime = p18.ReadingTime;
|
result.ReadingTime = p20.ReadingTime;
|
||||||
result.Summery = p18.Summery;
|
result.Summery = p20.Summery;
|
||||||
result.IsSuggested = p18.IsSuggested;
|
result.IsSuggested = p20.IsSuggested;
|
||||||
result.CategoryId = p18.CategoryId;
|
result.CategoryId = p20.CategoryId;
|
||||||
result.Category = funcMain5(new Never(), result.Category, p18);
|
result.Category = funcMain8(new Never(), result.Category, p20);
|
||||||
result.Id = p18.Id;
|
result.Id = p20.Id;
|
||||||
result.CreatedAt = p18.CreatedAt;
|
result.CreatedAt = p20.CreatedAt;
|
||||||
result.ModifiedAt = p18.ModifiedAt;
|
result.ModifiedAt = p20.ModifiedAt;
|
||||||
return result;
|
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,
|
Title = p24.Title,
|
||||||
Slug = p22.Slug,
|
Slug = p24.Slug,
|
||||||
Tags = p22.Tags,
|
Tags = p24.Tags,
|
||||||
ReadingTime = p22.ReadingTime,
|
ReadingTime = p24.ReadingTime,
|
||||||
Summery = p22.Summery,
|
Summery = p24.Summery,
|
||||||
IsSuggested = p22.IsSuggested,
|
IsSuggested = p24.IsSuggested,
|
||||||
CategoryId = p22.CategoryId,
|
CategoryId = p24.CategoryId,
|
||||||
CategoryName = p22.Category == null ? null : p22.Category.Name,
|
CategoryName = p24.Category == null ? null : p24.Category.Name,
|
||||||
MainImage = p22.Files.Count > 0 && p22.Files.Any<BlogStorageFile>(funcMain6) ? p22.Files.FirstOrDefault<BlogStorageFile>(funcMain7).FileName : string.Empty,
|
MainImage = p24.Files.Count > 0 && p24.Files.Any<BlogStorageFile>(funcMain9) ? p24.Files.FirstOrDefault<BlogStorageFile>(funcMain10).FileName : string.Empty,
|
||||||
ModifiedAt = p22.ModifiedAt,
|
ModifiedAt = p24.ModifiedAt,
|
||||||
Id = p22.Id,
|
Id = p24.Id,
|
||||||
CreatedAt = p22.CreatedAt
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
BlogSDto result = p24 ?? new BlogSDto();
|
BlogSDto result = p26 ?? new BlogSDto();
|
||||||
|
|
||||||
result.Title = p23.Title;
|
result.Title = p25.Title;
|
||||||
result.Slug = p23.Slug;
|
result.Slug = p25.Slug;
|
||||||
result.Tags = p23.Tags;
|
result.Tags = p25.Tags;
|
||||||
result.ReadingTime = p23.ReadingTime;
|
result.ReadingTime = p25.ReadingTime;
|
||||||
result.Summery = p23.Summery;
|
result.Summery = p25.Summery;
|
||||||
result.IsSuggested = p23.IsSuggested;
|
result.IsSuggested = p25.IsSuggested;
|
||||||
result.CategoryId = p23.CategoryId;
|
result.CategoryId = p25.CategoryId;
|
||||||
result.CategoryName = p23.Category == null ? null : p23.Category.Name;
|
result.CategoryName = p25.Category == null ? null : p25.Category.Name;
|
||||||
result.MainImage = p23.Files.Count > 0 && p23.Files.Any<BlogStorageFile>(funcMain6) ? p23.Files.FirstOrDefault<BlogStorageFile>(funcMain7).FileName : string.Empty;
|
result.MainImage = p25.Files.Count > 0 && p25.Files.Any<BlogStorageFile>(funcMain9) ? p25.Files.FirstOrDefault<BlogStorageFile>(funcMain10).FileName : string.Empty;
|
||||||
result.ModifiedAt = p23.ModifiedAt;
|
result.ModifiedAt = p25.ModifiedAt;
|
||||||
result.Id = p23.Id;
|
result.Id = p25.Id;
|
||||||
result.CreatedAt = p23.CreatedAt;
|
result.CreatedAt = p25.CreatedAt;
|
||||||
return result;
|
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,
|
Title = p27.Title,
|
||||||
Slug = p25.Slug,
|
Slug = p27.Slug,
|
||||||
Tags = p25.Tags,
|
Tags = p27.Tags,
|
||||||
ReadingTime = p25.ReadingTime,
|
ReadingTime = p27.ReadingTime,
|
||||||
Summery = p25.Summery,
|
Summery = p27.Summery,
|
||||||
IsSuggested = p25.IsSuggested,
|
IsSuggested = p27.IsSuggested,
|
||||||
CategoryId = p25.CategoryId,
|
CategoryId = p27.CategoryId,
|
||||||
CategoryName = p25.Category.Name,
|
CategoryName = p27.Category.Name,
|
||||||
MainImage = p25.Files.Count > 0 && p25.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p25.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
|
MainImage = p27.Files.Count > 0 && p27.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p27.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
|
||||||
ModifiedAt = p25.ModifiedAt,
|
ModifiedAt = p27.ModifiedAt,
|
||||||
Id = p25.Id,
|
Id = p27.Id,
|
||||||
CreatedAt = p25.CreatedAt
|
CreatedAt = p27.CreatedAt
|
||||||
};
|
};
|
||||||
|
|
||||||
private static List<BlogStorageFile> funcMain1(List<StorageFileSDto> p2)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
List<BlogStorageFile> result = new List<BlogStorageFile>(p5.Count);
|
List<BlogStorageFile> result = new List<BlogStorageFile>(p7.Count);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int len = p5.Count;
|
int len = p7.Count;
|
||||||
|
|
||||||
while (i < len)
|
while (i < len)
|
||||||
{
|
{
|
||||||
StorageFileSDto item = p5[i];
|
StorageFileSDto item = p7[i];
|
||||||
result.Add(item == null ? null : new BlogStorageFile()
|
result.Add(item == null ? null : new BlogStorageFile()
|
||||||
{
|
{
|
||||||
Name = item.Name,
|
Name = item.Name,
|
||||||
|
@ -301,82 +325,92 @@ namespace Netina.Domain.Mappers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<StorageFileSDto> funcMain3(List<BlogStorageFile> p10)
|
private static bool funcMain4(BlogStorageFile f)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
return f.IsPrimary;
|
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;
|
return f.IsPrimary;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
.Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f=>f.IsPrimary) ? o.Files.FirstOrDefault(f=>f.IsPrimary)!.FileName : string.Empty)
|
||||||
.TwoWays();
|
.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>()
|
config.NewConfig<BlogCategory, BlogCategorySDto>()
|
||||||
.Map("BlogCount", o => o.Blogs.Count)
|
.Map("BlogCount", o => o.Blogs.Count)
|
||||||
.TwoWays();
|
.TwoWays();
|
||||||
|
|
|
@ -190,7 +190,7 @@ public class DbInitializerService : IDbInitializerService
|
||||||
{
|
{
|
||||||
//var noSlugProducts = await _repositoryWrapper.SetRepository<Product>()
|
//var noSlugProducts = await _repositoryWrapper.SetRepository<Product>()
|
||||||
// .TableNoTracking
|
// .TableNoTracking
|
||||||
// .Where(p => p.Slug==string.Empty)
|
// .Where(p => p.Slug == string.Empty)
|
||||||
// .ToListAsync();
|
// .ToListAsync();
|
||||||
|
|
||||||
//if (noSlugProducts.Count > 0)
|
//if (noSlugProducts.Count > 0)
|
||||||
|
@ -207,7 +207,7 @@ public class DbInitializerService : IDbInitializerService
|
||||||
|
|
||||||
//var noSlugProductCategories = await _repositoryWrapper.SetRepository<ProductCategory>()
|
//var noSlugProductCategories = await _repositoryWrapper.SetRepository<ProductCategory>()
|
||||||
// .TableNoTracking
|
// .TableNoTracking
|
||||||
// .Where(pc=>pc.Slug == string.Empty)
|
// .Where(pc => pc.Slug == string.Empty)
|
||||||
// .ToListAsync();
|
// .ToListAsync();
|
||||||
//if (noSlugProductCategories.Count > 0)
|
//if (noSlugProductCategories.Count > 0)
|
||||||
//{
|
//{
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="HtmlAgilityPack" Version="1.11.60" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Refit" Version="7.0.0" />
|
<PackageReference Include="Refit" Version="7.0.0" />
|
||||||
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.0.0" />
|
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.0.0" />
|
||||||
|
|
|
@ -9,6 +9,9 @@ using Netina.Domain.Enums;
|
||||||
using Netina.WordPressDBConverter.Services.RestServices;
|
using Netina.WordPressDBConverter.Services.RestServices;
|
||||||
using Refit;
|
using Refit;
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
|
||||||
var postMetaReader = new StreamReader("F:\\wp_postmeta.json");
|
var postMetaReader = new StreamReader("F:\\wp_postmeta.json");
|
||||||
|
@ -48,9 +51,6 @@ var posts = JsonConvert.DeserializeObject<List<WordPressPostDto>>(json);
|
||||||
if (posts == null)
|
if (posts == null)
|
||||||
throw new Exception("Posts is null");
|
throw new Exception("Posts is null");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//CREATE CATEGORY PART
|
|
||||||
List<SeedBlogCategoryRequestDto> categories = new List<SeedBlogCategoryRequestDto>();
|
List<SeedBlogCategoryRequestDto> categories = new List<SeedBlogCategoryRequestDto>();
|
||||||
|
|
||||||
List<WordPressPostTagDto> tags = new List<WordPressPostTagDto>();
|
List<WordPressPostTagDto> tags = new List<WordPressPostTagDto>();
|
||||||
|
@ -82,18 +82,21 @@ foreach (var taxonomy in termTaxonomies)
|
||||||
|
|
||||||
}
|
}
|
||||||
var categoriesRest = new Dictionary<int, Guid>();
|
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 !");
|
Console.WriteLine($"{categories.Count} BlogCategory Added Success !");
|
||||||
|
|
||||||
|
|
||||||
//CREATE BLOG PART
|
//CREATE BLOG PART
|
||||||
List<SeedBlogRequestDto> blogs = new List<SeedBlogRequestDto>();
|
List<SeedBlogRequestDto> blogs = new List<SeedBlogRequestDto>();
|
||||||
var random = new Random(1532);
|
var random = new Random(1532);
|
||||||
int thumbCounter = 0;
|
int postedCounter = 0;
|
||||||
int postCounter = 0;
|
int postCounter = 0;
|
||||||
|
int uploadedCounter = 0;
|
||||||
foreach (var wordPressPostDto in posts.Where(p => p.post_type == "page"))
|
var wpPosts = posts.Where(p => p.post_type is "page" or "post").Skip(336).ToList();
|
||||||
|
foreach (var wordPressPostDto in wpPosts)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
SeedBlogRequestDto blog;
|
SeedBlogRequestDto blog;
|
||||||
Guid categoryId = default;
|
Guid categoryId = default;
|
||||||
string postTags = string.Empty;
|
string postTags = string.Empty;
|
||||||
|
@ -112,36 +115,78 @@ foreach (var wordPressPostDto in posts.Where(p => p.post_type == "page"))
|
||||||
|
|
||||||
if (categoryId == default)
|
if (categoryId == default)
|
||||||
categoryId = categoriesRest.FirstOrDefault(c => c.Key == 0).Value;
|
categoryId = categoriesRest.FirstOrDefault(c => c.Key == 0).Value;
|
||||||
|
|
||||||
var files = new List<StorageFileSDto>();
|
var files = new List<StorageFileSDto>();
|
||||||
|
string pattern = "<img\\s+[^>]*>";
|
||||||
|
|
||||||
var thumbnailMeta = postMetas.FirstOrDefault(pm => pm.post_id == wordPressPostDto.ID && pm.meta_key == "_thumbnail_id");
|
// Use Regex to match the pattern in the HTML content
|
||||||
if (thumbnailMeta != null)
|
MatchCollection matches = Regex.Matches(wordPressPostDto.post_content, pattern);
|
||||||
|
if (matches.Count > 0)
|
||||||
{
|
{
|
||||||
var thumbnail = posts.FirstOrDefault(p => p.ID.ToInt() == thumbnailMeta.meta_value.ToInt());
|
foreach (Match match in matches)
|
||||||
if (thumbnail != null)
|
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine(match.Value);
|
||||||
|
|
||||||
|
// 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();
|
using var httpClient = new HttpClient();
|
||||||
var imageBytes = await httpClient.GetByteArrayAsync(thumbnail.guid);
|
var imageBytes = await httpClient.GetByteArrayAsync(oldSrc);
|
||||||
var uploadFile = new FileUploadRequest
|
var uploadFile = new FileUploadRequest
|
||||||
{
|
{
|
||||||
ContentType = thumbnail.post_mime_type,
|
ContentType = "image/jpeg",
|
||||||
FileName = $"{StringExtensions.GetId(10)}.jpeg",
|
FileName = $"{StringExtensions.GetId(10)}.jpg",
|
||||||
FileUploadType = FileUploadType.Image,
|
FileUploadType = FileUploadType.Image,
|
||||||
StringBaseFile = Convert.ToBase64String(imageBytes),
|
StringBaseFile = Convert.ToBase64String(imageBytes),
|
||||||
};
|
};
|
||||||
var fileRest = await RestWrapper.Instance.UploadRestApi.UploadAsync(uploadFile);
|
var fileRest = await RestWrapper.Instance.UploadRestApi.UploadAsync(uploadFile);
|
||||||
|
string newSrc = $"https://storage.hamyanedalat.com/{fileRest.FileLocation}";
|
||||||
files.Add(new StorageFileSDto
|
wordPressPostDto.post_content = wordPressPostDto.post_content.Replace(oldSrc, newSrc);
|
||||||
|
uploadedCounter++;
|
||||||
|
Console.WriteLine($"{uploadedCounter} File Uploaded Success !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
FileLocation = fileRest.FileLocation,
|
Console.WriteLine(e.Message);
|
||||||
FileName = fileRest.FileName,
|
continue;
|
||||||
Name = fileRest.FileName,
|
|
||||||
FileType = StorageFileType.Image
|
|
||||||
});
|
|
||||||
Console.WriteLine($"Thumbnail uploaded : {thumbCounter++}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//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
|
blog = new SeedBlogRequestDto
|
||||||
{
|
{
|
||||||
|
@ -156,12 +201,18 @@ foreach (var wordPressPostDto in posts.Where(p => p.post_type == "page"))
|
||||||
|
|
||||||
blogs.Add(blog);
|
blogs.Add(blog);
|
||||||
|
|
||||||
await RestWrapper.Instance.SeedRestApi.SeedBlogsAsync(new List<SeedBlogRequestDto> { blog }, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
|
await RestWrapper.Instance.SeedRestApi.SeedBlogsAsync(new List<SeedBlogRequestDto> { blog },
|
||||||
|
"kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
|
||||||
|
|
||||||
Console.WriteLine($"{postCounter++} / {blogs.Count} Blog Added Success !");
|
Console.WriteLine($"{postCounter++} / {wpPosts.Count()} Blog Added Success !");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue