Example #1
0
        /// <summary>
        ///     将timetable写入xml
        /// </summary>
        public static void SaveCheckpointListXml(Player.Player player)
        {
            var xd = new XDocument(new XElement("CheckpointList"));

            (from checkpoint in _timeTable
             where checkpoint.CheckpointCanBeSaved
             select checkpoint).ForEach(cp => xd.Element("CheckpointList")?.Add(cp.ConvertCheckpointToXElement()));
            Debug.WriteLine(xd);

            // var path = HttpContext.Current.Server.MapPath("~/Data/CheckpointList/checkpoints.xml");
            var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data/" + player.PlayerNumber + "/checkpoints.xml");

            xd.Save(path);
            if (File.Exists(path))
            {
                Debug.WriteLine("Saved!");
            }
            Debug.WriteLine(path);
        }
Example #2
0
        /// <summary>
        ///     从XML中读取CheckpointList
        /// </summary>
        public static void ReadCheckpointListXml(Player.Player player)
        {
            // var path = HttpContext.Current.Server.MapPath("~/Data/CheckpointList/checkpoints.xml");
            var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\" + player.PlayerNumber + "\\checkpoints.xml");

            if (File.Exists(path))
            {
                var xd = XDocument.Load(path);

                foreach (var element in (xd.Element("CheckpointList")?.Elements("Checkpoint") ??
                                         throw new InvalidOperationException())
                         .Select(xe => xe))
                {
                    var tempCp = Checkpoint.Checkpoint.ReadCheckpointXml(element, player);
                    if (!CheckpointListContains(tempCp))
                    {
                        AddCheckpoint(tempCp);
                    }
                }
            }
        }