private void Connect() { DisconnectCommand.Execute(); _mySocket = new WebSocket(WSEndPoint); var observer = Observable .Using( () => _mySocket, ws => Observable .FromEventPattern <EventHandler <MessageEventArgs>, MessageEventArgs>( handler => ws.OnMessage += handler, handler => ws.OnMessage -= handler)); _myDisposable = observer.Subscribe(ep => { Status = "WS Recieved"; ReceivedMessage = "received:" + ep.EventArgs.Data; }); _mySocket.Connect(); Status = "WS Connected."; }
public async Task ExecuteTest() { var mockFileServer = new Mock <IServer>(); var client = new TcpClient(); var command = new DisconnectCommand(mockFileServer.Object, client); await command.Execute(); mockFileServer.Verify(m => m.RequestDisconnection(client)); }
private void HandleSelectedDevice(DeviceListItemViewModel device) { var config = new ActionSheetConfig(); if (device.IsConnected) { config.Add("Details", () => { ShowViewModel <ServiceListViewModel>(new MvxBundle(new Dictionary <string, string> { { DeviceIdKey, device.Device.Id.ToString() } })); }); config.Add("Update RSSI", async() => { try { _userDialogs.ShowLoading(); await device.Device.UpdateRssiAsync(); device.RaisePropertyChanged(nameof(device.Rssi)); _userDialogs.HideLoading(); _userDialogs.Toast($"RSSI updated {device.Rssi}", TimeSpan.FromSeconds(1000)); } catch (Exception ex) { _userDialogs.HideLoading(); await _userDialogs.AlertAsync($"Failed to update rssi. Exception: {ex.Message}"); } }); config.Destructive = new ActionSheetOption("Disconnect", () => DisconnectCommand.Execute(device)); } else { config.Add("Connect", async() => { if (await ConnectDeviceAsync(device)) { var navigation = Mvx.Resolve <IMvxNavigationService>(); await navigation.Navigate <ServiceListViewModel, MvxBundle>(new MvxBundle(new Dictionary <string, string> { { DeviceIdKey, device.Device.Id.ToString() } })); } }); config.Add("Connect & Dispose", () => ConnectDisposeCommand.Execute(device)); } config.Add("Copy GUID", () => CopyGuidCommand.Execute(device)); config.Cancel = new ActionSheetOption("Cancel"); config.SetTitle("Device Options"); _userDialogs.ActionSheet(config); }
public void DisconnectCommand_ExecuteRequest_1() { int returnCode = 0; Mock <IIrbisConnection> mock = GetConnectionMock(); IIrbisConnection connection = mock.Object; DisconnectCommand command = new DisconnectCommand(connection); ResponseBuilder builder = new ResponseBuilder() .StandardHeader(CommandCode.UnregisterClient, 123, 456) .NewLine() .Append(returnCode) .NewLine(); TestingSocket socket = (TestingSocket)connection.Socket; socket.Response = builder.Encode(); ClientQuery query = command.CreateQuery(); ServerResponse response = command.Execute(query); Assert.AreEqual(returnCode, response.ReturnCode); }
private void HandleSelectedDevice(DeviceListItemViewModel device, int type) { //type = 1 if slave, type = 2 if master. var config = new ActionSheetConfig(); if (device.IsConnected) { config.Destructive = new ActionSheetOption("Disconnect", () => DisconnectCommand.Execute(device)); } else { config.Add("Connect", async() => { if (await ConnectDeviceAsync(device)) { switch (type) { case 1: device.IsSlave = true; GraphViewModel.SlaveDeviceId = device.Device.Id; var ServiceSlave = await device.Device.GetServiceAsync(Guid.Parse("0000180d-0000-1000-8000-00805f9b34fb")); var CharacteristicSlave = await ServiceSlave.GetCharacteristicAsync(Guid.Parse("00002a37-0000-1000-8000-00805f9b34fb")); await CharacteristicSlave.StartUpdatesAsync(); break; case 2: device.IsMaster = true; GraphViewModel.MasterDeviceId = device.Device.Id; var ServiceMaster = await device.Device.GetServiceAsync(Guid.Parse("0000180d-0000-1000-8000-00805f9b34fb")); var CharacteristicMaster = await ServiceMaster.GetCharacteristicAsync(Guid.Parse("00002a37-0000-1000-8000-00805f9b34fb")); await CharacteristicMaster.StartUpdatesAsync(); break; } } }); } config.Cancel = new ActionSheetOption("Cancel"); config.SetTitle("Device Options"); _userDialogs.ActionSheet(config); }
DisconnectResponse IEasConnection.Disconnect(DisconnectRequest disconnectRequest) { DisconnectCommand disconnectCommand = new DisconnectCommand(this.EasConnectionSettings); return(disconnectCommand.Execute(disconnectRequest)); }
private void HandleSelectedDevice(DeviceListItemViewModel device) { var config = new ActionSheetConfig(); if (device.IsConnected) { config.Add("Update RSSI", async() => { try { _userDialogs.ShowLoading(); await device.Device.UpdateRssiAsync(); device.RaisePropertyChanged(nameof(device.Rssi)); _userDialogs.HideLoading(); _userDialogs.ShowSuccess($"RSSI updated {device.Rssi}", 1000); } catch (Exception ex) { _userDialogs.HideLoading(); _userDialogs.ShowError($"Failed to update rssi. Exception: {ex.Message}"); } }); config.Destructive = new ActionSheetOption("Disconnect", () => DisconnectCommand.Execute(device)); } else { config.Add("Connect", async() => { if (await ConnectDeviceAsync(device)) { ShowViewModel <ServiceListViewModel>(new MvxBundle(new Dictionary <string, string> { { DeviceIdKey, device.Device.Id.ToString() } })); } }); //config.Add("Connect & Dispose", () => ConnectDisposeCommand.Execute(device)); config.Add("Save Advertised Data", () => { if (device.Device.AdvertisementRecords == null || device.Device.AdvertisementRecords.Count == 0) { _userDialogs.Alert("No Data Found"); return; } var advModel = new AdvertisementData() { Id = Guid.NewGuid(), DeviceId = device.Id.ToString(), Name = device.Name, Data = device.Device.AdvertisementRecords[0].Data }; _advertisementDataRepository.InsertDevice(advModel); }); } config.Add("Copy ID", () => CopyGuidCommand.Execute(device)); config.Cancel = new ActionSheetOption("Cancel"); config.SetTitle("Device Options"); _userDialogs.ActionSheet(config); }