using LiteDB; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.PMR.Diagnostics; using Tango.PMR.Insights; using Tango.Transport.Compression; namespace Tango.Insights { public class InsightsFrame { [BsonId(true)] public int Id { get; set; } public DateTime Time { get; set; } public bool IsEmpty { get; set; } public byte[] MonitorsData { get; set; } public static InsightsFrame CreateEmpty(DateTime timeUtc) { InsightsFrame frame = new InsightsFrame(); frame.Time = timeUtc; frame.IsEmpty = true; frame.MonitorsData = null; return frame; } public static InsightsFrame FromDiagnosticsMonitors(DiagnosticsMonitors diagnosticsMonitors, DateTime timeUtc) { InsightsMonitors insightsMonitors = InsightsHelper.MapMonitors(diagnosticsMonitors); return FromInsightsMonitors(insightsMonitors, timeUtc); } public static InsightsFrame FromInsightsMonitors(InsightsMonitors insightsMonitors, DateTime timeUtc) { InsightsFrame frame = new InsightsFrame(); frame.Time = timeUtc; byte[] data = insightsMonitors.ToBytes(); byte[] compressedData = GZipHelper.Compress(data); frame.MonitorsData = compressedData; return frame; } public InsightsMonitors ToInsightsMonitors() { if (IsEmpty) { return InsightsHelper.CreateEmptyGap(); } else { var uncompressed = GZipHelper.Decompress(MonitorsData); var insightsMonitors = InsightsMonitors.Parser.ParseFrom(uncompressed); return insightsMonitors; } } } }