-
Notifications
You must be signed in to change notification settings - Fork 494
/
ChangeFeedItem.cs
76 lines (72 loc) · 3.19 KB
/
ChangeFeedItem.cs
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
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos
{
using Newtonsoft.Json;
/// <summary>
/// The typed response that contains the current, previous, and metadata change feed resource when <see cref="ChangeFeedMode"/> is initialized to <see cref="ChangeFeedMode.AllVersionsAndDeletes"/>.
/// </summary>
/// <example>
/// <code>
/// <![CDATA[
/// public class ToDoActivity
/// {
/// public string type { get; set; }
/// public string id { get; set; }
/// public string status { get; set; }
/// }
///
/// ChangeFeedMode changeFeedMode = ChangeFeedMode.AllVersionsAndDeletes;
/// PartitionKey partitionKey = new PartitionKey(@"learning");
/// ChangeFeedStartFrom changeFeedStartFrom = ChangeFeedStartFrom.Now(FeedRange.FromPartitionKey(partitionKey));
///
/// using (FeedIterator<ChangeFeedItem<ToDoActivity>> feedIterator = container.GetChangeFeedIterator<ChangeFeedItemChanges<ToDoActivity>>(
/// changeFeedStartFrom: changeFeedStartFrom,
/// changeFeedMode: changeFeedMode))
/// {
/// while (feedIterator.HasMoreResults)
/// {
/// FeedResponse<ChangeFeedItem<ToDoActivity>> feedResponse = await feedIterator.ReadNextAsync();
///
/// if (feedResponse.StatusCode != HttpStatusCode.NotModified)
/// {
/// IEnumerable<ChangeFeedItem<ToDoActivity>> feedResource = feedResponse.Resource;
///
/// foreach(ChangeFeedItem<ToDoActivity> itemChanges in feedResource)
/// {
/// ToDoActivity currentToDoActivity = itemChanges.Current;
/// ToDoActivity previousToDoActivity = itemChanges.Previous;
/// ChangeFeedMetadata toDoActivityMetadata = itemChanges.Metadata;
/// }
/// }
/// }
/// }
/// ]]>
/// </code>
/// </example>
/// <remarks><see cref="ChangeFeedItem{T}"/> is an optional helper class that uses Newtonsoft serialization libraries. Users are welcome to create their own custom helper class.</remarks>
#if PREVIEW
public
#else
internal
#endif
class ChangeFeedItem<T>
{
/// <summary>
/// The full fidelity change feed current item.
/// </summary>
[JsonProperty(PropertyName = "current")]
public T Current { get; set; }
/// <summary>
/// The full fidelity change feed metadata.
/// </summary>
[JsonProperty(PropertyName = "metadata", NullValueHandling = NullValueHandling.Ignore)]
public ChangeFeedMetadata Metadata { get; set; }
/// <summary>
/// For delete operations, previous image is always going to be provided. The previous image on replace operations is not going to be exposed by default and requires account-level or container-level opt-in.
/// </summary>
[JsonProperty(PropertyName = "previous", NullValueHandling = NullValueHandling.Ignore)]
public T Previous { get; set; }
}
}