- Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSyncEngine.cs
More file actions
Latest commit
59 lines (53 loc) · 2.42 KB
/
Copy pathSyncEngine.cs
File metadata and controls
59 lines (53 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
usingSystem;
usingSystem.Linq;
usingSystem.Text.Json;
usingSystem.Collections.Generic;
usingSystem.Reflection;
namespaceNETCoreSyncServer
{
publicabstractclassSyncEngine
{
publicDictionary<string,object?>CustomInfo{get;set;}=null!;
abstractpubliclongGetNextTimeStamp();
abstractpublicIQueryableGetQueryable(Typetype);
abstractpublicvoidInsert(Typetype,dynamicserverData);
abstractpublicvoidUpdate(Typetype,dynamicserverData);
virtualpublicDictionary<string,string>ClientPropertyNameToServerPropertyName(Typetype)
{
returnnewDictionary<string,string>();
}
virtualpublicdynamicPopulateServerData(Typetype,Dictionary<string,object?>clientData,dynamic?serverData)
{
if(serverData==null)
{
serverData=Activator.CreateInstance(type)!;
}
List<PropertyInfo>properties=type.GetProperties(BindingFlags.Public|BindingFlags.Instance).Where(w =>w.CanWrite).ToList();
varkeys=clientData.Keys.ToList();
foreach(varkeyinkeys)
{
varproperty=properties.Where(w =>w.Name.ToLower()==key.ToLower()).FirstOrDefault();
if(property==null)continue;
varvalue=clientData[key];
if(valueisJsonElement)
{
// The current Moor's default implementation of toJson() is converting DateTime to epoch milliseconds (in the _DefaultValueSerializer class).
// We now attempt to detect such condition for DateTime type.
if((property.PropertyType==typeof(DateTime)||property.PropertyType==typeof(DateTime?))&&((JsonElement)value).ValueKind==JsonValueKind.Number)
{
value=DateTimeOffset.FromUnixTimeMilliseconds(((JsonElement)value).GetInt64()).LocalDateTime;
}
else
{
value=JsonSerializer.Deserialize(((JsonElement)value).GetRawText(),property.PropertyType);
}
}
property.SetValue(serverData,value);
}
returnserverData;
}
virtualpublicvoidModifySerializedServerData(Dictionary<string,object?>serializedServerData)
{
}
}
}