aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreHelper.cs
blob: a702c34655c157794629f47a979a141b27ea7b23 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;

namespace Tango.DataStore.EF
{
    public static class EFDataStoreHelper
    {
        public static byte[] CreateBytes(DataType type, Object obj)
        {
            return DataStoreHelper.CreateBytes(type, obj);
        }

        public static Object CreateObject(DataType type, byte[] bytes)
        {
            return DataStoreHelper.CreateObject(type, bytes);
        }

        public static IDataStoreItem CreateDataStoreItem(DataStoreItem item)
        {
            return new EFDataStoreItem()
            {
                Guid = item.Guid,
                Date = item.LastUpdated,
                IsSynchronized = item.IsSynchronized,
                Key = item.Key,
                Type = (DataType)item.DataType,
                Value = CreateObject((DataType)item.DataType, item.Value)
            };
        }

        public static IDataStoreItem CreateDataStoreItem(GlobalDataStoreItem item)
        {
            return new EFDataStoreItem()
            {
                Guid = item.Guid,
                Date = item.LastUpdated,
                IsSynchronized = true,
                Key = item.Key,
                Type = (DataType)item.DataType,
                Value = CreateObject((DataType)item.DataType, item.Value)
            };
        }

        public static DataStoreItem CreateLocalDbDataStoreItem(IDataStoreItem item, String collection)
        {
            return new DataStoreItem()
            {
                Guid = item.Guid,
                CollectionName = collection,
                LastUpdated = item.Date,
                IsSynchronized = item.IsSynchronized,
                Key = item.Key,
                DataType = (int)item.Type,
                Value = CreateBytes(item.Type, item.Value)
            };
        }

        public static GlobalDataStoreItem CreateGlobalDbDataStoreItem(IDataStoreItem item, String collection)
        {
            return new GlobalDataStoreItem()
            {
                Guid = item.Guid,
                CollectionName = collection,
                LastUpdated = item.Date,
                Key = item.Key,
                DataType = (int)item.Type,
                Value = CreateBytes(item.Type, item.Value)
            };
        }
    }
}