-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathChangeFeedMetadata.cs
More file actions
129 lines (119 loc) · 6.21 KB
/
ChangeFeedMetadata.cs
File metadata and controls
129 lines (119 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using Microsoft.Azure.Cosmos.Resource.FullFidelity;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
/// <summary>
/// The metadata of a change feed resource with <see cref="ChangeFeedMode"/> is initialized to <see cref="ChangeFeedMode.AllVersionsAndDeletes"/>.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
class ChangeFeedMetadata
{
private readonly static DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
/// <summary>
/// The change's conflict resolution timestamp.
/// </summary>
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public DateTime? ConflictResolutionTimestamp => this.ConflictResolutionTimestampInSeconds.HasValue ? UnixEpoch.AddSeconds(this.ConflictResolutionTimestampInSeconds.Value) : null;
[System.Text.Json.Serialization.JsonInclude]
[System.Text.Json.Serialization.JsonPropertyName(ChangeFeedMetadataFields.ConflictResolutionTimestamp)]
[JsonProperty(PropertyName = ChangeFeedMetadataFields.ConflictResolutionTimestamp)]
internal double? ConflictResolutionTimestampInSeconds { get; set; }
/// <summary>
/// The current change's logical sequence number.
/// </summary>
[System.Text.Json.Serialization.JsonInclude]
[System.Text.Json.Serialization.JsonPropertyName(ChangeFeedMetadataFields.Lsn)]
[JsonProperty(PropertyName = ChangeFeedMetadataFields.Lsn, NullValueHandling = NullValueHandling.Ignore)]
public long Lsn { get; internal set; }
/// <summary>
/// The change's feed operation type <see cref="ChangeFeedOperationType"/>.
/// </summary>
[Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))]
[System.Text.Json.Serialization.JsonInclude]
[System.Text.Json.Serialization.JsonPropertyName(ChangeFeedMetadataFields.OperationType)]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
[JsonProperty(PropertyName = ChangeFeedMetadataFields.OperationType, NullValueHandling = NullValueHandling.Ignore)]
public ChangeFeedOperationType OperationType { get; internal set; }
/// <summary>
/// The previous change's logical sequence number.
/// </summary>
[System.Text.Json.Serialization.JsonInclude]
[System.Text.Json.Serialization.JsonPropertyName(ChangeFeedMetadataFields.PreviousImageLSN)]
[JsonProperty(PropertyName = ChangeFeedMetadataFields.PreviousImageLSN, NullValueHandling = NullValueHandling.Ignore)]
public long PreviousLsn { get; internal set; }
/// <summary>
/// Used to distinguish explicit deletes (e.g. via DeleteItem) from deletes caused by TTL expiration (a collection may define time-to-live policy for documents).
/// </summary>
[System.Text.Json.Serialization.JsonInclude]
[System.Text.Json.Serialization.JsonPropertyName(ChangeFeedMetadataFields.TimeToLiveExpired)]
[JsonProperty(PropertyName = ChangeFeedMetadataFields.TimeToLiveExpired, NullValueHandling = NullValueHandling.Ignore)]
public bool IsTimeToLiveExpired { get; internal set; }
/// <summary>
/// Applicable for delete operations only, otherwise null.
/// The id of the previous item version.
/// </summary>
[System.Text.Json.Serialization.JsonInclude]
[System.Text.Json.Serialization.JsonPropertyName(ChangeFeedMetadataFields.Id)]
[JsonProperty(PropertyName = ChangeFeedMetadataFields.Id, NullValueHandling = NullValueHandling.Ignore)]
public string Id { get; internal set; }
/// <summary>
/// Applicable for delete operations only, otherwise null.
/// The partition key of the previous item version represented as a dictionary where the key is the partition key property name
/// and the value is the partition key property value. All levels of hierarchy will be present if a hierarchical partition key (HPK) is used.
/// </summary>
/// <remarks>
/// <para>
/// For single partition key containers, the dictionary will contain one entry with the partition key path name (without the leading '/')
/// as the key and the partition key value as the value.
/// </para>
/// <para>
/// For hierarchical partition key containers, the dictionary will contain multiple entries, one for each level of the hierarchy,
/// as defined in the container's partition key definition.
/// </para>
/// <para>
/// Example for a single partition key container with partition key path "/tenantId":
/// <code>
/// {
/// "tenantId": "tenant123"
/// }
/// </code>
/// </para>
/// <para>
/// Example for a hierarchical partition key container with partition key paths ["/tenantId", "/userId", "/sessionId"]:
/// <code>
/// {
/// "tenantId": "tenant123",
/// "userId": "user456",
/// "sessionId": "session789"
/// }
/// </code>
/// </para>
/// <para>
/// The partition key values can be of different types (string, number, boolean, null) depending on the document's schema.
/// For example, with partition key paths ["/category", "/priority"]:
/// <code>
/// {
/// "category": "electronics",
/// "priority": 1
/// }
/// </code>
/// </para>
/// </remarks>
[System.Text.Json.Serialization.JsonInclude]
[System.Text.Json.Serialization.JsonPropertyName(ChangeFeedMetadataFields.PartitionKey)]
[JsonProperty(PropertyName = ChangeFeedMetadataFields.PartitionKey, NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<string, object> PartitionKey { get; internal set; }
}
}