|
1 | 1 | using System.ComponentModel.Composition;
|
2 | 2 | using System.Diagnostics;
|
3 | 3 | using System.Dynamic;
|
4 |
| -using System.Globalization; |
5 |
| -using System.Reflection; |
6 | 4 | using System.Text;
|
7 | 5 | using System.Text.RegularExpressions;
|
8 |
| -using Azure.Identity; |
9 | 6 | using Cosmos.DataTransfer.Interfaces;
|
10 | 7 | using Microsoft.Azure.Cosmos;
|
11 | 8 | using Microsoft.Extensions.Configuration;
|
@@ -95,7 +92,7 @@ void ReportCount(int i)
|
95 | 92 | }
|
96 | 93 | }
|
97 | 94 |
|
98 |
| - var convertedObjects = dataItems.Select(di => BuildObject(di, true)).Where(o => o != null).OfType<ExpandoObject>(); |
| 95 | + var convertedObjects = dataItems.Select(di => di.BuildDynamicObjectTree(true)).Where(o => o != null).OfType<ExpandoObject>(); |
99 | 96 | var batches = convertedObjects.Buffer(settings.BatchSize);
|
100 | 97 | var retry = GetRetryPolicy(settings.MaxRetryCount, settings.InitialRetryDurationMs);
|
101 | 98 | await foreach (var batch in batches.WithCancellation(cancellationToken))
|
@@ -176,57 +173,6 @@ private static MemoryStream CreateItemStream(ExpandoObject item)
|
176 | 173 | return ((IDictionary<string, object?>)item)[propertyName]?.ToString();
|
177 | 174 | }
|
178 | 175 |
|
179 |
| - internal static ExpandoObject? BuildObject(IDataItem? source, bool requireStringId = false) |
180 |
| - { |
181 |
| - if (source == null) |
182 |
| - return null; |
183 |
| - |
184 |
| - var fields = source.GetFieldNames().ToList(); |
185 |
| - var item = new ExpandoObject(); |
186 |
| - if (requireStringId && !fields.Contains("id", StringComparer.CurrentCultureIgnoreCase)) |
187 |
| - { |
188 |
| - item.TryAdd("id", Guid.NewGuid().ToString()); |
189 |
| - } |
190 |
| - foreach (string field in fields) |
191 |
| - { |
192 |
| - object? value = source.GetValue(field); |
193 |
| - var fieldName = field; |
194 |
| - if (string.Equals(field, "id", StringComparison.CurrentCultureIgnoreCase) && requireStringId) |
195 |
| - { |
196 |
| - value = value?.ToString(); |
197 |
| - fieldName = "id"; |
198 |
| - } |
199 |
| - else if (value is IDataItem child) |
200 |
| - { |
201 |
| - value = BuildObject(child); |
202 |
| - } |
203 |
| - else if (value is IEnumerable<object?> array) |
204 |
| - { |
205 |
| - value = BuildArray(array); |
206 |
| - } |
207 |
| - |
208 |
| - item.TryAdd(fieldName, value); |
209 |
| - } |
210 |
| - |
211 |
| - return item; |
212 |
| - |
213 |
| - static object BuildArray(IEnumerable<object?> array) |
214 |
| - { |
215 |
| - return array.Select(dataItem => |
216 |
| - { |
217 |
| - if (dataItem is IDataItem childObject) |
218 |
| - { |
219 |
| - return BuildObject(childObject); |
220 |
| - } |
221 |
| - else if (dataItem is IEnumerable<object?> array) |
222 |
| - { |
223 |
| - return BuildArray(array); |
224 |
| - } |
225 |
| - return dataItem; |
226 |
| - }).ToArray(); |
227 |
| - } |
228 |
| - } |
229 |
| - |
230 | 176 | public IEnumerable<IDataExtensionSettings> GetSettings()
|
231 | 177 | {
|
232 | 178 | yield return new CosmosSinkSettings();
|
|
0 commit comments