|
16 | 16 | using Microsoft.Azure.Commands.Sql.DataClassification.Model;
|
17 | 17 | using Microsoft.Azure.Management.Sql.Models;
|
18 | 18 | using System;
|
| 19 | +using System.Collections.Concurrent; |
19 | 20 | using System.Collections.Generic;
|
20 | 21 | using System.Linq;
|
21 | 22 | using System.Threading.Tasks;
|
@@ -62,25 +63,26 @@ internal void SetSensitivityLabels(ManagedDatabaseSensitivityClassificationModel
|
62 | 63 | internal void ModifySensitivityLabels(SensitivityClassificationModel model,
|
63 | 64 | Action<SensitivityLabelModel> modifySensitivityLabel)
|
64 | 65 | {
|
65 |
| - int failuresNumber = 0; |
66 |
| - Exception exception = null; |
67 |
| - foreach (SensitivityLabelModel sensitivityLabelModel in model.SensitivityLabels) |
68 |
| - { |
69 |
| - try |
70 |
| - { |
71 |
| - modifySensitivityLabel(sensitivityLabelModel); |
72 |
| - } |
73 |
| - catch (Exception e) |
| 66 | + ConcurrentQueue<Exception> exceptions = new ConcurrentQueue<Exception>(); |
| 67 | + Parallel.ForEach<SensitivityLabelModel>(model.SensitivityLabels, |
| 68 | + sensitivityLabelModel => |
74 | 69 | {
|
75 |
| - exception = e; |
76 |
| - failuresNumber++; |
77 |
| - } |
78 |
| - } |
79 |
| - |
80 |
| - if (failuresNumber > 0) |
| 70 | + try |
| 71 | + { |
| 72 | + modifySensitivityLabel(sensitivityLabelModel); |
| 73 | + } |
| 74 | + catch (Exception e) |
| 75 | + { |
| 76 | + exceptions.Enqueue(e); |
| 77 | + } |
| 78 | + }); |
| 79 | + |
| 80 | + if (!exceptions.IsEmpty) |
81 | 81 | {
|
82 |
| - throw (failuresNumber == 1) ? exception : |
83 |
| - new Exception($"Operation failed for {failuresNumber} sensitivity classifications", exception); |
| 82 | + int exceptionsCount = exceptions.Count; |
| 83 | + Exception lastException = exceptions.Last(); |
| 84 | + throw (exceptionsCount == 1) ? lastException : |
| 85 | + new Exception($"Operation failed for {exceptionsCount} sensitivity classifications", lastException); |
84 | 86 | }
|
85 | 87 | }
|
86 | 88 |
|
|
0 commit comments