Skip to content

Commit 4890d7a

Browse files
committed
[FIX]#66
格式化代码
1 parent 4e6d406 commit 4890d7a

File tree

184 files changed

+1104
-1565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+1104
-1565
lines changed

src/DotnetSpider.Broker.Test/NodeHubTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
using Microsoft.AspNetCore.SignalR;
55
using Moq;
66
using Moq.EntityFrameworkCore;
7-
using System;
87
using System.Collections.Generic;
9-
using System.Text;
108
using Xunit;
119

1210
namespace DotnetSpider.Broker.Test

src/DotnetSpider.Broker/Controllers/JobController.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Mvc;
6-
using Microsoft.Extensions.Logging;
1+
using Microsoft.Extensions.Logging;
72

83
namespace DotnetSpider.Broker.Controllers
94
{

src/DotnetSpider.Broker/Data/JobStatus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace DotnetSpider.Broker.Data
77
/// <summary>
88
/// 爬虫状态
99
/// </summary>
10-
[System.Flags]
10+
[Flags]
1111
[JsonConverter(typeof(StringEnumConverter))]
1212
public enum Status
1313
{

src/DotnetSpider.Broker/Migrations/BrokerDbContextModelSnapshot.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.EntityFrameworkCore;
55
using Microsoft.EntityFrameworkCore.Infrastructure;
66
using Microsoft.EntityFrameworkCore.Metadata;
7-
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
87

98
namespace DotnetSpider.Broker.Migrations
109
{

src/DotnetSpider.Core.Test/HttpExecuteRecordTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void Record()
1111
{
1212
if (Env.IsWindows)
1313
{
14-
var result = HttpClientDownloader.Default.GetAsync("http://localhost:30013").Result;
14+
var result = DotnetSpider.Downloader.Downloader.Default.GetAsync("http://localhost:30013").Result;
1515
if (result.StatusCode == HttpStatusCode.OK)
1616
{
1717
Env.HubServiceTaskApiUrl = "http://localhost:30013/api/v1.0/task";

src/DotnetSpider.Core.Test/SpiderTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public void FastExit()
243243

244244
internal class TestDownloader : DotnetSpider.Downloader.Downloader
245245
{
246-
protected override Response DowloadContent(Request request)
246+
protected override Response DownloadContent(Request request)
247247
{
248248
return new Response() { Request = request, Content = "aabbcccdefg下载人数100", TargetUrl = request.Url };
249249
}
@@ -259,7 +259,7 @@ protected override void Handle(Page page)
259259

260260
internal class FileDownloader : DotnetSpider.Downloader.Downloader
261261
{
262-
protected override Response DowloadContent(Request request)
262+
protected override Response DownloadContent(Request request)
263263
{
264264
return new Response { Request = request };
265265
}

src/DotnetSpider.Core/AppBase.cs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using DotnetSpider.Core.Infrastructure;
22
using Microsoft.Extensions.Logging;
33
using Serilog;
4-
using Serilog.Sinks.SystemConsole.Themes;
54
using System;
6-
using System.Collections.Generic;
75
using System.Threading.Tasks;
86

97
namespace DotnetSpider.Core
@@ -13,27 +11,6 @@ namespace DotnetSpider.Core
1311
/// </summary>
1412
public abstract class AppBase : Named, IAppBase
1513
{
16-
public static SystemConsoleTheme ConsoleLogTheme { get; set; } = new SystemConsoleTheme(
17-
new Dictionary<ConsoleThemeStyle, SystemConsoleThemeStyle>
18-
{
19-
[ConsoleThemeStyle.Text] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Gray },
20-
[ConsoleThemeStyle.SecondaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray },
21-
[ConsoleThemeStyle.TertiaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray },
22-
[ConsoleThemeStyle.Invalid] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Yellow },
23-
[ConsoleThemeStyle.Null] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
24-
[ConsoleThemeStyle.Name] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
25-
[ConsoleThemeStyle.String] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
26-
[ConsoleThemeStyle.Number] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
27-
[ConsoleThemeStyle.Boolean] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
28-
[ConsoleThemeStyle.Scalar] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
29-
[ConsoleThemeStyle.LevelVerbose] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Cyan },
30-
[ConsoleThemeStyle.LevelDebug] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray },
31-
[ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
32-
[ConsoleThemeStyle.LevelWarning] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Yellow },
33-
[ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Red },
34-
[ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Red }
35-
});
36-
3714
private string _identity = Guid.NewGuid().ToString("N");
3815
private ILoggerFactory _loggerFactory;
3916

@@ -54,11 +31,12 @@ public string Identity
5431

5532
if (string.IsNullOrWhiteSpace(value))
5633
{
57-
throw new ArgumentException($"{nameof(Identity)} should not be empty or null.");
34+
throw new ArgumentException($"{nameof(Identity)} should not be empty or null");
5835
}
36+
5937
if (value.Length > Env.IdentityMaxLength)
6038
{
61-
throw new ArgumentException($"Length of identity should less than {Env.IdentityMaxLength}.");
39+
throw new ArgumentException($"Length of identity should less than {Env.IdentityMaxLength}");
6240
}
6341

6442
_identity = value;
@@ -73,12 +51,12 @@ public string Identity
7351
/// <summary>
7452
/// start time of spider.
7553
/// </summary>
76-
protected DateTime StartTime { get; private set; }
54+
public DateTime StartTime { get; private set; }
7755

7856
/// <summary>
7957
/// end time of spider.
8058
/// </summary>
81-
protected DateTime ExitTime { get; private set; }
59+
public DateTime ExitTime { get; private set; }
8260

8361
/// <summary>
8462
/// 运行记录接口
@@ -115,7 +93,7 @@ public void Run(params string[] arguments)
11593

11694
var loggerConfiguration = new LoggerConfiguration()
11795
.MinimumLevel.Verbose()
118-
.WriteTo.Console(theme: ConsoleLogTheme)
96+
.WriteTo.Console(theme: SerilogConsoleTheme.ConsoleLogTheme)
11997
.WriteTo.RollingFile("dotnetspider.log");
12098

12199
if (Env.HubServiceLog)
@@ -131,14 +109,17 @@ public void Run(params string[] arguments)
131109

132110
if (ExecuteRecord == null)
133111
{
134-
ExecuteRecord = string.IsNullOrWhiteSpace(Env.HubServiceUrl) ? (IExecuteRecord)new NullExecuteRecord() : new HttpExecuteRecord();
112+
ExecuteRecord = string.IsNullOrWhiteSpace(Env.HubServiceUrl)
113+
? (IExecuteRecord) new NullExecuteRecord()
114+
: new HttpExecuteRecord();
135115
ExecuteRecord.Logger = Logger;
136116
}
137117

138118
if (!ExecuteRecord.Add(TaskId, Name, Identity))
139119
{
140-
Logger.LogError($"Add execute record: {Identity} failed.");
120+
Logger.LogError($"Add execute record: {Identity} failed");
141121
}
122+
142123
try
143124
{
144125
StartTime = DateTime.Now;
@@ -148,7 +129,7 @@ public void Run(params string[] arguments)
148129
{
149130
ExitTime = DateTime.Now;
150131
ExecuteRecord.Remove(TaskId, Name, Identity);
151-
Logger.LogInformation($"Consume: {(ExitTime - StartTime).TotalSeconds} seconds.");
132+
Logger.LogInformation($"Consume: {(ExitTime - StartTime).TotalSeconds} seconds");
152133
PrintInfo.PrintLine();
153134
}
154135
}
@@ -159,4 +140,4 @@ public void Run(params string[] arguments)
159140

160141
public abstract void Exit(Action action = null);
161142
}
162-
}
143+
}

src/DotnetSpider.Core/Env.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ internal static void Reload()
277277

278278
HostName = Dns.GetHostName();
279279

280-
var interf = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(i =>
280+
var networkInterface = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(i =>
281281
(i.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||
282282
i.NetworkInterfaceType == NetworkInterfaceType.Wireless80211) && i.OperationalStatus == OperationalStatus.Up);
283283

284-
if (interf != null)
284+
if (networkInterface != null)
285285
{
286-
var unicastAddresses = interf.GetIPProperties().UnicastAddresses;
286+
var unicastAddresses = networkInterface.GetIPProperties().UnicastAddresses;
287287
Ip = unicastAddresses.FirstOrDefault(a =>
288288
a.IPv4Mask?.ToString() != "255.255.255.255" && a.Address.AddressFamily == AddressFamily.InterNetwork)?.Address
289289
.ToString();

src/DotnetSpider.Core/IAppBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// 标准任务接口
55
/// </summary>
6-
public interface IAppBase : IRunable, IIdentity, ITask, INamed
6+
public interface IAppBase : IRunnable, IIdentity, ITask, INamed
77
{
88
}
99
}

src/DotnetSpider.Core/INamed.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public abstract class Named : INamed
2626
protected Named()
2727
{
2828
var type = GetType();
29-
var nameAttribute = type.GetCustomAttributes(typeof(TaskName), true).FirstOrDefault() as TaskName;
30-
Name = nameAttribute != null ? nameAttribute.Name : type.Name;
29+
Name = type.GetCustomAttributes(typeof(TaskName), true).FirstOrDefault() is TaskName nameAttribute ? nameAttribute.Name : type.Name;
3130
}
3231
}
3332
}

0 commit comments

Comments
 (0)