Esempio n. 1
0
        public ITimestampStringConverter Resolve(string format)
        {
            string[] formatParts = format?.Split(new char[] { ':' }, count: 2, options: StringSplitOptions.RemoveEmptyEntries);

            string converterId   = formatParts?.FirstOrDefault();
            string configuration = formatParts?.Skip(1).FirstOrDefault();

            ITimestampStringConverter converter = String.IsNullOrWhiteSpace(converterId)
                                                ? CreateDefaultConverter()
                                                : ResolveConverterFromId(converterId);

            // if was not resolved and no configuration is provided but converterId has value,
            // value of the converterId may be the configuration for the default converter.
            if (converter == null &&
                String.IsNullOrWhiteSpace(configuration) &&
                String.IsNullOrWhiteSpace(converterId) == false)
            {
                converter     = CreateDefaultConverter();
                configuration = converterId;
            }

            if (String.IsNullOrWhiteSpace(configuration) == false)
            {
                converter.Configure(configuration);
            }

            return(converter);
        }
Esempio n. 2
0
        private static IEnumerable <Selection> ReadSelectionFromOptions(SelectorOptions options)
        {
            ITimestampStringConverter timestampConverter = TimestampStringConverterResolver.Default.Resolve(options.TimestampFormat);

            var selection = Selection.Parse(options.FromTimestamp, options.ToTimestamp, timestampConverter);

            return(new[] { selection });
        }
Esempio n. 3
0
        private static void Configure(FilterContext context, BaseFilterOptions options)
        {
            ITimestampStringConverter timestampConverter = TimestampStringConverterResolver.Default.Resolve(options.TimestampFormat);

            if (String.IsNullOrWhiteSpace(options.FromTimestampString) == false)
            {
                options.FromTimestamp = timestampConverter.Convert(options.FromTimestampString);
            }

            if (String.IsNullOrWhiteSpace(options.ToTimestampString) == false)
            {
                options.ToTimestamp = timestampConverter.Convert(options.ToTimestampString);
            }
        }
        protected override void ConfigureOverride(FilterContext context, ITimestampSerializationOptions options)
        {
            ITimestampStringConverter timestampConverter = TimestampStringConverterResolver.Default.Resolve(options.TimestampFormat);

            var converters = new ISerializationConfiguration[] {
                new CsvConvertersSerializationConfiguration(new SelectionCsvConverter())
            };


            context.IO
            .Formats
            .GetOrDefault(FileFormat.CSV)?
            .Configurations
            .AddRange(converters);
        }
        private void SetupDateTimeOffsetSerialization(JsonSerializer serializer, ITimestampStringConverter timestampConverter)
        {
            serializer.DateTimeZoneHandling = DateTimeZoneHandling.Local;

            if (timestampConverter == null)
            {
                serializer.DateFormatHandling = DateFormatHandling.IsoDateFormat;
                serializer.DateParseHandling  = DateParseHandling.DateTimeOffset;
            }
            else
            {
                serializer.DateTimeZoneHandling = DateTimeZoneHandling.Local;
                serializer.DateParseHandling    = DateParseHandling.None;

                serializer.Converters.Add(new DateTimeOffsetJsonConverter(timestampConverter));
            }
        }
