in src/MIMConfigDocumenter/ServiceCommonDocumenter.cs [555:728]
protected AttributeChange GetAttributeChange(string attributeName)
{
Logger.Instance.WriteMethodEntry("Attribute Name : '{0}'", attributeName);
try
{
var attributeChange = new AttributeChange(attributeName);
var pilotAttribute = this.PilotXml.XPathSelectElement(this.GetAttributeXPath(attributeName, true));
var productionAttribute = this.ProductionXml.XPathSelectElement(this.GetAttributeXPath(attributeName, false));
if (pilotAttribute == null && productionAttribute == null)
{
return attributeChange;
}
attributeChange.IsMultivalue = pilotAttribute != null ? (string)pilotAttribute.Element("IsMultiValue") == "true" : productionAttribute != null ? (string)productionAttribute.Element("IsMultiValue") == "true" : false;
attributeChange.HasReference = pilotAttribute != null ? (string)pilotAttribute.Element("HasReference") == "true" : productionAttribute != null ? (string)productionAttribute.Element("HasReference") == "true" : false;
if (attributeChange.IsMultivalue)
{
switch (this.CurrentChangeObjectState)
{
case "Create":
{
foreach (var value in pilotAttribute.XPathSelectElements("Values/child::node()"))
{
var attributeValue = new AttributeValueChange();
attributeChange.AttributeModificationType = DataRowState.Added;
attributeValue.ValueModificationType = attributeChange.AttributeModificationType;
attributeValue.NewValue = (string)value;
if (attributeChange.HasReference)
{
this.TryDereferenceValue(attributeValue);
}
attributeChange.AttributeValues.Add(attributeValue);
}
}
break;
case "Delete":
{
foreach (var value in productionAttribute.XPathSelectElements("Values/child::node()"))
{
var attributeValue = new AttributeValueChange();
attributeChange.AttributeModificationType = DataRowState.Deleted;
attributeValue.ValueModificationType = attributeChange.AttributeModificationType;
attributeValue.OldValue = (string)value;
attributeValue.NewValue = attributeValue.OldValue;
if (attributeChange.HasReference)
{
this.TryDereferenceValue(attributeValue);
}
}
}
break;
case "Put":
{
if (pilotAttribute != null)
{
foreach (var value in pilotAttribute.XPathSelectElements("Values/child::node()"))
{
var attributeValue = new AttributeValueChange();
attributeValue.NewValue = (string)value;
attributeValue.ValueModificationType = this.TestAttributeValueChange(attributeName, attributeValue.NewValue, DataRowState.Added) ? DataRowState.Added : DataRowState.Unchanged;
if (attributeChange.HasReference)
{
this.TryDereferenceValue(attributeValue);
}
attributeChange.AttributeValues.Add(attributeValue);
if (attributeChange.AttributeModificationType != DataRowState.Modified)
{
attributeChange.AttributeModificationType = attributeValue.ValueModificationType;
}
}
}
if (productionAttribute != null)
{
foreach (var value in productionAttribute.XPathSelectElements("Values/child::node()"))
{
if (this.TestAttributeValueChange(attributeName, (string)value, DataRowState.Deleted))
{
var attributeValue = new AttributeValueChange();
attributeValue.OldValue = (string)value;
attributeValue.ValueModificationType = DataRowState.Deleted;
if (attributeChange.HasReference)
{
this.TryDereferenceValue(attributeValue);
}
attributeValue.NewValue = attributeValue.OldValue;
attributeChange.AttributeValues.Add(attributeValue);
if (attributeChange.AttributeModificationType != DataRowState.Modified)
{
attributeChange.AttributeModificationType = attributeValue.ValueModificationType;
}
}
}
}
}
break;
default:
break;
}
}
else
{
var attributeValue = new AttributeValueChange();
switch (this.CurrentChangeObjectState)
{
case "Create":
{
attributeChange.AttributeModificationType = DataRowState.Added;
attributeValue.ValueModificationType = attributeChange.AttributeModificationType;
attributeValue.NewValue = (string)pilotAttribute.Element("Value");
if (attributeChange.HasReference)
{
this.TryDereferenceValue(attributeValue);
}
}
break;
case "Delete":
{
attributeChange.AttributeModificationType = DataRowState.Deleted;
attributeValue.ValueModificationType = attributeChange.AttributeModificationType;
attributeValue.OldValue = (string)productionAttribute.Element("Value");
attributeValue.NewValue = attributeValue.OldValue;
if (attributeChange.HasReference)
{
this.TryDereferenceValue(attributeValue);
}
}
break;
case "Put":
{
attributeChange.AttributeModificationType = this.CurrentChangeObject.XPathSelectElement(ServiceCommonDocumenter.GetChangeAttributeXPath(attributeName, DataRowState.Modified)) == null ? DataRowState.Unchanged : DataRowState.Modified;
attributeValue.ValueModificationType = attributeChange.AttributeModificationType;
attributeValue.NewValue = pilotAttribute != null ? (string)pilotAttribute.Element("Value") : string.Empty;
attributeValue.OldValue = productionAttribute != null ? (string)productionAttribute.Element("Value") : string.Empty;
if (attributeChange.HasReference)
{
this.TryDereferenceValue(attributeValue);
}
}
break;
}
attributeChange.AttributeValues.Add(attributeValue);
}
return attributeChange;
}
catch (XPathException e)
{
var errorMsg = e.Message + "Attribute Name : '" + attributeName + "'. " + e.StackTrace;
Logger.Instance.WriteError(errorMsg);
return new AttributeChange(attributeName);
}
finally
{
Logger.Instance.WriteMethodExit("Attribute Name : '{0}'", attributeName);
}
}