Added odb.ng.diff
parent
f19d93f334
commit
9e00a3ee69
|
@ -133,6 +133,7 @@
|
|||
<Folder Include="odb\ng\storage\fs\" />
|
||||
<Folder Include="cache\" />
|
||||
<Folder Include="collections\" />
|
||||
<Folder Include="odb\ng\diff\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ln.logging\ln.logging.csproj">
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using ln.types.odb.values;
|
||||
namespace ln.types.odb.ng.diff
|
||||
{
|
||||
public abstract class Diff
|
||||
{
|
||||
|
||||
public abstract ODBValue Apply(ODBValue src);
|
||||
|
||||
public static Diff Construct(ODBValue src,ODBValue dst)
|
||||
{
|
||||
if (!src.GetType().Equals(dst.GetType()))
|
||||
{
|
||||
return new SimpleDiff(dst);
|
||||
}
|
||||
else if (src is Document)
|
||||
{
|
||||
return new DocumentDiff(src as Document, dst as Document);
|
||||
} else if (src is ODBList)
|
||||
{
|
||||
return new ListDiff(src as ODBList, dst as ODBList);
|
||||
}
|
||||
|
||||
return new SimpleDiff(dst);
|
||||
}
|
||||
|
||||
|
||||
class SimpleDiff : Diff
|
||||
{
|
||||
public ODBValue DestinationValue { get; }
|
||||
|
||||
public SimpleDiff(ODBValue dst)
|
||||
{
|
||||
DestinationValue = dst.Clone();
|
||||
}
|
||||
|
||||
public override ODBValue Apply(ODBValue src)
|
||||
{
|
||||
return DestinationValue;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("[SimpleDiff DestinationValue={0}]",DestinationValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ln.types.odb.values;
|
||||
using System.Linq;
|
||||
namespace ln.types.odb.ng.diff
|
||||
{
|
||||
public class DocumentDiff : Diff
|
||||
{
|
||||
Dictionary<ODBValue, Diff> propertyDiffs = new Dictionary<ODBValue, Diff>();
|
||||
|
||||
public DocumentDiff(Document src, Document dst)
|
||||
{
|
||||
HashSet<ODBValue> keys = new HashSet<ODBValue>(src.Keys);
|
||||
foreach (ODBValue key in dst.Keys)
|
||||
keys.Add(key);
|
||||
|
||||
foreach (ODBValue key in keys)
|
||||
{
|
||||
if (!src[key].Equals(dst[key]))
|
||||
propertyDiffs.Add(key, Diff.Construct(src[key], dst[key]));
|
||||
}
|
||||
}
|
||||
|
||||
public override ODBValue Apply(ODBValue 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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using ln.types.odb.values;
|
||||
|
||||
namespace ln.types.odb.ng.diff
|
||||
{
|
||||
public class ListDiff : Diff
|
||||
{
|
||||
public ListDiff(ODBList src,ODBList dst)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override ODBValue Apply(ODBValue src)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue