Browse Source

Handling of arrays and dictionaries as input parameters, arrays as a result

Change-Id: I0522086580590fe7c8437ead9fe538abc7b9ee62
Stan Lagun 5 years ago
parent
commit
61c1732341
2 changed files with 34 additions and 2 deletions
  1. 33
    1
      WindowsAgent/PlanExecutor.cs
  2. 1
    1
      WindowsAgent/Program.cs

+ 33
- 1
WindowsAgent/PlanExecutor.cs View File

@@ -1,10 +1,12 @@
1 1
 using System;
2
+using System.Collections;
2 3
 using System.Collections.Generic;
3 4
 using System.IO;
4 5
 using System.Linq;
5 6
 using System.Management.Automation;
6 7
 using System.Management.Automation.Runspaces;
7 8
 using System.Text;
9
+using Newtonsoft.Json.Linq;
8 10
 using NLog;
9 11
 using Newtonsoft.Json;
10 12
 
@@ -71,7 +73,8 @@ namespace Mirantis.Murano.WindowsAgent
71 73
 					{
72 74
 						foreach (var kvp in command.Arguments)
73 75
 						{
74
-							psCommand.Parameters.Add(kvp.Key, kvp.Value);
76
+							var value = ConvertArgument(kvp.Value);
77
+							psCommand.Parameters.Add(kvp.Key, value);
75 78
 						}
76 79
 					}
77 80
 
@@ -148,6 +151,31 @@ namespace Mirantis.Murano.WindowsAgent
148 151
 				}
149 152
 			}
150 153
 		}
154
+
155
+		private static object ConvertArgument(object arg)
156
+		{
157
+			if (arg is JArray)
158
+			{
159
+				var array = arg as JArray;
160
+				return array.Select(ConvertArgument).ToArray();
161
+			}
162
+			else if (arg is JValue)
163
+			{
164
+				var value = (JValue) arg;
165
+				return value.Value;
166
+			}
167
+			else if (arg is JObject)
168
+			{
169
+				var dict = (JObject)arg;
170
+				var result = new Hashtable();
171
+				foreach (var item in dict)
172
+				{
173
+					result.Add(item.Key, ConvertArgument(item.Value));
174
+				}
175
+				return result;
176
+			}
177
+			return arg;
178
+		}
151 179
 	
152 180
 		private static object SerializePsObject(PSObject obj)
153 181
 		{
@@ -166,6 +194,10 @@ namespace Mirantis.Murano.WindowsAgent
166 194
 				}
167 195
 				return result;
168 196
 			}
197
+			else if (obj.BaseObject is IEnumerable<PSObject>)
198
+			{
199
+				return ((IEnumerable<PSObject>) obj.BaseObject).Select(SerializePsObject).ToArray();
200
+			}
169 201
 			else
170 202
 			{
171 203
 				return obj.BaseObject;

+ 1
- 1
WindowsAgent/Program.cs View File

@@ -30,7 +30,7 @@ namespace Mirantis.Murano.WindowsAgent
30 30
 		{
31 31
 			base.OnStart(args);
32 32
 
33
-			Log.Info("Version 0.4");
33
+			Log.Info("Version 0.5");
34 34
 
35 35
 			this.rabbitMqClient = new RabbitMqClient();
36 36
 

Loading…
Cancel
Save