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

-2
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

+1-6
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

+1-1
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

-1
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

+1-1
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

+2-2
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

+13-32
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

+3-3
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

+1-1
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

+1-2
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
}

src/DotnetSpider.Core/IRunable.cs src/DotnetSpider.Core/IRunnable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace DotnetSpider.Core
44
{
5-
public interface IRunable : IControllable
5+
public interface IRunnable : IControllable
66
{
77
/// <summary>
88
/// 运行程序

src/DotnetSpider.Core/Infrastructure/Adsl.cs

+7-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private struct Rasconn
1717
private static extern uint RasHangUp(IntPtr hrasconn);
1818

1919
[DllImport("wininet.dll")]
20-
private static extern int InternetDial(IntPtr hwnd, [In]string lpszConnectionid, uint dwFlags, ref int lpdwConnection, uint dwReserved);
20+
private static extern int InternetDial(IntPtr hwnd, [In]string lpszConnectionId, uint dwFlags, ref int lpdwConnection, uint dwReserved);
2121

2222
[DllImport("Rasapi32.dll", EntryPoint = "RasEnumConnectionsA", SetLastError = true)]
2323
private static extern int RasEnumConnections
@@ -34,7 +34,7 @@ ref int lpcConnections // number of connections written to buffer
3434
/// <returns></returns>
3535
public int Connect(string adslName)
3636
{
37-
int lpdwConnection = 0;
37+
var lpdwConnection = 0;
3838
return InternetDial(IntPtr.Zero, adslName, 2, ref lpdwConnection, 0);
3939
}
4040

@@ -43,19 +43,19 @@ public int Connect(string adslName)
4343
/// </summary>
4444
public void Disconnect()
4545
{
46-
var intprt = GetAdslIntPrt();
47-
RasHangUp(intprt);
46+
var intPrt = GetAdslIntPrt();
47+
RasHangUp(intPrt);
4848
}
4949

5050
private IntPtr GetAdslIntPrt()
5151
{
52-
Rasconn lprasConn = new Rasconn
52+
var lprasConn = new Rasconn
5353
{
5454
Hrasconn = IntPtr.Zero
5555
};
5656

5757

58-
int lpcConnections = 0;
58+
var lpcConnections = 0;
5959
#if !NETSTANDARD
6060
var lpcb = Marshal.SizeOf(typeof(Rasconn));
6161
#else
@@ -64,12 +64,7 @@ private IntPtr GetAdslIntPrt()
6464

6565
var nRet = RasEnumConnections(ref lprasConn, ref lpcb, ref lpcConnections);
6666

67-
if (nRet != 0)
68-
{
69-
return IntPtr.Zero;
70-
}
71-
72-
return lprasConn.Hrasconn;
67+
return nRet != 0 ? IntPtr.Zero : lprasConn.Hrasconn;
7368
}
7469
}
7570
}

src/DotnetSpider.Core/Infrastructure/AutomicInteger.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public int Dec()
5757
/// <returns>更新成功时返回true</returns>
5858
public bool CompareAndSet(int expectedValue, int newValue)
5959
{
60-
int original = Interlocked.CompareExchange(ref _value, newValue, expectedValue);
60+
var original = Interlocked.CompareExchange(ref _value, newValue, expectedValue);
6161
return original == expectedValue;
6262
}
6363

src/DotnetSpider.Core/Infrastructure/AutomicLong.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public long Dec()
5757
/// <returns>更新成功时返回true</returns>
5858
public bool CompareAndSet(long expectedValue, long newValue)
5959
{
60-
long original = Interlocked.CompareExchange(ref _value, newValue, expectedValue);
60+
var original = Interlocked.CompareExchange(ref _value, newValue, expectedValue);
6161
return original == expectedValue;
6262
}
6363

