Skip to content

Commit

Permalink
Migration to .NET Core 3.1 LTS (#122)
Browse files Browse the repository at this point in the history
* Updated package WebEssentials.AspNetCore.OutputCaching

* Updated package WilderMinds.MetaWeblog which now requires an async implementation

* Fold private non-sync into async methods

* Updated package WebMarkupMin.AspNetCore2

* Updated package WebEssentials.AspNetCore.PWA

* Updated package LigerShark.WebOptimizer.Core to latest version that works on .NET Core 2

* Changed target framework to .NET Core App 2.2. Updated package Microsoft.VisualStudio.Web.BrowserLink

* Mmigrated to .NET Core 3.1

* Updated readme.md to reflect change to .NET Core 3.1
  • Loading branch information
ManfredLange authored and madskristensen committed Dec 9, 2019
1 parent 749026c commit 4a62138
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 106 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Blog engine for ASP.NET Core 2.0
# Blog engine for ASP.NET Core 3.1

A full-featured yet simple blog engine built on ASP.NET Core 2.0.
A full-featured yet simple blog engine built on ASP.NET Core 3.1.

[![Build status](https://ci.appveyor.com/api/projects/status/lwjrlpvmhg50wwbs?svg=true)](https://ci.appveyor.com/project/madskristensen/miniblog-core)
[![NuGet](https://img.shields.io/nuget/v/MadsKristensen.AspNetCore.Miniblog.svg)](https://nuget.org/packages/MadsKristensen.AspNetCore.Miniblog/)
Expand Down
17 changes: 8 additions & 9 deletions src/Miniblog.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.ImageOptimizer" Version="1.1.0.39" />
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="1.0.197" />
<PackageReference Include="LigerShark.WebOptimizer.Sass" Version="1.0.33-beta" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="3.0.250" />
<PackageReference Include="LigerShark.WebOptimizer.Sass" Version="3.0.40-beta" />
<PackageReference Include="Microsoft.SyndicationFeed.ReaderWriter" Version="1.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="WebEssentials.AspNetCore.CdnTagHelpers" Version="1.0.16" />
<PackageReference Include="WebEssentials.AspNetCore.OutputCaching" Version="1.0.16" />
<PackageReference Include="WebEssentials.AspNetCore.PWA" Version="1.0.25" />
<PackageReference Include="WebEssentials.AspNetCore.OutputCaching" Version="1.0.28" />
<PackageReference Include="WebEssentials.AspNetCore.PWA" Version="1.0.59" />
<PackageReference Include="WebEssentials.AspNetCore.StaticFilesWithCache" Version="1.0.1" />
<PackageReference Include="WebMarkupMin.AspNetCore2" Version="2.4.2" />
<PackageReference Include="WilderMinds.MetaWeblog" Version="1.2.3" />
<PackageReference Include="WebMarkupMin.AspNetCore2" Version="2.7.0" />
<PackageReference Include="WilderMinds.MetaWeblog" Version="2.0.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Services/FileBlogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FileBlogService : IBlogService
private readonly IHttpContextAccessor _contextAccessor;
private readonly string _folder;

public FileBlogService(IHostingEnvironment env, IHttpContextAccessor contextAccessor)
public FileBlogService(IWebHostEnvironment env, IHttpContextAccessor contextAccessor)
{
_folder = Path.Combine(env.WebRootPath, POSTS);
_contextAccessor = contextAccessor;
Expand Down
214 changes: 136 additions & 78 deletions src/Services/MetaWeblogService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
Expand All @@ -23,136 +24,160 @@ public MetaWeblogService(IBlogService blog, IConfiguration config, IHttpContextA
_context = context;
}

public string AddPost(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
public Task<string> AddPostAsync(string blogid, string username, string password, Post post, bool publish)
{
ValidateUser(username, password);

var newPost = new Models.Post
return Task.Run(() =>
{
Title = post.title,
Slug = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : Models.Post.CreateSlug(post.title),
Content = post.description,
IsPublished = publish,
Categories = post.categories
};
var newPost = new Models.Post
{
Title = post.title,
Slug = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : Models.Post.CreateSlug(post.title),
Content = post.description,
IsPublished = publish,
Categories = post.categories
};
if (post.dateCreated != DateTime.MinValue)
{
newPost.PubDate = post.dateCreated;
}
if (post.dateCreated != DateTime.MinValue)
{
newPost.PubDate = post.dateCreated;
}
_blog.SavePost(newPost).GetAwaiter().GetResult();
_blog.SavePost(newPost).GetAwaiter().GetResult();
return newPost.ID;
return newPost.ID;
});
}

public bool DeletePost(string key, string postid, string username, string password, bool publish)
public Task<bool> DeletePostAsync(string key, string postid, string username, string password, bool publish)
{
ValidateUser(username, password);

var post = _blog.GetPostById(postid).GetAwaiter().GetResult();

if (post != null)
return Task.Run(() =>
{
_blog.DeletePost(post).GetAwaiter().GetResult();
return true;
}
var post = _blog.GetPostById(postid).GetAwaiter().GetResult();
return false;
if (post != null)
{
_blog.DeletePost(post).GetAwaiter().GetResult();
return true;
}
return false;
});
}

public bool EditPost(string postid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
public Task<bool> EditPostAsync(string postid, string username, string password, Post post, bool publish)
{
ValidateUser(username, password);

var existing = _blog.GetPostById(postid).GetAwaiter().GetResult();

if (existing != null)
return Task.Run(() =>
{
existing.Title = post.title;
existing.Slug = post.wp_slug;
existing.Content = post.description;
existing.IsPublished = publish;
existing.Categories = post.categories;
ValidateUser(username, password);
if (post.dateCreated != DateTime.MinValue)
var existing = _blog.GetPostById(postid).GetAwaiter().GetResult();
if (existing != null)
{
existing.PubDate = post.dateCreated;
}
existing.Title = post.title;
existing.Slug = post.wp_slug;
existing.Content = post.description;
existing.IsPublished = publish;
existing.Categories = post.categories;
_blog.SavePost(existing).GetAwaiter().GetResult();
if (post.dateCreated != DateTime.MinValue)
{
existing.PubDate = post.dateCreated;
}
return true;
}
_blog.SavePost(existing).GetAwaiter().GetResult();
return true;
}
return false;
return false;
});
}

public CategoryInfo[] GetCategories(string blogid, string username, string password)
public Task<CategoryInfo[]> GetCategoriesAsync(string blogid, string username, string password)
{
ValidateUser(username, password);

return _blog.GetCategories().GetAwaiter().GetResult()
.Select(cat =>
new CategoryInfo
{
categoryid = cat,
title = cat
})
.ToArray();
return Task.Run(() =>
{
ValidateUser(username, password);
return _blog.GetCategories().GetAwaiter().GetResult()
.Select(cat =>
new CategoryInfo
{
categoryid = cat,
title = cat
})
.ToArray();
});
}

public WilderMinds.MetaWeblog.Post GetPost(string postid, string username, string password)
public Task<Post> GetPostAsync(string postid, string username, string password)
{
ValidateUser(username, password);
return Task.Run(() =>
{
ValidateUser(username, password);
var post = _blog.GetPostById(postid).GetAwaiter().GetResult();
var post = _blog.GetPostById(postid).GetAwaiter().GetResult();
if (post != null)
{
return ToMetaWebLogPost(post);
}
if (post != null)
{
return ToMetaWebLogPost(post);
}
return null;
return null;
});
}

public WilderMinds.MetaWeblog.Post[] GetRecentPosts(string blogid, string username, string password, int numberOfPosts)
public Task<Post[]> GetRecentPostsAsync(string blogid, string username, string password, int numberOfPosts)
{
ValidateUser(username, password);
return Task.Run(() =>
{
ValidateUser(username, password);
return _blog.GetPosts(numberOfPosts).GetAwaiter().GetResult().Select(ToMetaWebLogPost).ToArray();
return _blog.GetPosts(numberOfPosts).GetAwaiter().GetResult().Select(ToMetaWebLogPost).ToArray();
});
}

public BlogInfo[] GetUsersBlogs(string key, string username, string password)
public Task<BlogInfo[]> GetUsersBlogsAsync(string key, string username, string password)
{
ValidateUser(username, password);
return Task.Run(() =>
{
ValidateUser(username, password);
var request = _context.HttpContext.Request;
string url = request.Scheme + "://" + request.Host;
var request = _context.HttpContext.Request;
string url = request.Scheme + "://" + request.Host;
return new[] { new BlogInfo {
blogid ="1",
blogName = _config["blog:name"] ?? nameof(MetaWeblogService),
url = url
}};
return new[] { new BlogInfo {
blogid ="1",
blogName = _config["blog:name"] ?? nameof(MetaWeblogService),
url = url
}};
});
}

public MediaObjectInfo NewMediaObject(string blogid, string username, string password, MediaObject mediaObject)
public Task<MediaObjectInfo> NewMediaObjectAsync(string blogid, string username, string password, MediaObject mediaObject)
{
ValidateUser(username, password);
byte[] bytes = Convert.FromBase64String(mediaObject.bits);
string path = _blog.SaveFile(bytes, mediaObject.name).GetAwaiter().GetResult();
return Task.Run(() =>
{
ValidateUser(username, password);
byte[] bytes = Convert.FromBase64String(mediaObject.bits);
string path = _blog.SaveFile(bytes, mediaObject.name).GetAwaiter().GetResult();
return new MediaObjectInfo { url = path };
return new MediaObjectInfo { url = path };
});
}

public UserInfo GetUserInfo(string key, string username, string password)
public Task<UserInfo> GetUserInfoAsync(string key, string username, string password)
{
ValidateUser(username, password);
throw new NotImplementedException();
}

public int AddCategory(string key, string username, string password, NewCategory category)
public Task<int> AddCategoryAsync(string key, string username, string password, NewCategory category)
{
ValidateUser(username, password);
throw new NotImplementedException();
Expand Down Expand Up @@ -187,5 +212,38 @@ private WilderMinds.MetaWeblog.Post ToMetaWebLogPost(Models.Post post)
categories = post.Categories.ToArray()
};
}

public Task<Page> GetPageAsync(string blogid, string pageid, string username, string password)
{
throw new NotImplementedException();
}

public Task<Page[]> GetPagesAsync(string blogid, string username, string password, int numPages)
{
throw new NotImplementedException();
}

public Task<Author[]> GetAuthorsAsync(string blogid, string username, string password)
{
throw new NotImplementedException();
}

public Task<string> AddPageAsync(string blogid, string username, string password, Page page, bool publish)
{
ValidateUser(username, password);
throw new NotImplementedException();
}

public Task<bool> EditPageAsync(string blogid, string pageid, string username, string password, Page page, bool publish)
{
ValidateUser(username, password);
throw new NotImplementedException();
}

public Task<bool> DeletePageAsync(string blogid, string username, string password, string pageid)
{
ValidateUser(username, password);
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 4a62138

Please sign in to comment.