/// <summary> /// Stores a list of statements to the LRS /// </summary> /// <param name="statements">The list of statements to store</param> public async Task SendStatementAsync(IEnumerable <Statement> statements) { using (var content = new StringContent(JsonConvert.SerializeObject(statements.ToList(), JsonSerializerSettingsFactory.CreateSettings()), Encoding.UTF8, "application/json")) { using (var response = await HttpClient.PostAsync($"{_statementEndPoint}", content)) { if (!response.IsSuccessStatusCode) { var responseContent = await response.Content.ReadAsStringAsync(); throw new InvalidOperationException($"Could not send statements.\r\nLRS responded with: \r\n{(int)response.StatusCode} {response.ReasonPhrase}\r\n{responseContent}"); } } } }
/// <summary> /// Creates a JSON representation of the Actor based on the Experience API /// specification. /// </summary> /// <param name="prettyPrint">If set to true, the json will have indentation for easier readability.</param> /// <returns>The JSON representation of the Actor</returns> public string ToJson(bool prettyPrint = false) { return(JsonConvert.SerializeObject(this, prettyPrint ? Formatting.Indented : Formatting.None, JsonSerializerSettingsFactory.CreateSettings())); }