域名排序
This commit is contained in:
parent
f29dca6b43
commit
c542c628f1
@ -7,7 +7,7 @@ namespace FastGithub.Configuration
|
||||
/// 表示域名表达式
|
||||
/// *表示除.之外任意0到多个字符
|
||||
/// </summary>
|
||||
sealed class DomainPattern : IComparable<DomainPattern>
|
||||
public class DomainPattern : IComparable<DomainPattern>
|
||||
{
|
||||
private readonly Regex regex;
|
||||
private readonly string domainPattern;
|
||||
|
||||
@ -117,9 +117,9 @@ namespace FastGithub.Configuration
|
||||
/// 获取所有域名表达式
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string[] GetDomainPatterns()
|
||||
public DomainPattern[] GetDomainPatterns()
|
||||
{
|
||||
return this.domainConfigs.Keys.Select(item => item.ToString()).ToArray();
|
||||
return this.domainConfigs.Keys.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using FastGithub.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -71,7 +72,7 @@ namespace FastGithub.DomainResolve
|
||||
return;
|
||||
}
|
||||
|
||||
var fileStream = File.OpenRead(DATA_FILE);
|
||||
using var fileStream = File.OpenRead(DATA_FILE);
|
||||
var domains = await JsonSerializer.DeserializeAsync<string[]>(fileStream, cancellationToken: cancellationToken);
|
||||
if (domains == null)
|
||||
{
|
||||
@ -91,11 +92,24 @@ namespace FastGithub.DomainResolve
|
||||
/// 保存数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task SaveDataAsync()
|
||||
public async Task<bool> SaveDataAsync()
|
||||
{
|
||||
var domains = this.domainIPAddressHashSet.Keys
|
||||
.Select(item => new DomainPattern(item))
|
||||
.OrderBy(item => item)
|
||||
.Select(item => item.ToString())
|
||||
.ToArray();
|
||||
|
||||
try
|
||||
{
|
||||
var domains = this.domainIPAddressHashSet.Keys.ToArray();
|
||||
using var fileStream = File.OpenWrite(DATA_FILE);
|
||||
await JsonSerializer.SerializeAsync(fileStream, domains);
|
||||
await JsonSerializer.SerializeAsync(fileStream, domains, new JsonSerializerOptions { WriteIndented = true });
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user