public static string FormatName(this PingTrackerKind kind) { return(kind switch { PingTrackerKind.Aggregate => Loc.Localize("PingTrackerKindAutodetect", string.Empty), PingTrackerKind.COM => Loc.Localize("PingTrackerKindCOM", string.Empty), PingTrackerKind.IpHlpApi => Loc.Localize("PingTrackerKindWin32API", string.Empty), PingTrackerKind.Packets => Loc.Localize("PingTrackerKindPackets", string.Empty), _ => throw new ArgumentOutOfRangeException(nameof(kind)), });
protected PingTracker(PingConfiguration config, GameAddressDetector addressDetector, PingTrackerKind kind) { this.tokenSource = new CancellationTokenSource(); this.config = config; this.addressDetector = addressDetector; SeAddress = IPAddress.Loopback; RTTTimes = new ConcurrentQueue <float>(); Kind = kind; }
private PingTracker RequestNewPingTracker(PingTrackerKind kind) { this.pingTracker?.Dispose(); PingTracker newTracker = kind switch { PingTrackerKind.Aggregate => new AggregatePingTracker(this.config, this.addressDetector, this.network), PingTrackerKind.COM => new ComponentModelPingTracker(this.config, this.addressDetector), PingTrackerKind.IpHlpApi => new IpHlpApiPingTracker(this.config, this.addressDetector), PingTrackerKind.Packets => new PacketPingTracker(this.config, this.addressDetector, this.network), _ => throw new ArgumentOutOfRangeException(nameof(kind)), }; this.pingTracker = newTracker; if (this.pingTracker == null) { throw new InvalidOperationException($"Failed to create ping tracker \"{kind}\". The provided arguments may be incorrect."); } this.pingTracker.Start(); return(newTracker); }