/// <summary> /// Read the ToDoItemId from the stream and consume to the end of the payload. /// </summary> /// <param name="streamReader">The reader from which to read the id.</param> /// <returns>The ID read from the payload.</returns> public static Guid ReadToDoItemId(ref Utf8JsonStreamReader streamReader) { if (streamReader.TokenType != JsonTokenType.StartObject) { throw new JsonException("Expected to be at the start of the event payload."); } // Read the ID streamReader.Read(); if (streamReader.TokenType != JsonTokenType.PropertyName || !streamReader.Match(IdPropertyString)) { throw new JsonException($"Expected to find the {IdPropertyString}."); } streamReader.Read(); if (streamReader.TokenType != JsonTokenType.String) { throw new JsonException("Expected to find a string-encoded GUID property."); } Guid id = streamReader.GetGuid(); // Read to the end of the object streamReader.Read(); if (streamReader.TokenType != JsonTokenType.EndObject) { throw new JsonException("Expected to be at the end of the event payload."); } return(id); }
/// <summary> /// Read the start date from the stream and consume to the end of the payload. /// </summary> /// <param name="streamReader">The reader from which to read the start date.</param> /// <returns>The start date read from the payload.</returns> public static DateTimeOffset ReadStartDate(ref Utf8JsonStreamReader streamReader) { if (streamReader.TokenType != JsonTokenType.StartObject) { throw new JsonException("Expected to be at the start of the event payload."); } // Read the ID streamReader.Read(); if (streamReader.TokenType != JsonTokenType.PropertyName || !streamReader.Match(StartDatePropertyString)) { throw new JsonException($"Expected to find the {StartDatePropertyString}."); } streamReader.Read(); if (streamReader.TokenType != JsonTokenType.String) { throw new JsonException("Expected to find a string-encoded DateTimeOffset property."); } DateTimeOffset startDate = streamReader.GetDateTimeOffset(); // Read to the end of the object streamReader.Read(); if (streamReader.TokenType != JsonTokenType.EndObject) { throw new JsonException("Expected to be at the end of the event payload."); } return(startDate); }
/// <summary> /// Read the owner from the stream and consume to the end of the payload. /// </summary> /// <param name="streamReader">The reader from which to read the id.</param> /// <returns>The ID read from the payload.</returns> public static string ReadOwner(ref Utf8JsonStreamReader streamReader) { if (streamReader.TokenType != JsonTokenType.StartObject) { throw new JsonException("Expected to be at the start of the event payload."); } // Read the ID streamReader.Read(); if (streamReader.TokenType != JsonTokenType.PropertyName || !streamReader.Match(OwnerPropertyString)) { throw new JsonException($"Expected to find the {OwnerPropertyString}."); } streamReader.Read(); if (streamReader.TokenType != JsonTokenType.String) { throw new JsonException("Expected to find a string property."); } string owner = streamReader.GetString() ?? throw new JsonException("Expected to find an owner."); // Read to the end of the object streamReader.Read(); if (streamReader.TokenType != JsonTokenType.EndObject) { throw new JsonException("Expected to be at the end of the event payload."); } return(owner); }
/// <summary> /// Find the value of the payload property in the event. /// </summary> /// <param name="streamReader">The <see cref="Utf8JsonStreamReader"/> from which we are reading the event.</param> public static void FindPayload(ref Utf8JsonStreamReader streamReader) { streamReader.Read(); if (streamReader.TokenType != JsonTokenType.PropertyName || !streamReader.Match(EventPayloadPropertyNameString)) { throw new JsonException($"Expected to find the {EventPayloadPropertyNameString} property."); } // position at the start of the payload streamReader.Read(); }
private static bool FindDocumentsProperty(ref Utf8JsonStreamReader streamReader) { while (streamReader.TokenType != JsonTokenType.PropertyName || !streamReader.Match(DocumentsName)) { if (!streamReader.Read()) { return(false); } } return(true); }
/// <summary> /// Find the event type value in the stream reader. /// </summary> /// <param name="streamReader">The stream reader in which to find the event type.</param> public static void FindEventType(ref Utf8JsonStreamReader streamReader) { streamReader.Read(); if (streamReader.TokenType != JsonTokenType.PropertyName || !streamReader.Match(EventTypePropertyNameString)) { throw new JsonException($"Expected to find the {EventTypePropertyNameString} property."); } streamReader.Read(); if (streamReader.TokenType != JsonTokenType.String) { throw new JsonException($"Expected the {EventTypePropertyNameString} property to be a string."); } }
/// <summary> /// Read the event sequence number from the <see cref="Utf8JsonStreamReader"/>. /// </summary> /// <param name="streamReader">The stream reader from which to read the event sequence number.</param> /// <returns>The event sequence number.</returns> public static long ReadEventSequenceNumber(ref Utf8JsonStreamReader streamReader) { streamReader.Read(); if (streamReader.TokenType != JsonTokenType.PropertyName || !streamReader.Match(EventSequenceNumberPropertyNameString)) { throw new JsonException($"Expected to find the {EventSequenceNumberPropertyNameString} property."); } streamReader.Read(); if (streamReader.TokenType != JsonTokenType.Number) { throw new JsonException($"Expected the {EventSequenceNumberPropertyNameString} property to be a number."); } return(streamReader.GetInt64()); }