using System;
using System.Collections.Generic;
using System.Linq;
namespace FastGithub.DomainResolve
{
///
/// IP测速结果
///
sealed class IPAddressTestResult
{
private static readonly TimeSpan lifeTime = TimeSpan.FromMinutes(2d);
private readonly int creationTickCount = Environment.TickCount;
///
/// 获取空的
///
public static IPAddressTestResult Empty = new(Array.Empty());
///
/// 获取是否为空
///
public bool IsEmpty => this.AddressElapseds.Length == 0;
///
/// 获取是否已过期
///
public bool IsExpired => lifeTime < TimeSpan.FromMilliseconds(Environment.TickCount - this.creationTickCount);
///
/// 获取测速结果
///
public IPAddressElapsed[] AddressElapseds { get; }
///
/// 测速结果
///
///
public IPAddressTestResult(IEnumerable addressElapseds)
{
this.AddressElapseds = addressElapseds.OrderBy(item => item.Elapsed).ToArray();
}
}
}