protected override void SerializeJson(JsonTextWriter writer, TransportContext context) { var serializer = JsonSerializer.Create(App.JsonSettings); Log.Debug("Creating JSON payload for {0} data points", _query.Package.Count); var payloadItems = from p in _query.Package select UploadPayload.Create(p); var jsonPayloadItems = serializer.SerializeToString(payloadItems); var lastPiece = _query.Package.Last(); var anchorage = lastPiece.Anchorage; var vehicle = lastPiece.Vehicle; var numberOfPeople = lastPiece.NumberOfPeople; var metadata = UploadMetadata.Create(); metadata.NumberOfPeople = numberOfPeople; var jsonMetadata = serializer.SerializeToString(metadata); //JSON payload output writer.WriteStartObject(); writer.WritePropertyName("secret"); writer.WriteValue(_query.SecretHash.ToBase64()); writer.WritePropertyName("metadata"); writer.WriteValue(jsonMetadata); writer.WritePropertyName("anchorage-type"); writer.WriteValue(anchorage); writer.WritePropertyName("vehicle-type"); writer.WriteValue(vehicle); writer.WritePropertyName("number-of-people"); writer.WriteValue(numberOfPeople); writer.WritePropertyName("payload"); writer.WriteValue(jsonPayloadItems); writer.WritePropertyName("payload-hash"); writer.WriteValue(jsonPayloadItems.ToSha512Hash().ToBase64()); writer.WritePropertyName("time"); writer.WriteValue(DateTime.UtcNow); writer.WriteEndObject(); }
public async Task ScenarioUpload(int scenarioId, int organisationId, int userId, int partitionId, int partitionCount, CancellationToken cancellationToken = default(CancellationToken)) { var payload = new UploadPayload { ScenarioId = scenarioId, OrganisationId = organisationId, UserId = userId, PartitionId = partitionId, PartitionCount = partitionCount }; await _client.InvokeAsync(new InvokeRequest { FunctionName = _functionName, InvocationType = "Event", Payload = JsonConvert.SerializeObject(payload) }, cancellationToken); }