public void IsValidRequest(LogMessageRequest request) { if (request == null) { throw new ArgumentNullException("request is null"); } this.IsValidRequest(request.Token); }
protected LogMessageRequest GetLogMessageRequest() { var request = new LogMessageRequest() { Token = SetTokenRequest(), Message = "IAmALogMessage" }; return(request); }
public IHttpActionResult LogMessageV1(LogMessageRequest request) { if (!request.IsValid) { return(BadRequest("Invalid request provided, please check your request body.")); } var response = _loggingService.LogMessage(request); return(Ok(response)); }
public LogMessageResponse LogMessage(LogMessageRequest request) { var response = new LogMessageResponse { Request = request }; GetLogMessageLookupValues(request.LogMessage); _logRepository.LogMessage(request.LogMessage); return(response); }
public IActionResult Log([FromBody] LogMessageRequest request) { try { this.validationHelper.IsValidRequest(request); this.service.LogAuthenticated(request.Message, request.Token.EncodedUserName, request.Token.EncodedToken); return(Ok()); // 200 } catch (Exception ex) { return(StatusCode(Convert.ToInt32(HttpStatusCode.InternalServerError))); } }
public async Task <string> SendLogsAsync(LogMessageRequest message) { _logger.LogInformation("At SendLogMessageAsync"); var request = new HttpRequestMessage(HttpMethod.Post, "messages"); string messageJson = JsonConvert.SerializeObject(message); request.Content = new StringContent(messageJson, Encoding.UTF8, "application/json"); var client = _clientFactory.CreateClient("externalservice"); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsStringAsync()); } else { throw new Exception((int)response.StatusCode + "-" + response.StatusCode.ToString()); } }
public void LogMessage(string message)//, string encodedUserName, string encodedToken) { var token = DemoUserLogin(); var request = new LogMessageRequest() { Message = message, Token = new TokenRequest() { EncodedUserName = Shared.misc.Utilities.EncodeClientBase64String(Shared.Constants.DEMO_USER), EncodedToken = Shared.misc.Utilities.EncodeClientBase64String(token) } }; var json = JsonConvert.SerializeObject(request); var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); var url = host + "/log"; httpClient.Post(url, content); }
/// <summary> /// Logs a generic message from the client, such as `Failed to render component`, `Profile page is running slow`, `More than 500 users have accessed this result.`, etc. /// Documentation https://developers.google.com/partners/v2/reference/clientMessages/log /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated partners service.</param> /// <param name="body">A valid partners v2 body.</param> /// <returns>LogMessageResponseResponse</returns> public static LogMessageResponse Log(partnersService service, LogMessageRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Make the request. return(service.ClientMessages.Log(body).Execute()); } catch (Exception ex) { throw new Exception("Request ClientMessages.Log failed.", ex); } }
public void Log_HappyPathTest() { var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); var request = new LogMessageRequest() { Token = new TokenRequest() { EncodedUserName = "******", EncodedToken = "encodedToken" }, Message = "IAmALogMessage" }; IActionResult result = tgimbaApi.Log(request); OkResult requestResult = (OkResult)result; Assert.IsNotNull(requestResult); Assert.AreEqual(200, requestResult.StatusCode); tgimbaService.Verify(x => x.LogAuthenticated(It.Is <string>(s => s == request.Message), It.IsAny <string>(), It.IsAny <string>()) , Times.Once); }
public async Task <LogMessageResponse> SendLogMessageAsync(Message[] messages) { if (messages == null || !messages.Any()) { throw new InvalidOperationException("Invalid message to send"); } //fields var fields = messages.Select(x => new Field { Id = Guid.NewGuid().ToString(), Summary = x.Title, Message = x.Text, ReceivedAt = DateTime.UtcNow }).ToList(); //records var records = fields.Select(field => new RecordRequest() { Field = field }).ToArray(); //log message var logRequest = new LogMessageRequest() { Records = records }; logRequest.Validate(); var response = await _service.SendLogsAsync(logRequest); if (response != null) { var result = JsonConvert.DeserializeObject <LogMessageResponse>(response); return(result); } return(null); }
public void Log_GeneralErrorTest() { var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); tgimbaService.Setup(x => x.LogAuthenticated(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Throws(new Exception("I am an exception")); var request = new LogMessageRequest() { Token = new TokenRequest() { EncodedUserName = "******", EncodedToken = "encodedToken" }, Message = "IAmALogMessage" }; IActionResult result = tgimbaApi.Log(request); StatusCodeResult requestResult = (StatusCodeResult)result; Assert.IsNotNull(requestResult); Assert.AreEqual(500, requestResult.StatusCode); }
public IActionResult Log([FromBody] LogMessageRequest request) { return(this.sharedTgimbaApiController.Log(request)); }