61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ln.objects.catalog;
|
|
|
|
namespace ln.types.odb.ng.diff
|
|
{
|
|
public class DocumentDiff : Diff
|
|
{
|
|
Dictionary<ODBEntity, Diff> propertyDiffs = new Dictionary<ODBEntity, Diff>();
|
|
|
|
public DocumentDiff(Document src, Document dst)
|
|
{
|
|
HashSet<ODBEntity> keys = new HashSet<ODBEntity>(src.Keys);
|
|
foreach (ODBEntity key in dst.Keys)
|
|
keys.Add(key);
|
|
|
|
foreach (ODBEntity key in keys)
|
|
{
|
|
if (src[key].CompareTo(dst[key]) != 0)
|
|
propertyDiffs.Add(key, Diff.Construct(src[key], dst[key]));
|
|
}
|
|
}
|
|
|
|
public override ODBEntity Apply(ODBEntity src)
|
|
{
|
|
Document srcDocument = src as Document;
|
|
|
|
foreach (ODBValue key in propertyDiffs.Keys)
|
|
{
|
|
srcDocument[key] = propertyDiffs[key].Apply(srcDocument[key]);
|
|
}
|
|
|
|
return src;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("[DocumentDiff ChangedProperties=({0})]",string.Join(",",propertyDiffs.Keys));
|
|
}
|
|
|
|
public override string ToTreeString(int indent)
|
|
{
|
|
indent += 2;
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
stringBuilder.AppendFormat("DocumentDiff ChangedProperties=({0})",string.Join(",",propertyDiffs.Keys));
|
|
foreach (ODBEntity key in propertyDiffs.Keys)
|
|
{
|
|
stringBuilder.AppendLine();
|
|
stringBuilder.AppendFormat("{0}{1,-32} {2}", new string(' ', indent), key, propertyDiffs[key].ToTreeString(indent));
|
|
}
|
|
|
|
return stringBuilder.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
}
|