Fauna v10 .NET/C# Driver 1.0.1
 
Loading...
Searching...
No Matches
EventSource.cs
Go to the documentation of this file.
1using System.Text.Json;
2
3namespace Fauna.Types;
4
8public sealed class EventSource : IEquatable<EventSource>
9{
13 internal string Token { get; }
14
15 internal EventOptions Options { get; set; }
16
21 public EventSource(string token)
22 {
23 Token = token;
24 Options = new EventOptions();
25 }
26
31 public void Serialize(Stream stream)
32 {
33 var writer = new Utf8JsonWriter(stream);
34 writer.WriteStartObject();
35 writer.WriteString("token", Token);
36 if (Options.Cursor != null)
37 {
38 writer.WriteString("cursor", Options.Cursor);
39 }
40 else if (Options.StartTs != null)
41 {
42 writer.WriteNumber("start_ts", Options.StartTs.Value);
43 }
44
45 if (Options.PageSize is > 0)
46 {
47 writer.WriteNumber("page_size", Options.PageSize.Value);
48 }
49
50 writer.WriteEndObject();
51 writer.Flush();
52 }
53
54
60 public bool Equals(EventSource? other)
61 {
62 if (ReferenceEquals(null, other)) return false;
63 if (ReferenceEquals(this, other)) return true;
64 return Token == other.Token;
65 }
66
72 public override bool Equals(object? obj)
73 {
74 if (ReferenceEquals(null, obj)) return false;
75 if (ReferenceEquals(this, obj)) return true;
76 if (obj.GetType() != GetType()) return false;
77 return Equals((EventSource)obj);
78 }
79
84 public override int GetHashCode()
85 {
86 return Token.GetHashCode();
87 }
88}
89
93public class EventOptions
94{
99 public string? Cursor { get; internal set; }
100
104 public long? StartTs { get; protected init; }
105
109 public int? PageSize { get; protected init; }
110}
System.IO.Stream Stream
Definition Client.cs:8
Represents the options for a Fauna EventSource.
string? Cursor
Cursor returned from Fauna.
long? StartTs
Start timestamp returned for the feed. Used to resume the Feed.
int? PageSize
Limit page size for the Feed.
Represents a Fauna EventSource for initializing Streams and Feeds.
Definition EventSource.cs:9
override int GetHashCode()
The default hash function.
EventSource(string token)
Initializes an EventSource.
void Serialize(Stream stream)
Serializes the event source to the provided Stream.
override bool Equals(object? obj)
Determines whether the specified object is equal to the current Stream.
bool Equals(EventSource? other)
Determines whether the specified Stream is equal to the current Stream.