Skip to content

Commit cdfe5d6

Browse files
committed
Update DataClassificationAdapter.cs
1 parent 15ba0f1 commit cdfe5d6

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Microsoft.Azure.Commands.Sql.DataClassification.Model;
1717
using Microsoft.Azure.Management.Sql.Models;
1818
using System;
19+
using System.Collections.Concurrent;
1920
using System.Collections.Generic;
2021
using System.Linq;
2122
using System.Threading.Tasks;
@@ -62,25 +63,26 @@ internal void SetSensitivityLabels(ManagedDatabaseSensitivityClassificationModel
6263
internal void ModifySensitivityLabels(SensitivityClassificationModel model,
6364
Action<SensitivityLabelModel> modifySensitivityLabel)
6465
{
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 =>
7469
{
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)
8181
{
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);
8486
}
8587
}
8688

0 commit comments

Comments
 (0)