Exemple #1
0
        public void Write(TimetableType?forceType = null, TimetableVersion?forceVersion = null)
        {
            var t = forceType ?? tt.Type;
            var v = forceVersion ?? tt.Version;

            if (t == TimetableType.Linear)
            {
                var pos = GetPosition(Timetable.LINEAR_ROUTE_ID).Value.ToString("0.0", CultureInfo.InvariantCulture);
                if (v == TimetableVersion.JTG2_x)
                {
                    sta.SetAttribute("km", pos);
                    sta.RemoveAttribute("kml");
                    sta.RemoveAttribute("kmr");
                }
                else // jTG 3.0
                {
                    sta.SetAttribute("kml", pos);
                    sta.SetAttribute("kmr", pos);
                    sta.RemoveAttribute("km");
                }
            }
            else
            {
                var posStrings = positions.Select(kvp => kvp.Key.ToString() + ":" + kvp.Value.ToString("0.0", CultureInfo.InvariantCulture));
                var text       = string.Join(";", posStrings);
                sta.SetAttribute("km", text);
                sta.RemoveAttribute("kml");
                sta.RemoveAttribute("kmr");
            }
        }
        /// <summary>
        /// Write all positions back to the XML attribute.
        /// </summary>
        /// <param name="forceType">Force either network or linear mode (only to be used by conversions!).</param>
        public void Write(TimetableType?forceType = null)
        {
            var t = forceType ?? tt.Type;

            if (t == TimetableType.Linear)
            {
                var posFloat = GetPosition(Timetable.LINEAR_ROUTE_ID) ?? throw new Exception("No linear position found while attempting to write linear positions.");
                var pos      = posFloat.ToString("0.0", CultureInfo.InvariantCulture);
                sta.SetAttribute("kml", pos);
                sta.SetAttribute("kmr", pos);
                sta.RemoveAttribute("km");
            }
            else
            {
                var posStrings = positions.Select(kvp => kvp.Key.ToString() + ":" + kvp.Value.ToString("0.0", CultureInfo.InvariantCulture));
                var text       = string.Join(";", posStrings);
                sta.SetAttribute("km", text);
                sta.RemoveAttribute("kml");
                sta.RemoveAttribute("kmr");
            }
        }