Skip to content

Commit

Permalink
simplify endpoint info parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
kisantia committed Jun 11, 2019
1 parent ad5e11b commit 3c5db95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void Execute(TaskExecutionMode mode)
{
DeploymentOptions = new DeploymentOptions(compare.Options),
Success = true,
SourceEndpointInfo = this.GetEndpointInfo(true),
TargetEndpointInfo = this.GetEndpointInfo(false),
SourceEndpointInfo = this.GetEndpointInfo(true, compare.Source),
TargetEndpointInfo = this.GetEndpointInfo(false, compare.Target),
OriginalTargetName = this.GetOriginalTargetName(),
OriginalTargetConnectionString = this.GetOriginalTargetConnectionString(),
ExcludedSourceElements = this.GetExcludedElements(true),
Expand All @@ -98,31 +98,32 @@ public void Execute(TaskExecutionMode mode)
}
}

private SchemaCompareEndpointInfo GetEndpointInfo(bool source)
private SchemaCompareEndpointInfo GetEndpointInfo(bool source, SchemaCompareEndpoint endpoint)
{
XmlNodeList connectionBasedModelProviderNodes = this.scmpInfo.DocumentElement.SelectNodes("descendant::ConnectionBasedModelProvider");
XmlNodeList fileBasedModelProviderNodes = this.scmpInfo.DocumentElement.SelectNodes("descendant::FileBasedModelProvider");

SchemaCompareEndpointInfo endpointInfo = new SchemaCompareEndpointInfo();
string searchingFor = source ? "Source" : "Target";

foreach (XmlNode node in fileBasedModelProviderNodes)
// if the endpoint is a dacpac we don't need to parse the xml
SchemaCompareDacpacEndpoint dacpacEndpoint = endpoint as SchemaCompareDacpacEndpoint;
if (dacpacEndpoint != null)
{
if (node.ParentNode.Name.Contains(searchingFor))
{
endpointInfo.PackageFilePath = node.InnerText;
endpointInfo.EndpointType = SchemaCompareEndpointType.Dacpac;
}
endpointInfo.EndpointType = SchemaCompareEndpointType.Dacpac;
endpointInfo.PackageFilePath = dacpacEndpoint.FilePath;
}

foreach (XmlNode node in connectionBasedModelProviderNodes)
else
{
if (node.ParentNode.Name.Contains(searchingFor))
// need to parse xml to get connection string of database
XmlNodeList connectionBasedModelProviderNodes = this.scmpInfo.DocumentElement.SelectNodes("descendant::ConnectionBasedModelProvider");
string searchingFor = source ? "Source" : "Target";

foreach (XmlNode node in connectionBasedModelProviderNodes)
{
endpointInfo.ConnectionDetails = SchemaCompareService.ConnectionServiceInstance.ParseConnectionString(node.InnerText);
endpointInfo.ConnectionDetails.ConnectionString = node.InnerText;
endpointInfo.DatabaseName = endpointInfo.ConnectionDetails.DatabaseName;
endpointInfo.EndpointType = SchemaCompareEndpointType.Database;
if (node.ParentNode.Name.Contains(searchingFor))
{
endpointInfo.ConnectionDetails = SchemaCompareService.ConnectionServiceInstance.ParseConnectionString(node.InnerText);
endpointInfo.ConnectionDetails.ConnectionString = node.InnerText;
endpointInfo.DatabaseName = endpointInfo.ConnectionDetails.DatabaseName;
endpointInfo.EndpointType = SchemaCompareEndpointType.Database;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,19 +629,7 @@ private SchemaCompareOpenScmpResult CreateAndOpenScmp(SchemaCompareEndpoint sour
Assert.NotNull(schemaCompareOpenScmpOperation.Result);
Assert.True(schemaCompareOpenScmpOperation.Result.Success);

// cleanup
SchemaCompareTestUtils.VerifyAndCleanup(filePath);
SchemaCompareTestUtils.VerifyAndCleanup(sourceDacpacFilePath);
SchemaCompareTestUtils.VerifyAndCleanup(targetDacpacFilePath);
}
finally
{
sourceDb.Cleanup();
targetDb.Cleanup();
}
}

}
return schemaCompareOpenScmpOperation.Result;
}
}
}

0 comments on commit 3c5db95

Please sign in to comment.