public void Execute(object parameter) { remoteVM.addRaspberryPi(); }
public async void Execute(object parameter) { TcpClient registryServerSocket = new TcpClient(); Request request = new Request("getRegisteredDevices", null); try { await registryServerSocket.ConnectAsync("192.168.178.21", 54320); } catch (Exception e) { vmDebug.AddDebugInfo("[ERROR]", "Error connecting to the Registry Server: " + e.Message); return; } try { Transfer.sendObject(registryServerSocket.GetStream(), request); } catch (Exception e) { vmDebug.AddDebugInfo("[ERROR]", "Error sending to the RegistryServer: " + e.Message); return; } Object result; try { result = Transfer.receiveObject(registryServerSocket.GetStream()); } catch (Exception e) { vmDebug.AddDebugInfo("[ERROR]", "Error receiving from the RegistryServer: " + e.Message); return; } if (result.GetType() == typeof(SuccessResult)) { List <RaspberryPiItem> connectedList = remoteVM.BackendList.Where(item => item.Connected).ToList(); remoteVM.BackendList.Clear(); foreach (var entry in connectedList) { remoteVM.BackendList.Add(entry); } SuccessResult successResult = (SuccessResult)result; Dictionary <string, string> dictionary = (Dictionary <string, string>)successResult.result; foreach (var entry in dictionary) { remoteVM.addRaspberryPi(entry.Key, entry.Value); } } else if (result.GetType() == typeof(ExceptionResult)) { vmDebug.AddDebugInfo("[ERROR]", "Error Result from the RegistryServer: " + ((ExceptionResult)result).exceptionMessage); } else { vmDebug.AddDebugInfo("[ERROR]", "Unhandled Registry Server Result Type: " + result.GetType().ToString()); } registryServerSocket.Close(); }