25
25
using Microsoft . UI . Xaml . Controls ;
26
26
using Microsoft . Windows . Widgets ;
27
27
using Microsoft . Windows . Widgets . Hosts ;
28
- using Newtonsoft . Json . Linq ;
29
28
using Serilog ;
30
29
31
30
namespace DevHome . Dashboard . ViewModels ;
@@ -311,20 +310,29 @@ private Grid GetErrorCard(string error, string subError = null)
311
310
return grid ;
312
311
}
313
312
314
- private string MergeJsonData ( string jsonStringA , string jsonStringB )
313
+ private Newtonsoft . Json . Linq . JObject WrapJsonString ( string jsonString )
315
314
{
316
- if ( string . IsNullOrEmpty ( jsonStringA ) )
315
+ return new Newtonsoft . Json . Linq . JObject { [ "data" ] = jsonString } ;
316
+ }
317
+
318
+ private string MergeJsonData ( Windows . Data . Json . JsonValue actionValue , Windows . Data . Json . JsonObject inputsObject )
319
+ {
320
+ Newtonsoft . Json . Linq . JObject objA = [ ] ;
321
+ Newtonsoft . Json . Linq . JObject objB = [ ] ;
322
+
323
+ if ( actionValue ? . ValueType == Windows . Data . Json . JsonValueType . Object )
317
324
{
318
- return jsonStringB ;
325
+ objA = Newtonsoft . Json . Linq . JObject . Parse ( actionValue . Stringify ( ) ) ;
319
326
}
320
-
321
- if ( string . IsNullOrEmpty ( jsonStringB ) )
327
+ else if ( actionValue ? . ValueType == Windows . Data . Json . JsonValueType . String )
322
328
{
323
- return jsonStringA ;
329
+ objA = WrapJsonString ( actionValue . Stringify ( ) ) ;
324
330
}
325
331
326
- var objA = JObject . Parse ( jsonStringA ) ;
327
- var objB = JObject . Parse ( jsonStringB ) ;
332
+ if ( inputsObject ? . ValueType != Windows . Data . Json . JsonValueType . Null )
333
+ {
334
+ objB = Newtonsoft . Json . Linq . JObject . Parse ( inputsObject . Stringify ( ) ) ;
335
+ }
328
336
329
337
objA . Merge ( objB ) ;
330
338
@@ -341,22 +349,10 @@ private async void HandleAdaptiveAction(RenderedAdaptiveCard sender, AdaptiveAct
341
349
}
342
350
else if ( args . Action is AdaptiveExecuteAction executeAction )
343
351
{
344
- var actionData = string . Empty ;
345
- var inputsData = string . Empty ;
346
-
347
- var dataType = executeAction . DataJson . ValueType ;
348
- if ( dataType != Windows . Data . Json . JsonValueType . Null )
349
- {
350
- actionData = executeAction . DataJson . Stringify ( ) ;
351
- }
352
-
353
- var inputType = args . Inputs . AsJson ( ) . ValueType ;
354
- if ( inputType != Windows . Data . Json . JsonValueType . Null )
355
- {
356
- inputsData = args . Inputs . AsJson ( ) . Stringify ( ) ;
357
- }
352
+ Windows . Data . Json . JsonValue actionValue = executeAction . DataJson ;
353
+ Windows . Data . Json . JsonObject inputsObject = args . Inputs . AsJson ( ) ;
358
354
359
- var dataToSend = MergeJsonData ( actionData , inputsData ) ;
355
+ var dataToSend = MergeJsonData ( actionValue , inputsObject ) ;
360
356
361
357
_log . Information ( $ "Verb = { executeAction . Verb } , Data = { dataToSend } ") ;
362
358
await Widget . NotifyActionInvokedAsync ( executeAction . Verb , dataToSend ) ;
0 commit comments