This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathSyncResponse.cs
191 lines (167 loc) · 8.07 KB
/
SyncResponse.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Exchange Web Services Managed API
*
* Copyright (c) Microsoft Corporation
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
namespace Microsoft.Exchange.WebServices.Data
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
/// <summary>
/// Represents the base response class for synchronuization operations.
/// </summary>
/// <typeparam name="TServiceObject">ServiceObject type.</typeparam>
/// <typeparam name="TChange">Change type.</typeparam>
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class SyncResponse<TServiceObject, TChange> : ServiceResponse
where TServiceObject : ServiceObject
where TChange : Change
{
private ChangeCollection<TChange> changes = new ChangeCollection<TChange>();
private PropertySet propertySet;
/// <summary>
/// Initializes a new instance of the <see cref="SyncResponse<TServiceObject, TChange>"/> class.
/// </summary>
/// <param name="propertySet">Property set.</param>
internal SyncResponse(PropertySet propertySet)
: base()
{
this.propertySet = propertySet;
EwsUtilities.Assert(
this.propertySet != null,
"SyncResponse.ctor",
"PropertySet should not be null");
}
/// <summary>
/// Gets the name of the includes last in range XML element.
/// </summary>
/// <returns>XML element name.</returns>
internal abstract string GetIncludesLastInRangeXmlElementName();
/// <summary>
/// Creates the change instance.
/// </summary>
/// <returns>TChange instance</returns>
internal abstract TChange CreateChangeInstance();
/// <summary>
/// Gets the name of the change element.
/// </summary>
/// <returns>Change element name.</returns>
internal abstract string GetChangeElementName();
/// <summary>
/// Gets the name of the change id element.
/// </summary>
/// <returns>Change id element name.</returns>
internal abstract string GetChangeIdElementName();
/// <summary>
/// Reads response elements from XML.
/// </summary>
/// <param name="reader">The reader.</param>
internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
{
this.Changes.SyncState = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.SyncState);
this.Changes.MoreChangesAvailable = !reader.ReadElementValue<bool>(XmlNamespace.Messages, this.GetIncludesLastInRangeXmlElementName());
reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Changes);
if (!reader.IsEmptyElement)
{
do
{
reader.Read();
if (reader.IsStartElement())
{
TChange change = this.CreateChangeInstance();
switch (reader.LocalName)
{
case XmlElementNames.Create:
change.ChangeType = ChangeType.Create;
break;
case XmlElementNames.Update:
change.ChangeType = ChangeType.Update;
break;
case XmlElementNames.Delete:
change.ChangeType = ChangeType.Delete;
break;
case XmlElementNames.ReadFlagChange:
change.ChangeType = ChangeType.ReadFlagChange;
break;
default:
reader.SkipCurrentElement();
break;
}
if (change != null)
{
reader.Read();
reader.EnsureCurrentNodeIsStartElement();
switch (change.ChangeType)
{
case ChangeType.Delete:
case ChangeType.ReadFlagChange:
change.Id = change.CreateId();
change.Id.LoadFromXml(reader, change.Id.GetXmlElementName());
if (change.ChangeType == ChangeType.ReadFlagChange)
{
reader.Read();
reader.EnsureCurrentNodeIsStartElement();
ItemChange itemChange = change as ItemChange;
EwsUtilities.Assert(
itemChange != null,
"SyncResponse.ReadElementsFromXml",
"ReadFlagChange is only valid on ItemChange");
itemChange.IsRead = reader.ReadElementValue<bool>(XmlNamespace.Types, XmlElementNames.IsRead);
}
break;
default:
change.ServiceObject = EwsUtilities.CreateEwsObjectFromXmlElementName<TServiceObject>(
reader.Service,
reader.LocalName);
change.ServiceObject.LoadFromXml(
reader,
true, /* clearPropertyBag */
this.propertySet,
this.SummaryPropertiesOnly);
break;
}
reader.ReadEndElementIfNecessary(XmlNamespace.Types, change.ChangeType.ToString());
this.changes.Add(change);
}
}
}
while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Changes));
}
}
/// <summary>
/// Gets a list of changes that occurred on the synchronized folder.
/// </summary>
public ChangeCollection<TChange> Changes
{
get { return this.changes; }
}
/// <summary>
/// Gets a value indicating whether this request returns full or summary properties.
/// </summary>
internal abstract bool SummaryPropertiesOnly
{
get;
}
}
}