aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Telemetry/TelemetryBase.cs
blob: ca6c2925ed22f8fc7796738976db0cb954540010 (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
using LiteDB;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Telemetry
{
    public class TelemetryBase : ITelemetry
    {
        [BsonId(true)]
        public int Id { get; set; }
        public DateTime Time { get; set; }
        public List<TelemetryPendingDestination> PendingDestinations { get; set; }

        public TelemetryBase()
        {
            PendingDestinations = new List<TelemetryPendingDestination>();
        }

        public byte[] ToBytes(Formatting format = Formatting.None, bool flatten = true)
        {
            return Encoding.UTF8.GetBytes(ToJson(format, flatten));
        }

        public string ToJson(Formatting format = Formatting.None, bool flatten = true)
        {
            if (flatten)
            {
                return JsonFlattener.FlattenObjectToFlatJson(this, format);
            }
            else
            {
                return JsonConvert.SerializeObject(this, format);
            }
        }
    }
}