@@ -163,11 +163,16 @@ internal static XmlRpcValue GetParam(string key, bool useCache = false)
163
163
return payload ;
164
164
}
165
165
166
- private static bool SafeGet < T > ( string key , out T dest , T def = default ( T ) )
166
+ private static bool SafeGet < T > ( string key , out T dest , bool useCache = false )
167
+ {
168
+ return SafeGetDefault ( key , out dest , default ( T ) , useCache ) ;
169
+ }
170
+
171
+ private static bool SafeGetDefault < T > ( string key , out T dest , T def = default ( T ) , bool useCache = false )
167
172
{
168
173
try
169
174
{
170
- XmlRpcValue v = GetParam ( key ) ;
175
+ XmlRpcValue v = GetParam ( key , useCache ) ;
171
176
if ( v == null || ! v . IsEmpty )
172
177
{
173
178
if ( def == null )
@@ -271,53 +276,53 @@ private static XmlRpcValue GetParamTypeChecked(string key, XmlRpcType expectedTy
271
276
return result ;
272
277
}
273
278
274
- public static int GetInt ( string key ) =>
275
- GetParamChecked ( key ) . GetInt ( ) ;
279
+ public static int GetInt ( string key , bool useCache = true ) =>
280
+ GetParamChecked ( key , useCache ) . GetInt ( ) ;
276
281
277
- public static bool GetBool ( string key ) =>
278
- GetParamChecked ( key ) . GetBool ( ) ;
282
+ public static bool GetBool ( string key , bool useCache = true ) =>
283
+ GetParamChecked ( key , useCache ) . GetBool ( ) ;
279
284
280
- public static double GetDouble ( string key ) =>
281
- GetParamChecked ( key ) . GetDouble ( ) ;
285
+ public static double GetDouble ( string key , bool useCache = true ) =>
286
+ GetParamChecked ( key , useCache ) . GetDouble ( ) ;
282
287
283
- public static string GetString ( string key ) =>
284
- GetParamChecked ( key ) . GetString ( ) ;
288
+ public static string GetString ( string key , bool useCache = true ) =>
289
+ GetParamChecked ( key , useCache ) . GetString ( ) ;
285
290
286
- public static DateTime GetDateTime ( string key )
291
+ public static DateTime GetDateTime ( string key , bool useCache = true )
287
292
{
288
- var rpcResult = GetParamTypeChecked ( key , XmlRpcType . DateTime ) ;
293
+ var rpcResult = GetParamTypeChecked ( key , XmlRpcType . DateTime , useCache ) ;
289
294
return rpcResult . GetDateTime ( ) ;
290
295
}
291
296
292
- public static byte [ ] GetBinary ( string key )
297
+ public static byte [ ] GetBinary ( string key , bool useCache = true )
293
298
{
294
- var rpcResult = GetParamTypeChecked ( key , XmlRpcType . Base64 ) ;
299
+ var rpcResult = GetParamTypeChecked ( key , XmlRpcType . Base64 , useCache ) ;
295
300
return rpcResult . GetBinary ( ) ;
296
301
}
297
302
298
- public static bool Get ( string key , out XmlRpcValue dest ) =>
299
- SafeGet ( key , out dest ) ;
303
+ public static bool Get ( string key , out XmlRpcValue dest , bool useCache = true ) =>
304
+ SafeGet ( key , out dest , useCache ) ;
300
305
301
- public static bool Get ( string key , out bool dest ) =>
302
- SafeGet ( key , out dest ) ;
306
+ public static bool Get ( string key , out bool dest , bool useCache = true ) =>
307
+ SafeGet ( key , out dest , useCache ) ;
303
308
304
- public static bool Get ( string key , out bool dest , bool def ) =>
305
- SafeGet ( key , out dest , def ) ;
309
+ public static bool Get ( string key , out bool dest , bool def , bool useCache = true ) =>
310
+ SafeGetDefault ( key , out dest , def , useCache ) ;
306
311
307
- public static bool Get ( string key , out int dest ) =>
308
- SafeGet ( key , out dest ) ;
312
+ public static bool Get ( string key , out int dest , bool useCache = true ) =>
313
+ SafeGet ( key , out dest , useCache ) ;
309
314
310
- public static bool Get ( string key , out int dest , int def ) =>
311
- SafeGet ( key , out dest , def ) ;
315
+ public static bool Get ( string key , out int dest , int def , bool useCache = true ) =>
316
+ SafeGetDefault ( key , out dest , def , useCache ) ;
312
317
313
- public static bool Get ( string key , out double dest ) =>
314
- SafeGet ( key , out dest ) ;
318
+ public static bool Get ( string key , out double dest , bool useCache = true ) =>
319
+ SafeGet ( key , out dest , useCache ) ;
315
320
316
- public static bool Get ( string key , out double dest , double def ) =>
317
- SafeGet ( key , out dest , def ) ;
321
+ public static bool Get ( string key , out double dest , double def , bool useCache = true ) =>
322
+ SafeGetDefault ( key , out dest , def , useCache ) ;
318
323
319
- public static bool Get ( string key , out string dest , string def = null ) =>
320
- SafeGet ( key , out dest , def ) ;
324
+ public static bool Get ( string key , out string dest , string def = null , bool useCache = true ) =>
325
+ SafeGetDefault ( key , out dest , def , useCache ) ;
321
326
322
327
public static async Task < IList < string > > List ( )
323
328
{
@@ -433,11 +438,7 @@ public static void Update(string key, XmlRpcValue value)
433
438
434
439
lock ( gate )
435
440
{
436
- if ( ! cachedValues . ContainsKey ( key ) )
437
- cachedValues . Add ( key , value ) ;
438
- else
439
- cachedValues [ key ] = value ;
440
-
441
+ cachedValues [ key ] = value ;
441
442
if ( ! subscriptions . TryGetValue ( key , out callbacks ) )
442
443
return ;
443
444
@@ -461,8 +462,6 @@ public static void ParamUpdateCallback(XmlRpcValue val, XmlRpcValue result)
461
462
val . Set ( 0 , 1 ) ;
462
463
val . Set ( 1 , "" ) ;
463
464
val . Set ( 2 , 0 ) ;
464
- //update(XmlRpcValue.LookUp(parm)[1].Get<string>(), XmlRpcValue.LookUp(parm)[2]);
465
- /// TODO: check carefully this stuff. It looks strange
466
465
Update ( val [ 1 ] . GetString ( ) , val [ 2 ] ) ;
467
466
}
468
467
@@ -493,7 +492,7 @@ private static async Task<bool> GetParamAsync(string key, XmlRpcValue resultValu
493
492
{
494
493
lock ( gate )
495
494
{
496
- cachedValues . Add ( mappepKey , resultValue . Clone ( ) ) ;
495
+ cachedValues [ mappepKey ] = resultValue . Clone ( ) ;
497
496
}
498
497
}
499
498
@@ -527,7 +526,7 @@ public static bool GetImpl(string key, out XmlRpcValue value, bool useCache)
527
526
{
528
527
lock ( gate )
529
528
{
530
- cachedValues . Add ( mappepKey , value ) ;
529
+ cachedValues [ mappepKey ] = value ;
531
530
}
532
531
}
533
532
0 commit comments