Skip to content

Commit e4526f7

Browse files
authored
Merge pull request #9 from dotnetprog/feature/AdjustmentsonOissues
Push somes fixes
2 parents 9ae36ff + 5dcfece commit e4526f7

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

src/Dataverse.ConfigurationMigrationTool/Console.Tests/Features/Import/ValueConverters/DataverseValueConverterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void GivenAnUnsupportedAttributeMetadata_WhenConverted_ThenItShouldThrowP
9393
{
9494
//Arrange
9595
var field = new Field() { Name = "test", Value = "125462" };
96-
var amd = new MemoAttributeMetadata();
96+
var amd = new ImageAttributeMetadata();
9797
//Act
9898
Action act = () => converter.Convert(amd, field);
9999
//Assert

src/Dataverse.ConfigurationMigrationTool/Dataverse.ConfigurationMigrationTool.Console/Features/CommandProcessorHostingService.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ where Attribute.IsDefined(type, typeof(CommandVerbAttribute)) &&
4040
throw new InvalidOperationException($"No command found for verb '{_options.CommandVerb}'");
4141
}
4242
var command = ActivatorUtilities.CreateInstance(scope.ServiceProvider, mathingVerbCommandType) as ICommand;
43-
await command.Execute();
43+
if (command == null)
44+
{
45+
throw new InvalidOperationException($"Command type '{mathingVerbCommandType.FullName}' could not be instantiated.");
46+
}
47+
try
48+
{
49+
await command.Execute();
50+
}
51+
catch
52+
{
53+
Environment.ExitCode = -100;
54+
throw;
55+
}
4456

4557

4658
}

src/Dataverse.ConfigurationMigrationTool/Dataverse.ConfigurationMigrationTool.Console/Features/Import/Commands/ImportCommands.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ public ImportCommands(ILogger<ImportCommands> logger,
2626
_options = options.Value;
2727
}
2828

29-
public async Task Execute() => await Import(_options.schema, _options.data);
29+
public Task Execute() => Import(_options.schema, _options.data);
3030

3131

3232
private async Task Import(string schemafilepath, string datafilepath)
3333
{
34-
35-
var ImportQueue = new Queue<ImportDataTask>();
3634
var schema = await _importDataProvider.ReadSchemaFromFile(schemafilepath);
3735
var importdata = await _importDataProvider.ReadFromFile(datafilepath);
3836

@@ -48,19 +46,19 @@ private async Task Import(string schemafilepath, string datafilepath)
4846
throw new Exception("Provided Schema was not valid.");
4947
}
5048
_logger.LogInformation("Schema validation succeeded.");
49+
var ImportQueue = CreateQueue(schema);
5150

52-
foreach (var schemaEntity in schema.Entity)
51+
52+
var taskResults = await ProcessQueue(ImportQueue, importdata);
53+
if (taskResults.Any(r => r == TaskResult.Failed))
5354
{
54-
ImportQueue.Enqueue(new ImportDataTask { EntitySchema = schemaEntity });
55-
if (schemaEntity.Relationships.Relationship.Any())
56-
{
57-
foreach (var relationshipSchema in schemaEntity.Relationships.Relationship)
58-
{
59-
ImportQueue.Enqueue(new ImportDataTask { RelationshipSchema = relationshipSchema, SouceEntityName = schemaEntity.Name });
60-
}
61-
}
55+
_logger.LogError("Import process failed.");
56+
throw new Exception("Import process failed.");
6257
}
6358

59+
}
60+
private async Task<IEnumerable<TaskResult>> ProcessQueue(Queue<ImportDataTask> ImportQueue, Entities importdata)
61+
{
6462
var taskResults = new List<TaskResult>();
6563
while (ImportQueue.Count > 0)
6664
{
@@ -78,7 +76,7 @@ private async Task Import(string schemafilepath, string datafilepath)
7876
}
7977
if (importTask.RelationshipSchema != null &&
8078
ImportQueue.Any(t => t.EntitySchema != null &&
81-
t.EntitySchema.Name == importTask.RelationshipSchema.M2mTargetEntity || t.EntitySchema.Name == importTask.SouceEntityName))
79+
(t.EntitySchema.Name == importTask.RelationshipSchema.M2mTargetEntity || t.EntitySchema.Name == importTask.SouceEntityName)))
8280
{
8381
ImportQueue.Enqueue(importTask);
8482
continue;
@@ -90,14 +88,23 @@ private async Task Import(string schemafilepath, string datafilepath)
9088

9189

9290
}
93-
if (taskResults.Any(r => r == TaskResult.Failed))
91+
return taskResults;
92+
}
93+
private static Queue<ImportDataTask> CreateQueue(ImportSchema schema)
94+
{
95+
var ImportQueue = new Queue<ImportDataTask>();
96+
foreach (var schemaEntity in schema.Entity)
9497
{
95-
_logger.LogError("Import process failed.");
96-
throw new Exception("Import process failed.");
98+
ImportQueue.Enqueue(new ImportDataTask { EntitySchema = schemaEntity });
99+
if (schemaEntity.Relationships.Relationship.Any())
100+
{
101+
foreach (var relationshipSchema in schemaEntity.Relationships.Relationship)
102+
{
103+
ImportQueue.Enqueue(new ImportDataTask { RelationshipSchema = relationshipSchema, SouceEntityName = schemaEntity.Name });
104+
}
105+
}
97106
}
98-
99-
100-
107+
return ImportQueue;
101108
}
102109

103110
}

src/Dataverse.ConfigurationMigrationTool/Dataverse.ConfigurationMigrationTool.Console/Features/Import/ValueConverters/DataverseValueConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public object Convert(AttributeMetadata attributeMetadata, Field field)
2424
switch (attributeMetadata.AttributeType.Value)
2525
{
2626
case AttributeTypeCode.String:
27+
case AttributeTypeCode.Memo:
2728
return _mainConverter.Convert<string>(value);
2829
case AttributeTypeCode.Picklist:
2930
case AttributeTypeCode.State:

src/Dataverse.ConfigurationMigrationTool/Dataverse.ConfigurationMigrationTool.Console/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Information"
4+
"Default": "Information",
5+
"Dataverse.ConfigurationMigrationTool.Console.Services.Dataverse.SdkDataverseServiceFactory": "Warning"
56
}
67
},
78
"Dataverse": {

0 commit comments

Comments
 (0)