Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kisantia committed Jun 13, 2019
1 parent 40069d5 commit f13b4e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SchemaCompareObjectId
/// <summary>
/// Name to create object identifier
/// </summary>
public string Name;
public string[] NameParts;

/// <summary>
/// sql object type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml;
using System.Xml.Linq;

namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
{
Expand All @@ -31,7 +33,7 @@ class SchemaCompareOpenScmpOperation : ITaskOperation

public SchemaCompareOpenScmpResult Result { get; private set; }

private XmlDocument scmpInfo { get; set; }
private XDocument scmpInfo { get; set; }

public SchemaCompareOpenScmpOperation(SchemaCompareOpenScmpParams parameters)
{
Expand Down Expand Up @@ -75,8 +77,7 @@ public void Execute(TaskExecutionMode mode)
SchemaComparison compare = new SchemaComparison(this.Parameters.filePath);

// load xml file because some parsing still needs to be done
this.scmpInfo = new XmlDocument();
this.scmpInfo.Load(this.Parameters.filePath);
this.scmpInfo = XDocument.Load(this.Parameters.filePath);

this.Result = new SchemaCompareOpenScmpResult()
{
Expand All @@ -93,7 +94,7 @@ public void Execute(TaskExecutionMode mode)
catch (Exception e)
{
ErrorMessage = e.Message;
Logger.Write(TraceEventType.Error, string.Format("Schema compare open scmp operation failed with exception {0}", e.Message));
Logger.Write(TraceEventType.Error, string.Format("Schema compare open scmp operation failed with exception {0}", e));
throw;
}
}
Expand All @@ -112,19 +113,19 @@ private SchemaCompareEndpointInfo GetEndpointInfo(bool source, SchemaCompareEndp
else
{
// need to parse xml to get connection string of database
XmlNodeList connectionBasedModelProviderNodes = this.scmpInfo.DocumentElement.SelectNodes("descendant::ConnectionBasedModelProvider");
var result = this.scmpInfo.Descendants("ConnectionBasedModelProvider");
string searchingFor = source ? "Source" : "Target";

try
{
if (connectionBasedModelProviderNodes != null)
if (result != null)
{
foreach (XmlNode node in connectionBasedModelProviderNodes)
foreach (XElement node in result)
{
if (node.ParentNode.Name.Contains(searchingFor))
if (node.Parent.Name.ToString().Contains(searchingFor))
{
endpointInfo.ConnectionDetails = SchemaCompareService.ConnectionServiceInstance.ParseConnectionString(node.InnerText);
endpointInfo.ConnectionDetails.ConnectionString = node.InnerText;
endpointInfo.ConnectionDetails = SchemaCompareService.ConnectionServiceInstance.ParseConnectionString(node.Value);
endpointInfo.ConnectionDetails.ConnectionString = node.Value;
endpointInfo.DatabaseName = endpointInfo.ConnectionDetails.DatabaseName;
endpointInfo.EndpointType = SchemaCompareEndpointType.Database;
}
Expand All @@ -150,7 +151,7 @@ private List<SchemaCompareObjectId> GetExcludedElements(IList<SchemaComparisonEx
{
excludedElements.Add(new SchemaCompareObjectId()
{
Name = SchemaCompareOperation.GetName(entry.Identifier.ToString()),
NameParts = entry.Identifier.Parts.Cast<string>().ToArray(),
SqlObjectType = entry.TypeName
});
}
Expand All @@ -162,15 +163,21 @@ private List<SchemaCompareObjectId> GetExcludedElements(IList<SchemaComparisonEx
// The original target name is used to determine whether to use ExcludedSourceElements or ExcludedTargetElements if source and target were swapped
private string GetOriginalTargetName()
{
XmlNode node = this.scmpInfo.DocumentElement.SelectSingleNode("//PropertyElementName[Name='TargetDatabaseName']");
return node != null ? node.LastChild.InnerText : string.Empty;
var result = this.scmpInfo.Descendants("PropertyElementName")
.Where(x => x.Element("Name").Value == "TargetDatabaseName")
.Select(x => x.Element("Value")).FirstOrDefault();

return result != null ? result.Value : string.Empty;
}

// The original target connection string is used if comparing a dacpac and db with the same name
private string GetOriginalTargetConnectionString()
{
XmlNode node = this.scmpInfo.DocumentElement.SelectSingleNode("//PropertyElementName[Name='TargetConnectionString']");
return node != null ? node.LastChild.InnerText : string.Empty;
var result = this.scmpInfo.Descendants("PropertyElementName")
.Where(x => x.Element("Name").Value == "TargetConnectionString")
.Select(x => x.Element("Value")).FirstOrDefault();

return result != null ? result.Value : string.Empty;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static string FormatScript(string script)
return script;
}

public static string GetName(string name)
private static string GetName(string name)
{
// remove brackets from name
return Regex.Replace(name, @"[\[\]]", "");
Expand Down

0 comments on commit f13b4e2

Please sign in to comment.