@@ -163,11 +163,16 @@ internal static XmlRpcValue GetParam(string key, bool useCache = false)
163163 return payload ;
164164 }
165165
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 )
167172 {
168173 try
169174 {
170- XmlRpcValue v = GetParam ( key ) ;
175+ XmlRpcValue v = GetParam ( key , useCache ) ;
171176 if ( v == null || ! v . IsEmpty )
172177 {
173178 if ( def == null )
@@ -271,53 +276,53 @@ private static XmlRpcValue GetParamTypeChecked(string key, XmlRpcType expectedTy
271276 return result ;
272277 }
273278
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 ( ) ;
276281
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 ( ) ;
279284
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 ( ) ;
282287
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 ( ) ;
285290
286- public static DateTime GetDateTime ( string key )
291+ public static DateTime GetDateTime ( string key , bool useCache = true )
287292 {
288- var rpcResult = GetParamTypeChecked ( key , XmlRpcType . DateTime ) ;
293+ var rpcResult = GetParamTypeChecked ( key , XmlRpcType . DateTime , useCache ) ;
289294 return rpcResult . GetDateTime ( ) ;
290295 }
291296
292- public static byte [ ] GetBinary ( string key )
297+ public static byte [ ] GetBinary ( string key , bool useCache = true )
293298 {
294- var rpcResult = GetParamTypeChecked ( key , XmlRpcType . Base64 ) ;
299+ var rpcResult = GetParamTypeChecked ( key , XmlRpcType . Base64 , useCache ) ;
295300 return rpcResult . GetBinary ( ) ;
296301 }
297302
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 ) ;
300305
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 ) ;
303308
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 ) ;
306311
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 ) ;
309314
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 ) ;
312317
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 ) ;
315320
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 ) ;
318323
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 ) ;
321326
322327 public static async Task < IList < string > > List ( )
323328 {
@@ -433,11 +438,7 @@ public static void Update(string key, XmlRpcValue value)
433438
434439 lock ( gate )
435440 {
436- if ( ! cachedValues . ContainsKey ( key ) )
437- cachedValues . Add ( key , value ) ;
438- else
439- cachedValues [ key ] = value ;
440-
441+ cachedValues [ key ] = value ;
441442 if ( ! subscriptions . TryGetValue ( key , out callbacks ) )
442443 return ;
443444
@@ -461,8 +462,6 @@ public static void ParamUpdateCallback(XmlRpcValue val, XmlRpcValue result)
461462 val . Set ( 0 , 1 ) ;
462463 val . Set ( 1 , "" ) ;
463464 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
466465 Update ( val [ 1 ] . GetString ( ) , val [ 2 ] ) ;
467466 }
468467
@@ -493,7 +492,7 @@ private static async Task<bool> GetParamAsync(string key, XmlRpcValue resultValu
493492 {
494493 lock ( gate )
495494 {
496- cachedValues . Add ( mappepKey , resultValue . Clone ( ) ) ;
495+ cachedValues [ mappepKey ] = resultValue . Clone ( ) ;
497496 }
498497 }
499498
@@ -527,7 +526,7 @@ public static bool GetImpl(string key, out XmlRpcValue value, bool useCache)
527526 {
528527 lock ( gate )
529528 {
530- cachedValues . Add ( mappepKey , value ) ;
529+ cachedValues [ mappepKey ] = value ;
531530 }
532531 }
533532
0 commit comments