ODB Diff WIP
parent
5cf57e6a2b
commit
54ef7ba55d
|
@ -24,6 +24,9 @@ namespace ln.types.odb.ng.diff
|
|||
return new SimpleDiff(dst);
|
||||
}
|
||||
|
||||
public string TreeString => ToTreeString(0);
|
||||
public abstract string ToTreeString(int indent);
|
||||
|
||||
|
||||
class SimpleDiff : Diff
|
||||
{
|
||||
|
@ -43,6 +46,11 @@ namespace ln.types.odb.ng.diff
|
|||
{
|
||||
return String.Format("[SimpleDiff DestinationValue={0}]",DestinationValue);
|
||||
}
|
||||
|
||||
public override string ToTreeString(int indent)
|
||||
{
|
||||
return String.Format("= {0}", DestinationValue.ToTreeString(indent+2));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using ln.types.odb.values;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
namespace ln.types.odb.ng.diff
|
||||
{
|
||||
public class DocumentDiff : Diff
|
||||
|
@ -38,5 +39,21 @@ namespace ln.types.odb.ng.diff
|
|||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using ln.types.odb.values;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ln.types.odb.ng.diff
|
||||
{
|
||||
|
@ -27,20 +28,75 @@ namespace ln.types.odb.ng.diff
|
|||
remove.AddRange(srcItems.Select((i) => i.Identity));
|
||||
add.AddRange(dstItems);
|
||||
|
||||
Dictionary<ODBValue, ODBEntity> srcLookup = new Dictionary<ODBValue, ODBEntity>();
|
||||
foreach (ODBEntity entity in common)
|
||||
{
|
||||
}
|
||||
srcLookup.Add(entity.Identity, entity);
|
||||
|
||||
foreach (ODBEntity entity in commonDst)
|
||||
{
|
||||
ODBValue identity = entity.Identity;
|
||||
ODBEntity srcEntity = srcLookup[identity];
|
||||
|
||||
if (entity.CompareTo(srcEntity) != 0)
|
||||
update.Add(identity, Diff.Construct(srcEntity, entity));
|
||||
}
|
||||
}
|
||||
|
||||
public override ODBEntity Apply(ODBEntity src)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
ODBList list = src as ODBList;
|
||||
|
||||
foreach (ODBEntity entity in list.ToArray())
|
||||
{
|
||||
ODBValue identity = entity.Identity;
|
||||
|
||||
if (remove.Contains(identity))
|
||||
{
|
||||
list.Remove(entity);
|
||||
} else if (update.ContainsKey(identity))
|
||||
{
|
||||
update[identity].Apply(entity);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ODBEntity entity in add)
|
||||
{
|
||||
list.Add(entity.Clone());
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
public override string ToTreeString(int indent)
|
||||
{
|
||||
indent += 2;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.AppendFormat("ListDiff Remove={0} Change={1} Add={2}",remove.Count,update.Count,add.Count);
|
||||
foreach (ODBEntity key in remove)
|
||||
{
|
||||
stringBuilder.AppendLine();
|
||||
stringBuilder.AppendFormat("{0}-{1}", new string(' ', indent), key);
|
||||
}
|
||||
foreach (ODBValue key in update.Keys)
|
||||
{
|
||||
stringBuilder.AppendLine();
|
||||
stringBuilder.AppendFormat("{0} {1} {2}", new string(' ', indent), key, update[key].ToTreeString(indent));
|
||||
}
|
||||
foreach (ODBEntity key in add)
|
||||
{
|
||||
stringBuilder.AppendLine();
|
||||
stringBuilder.AppendFormat("{0}+{1}", new string(' ', indent), key.ToTreeString(indent));
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue