private void ApiPost(IApiContext apiContext) { JsonArray sequence = apiContext.Request.GetNamedArray("sequence", new JsonArray()); if (sequence.Count == 0) { return; } var codeSequence = new LPD433MHzCodeSequence(); foreach (IJsonValue item in sequence) { var code = item.GetObject(); uint value = (uint)code.GetNamedNumber("value", 0); byte length = (byte)code.GetNamedNumber("length", 0); byte repeats = (byte)code.GetNamedNumber("repeats", 1); if (value == 0 || length == 0) { throw new InvalidOperationException("Value or length is null."); } codeSequence.WithCode(new LPD433MHzCode(value, length, repeats)); } Send(codeSequence); }
private void ApiPost(IApiContext apiContext) { var sequence = apiContext.Request["sequence"].ToObject <JArray>(); if (sequence.Count == 0) { return; } var codeSequence = new LPD433MHzCodeSequence(); foreach (var item in sequence) { var code = item.ToObject <JObject>(); var value = (uint)code["value"]; var length = (byte)code["length"]; var repeats = (byte)code["repeats"]; if (value == 0 || length == 0) { throw new InvalidOperationException("Value or length is null."); } codeSequence.WithCode(new LPD433MHzCode(value, length, repeats)); } Send(codeSequence); }
private void ApiPost(IApiContext apiContext) { var sequence = apiContext.Request["sequence"].ToObject<JArray>(); if (sequence.Count == 0) { return; } var codeSequence = new LPD433MHzCodeSequence(); foreach (var item in sequence) { var code = item.ToObject<JObject>(); var value = (uint)code["value"]; var length = (byte)code["length"]; var repeats = (byte)code["repeats"]; if (value == 0 || length == 0) { throw new InvalidOperationException("Value or length is null."); } codeSequence.WithCode(new LPD433MHzCode(value, length, repeats)); } Send(codeSequence); }
private void ApiPost(HttpContext context) { JsonArray sequence = context.Request.JsonBody.GetNamedArray("sequence", new JsonArray()); if (sequence.Count == 0) { return; } var codeSequence = new LPD433MHzCodeSequence(); foreach (IJsonValue item in sequence) { var code = item.GetObject(); uint value = (uint)code.GetNamedNumber("value", 0); byte length = (byte)code.GetNamedNumber("length", 0); byte repeats = (byte)code.GetNamedNumber("repeats", 1); if (value == 0 || length == 0) { throw new InvalidOperationException("Value or length is null."); } codeSequence.WithCode(new LPD433MHzCode(value, length, repeats)); } Send(codeSequence); }
private void ApiPost(HttpContext context) { JsonObject requestData; if (!JsonObject.TryParse(context.Request.Body, out requestData)) { context.Response.StatusCode = HttpStatusCode.BadRequest; return; } JsonArray sequence = requestData.GetNamedArray("sequence", new JsonArray()); if (sequence.Count == 0) { return; } var codeSequence = new LPD433MHzCodeSequence(); foreach (IJsonValue item in sequence) { var code = item.GetObject(); uint value = (uint)code.GetNamedNumber("value", 0); byte length = (byte)code.GetNamedNumber("length", 0); byte repeats = (byte)code.GetNamedNumber("repeats", 1); if (value == 0 || length == 0) { throw new InvalidOperationException("Value or length is null."); } codeSequence.WithCode(new LPD433MHzCode(value, length, repeats)); } Send(codeSequence); }