Esempio n. 6
0
        public void ReadAll_RecordsWithDateTimestamp()
        {
            ITimestampStringConverter timestampConverter = TimestampStringConverterResolver.Default.Resolve("date");

            var serialization = new CsvSerializationFactory
                                (
                new CsvGazeToolkitDataConvertersSerializationConfiguration(),
                new CsvTimestampedDataSerializationConfiguration("Timestamp"),
                new CsvTimestampSerializationConfiguration(timestampConverter),
                new CsvConvertersSerializationConfiguration(new ValidationPointCsvConverter())
                                );

            DateTimeOffset startTimestamp = new DateTimeOffset(2018, 11, 20, 12, 08, 28, 477, TimeSpan.FromHours(2));
            DateTimeOffset startA         = startTimestamp;
            DateTimeOffset endA           = startTimestamp.AddSeconds(1);

            DateTimeOffset startB = endA.AddSeconds(2);
            DateTimeOffset endB   = startB.AddSeconds(1);

            DateTimeOffset startC = endB.AddSeconds(2);
            DateTimeOffset endC   = startC.AddSeconds(1);

            string[] lines = new[]
            {
                "Validation,Point,X,Y,StartTime,EndTime"
                , $"1,1,0.1,0.1,{timestampConverter.ConvertBack(startA)},{timestampConverter.ConvertBack(endA)}"
                , $"2,1,0.5,0.9,{timestampConverter.ConvertBack(startB)},{timestampConverter.ConvertBack(endB)}"
                , $"3,1,0.9,0.1,{timestampConverter.ConvertBack(startC)},{timestampConverter.ConvertBack(endC)}"
            };

            string input = String.Join(Environment.NewLine, lines);

            using (var inputReader = new StringReader(input))
                using (var reader = serialization.CreateReaderForType(inputReader, typeof(ValidationPoint), null))
                {
                    var records = reader.ReadAll <ValidationPoint>().ToList();

                    Assert.AreEqual(3, records.Count);

                    AssertRecord(new ValidationPoint(1, 1, new GazeToolkit.Point2(0.1, 0.1), startA, endA), records[0]);
                    AssertRecord(new ValidationPoint(2, 1, new GazeToolkit.Point2(0.5, 0.9), startB, endB), records[1]);
                    AssertRecord(new ValidationPoint(3, 1, new GazeToolkit.Point2(0.9, 0.1), startC, endC), records[2]);
                }
        }
Esempio n. 7
0
        protected override void ConfigureOverride(FilterContext context, ITimestampSerializationOptions options)
        {
            ITimestampStringConverter timestampConverter = TimestampStringConverterResolver.Default.Resolve(options.TimestampFormat);

            context.IO
            .Formats
            .GetOrDefault(FileFormat.JSON)?
            .Configurations
            .Add
            (
                new JsonTimestampSerializationConfiguration(timestampConverter)
            );

            context.IO
            .Formats
            .GetOrDefault(FileFormat.CSV)?
            .Configurations
            .Add
            (
                new CsvTimestampSerializationConfiguration(timestampConverter)
            );
        }
Esempio n. 8
0
        public static Selection Parse(string name, string fromValue, string toValue, ITimestampStringConverter timestampConverter)
        {
            if (timestampConverter == null)
            {
                throw new ArgumentNullException(nameof(timestampConverter));
            }

            DateTimeOffset?from = null;
            DateTimeOffset?to   = null;

            if (String.IsNullOrWhiteSpace(fromValue) == false)
            {
                from = timestampConverter.Convert(fromValue);
            }

            if (String.IsNullOrWhiteSpace(toValue) == false)
            {
                to = timestampConverter.Convert(toValue);
            }

            return(new Selection(name, from, to));
        }
 public JsonTimestampSerializationConfiguration(ITimestampStringConverter converter)
 {
     Converter = converter;
 }
 public DoublyTimestampedDataPayloadJsonConverter(string timestampField, string referenceTimestampField, ITimestampStringConverter referenceTimestampConverter)
 {
     _timestampField              = timestampField;
     _referenceTimestampField     = referenceTimestampField;
     _referenceTimestampConverter = referenceTimestampConverter;
 }
 private void SetupDateTimeOffsetSerialization(CsvSerializerContext serializer, ITimestampStringConverter timestampConverter)
 {
     if (timestampConverter != null)
     {
         serializer.Configuration.TypeConverterCache.AddConverter <DateTimeOffset>(new DateTimeOffsetTypeConverter(timestampConverter));
     }
 }
 public CsvTimestampSerializationConfiguration(ITimestampStringConverter timestampConverter)
 {
     TimestampConverter = timestampConverter;
 }
 public DateTimeOffsetTypeConverter(ITimestampStringConverter timestampConverter)
 {
     _timestampConverter = timestampConverter;
 }