aboutsummaryrefslogtreecommitdiff
path: root/Timeline
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-10-19 17:33:38 +0800
committer杨宇千 <crupest@outlook.com>2019-10-19 17:33:38 +0800
commit2984abc9aa0429380459e5b5b6fda2d20058041b (patch)
treef75fde126094e8310dd9e2588bb9b9e8baa79a3b /Timeline
parentdef8e8dd78812c019a0d6e8e5a3e2de4e82ae3e4 (diff)
downloadtimeline-2984abc9aa0429380459e5b5b6fda2d20058041b.tar.gz
timeline-2984abc9aa0429380459e5b5b6fda2d20058041b.tar.bz2
timeline-2984abc9aa0429380459e5b5b6fda2d20058041b.zip
...
Diffstat (limited to 'Timeline')
-rw-r--r--Timeline/GlobalSuppressions.cs9
-rw-r--r--Timeline/Models/Http/Common.cs2
-rw-r--r--Timeline/Program.cs2
-rw-r--r--Timeline/Services/UserService.cs61
-rw-r--r--Timeline/Startup.cs5
-rw-r--r--Timeline/Timeline.csproj7
6 files changed, 67 insertions, 19 deletions
diff --git a/Timeline/GlobalSuppressions.cs b/Timeline/GlobalSuppressions.cs
new file mode 100644
index 00000000..3c9c8341
--- /dev/null
+++ b/Timeline/GlobalSuppressions.cs
@@ -0,0 +1,9 @@
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "This is not a UI application.")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "This is not bad.")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "No need to check the null because it's ASP.Net's duty.", Scope = "namespaceanddescendants", Target = "Timeline.Controllers")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Error code constant identifiers use nested names.", Scope = "type", Target = "Timeline.ErrorCodes")]
diff --git a/Timeline/Models/Http/Common.cs b/Timeline/Models/Http/Common.cs
index af185e85..83e6a072 100644
--- a/Timeline/Models/Http/Common.cs
+++ b/Timeline/Models/Http/Common.cs
@@ -38,7 +38,7 @@ namespace Timeline.Models.Http
Message = message;
}
- public int Code { get; set; }
+ public int? Code { get; set; }
public string Message { get; set; }
}
diff --git a/Timeline/Program.cs b/Timeline/Program.cs
index dfc93b9e..7474fe2f 100644
--- a/Timeline/Program.cs
+++ b/Timeline/Program.cs
@@ -6,7 +6,7 @@ using Microsoft.Extensions.Hosting;
namespace Timeline
{
- public class Program
+ public static class Program
{
public static void Main(string[] args)
{
diff --git a/Timeline/Services/UserService.cs b/Timeline/Services/UserService.cs
index 347b8cbb..9564b34b 100644
--- a/Timeline/Services/UserService.cs
+++ b/Timeline/Services/UserService.cs
@@ -5,6 +5,7 @@ using System;
using System.Linq;
using System.Threading.Tasks;
using Timeline.Entities;
+using Timeline.Helpers;
using Timeline.Models;
using Timeline.Models.Validation;
using static Timeline.Helpers.MyLogHelper;
@@ -23,14 +24,20 @@ namespace Timeline.Services
{
private const string message = "The user does not exist.";
+ public UserNotExistException()
+ : base(message)
+ {
+
+ }
+
public UserNotExistException(string username)
- : base(FormatLogMessage(message, Pair("Username", username)))
+ : base(Log.Format(message, ("Username", username)))
{
Username = username;
}
public UserNotExistException(long id)
- : base(FormatLogMessage(message, Pair("Id", id)))
+ : base(Log.Format(message, ("Id", id)))
{
Id = id;
}
@@ -42,21 +49,29 @@ namespace Timeline.Services
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
/// <summary>
- /// The username that does not exist. May be null then <see cref="Id"/> is not null.
+ /// The username that does not exist.
/// </summary>
- public string Username { get; private set; }
+ public string Username { get; set; }
/// <summary>
- /// The id that does not exist. May be null then <see cref="Username"/> is not null.
+ /// The id that does not exist.
/// </summary>
- public long? Id { get; private set; }
+ public long? Id { get; set; }
}
[Serializable]
public class BadPasswordException : Exception
{
+ private const string message = "Password is wrong.";
+
+ public BadPasswordException()
+ : base(message)
+ {
+
+ }
+
public BadPasswordException(string badPassword)
- : base(FormatLogMessage("Password is wrong.", Pair("Bad Password", badPassword)))
+ : base(Log.Format(message, ("Bad Password", badPassword)))
{
Password = badPassword;
}
@@ -70,22 +85,31 @@ namespace Timeline.Services
/// <summary>
/// The wrong password.
/// </summary>
- public string Password { get; private set; }
+ public string Password { get; set; }
}
[Serializable]
public class BadTokenVersionException : Exception
{
+ private const string message = "Token version is expired.";
+
+ public BadTokenVersionException()
+ : base(message)
+ {
+
+ }
+
public BadTokenVersionException(long tokenVersion, long requiredVersion)
- : base(FormatLogMessage("Token version is expired.",
- Pair("Token Version", tokenVersion),
- Pair("Required Version", requiredVersion)))
+ : base(Log.Format(message,
+ ("Token Version", tokenVersion),
+ ("Required Version", requiredVersion)))
{
TokenVersion = tokenVersion;
RequiredVersion = requiredVersion;
}
+ public BadTokenVersionException(string message) : base(message) { }
public BadTokenVersionException(string message, Exception inner) : base(message, inner) { }
protected BadTokenVersionException(
@@ -95,12 +119,12 @@ namespace Timeline.Services
/// <summary>
/// The version in the token.
/// </summary>
- public long TokenVersion { get; private set; }
+ public long? TokenVersion { get; set; }
/// <summary>
/// The version required.
/// </summary>
- public long RequiredVersion { get; private set; }
+ public long? RequiredVersion { get; set; }
}
/// <summary>
@@ -109,6 +133,12 @@ namespace Timeline.Services
[Serializable]
public class UsernameBadFormatException : Exception
{
+ private const string message = "Username is of bad format.";
+
+ public UsernameBadFormatException() : base(message) { }
+ public UsernameBadFormatException(string message) : base(message) { }
+ public UsernameBadFormatException(string message, Exception inner) : base(message, inner) { }
+
public UsernameBadFormatException(string username, string message) : base(message) { Username = username; }
public UsernameBadFormatException(string username, string message, Exception inner) : base(message, inner) { Username = username; }
protected UsernameBadFormatException(
@@ -128,7 +158,10 @@ namespace Timeline.Services
[Serializable]
public class UserAlreadyExistException : Exception
{
- public UserAlreadyExistException(string username) : base($"User {username} already exists.") { Username = username; }
+ private const string message = "User already exists.";
+
+ public UserAlreadyExistException() : base(message) { }
+ public UserAlreadyExistException(string username) : base(Log.Format(message, ("Username", username))) { Username = username; }
public UserAlreadyExistException(string username, string message) : base(message) { Username = username; }
public UserAlreadyExistException(string message, Exception inner) : base(message, inner) { }
protected UserAlreadyExistException(
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index 8e8a6393..fc570fdd 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -27,11 +27,12 @@ namespace Timeline
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
- services.AddMvc()
+ services.AddControllers()
.ConfigureApiBehaviorOptions(options =>
{
options.InvalidModelStateResponseFactory = InvalidModelResponseFactory.Factory;
- });
+ })
+ .AddNewtonsoftJson();
services.Configure<JwtConfig>(Configuration.GetSection(nameof(JwtConfig)));
var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get<JwtConfig>();
diff --git a/Timeline/Timeline.csproj b/Timeline/Timeline.csproj
index f01b8e31..836dfb47 100644
--- a/Timeline/Timeline.csproj
+++ b/Timeline/Timeline.csproj
@@ -13,9 +13,14 @@
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
+ <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ </PackageReference>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.0.0-rc1.final" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-dev002868" />
- <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.5.0" />
+ <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
</ItemGroup>
</Project>