/// <summary> /// Disconnects a connected peer. /// </summary> /// <param name="viewModel">The model that represents the peer to disconnect.</param> /// <returns></returns> public void DisconnectPeer(DisconnectPeerViewModel viewModel) { var path = "/api/Network/disconnect"; path = path.Replace("{format}", "json"); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(viewModel); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling DisconnectPeer: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling DisconnectPeer: " + response.ErrorMessage, response.ErrorMessage); } return; }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="viewModel"> (optional)</param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task <ApiResponse <Object> > DisconnectPeerAsyncWithHttpInfo(DisconnectPeerViewModel viewModel = null) { var localVarPath = "/api/Network/disconnect"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json-patch+json", "application/json", "text/json", "application/_*+json" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (viewModel != null && viewModel.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(viewModel); // http body (model) parameter } else { localVarPostBody = viewModel; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("DisconnectPeer", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), null)); }
public IActionResult DisconnectPeer([FromBody] DisconnectPeerViewModel viewModel) { try { var endpoint = viewModel.PeerAddress.ToIPEndPoint(this.network.DefaultPort); INetworkPeer peer = this.connectionManager.ConnectedPeers.FindByEndpoint(endpoint); if (peer != null) { var peerBehavior = peer.Behavior <IConnectionManagerBehavior>(); peer.Disconnect($"{endpoint} was disconnected via the API."); } return(this.Ok()); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="viewModel"> (optional)</param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task DisconnectPeerAsync(DisconnectPeerViewModel viewModel = null) { await DisconnectPeerAsyncWithHttpInfo(viewModel); }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="viewModel"> (optional)</param> /// <returns></returns> public void DisconnectPeer(DisconnectPeerViewModel viewModel = null) { DisconnectPeerWithHttpInfo(viewModel); }