src/DotnetSpider.Core/Infrastructure/BloomFilter.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace DotnetSpider.Core.Infrastructure
1212
/// </summary>
1313
public class BloomFilter
1414
{
15-
private readonly BitArray _bitset;
15+
private readonly BitArray _bitSet;
1616
private readonly int _bitSetSize;
1717
private readonly double _bitsPerElement;
1818
private readonly int _expectedNumberOfFilterElements; // expected (maximum) number of elements to be added
@@ -41,7 +41,7 @@ public BloomFilter(double c, int n, int k)
4141
_bitsPerElement = c;
4242
_bitSetSize = (int)Math.Ceiling(c * n);
4343
_numberOfAddedElements = 0;
44-
_bitset = new BitArray(_bitSetSize);
44+
_bitSet = new BitArray(_bitSetSize);
4545
}
4646

4747
/// <summary>
@@ -83,7 +83,7 @@ public BloomFilter(double falsePositiveProbability, int expectedNumberOfElements
8383
public BloomFilter(int bitSetSize, int expectedNumberOfFilterElements, int actualNumberOfFilterElements, BitArray filterData)
8484
: this(bitSetSize, expectedNumberOfFilterElements)
8585
{
86-
_bitset = filterData;
86+
_bitSet = filterData;
8787
_numberOfAddedElements = actualNumberOfFilterElements;
8888
}
8989

@@ -185,7 +185,7 @@ public override bool Equals(object obj)
185185
{
186186
return false;
187187
}
188-
if (_bitset != other._bitset && (_bitset == null || !Equals(_bitset, other._bitset)))
188+
if (_bitSet != other._bitSet && (_bitSet == null || !Equals(_bitSet, other._bitSet)))
189189
{
190190
return false;
191191
}
@@ -200,7 +200,7 @@ public override bool Equals(object obj)
200200
public override int GetHashCode()
201201
{
202202
int hash = 7;
203-
hash = 61 * hash + (_bitset != null ? HashBytes(_bitset) : 0);
203+
hash = 61 * hash + (_bitSet != null ? HashBytes(_bitSet) : 0);
204204
hash = 61 * hash + _expectedNumberOfFilterElements;
205205
hash = 61 * hash + _bitSetSize;
206206
hash = 61 * hash + _k;
@@ -265,7 +265,7 @@ public int GetK()
265265
/// </summary>
266266
public void Clear()
267267
{
268-
_bitset.SetAll(false);
268+
_bitSet.SetAll(false);
269269
_numberOfAddedElements = 0;
270270
}
271271

@@ -288,7 +288,7 @@ public void Add(byte[] bytes)
288288
int[] hashes = CreateHashes(bytes, _k);
289289
foreach (int hash in hashes)
290290
{
291-
_bitset.Set(Math.Abs(hash % _bitSetSize), true);
291+
_bitSet.Set(Math.Abs(hash % _bitSetSize), true);
292292
}
293293
_numberOfAddedElements++;
294294
}
@@ -339,7 +339,7 @@ public bool Contains(object element)
339339
public bool Contains(byte[] bytes)
340340
{
341341
int[] hashes = CreateHashes(bytes, _k);
342-
return hashes.All(hash => _bitset.Get(Math.Abs(hash % _bitSetSize)));
342+
return hashes.All(hash => _bitSet.Get(Math.Abs(hash % _bitSetSize)));
343343
}
344344

345345
/// <summary>
@@ -361,7 +361,7 @@ public bool ContainsAll(IEnumerable<object> c)
361361
/// <returns>true if the bit is set, false if it is not.</returns>
362362
public bool GetBit(int bit)
363363
{
364-
return _bitset.Get(bit);
364+
return _bitSet.Get(bit);
365365
}
366366

367367
/// <summary>
@@ -371,7 +371,7 @@ public bool GetBit(int bit)
371371
/// <param name="value">If true, the bit is set. If false, the bit is cleared.</param>
372372
public void SetBit(int bit, bool value)
373373
{
374-
_bitset.Set(bit, value);
374+
_bitSet.Set(bit, value);
375375
}
376376

377377
/// <summary>
@@ -380,7 +380,7 @@ public void SetBit(int bit, bool value)
380380
/// <returns>bit set representing the Bloom filter.</returns>
381381
public BitArray GetBitSet()
382382
{
383-
return _bitset;
383+
return _bitSet;
384384
}
385385

386386
/// <summary>

0 commit comments

Comments
 (0)