@@ -178,89 +178,102 @@ private bool ValidateClientMessage(IDictionary<string, object> message, out int
178
178
Int32 . TryParse ( requestIdObj ? . ToString ( ) , out requestId ) ;
179
179
}
180
180
181
+ private bool GetDictEntry ( IDictionary < string , object > message , string key , out IDictionary < string , object > objDict )
182
+ {
183
+ if ( message . TryGetValue ( key , out object obj ) &&
184
+ obj is IDictionary < string , object > dict )
185
+ {
186
+ objDict = dict ;
187
+ return true ;
188
+ }
189
+
190
+ objDict = null ;
191
+ return false ;
192
+ }
193
+
181
194
void ProcessDeleteEventMessage ( IDictionary < string , object > message )
182
195
{
183
196
if ( ! ValidateClientMessage ( message , out int requestId ) )
184
197
return ;
185
198
186
- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
187
- {
188
- subscription . OnDelete ( ParseObjectCoder . Instance . Decode (
189
- message [ "object" ] as IDictionary < string , object > ,
190
- Decoder ,
191
- ParseClient . Instance . Services ) ) ;
192
- }
199
+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
200
+ return ;
201
+
202
+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
203
+ return ;
204
+
205
+ subscription . OnDelete ( ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ) ;
193
206
}
194
207
195
208
void ProcessLeaveEventMessage ( IDictionary < string , object > message )
196
209
{
197
210
if ( ! ValidateClientMessage ( message , out int requestId ) )
198
211
return ;
199
212
200
- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
201
- {
202
- subscription . OnLeave (
203
- ParseObjectCoder . Instance . Decode (
204
- message [ "object" ] as IDictionary < string , object > ,
205
- Decoder ,
206
- ParseClient . Instance . Services ) ,
207
- ParseObjectCoder . Instance . Decode (
208
- message [ "original" ] as IDictionary < string , object > ,
209
- Decoder ,
210
- ParseClient . Instance . Services ) ) ;
211
- }
213
+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
214
+ return ;
215
+
216
+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
217
+ return ;
218
+
219
+ if ( ! GetDictEntry ( message , "original" , out IDictionary < string , object > originalDict ) )
220
+ return ;
221
+
222
+ subscription . OnLeave (
223
+ ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ,
224
+ ParseObjectCoder . Instance . Decode ( originalDict , Decoder , ParseClient . Instance . Services ) ) ;
212
225
}
213
226
214
227
void ProcessUpdateEventMessage ( IDictionary < string , object > message )
215
228
{
216
229
if ( ! ValidateClientMessage ( message , out int requestId ) )
217
230
return ;
218
231
219
- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
220
- {
221
- subscription . OnUpdate (
222
- ParseObjectCoder . Instance . Decode (
223
- message [ "object" ] as IDictionary < string , object > ,
224
- Decoder ,
225
- ParseClient . Instance . Services ) ,
226
- ParseObjectCoder . Instance . Decode (
227
- message [ "original" ] as IDictionary < string , object > ,
228
- Decoder ,
229
- ParseClient . Instance . Services ) ) ;
230
- }
232
+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
233
+ return ;
234
+
235
+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
236
+ return ;
237
+
238
+ if ( ! GetDictEntry ( message , "original" , out IDictionary < string , object > originalDict ) )
239
+ return ;
240
+
241
+ subscription . OnUpdate (
242
+ ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ,
243
+ ParseObjectCoder . Instance . Decode ( originalDict , Decoder , ParseClient . Instance . Services ) ) ;
231
244
}
232
245
233
246
void ProcessEnterEventMessage ( IDictionary < string , object > message )
234
247
{
235
248
if ( ! ValidateClientMessage ( message , out int requestId ) )
236
249
return ;
237
250
238
- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
239
- {
240
- subscription . OnEnter (
241
- ParseObjectCoder . Instance . Decode (
242
- message [ "object" ] as IDictionary < string , object > ,
243
- Decoder ,
244
- ParseClient . Instance . Services ) ,
245
- ParseObjectCoder . Instance . Decode (
246
- message [ "original" ] as IDictionary < string , object > ,
247
- Decoder ,
248
- ParseClient . Instance . Services ) ) ;
249
- }
251
+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
252
+ return ;
253
+
254
+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
255
+ return ;
256
+
257
+ if ( ! GetDictEntry ( message , "original" , out IDictionary < string , object > originalDict ) )
258
+ return ;
259
+
260
+ subscription . OnEnter (
261
+ ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ,
262
+ ParseObjectCoder . Instance . Decode ( originalDict , Decoder , ParseClient . Instance . Services ) ) ;
250
263
}
251
264
252
265
void ProcessCreateEventMessage ( IDictionary < string , object > message )
253
266
{
254
267
if ( ! ValidateClientMessage ( message , out int requestId ) )
255
268
return ;
256
269
257
- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
258
- {
259
- subscription . OnCreate ( ParseObjectCoder . Instance . Decode (
260
- message [ "object" ] as IDictionary < string , object > ,
261
- Decoder ,
262
- ParseClient . Instance . Services ) ) ;
263
- }
270
+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
271
+ return ;
272
+
273
+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
274
+ return ;
275
+
276
+ subscription . OnCreate ( ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ) ;
264
277
}
265
278
266
279
void ProcessErrorMessage ( IDictionary < string , object > message )
@@ -277,8 +290,7 @@ void ProcessErrorMessage(IDictionary<string, object> message)
277
290
Boolean . TryParse ( reconnectObj ? . ToString ( ) , out bool reconnect ) ) )
278
291
return ;
279
292
280
- ParseLiveQueryErrorEventArgs errorArgs = new ParseLiveQueryErrorEventArgs ( code , error , reconnect ) ;
281
- Error ? . Invoke ( this , errorArgs ) ;
293
+ Error ? . Invoke ( this , new ParseLiveQueryErrorEventArgs ( code , error , reconnect ) ) ;
282
294
}
283
295
284
296
void ProcessUnsubscriptionMessage ( IDictionary < string , object > message )
0 commit comments