Exemple #1
0
        public static UtteranceData FromLine(string line) => line.ReadXmlFragment <UtteranceData>(reader =>
        {
            UtteranceData value;

            reader.ValidatedRead();

            if (reader.NodeType == XmlNodeType.Element && reader.Name == "U")
            {
                var isArtificial       = false;
                DateTimeOffset?started = null;
                TimeSpan?duration      = null;
                int?keyCount           = null;

                for (var work = reader.MoveToFirstAttribute(); work; work = reader.MoveToNextAttribute())
                {
                    switch (reader.Name)
                    {
                    case nameof(IsArtificial):
                        isArtificial = true;
                        break;

                    case nameof(Started):
                        started = DateTimeOffset.Parse(reader.Value, null, DateTimeStyles.RoundtripKind);
                        break;

                    case nameof(Duration):
                        duration = TimeSpan.FromMilliseconds(double.Parse(reader.Value));
                        break;

                    case nameof(KeyCount):
                        keyCount = int.Parse(reader.Value);
                        break;
                    }
                }
                reader.ValidatedRead();

                var sequence = TileSequence.FromEncoded(reader, XmlNodeType.EndElement);
                reader.ReadEndOfFragment();

                value = isArtificial ? new UtteranceData(sequence, true) : new UtteranceData(sequence, started, duration, keyCount);
            }
            else
            {
                var sequence = TileSequence.FromEncoded(line);

                value = new UtteranceData(sequence, false);
            }

            return(value);
        });