private static IList<RmAttributeChange> GetDifference(
Dictionary<RmAttributeName, RmAttributeValue> sourceAttributes,
Dictionary<RmAttributeName, RmAttributeValue> destinationAttributes)
{
IList<RmAttributeChange> changedAttributes = new List<RmAttributeChange>();
// iterate source attributes
foreach (KeyValuePair<RmAttributeName, RmAttributeValue> sourceItem in sourceAttributes) {
RmAttributeName sourceName = sourceItem.Key;
RmAttributeValue sourceValue = sourceItem.Value;
if (!destinationAttributes.ContainsKey(sourceName)) {
// the destination does not contain the attribute
if (sourceValue.IsMultiValue) {
// add all the values
foreach (IComparable value1 in sourceValue.Values) {
changedAttributes.Add(new RmAttributeChange(sourceName, value1, RmAttributeChangeOperation.Add));
}
} else {
changedAttributes.Add(new RmAttributeChange(sourceItem.Key, null, RmAttributeChangeOperation.Replace));
}
} else {
// the destination contains the attribute
RmAttributeValue destinationValue = destinationAttributes[sourceItem.Key];
if (sourceValue.IsMultiValue) {
foreach (IComparable value1 in sourceValue.Values) {
if (destinationValue.Values.Contains(value1) == false) {
changedAttributes.Add(new RmAttributeChange(sourceItem.Key, value1, RmAttributeChangeOperation.Add));
}
}
foreach (IComparable value2 in destinationValue.Values) {
if (sourceItem.Value.Values.Contains(value2) == false) {
changedAttributes.Add(new RmAttributeChange(sourceItem.Key, value2, RmAttributeChangeOperation.Delete));
}
}
} else {
if (destinationValue.Value != sourceValue.Value) {
RmAttributeChangeOperation operation;
if (
(
// <[MA] change 24-11-2011> - cleared reference attributes require Delete operation
destinationValue.Value is RmReference
||
// <[MA] change 05-03-2012> - cleared date attributes require Delete operation
destinationValue.Value is DateTime?
)
&& sourceValue.Value == null
)
{
operation = RmAttributeChangeOperation.Delete;
}
else
{
operation = RmAttributeChangeOperation.Replace;
}
changedAttributes.Add(new RmAttributeChange(sourceItem.Key, sourceValue.Value, operation));
// </[MA]>
}
}
}
}
// iterate destination attributes
foreach (KeyValuePair<RmAttributeName, RmAttributeValue> destinationItem in destinationAttributes) {
if (sourceAttributes.ContainsKey(destinationItem.Key) == false) {
foreach (IComparable value2 in destinationItem.Value.Values) {
changedAttributes.Add(new RmAttributeChange(destinationItem.Key, value2, RmAttributeChangeOperation.Delete));
}
}
}
return changedAttributes;
}