public async Task <IActionResult> SendTrustPing(string connectionId) { var context = await _agentContextProvider.GetContextAsync(); var connection = await _connectionService.GetAsync(context, connectionId); var message = new TrustPingMessage { ResponseRequested = true, Comment = "Hello" }; var slim = new SemaphoreSlim(0, 1); var success = false; using (var subscription = _eventAggregator.GetEventByType <ServiceMessageProcessingEvent>() .Where(_ => _.MessageType == CustomMessageTypes.TrustPingResponseMessageType) .Subscribe(_ => { success = true; slim.Release(); })) { await _messageService.SendAsync(context.Wallet, message, connection); await slim.WaitAsync(TimeSpan.FromSeconds(5)); return(RedirectToAction("Details", new { id = connectionId, trustPingSuccess = success })); } }
public async Task <IActionResult> SendPingAsync(OperationBody body) { var connectionId = body.Id; var data = body.Data; var context = await _agentContextProvider.GetContextAsync(); var THConnection = _connectionCache.Get <TestHarnessConnection>(connectionId); if (THConnection == null) { return(NotFound()); // Return early if not found } ConnectionRecord connection; try { connection = await _connectionService.GetAsync(context, connectionId); } catch { return(NotFound()); } var message = new TrustPingMessage { Comment = (string)data["comment"] }; await _messageService.SendAsync(context.Wallet, message, connection); THConnection.State = TestHarnessConnectionState.Complete; return(Ok(THConnection)); }
public async Task PingConnectionAsync() { // var dialog = UserDialogs.Instance.Loading("Pinging"); var context = await _agentContextProvider.GetContextAsync(); var message = new TrustPingMessage { ResponseRequested = true }; try { var response = await _messageService.SendReceiveAsync(context.Wallet, message, Record) as UnpackedMessageContext; var trustPingResponse = response.GetMessage <TrustPingResponseMessage>(); } catch (Exception) { //Swallow exception //TODO more granular error protection } // if (dialog.IsShowing) // { // dialog.Hide(); // dialog.Dispose(); // } // DialogService.Alert( // success ? // "Ping Response Recieved" : // "No Ping Response Recieved" // ); }
public async Task <IActionResult> SendTrustPing(string connectionId) { var context = new AgentContext { Wallet = await _walletService.GetWalletAsync(_walletOptions.WalletConfiguration, _walletOptions.WalletCredentials) }; var connection = await _connectionService.GetAsync(context, connectionId); var message = new TrustPingMessage { ResponseRequested = true, Comment = "Hello" }; bool responseRecieved = false; _eventAggregator.GetEventByType <ServiceMessageProcessingEvent>() .Where(_ => _.MessageType == CustomMessageTypes.TrustPingResponseMessageType) .Subscribe(_ => { responseRecieved = true; }); await _messageService.SendToConnectionAsync(context.Wallet, message, connection); var task = Task.Factory.StartNew(() => { while (!responseRecieved) { } return(true); }); task.Wait(5000); if (responseRecieved) { return(RedirectToAction("Details", new { id = connectionId, trustPingSuccess = true })); } return(RedirectToAction("Details", new { id = connectionId, trustPingSuccess = false })); }
public async Task <SendPingResponse> Handle ( SendPingRequest aSendPingRequest, CancellationToken aCancellationToken ) { IAgentContext agentContext = await AgentProvider.GetContextAsync(); ConnectionRecord connectionRecord = await ConnectionService.GetAsync(agentContext, aSendPingRequest.ConnectionId); var trustPingMessage = new TrustPingMessage(agentContext.UseMessageTypesHttps) { ResponseRequested = true, Comment = "Hello" }; var semaphoreSlim = new SemaphoreSlim(0, 1); bool success = false; using ( IDisposable subscription = EventAggregator.GetEventByType <ServiceMessageProcessingEvent>() .Where ( aServiceMessageProcessingEvent => aServiceMessageProcessingEvent.MessageType == TrustPingResponseMessageType ) .Subscribe(_ => { success = true; semaphoreSlim.Release(); }) ) { await MessageService.SendAsync(agentContext, trustPingMessage, connectionRecord); await semaphoreSlim.WaitAsync(TimeSpan.FromSeconds(5)); } var response = new SendPingResponse(aSendPingRequest.CorrelationId, success); return(response); }
public async Task PingConnectionAsync() { _agentContext = await _agentContextProvider.GetContextAsync(); var dialog = UserDialogs.Instance.Loading("Pinging"); var message = new TrustPingMessage { ResponseRequested = true }; bool success = false; try { var response = await _messageService.SendReceiveAsync(_agentContext, message, _record) as UnpackedMessageContext; var trustPingResponse = response.GetMessage <TrustPingResponseMessage>(); success = true; } catch (Exception) { //Swallow exception //TODO more granular error protection } if (dialog.IsShowing) { dialog.Hide(); dialog.Dispose(); } DialogService.Alert( success ? "Ping Response Recieved" : "No Ping Response Recieved" ); }