public void OnDestroy() { if (pingInstance != null) { PingManager.Unregister(pingInstance); } }
/// <summary> /// Defines the method to be called when the command is invoked. /// </summary> /// <param name="parameter">Data used by the command. If the /// command does not require data to be passed, this object /// can be set to null.</param> public void Execute(object parameter) { _canExecute = false; IsActive = true; OnCanExecuteChanged(); CurrentPingManager = new PingManager(HostName, TimeSpan.FromSeconds(1)); PingResults.Clear(); CurrentPingManager.PingResult += (sender, e) => { App.CurrentDispatcher.Invoke(() => { PingResults.Add(e); }); }; CurrentPingManager.Start(); Task.Factory.StartNew(() => { Thread.Sleep(5000); CurrentPingManager.Stop(); App.CurrentDispatcher.Invoke(() => { _canExecute = true; OnCanExecuteChanged(); IsActive = false; }); }); }
static void Main(string[] args) { var pingRequestFactory = new PingRequestFactory(); var configSource = new ConfigSource(Constant.Config, ConfigFormat.JsonFile); var logSource = new LogSource(Constant.Log, LogFormat.TextFile); var config = new ConfigFactory().GetInstance(configSource); var log = new LogFactory().GetInstance(logSource); var configData = new DefaultConfigFactory().GetInstance(configSource); PingManager pinger = null; try { pinger = new PingManager(pingRequestFactory, config, log); if (pinger.CheckConfig(configData)) { pinger.Start(false); Console.ReadKey(); } else { Console.WriteLine(Constant.Config + " не найден, поэтому он был создан"); } } finally { pinger?.Stop(); } Console.ReadKey(); }
public SocketClient(Client client) { this.Semaphore = new SemaphoreSlim(1); this.Client = client; Connection(Constants.AuthAddress, Constants.AuthPort); this.Ping = new PingManager(); }
public void ConstructorWithValidArguments_ShouldReturnInstance() { String hostName = "localhost"; TimeSpan timeBetweenPings = new TimeSpan(0, 0, 1); IPingManager instance = new PingManager(hostName, timeBetweenPings); Assert.IsNotNull(instance); }
private IEnumerator UpdateLatency() { while (isServer) { latency = PingManager.GetClientPing(connectionToClient.connectionId); yield return(new WaitForSeconds(playerLatencyUpdateTime)); } }
private void OnLoadSaveData(PingInstanceSaveData saveData) { if (ping != null && saveData != null) { ping.pingType = (PingType)saveData.PingType; PingManager.NotifyColor(ping); PingManager.NotifyVisible(ping); } }
public void ConstructorWithEmptyHost_ShouldThrowException() { String hostName = String.Empty; TimeSpan timeBetweenPings = new TimeSpan(0, 0, 1); IPingManager instance = new PingManager(hostName, timeBetweenPings); Assert.Fail("Should have thrown ArgumentException."); }
public void ConstructorWithInvalidTimeSpan_ShouldThrowException() { String hostName = "localhost"; TimeSpan timeBetweenPings = new TimeSpan(0, 0, 0); IPingManager instance = new PingManager(hostName, timeBetweenPings); Assert.Fail("Should have thrown ArgumentOutOfRangeException."); }
public void OnSelect(int index) { var values = (PingType[])Enum.GetValues(typeof(PingType)); var value = values[index + 1]; target.pingType = value; PingManager.NotifyVisible(target); Close(); }
/// <summary> /// Starts the UI updater threads/tasks. /// </summary> public static void StartUIUpdaters() { ConnectionStatusUpdater.StartThread(); ServerListUpdater.StartThread(); AccountInfoUpdater.StartTask(); VersionUpdater.StartTask(); ToastManager.StartThread(); PingManager.StartThread(); }
public void PingManagerCheckConfigNullArgumentFailTest() { var pingRequestFactory = Mock.Of <IFactory <IConfigData, IPing <IHostInput, IPingResponse> > >(); var config = Mock.Of <IConfig <IConfigSource, IEnumerable <IConfigData> > >(); var log = Mock.Of <ILogger <ILogSource, ILogData> >(); var pingManager = new PingManager(pingRequestFactory, config, log); Assert.ThrowsException <ArgumentNullException>(() => pingManager.CheckConfig(null)); }
public void OnHandClick(GUIHand hand) { // Kill self when clicked Ping.visible = false; Ping.enabled = false; PingManager.Unregister(Ping); Destroy(Ping); Destroy(gameObject); }
public async Task <List <VehicleStatus> > Get() { string s = Startup.botURL; PingManager manager = new PingManager(_vehiclerepository, Startup.botURL); List <Vehicle> vehicles = await new VehicleManager(_vehiclerepository).GetAllVehicles(); List <VehicleStatus> vehiclestatuslst = await manager.GetVehicleStatusesAsync(vehicles); _statusrepository.InsertRange(vehiclestatuslst); return(vehiclestatuslst); }
public void PingManagerCreateInstanceSuccessTest() { var pingRequestFactory = Mock.Of <IFactory <IConfigData, IPing <IHostInput, IPingResponse> > >(); var config = Mock.Of <IConfig <IConfigSource, IEnumerable <IConfigData> > >(); var log = Mock.Of <ILogger <ILogSource, ILogData> >(); var pingManager = new PingManager(pingRequestFactory, config, log); Assert.IsInstanceOfType(pingManager, typeof(PingManager)); }
public async Task <bool> IsRNCAlive(string ip) { bool alive = false; await Task.Run(() => { PingManager pingManager = new PingManager(); alive = pingManager.PingDevice(ip); }); return(alive); }
// Start is called before the first frame update void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Debug.Log("Instance already exists"); Destroy(this); } }
static void Main(string[] args) { pingManager = new PingManager(); validator = AddressValidatorProvider.GetValidator(); while (true) { ConfigureCommandLine(); PrintInvitationConsole(); var command = Console.ReadLine(); ExecuteCommand(command); } }
static IEnumerator SpawnDeathMarker() { // Delay spawning the marker so that it doesn't end up right in the player's face yield return(new WaitForSeconds(5)); GameObject pingBase = new GameObject(); GameObject pingModel = GameObject.Instantiate(Resources.Load <GameObject>("WorldEntities/Tools/DiveReelNode")); PingInstance ping = pingBase.AddComponent <PingInstance>(); Light pingLight = pingModel.AddComponent <Light>(); SphereCollider pingCollider = pingModel.AddComponent <SphereCollider>(); DeathMarkerInteractor pingInteractor = pingModel.AddComponent <DeathMarkerInteractor>(); pingCollider.radius = 0.35f; // Set options for the light. pingLight.color = new Color(112 / 255, 255 / 255, 3 / 255, 0.25f); pingLight.type = LightType.Point; pingLight.range = 10f; // Parent transforms pingModel.transform.SetParent(pingBase.transform); pingLight.transform.SetParent(pingModel.transform); pingCollider.transform.SetParent(pingModel.transform); // Set the ping to the player's position at death. Vector3 playerPos = SubnauticaDeathMarker.DeathPosition; pingBase.transform.position = playerPos; // Set information about the ping. ping.enabled = false; ping.pingType = PingType.Signal; ping.origin = pingBase.transform; ping.colorIndex = 0; ping.visible = true; if (SubnauticaDeathMarker.Config.AddCoords) { ping.SetLabel($"Death ({playerPos.x:F1}, {playerPos.y:F1}, {playerPos.z:F1})"); } else { ping.SetLabel("Death"); } ping.enabled = true; pingInteractor.Ping = ping; PingManager.Register(ping); }
private static void Postfix(uGUI_PingTab __instance) { CustomPings.Initialize(); var entries = (Dictionary <int, uGUI_PingEntry>)uGUI_PingTab_entries.GetValue(__instance); foreach (var entry in entries) { var id = entry.Key; var pingEntry = entry.Value; var pingInstance = PingManager.Get(id); pingEntry.icon.sprite = SpriteManager.Get(SpriteManager.Group.Pings, PingManager.sCachedPingTypeStrings.Get(pingInstance.pingType)); pingEntry.icon.color = CustomPings.GetColor(pingInstance.colorIndex); pingEntry.UpdateLabel(pingInstance.pingType, pingInstance.GetLabel()); pingEntry.visibility.isOn = pingInstance.visible; pingEntry.visibilityIcon.sprite = ((!pingInstance.visible) ? pingEntry.spriteHidden : pingEntry.spriteVisible); } }
public void PingWithInvalidSettings_ShouldFirePingResultEventWithFailure() { String hostName = "invalidhostname"; TimeSpan timeBetweenPings = new TimeSpan(0, 0, 1); IPingManager instance = new PingManager(hostName, timeBetweenPings); Boolean expected = true; Boolean actual = false; instance.PingResult += (sender, e) => { actual = !e.Success; // Only set if the event fired. }; instance.Start(); Thread.Sleep(5000); Assert.AreEqual(expected, actual); }
public void StopAfterRunning_ShouldFireEvent() { String hostName = "localhost"; TimeSpan timeBetweenPings = new TimeSpan(0, 0, 1); IPingManager instance = new PingManager(hostName, timeBetweenPings); Boolean expected = true; Boolean actual = false; instance.PingManagerStateChanged += (sender, e) => { actual = (e.NewState == PingManagerStates.Stopped); }; instance.Start(); instance.Stop(); Assert.AreEqual(expected, actual); }
public void StartAgainWhileAlreadyRunning_ShouldIgnoreAndReturn() { String hostName = "localhost"; TimeSpan timeBetweenPings = new TimeSpan(0, 0, 1); IPingManager instance = new PingManager(hostName, timeBetweenPings); Boolean expected = true; Boolean actual = false; instance.PingResult += (sender, e) => { actual = e.Success; // Only set if the event fired. }; instance.Start(); instance.Start(); // No exception should be thrown. }
private static void SendPingInfo(HttpListenerContext context) { Log("PingInfo request"); var pings = new List <PingInfo>(); using (var pingEnumerator = PingManager.GetEnumerator()) { while (pingEnumerator.MoveNext()) { var ping = pingEnumerator.Current.Value; pings.Add( new PingInfo { Color = ping.colorIndex, Label = ping.GetLabel(), // Yes, Z and Y are supposed to be reversed, // converting Subnautica coords to something more traditional. X = (int)Math.Round(ping.origin.position.x, MidpointRounding.AwayFromZero), Z = (int)Math.Round(ping.origin.position.y, MidpointRounding.AwayFromZero), Y = (int)Math.Round(ping.origin.position.z, MidpointRounding.AwayFromZero), Visible = ping.visible, Type = ping.pingType.ToString() }); } } var json = JsonConvert.SerializeObject(pings, Formatting.Indented); // Log($"JSON: {json}"); var buffer = Encoding.UTF8.GetBytes(json); Log($"Set Headers"); context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.ContentType = "application/json"; context.Response.ContentLength64 = buffer.Length; context.Response.AddHeader("Date", DateTime.Now.ToString("r")); context.Response.AddHeader("Last-Modified", DateTime.Now.ToString("r")); Log($"Stream PlayerInfo"); context.Response.OutputStream.Write(buffer, 0, buffer.Length); Log($"Flush Content"); context.Response.OutputStream.Flush(); }
private static void Postfix(uGUI_Pings __instance) { if (staticInstance != __instance) { staticInstance = __instance; pings = (Dictionary <int, uGUI_Ping>)uGUI_Pings_pings.GetValue(__instance); } foreach (var entry in pings) { var ping = PingManager.Get(entry.Key); var guiPing = entry.Value; guiPing.SetColor(CustomPings.GetColor(ping.colorIndex)); var sprite = SpriteManager.Get(SpriteManager.Group.Pings, Enum.GetName(typeof(PingType), ping.pingType)); guiPing.SetIcon(sprite); } }
public static void SimulateCommand(PlayerManager playerExecutedCommand, Action command) { int playersLatency = (int)PingManager.GetClientPing(playerExecutedCommand.netIdentity.connectionToClient.connectionId); //Logger.Log($"Player's ping is {playersLatency}", LogVerbosity.Debug); int frameId = CurrentFrame - playersLatency; //Debug.Log($"Current frame is {CurrentFrame}, using frame {frameId}"); //if (frameId > TCNetworkManager.Instance.maxFrameCount) // frameId = TCNetworkManager.Instance.maxFrameCount; Simulate <object>(frameId, () => { command(); return(null); }); }
/// <summary> /// Simulates an <see cref="Action" /> for a <see cref="PlayerManager" /> /// </summary> /// <param name="playerExecutedCommand"></param> /// <param name="command"></param> public static void Simulate(PlayerManager playerExecutedCommand, Action command) { double playerLatency = PingManager.GetClientPing(playerExecutedCommand.connectionToClient.connectionId); Simulate(playerLatency, command); }
public void OnInitialize(int id, PingType type, int colorIndex) { ping = PingManager.Get(id); Initialize(); }