using System;
using System.Net;
using System.Threading;
namespace FastGithub.Scanner
{
///
/// Github扫描上下文
///
sealed class GithubContext : DomainAddress, IEquatable
{
///
/// 获取或设置是否可用
///
public bool Available { get; set; }
///
/// 设置取消令牌
///
public CancellationToken CancellationToken { get; }
///
/// 获取扫描历史信息
///
public GithubContextHistory History { get; } = new();
///
/// Github扫描上下文
///
///
///
public GithubContext(string domain, IPAddress address)
: this(domain, address, CancellationToken.None)
{
}
///
/// Github扫描上下文
///
///
///
///
public GithubContext(string domain, IPAddress address, CancellationToken cancellationToken)
: base(domain, address)
{
this.CancellationToken = cancellationToken;
}
public bool Equals(GithubContext? other)
{
return base.Equals(other);
}
///
/// 转换为为统计信息
///
///
public string ToStatisticsString()
{
var rate = Math.Round(this.History.AvailableRate * 100, 2);
return $"{{Address={this.Address}, AvailableRate={rate}%, AvgElapsed={this.History.AvgElapsed.TotalSeconds}s}}";
}
}
}