private void PingNet() { var p = new Ping(); var po = new PingOptions(64, true); string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); var result = IPStatus.TimedOut; try { var reply = p.Send("www.google.com", 1000 * 5, buffer); result = reply.Status; } catch { result = IPStatus.DestinationHostUnreachable; } var makeNew = connections.Count == 0 || connections[connections.Count - 1].Status != result; if (makeNew) { var newConnection = new ConnectionBlock() { StartTime = DateTime.Now, EndTime = DateTime.Now, Status = result, Pings = 1 }; connections.Add(newConnection); } else { var oldConnection = connections[connections.Count - 1]; oldConnection.EndTime = DateTime.Now; oldConnection.Pings++; connections[connections.Count - 1] = oldConnection; } UpdateLabels(); p.Dispose(); }
private bool GetLastBlock(out ConnectionBlock block, Predicate <ConnectionBlock> predicate) { if (connections.Count > 0) { for (int i = connections.Count - 1; i >= 0; i--) { if (predicate.Invoke(connections[i])) { block = connections[i]; return(true); } } } block = new ConnectionBlock(); return(false); }
public MainPage() { this.InitializeComponent(); var defaultInst = NetworkTableInstance.Default; ConnectionBlock.StartNetworking(new NetworkTableConnectionHandler(defaultInst)); serverClientManager = new NetworkTableServerClientManager(defaultInst); defaultInst.GetEntry("Hello").SetString("42"); defaultInst.GetEntry("Inner/S1").SetString("56"); defaultInst.GetEntry("Inner/S2").SetString("56hh"); defaultInst.GetEntry("Inner/N2/v2").SetString("5asdasd6"); defaultInst.GetEntry("Inner/N2/v1").SetString("5hdfgh6"); entryHandler = new NetworkTableEntryHandler(defaultInst); TableTree.StartNetworking(entryHandler); }
private async Task ShowPreferencesInternal(bool isStart) { PreferencesPage preferencesDialog = new PreferencesPage(); if (isStart) { preferencesDialog.PrimaryButtonText = "Start"; preferencesDialog.CloseButtonText = "Quit"; } else { preferencesDialog.PrimaryButtonText = "Update"; preferencesDialog.CloseButtonText = "Cancel"; } var result = await preferencesDialog.ShowAsync(); if (result == ContentDialogResult.Primary) { var serverProperties = preferencesDialog.GetServerProperties(); if (serverProperties.ServerMode) { serverClientManager.StartServer(serverProperties.Port); } else { ConnectionBlock.ServerLocation = serverProperties.ServerLocation; serverClientManager.StartClient(serverProperties.ServerLocation, serverProperties.Port); } ConnectionBlock.UpdateConnectionLabel(); ConnectionBlock.Visibility = Visibility.Visible; } else if (isStart) { Application.Current.Exit(); } }