public HttpResponseMessage OnGetCalls() { this.Logger.Info("Getting calls"); if (Bot.Instance.CallHandlers.IsEmpty) { return(HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.NoContent)); } var calls = new List <Dictionary <string, string> >(); foreach (var callHandler in Bot.Instance.CallHandlers.Values) { var call = callHandler.Call; var callPath = "/" + HttpRouteConstants.CallRoute.Replace("{callLegId}", call.Id); var callUri = new Uri(new Uri("http://localhost"), callPath).AbsoluteUri; var values = new Dictionary <string, string> { { "legId", call.Id }, { "scenarioId", call.ScenarioId.ToString() }, { "call", callUri }, { "logs", callUri.Replace("/calls/", "/logs/") }, { "changeScreenSharingRole", callUri + "/" + HttpRouteConstants.OnChangeRoleRoute }, }; calls.Add(values); } var serializer = new CommsSerializer(pretty: true); var json = serializer.SerializeObject(calls); var response = HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.OK); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); return(response); }
public HttpResponseMessage Get() { string yourJson = "{\"coord\":{\"lon\":-122.08,\"lat\":37.42},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"base\":\"stations\",\"main\":{\"temp\":19.2,\"pressure\":1013,\"humidity\":60,\"temp_min\":18,\"temp_max\":21},\"visibility\":16093,\"wind\":{\"speed\":2.6,\"deg\":130},\"clouds\":{\"all\":90},\"dt\":1538412960,\"sys\":{\"type\":1,\"id\":428,\"message\":0.0055,\"country\":\"US\",\"sunrise\":1538402672,\"sunset\":1538445012},\"id\":5375480,\"name\":\"Mountain View\",\"cod\":200}"; var response = HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.OK); response.Content = new StringContent(yourJson, Encoding.UTF8, "application/json"); return(response); }
public HttpResponseMessage OnGetLogs( int skip = 0, int take = 1000) { //var logs = this.Observer.GetLogs(skip, take); var response = HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.OK); //response.Content = new StringContent(logs, Encoding.UTF8, "text/plain"); return(response); }
public async Task <HttpResponseMessage> ChangeScreenSharingRoleAsync(string callLegId, [FromBody] ChangeRoleBody changeRoleBody) { try { await Bot.Instance.ChangeSharingRoleAsync(callLegId, changeRoleBody.Role).ConfigureAwait(false); return(HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.OK)); } catch (Exception e) { return(null); //return e.InspectExceptionAndReturnResponse(); } }
public async Task <HttpResponseMessage> JoinCallAsync([FromBody] JoinCallBody joinCallBody) { try { var call = await Bot.Instance.JoinCallAsync(joinCallBody).ConfigureAwait(false); var callPath = "/" + HttpRouteConstants.CallRoute.Replace("{callLegId}", call.Id); var callUri = new Uri(new Uri("http://localhost"), callPath).AbsoluteUri; var values = new Dictionary <string, string> { { "legId", call.Id }, { "scenarioId", call.ScenarioId.ToString() }, { "call", callUri }, { "logs", callUri.Replace("/calls/", "/logs/") }, { "changeScreenSharingRole", callUri + "/" + HttpRouteConstants.OnChangeRoleRoute }, }; var serializer = new CommsSerializer(pretty: true); var json = serializer.SerializeObject(values); var response = HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.OK); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); return(response); } catch (ServiceException e) { HttpResponseMessage response = (int)e.StatusCode >= 300 ? HttpRequestMessageCommonExtensions.CreateResponse(this.Request, e.StatusCode) : HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.InternalServerError); if (e.ResponseHeaders != null) { foreach (var responseHeader in e.ResponseHeaders) { response.Headers.TryAddWithoutValidation(responseHeader.Key, responseHeader.Value); } } response.Content = new StringContent(e.ToString()); return(response); } catch (Exception e) { HttpResponseMessage response = HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.InternalServerError); response.Content = new StringContent(e.ToString()); return(response); } }
public async Task <HttpResponseMessage> OnEndCallAsync(string callLegId) { this.Logger.Info($"Ending call {callLegId}"); try { var removed = await Bot.Instance.EndCallByCallLegIdAsync(callLegId).ConfigureAwait(false); return(removed ? HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.OK) : HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.NotFound)); } catch (Exception e) { var response = HttpRequestMessageCommonExtensions.CreateResponse(this.Request, HttpStatusCode.InternalServerError); response.Content = new StringContent(e.ToString()); return(response); } }