private bool Store(int observationId, Observation[] observations) { using (LiteDatabase db = new LiteDatabase(_liteDBPathName)) { var col = db.GetCollection <BufferedObservation>(_OBSBUF_NAME); foreach (Observation o in observations) { BufferedObservation bo = new BufferedObservation() { ObservationId = observationId, Timestamp = o.Timestamp, }; if (o.GetType() == typeof(BooleanObservation)) { bo.DataType = (int)DataType.Boolean; bo.Value = DataTypeStringConverter.FormatBoolean((o as BooleanObservation).Value); } else if (o.GetType() == typeof(DoubleObservation)) { bo.DataType = (int)DataType.Double; bo.Value = DataTypeStringConverter.FormatDouble((o as DoubleObservation).Value); } else if (o.GetType() == typeof(IntegerObservation)) { bo.DataType = (int)DataType.Integer; bo.Value = DataTypeStringConverter.FormatInteger((o as IntegerObservation).Value); } else if (o.GetType() == typeof(PositionObservation)) { bo.DataType = (int)DataType.Position; bo.Value = DataTypeStringConverter.FormatPosition((o as PositionObservation).Value); } else if (o.GetType() == typeof(StringObservation)) { bo.DataType = (int)DataType.String; bo.Value = (o as StringObservation).Value; } else if (o.GetType() == typeof(StatisticsObservation)) { bo.DataType = (int)DataType.Statistics; bo.Value = DataTypeStringConverter.FormatStatistics((o as StatisticsObservation).Value); } else { throw new ArgumentException("Unknown observation data type: " + o.GetType().ToString()); } col.Insert(bo); } return(true); } }
public override string ToString() { StringBuilder sb = new StringBuilder(); foreach (IdentifiedObservations io in Package.Observations) { foreach (Observation o in io.Observations) { string value; if (o is BooleanObservation) { value = DataTypeStringConverter.FormatBoolean(((BooleanObservation)(o)).Value); } else if (o is DoubleObservation) { value = DataTypeStringConverter.FormatDouble(((DoubleObservation)(o)).Value); } else if (o is IntegerObservation) { value = DataTypeStringConverter.FormatInteger(((IntegerObservation)(o)).Value); } else if (o is PositionObservation) { value = DataTypeStringConverter.FormatPosition(((PositionObservation)(o)).Value); } else if (o is StringObservation) { value = ((StringObservation)(o)).Value; } else if (o is StatisticsObservation) { value = DataTypeStringConverter.FormatStatistics(((StatisticsObservation)(o)).Value); } else { throw new NotSupportedException("Unsupported observation data type: " + o.GetType().ToString()); } string line = string.Format("{0},{1},{2}\r\n", io.ObservationId, o.Timestamp.ToString("o"), value); sb.Append(line); } } return(sb.ToString()); }
public static string ObservationToValueString(Observation o, DataType dataType) { switch (dataType) { case DataType.Boolean: return(DataTypeStringConverter.FormatBoolean(((BooleanObservation)o).Value)); case DataType.Double: return(DataTypeStringConverter.FormatDouble(((DoubleObservation)o).Value)); case DataType.Integer: return(DataTypeStringConverter.FormatInteger(((IntegerObservation)o).Value)); case DataType.Position: return(DataTypeStringConverter.FormatPosition(((PositionObservation)o).Value)); case DataType.String: return(((StringObservation)o).Value); case DataType.Statistics: return(DataTypeStringConverter.FormatStatistics(((StatisticsObservation)o).Value)); default: return(null); } }
public void SetPosition(Position value) { Value = DataTypeStringConverter.FormatPosition(value); }