public bool Load() { try { if (new FileInfo(FileName).Length == 0) { // this is an empty file, probably thanks to our Explorer New->Trizbort Map menu option. Settings.Reset(); return true; } var doc = new XmlDocument(); doc.Load(FileName); var root = new XmlElementReader(doc.DocumentElement); if (!root.HasName("trizbort")) throw new InvalidDataException(string.Format("Not a {0} map file.", Application.ProductName)); // load info Title = root["info"]["title"].Text; Author = root["info"]["author"].Text; Description = root["info"]["description"].Text; History = root["info"]["history"].Text; // load all elements var map = root["map"]; var mapConnectionToLoadState = new Dictionary<Connection, object>(); foreach (var element in map.Children) { if (element.HasName("room")) { var room = new Room(this); room.ID = element.Attribute("id").ToInt(room.ID); room.Load(element); Elements.Add(room); } else if (element.HasName("line")) { var connection = new Connection(this); connection.ID = element.Attribute("id").ToInt(connection.ID); var loadState = connection.BeginLoad(element); if (loadState != null) { mapConnectionToLoadState.Add(connection, loadState); } Elements.Add(connection); } } // connect them together foreach (var pair in mapConnectionToLoadState) { var connection = pair.Key; var state = pair.Value; connection.EndLoad(state); } // load settings last, since their load can't be undone Settings.Reset(); Settings.Load(root["settings"]); return true; } catch (Exception ex) { MessageBox.Show(Program.MainForm, string.Format("There was a problem loading the map:\n\n{0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } }
public VertexPort(Vertex vertex, Connection connection) : base(connection) { Vertex = vertex; Connection = connection; }