private DomainReference ParseXmlFileReferences(string domainFileName) { DomainReference domRef = new DomainReference(domainFileName); //the workspace was already reset so the root directory should be good to go //find the master XML file and begin disecting the directory layout and file locations string masterFile = Globals.Dirs.DomainReferences + "\\" + domainFileName + ".xml"; if (!System.IO.File.Exists(masterFile)) { throw new DomainModelException("External domain reference " + domainFileName + " is missing."); } Sluggy.Utility.XmlParser xml; try{ bool validFile = false; xml = new Sluggy.Utility.XmlParser(masterFile); if (xml.Contents.Children[0].Name == "domain") { validFile = true; Sluggy.Utility.Tag domainTag = xml.Contents.Children[0]; foreach (Sluggy.Utility.Tag tag in domainTag.Children) { //HACK ALERT - might as well just hardcode a giant ugly-ass switch while I'm at it //remember, this is for a domain reference file. We aren't loading an files, just getting their //names and importing them into the workspace. #region room tag parsing if (tag.Name == "directory" && tag.Attributes["name"] == "room") { foreach (Sluggy.Utility.Tag roomTag in tag.Children) { string roomName; if (roomTag.Attributes.ContainsKey("name")) { roomName = roomTag.Attributes["name"]; } else { throw new DomainModelException("Missing room name in external domain " + domainFileName + "."); } domRef.Rooms.Add(domRef.ConvertRoomNameToFullPath(roomName), new FileReferenceModel(roomName, ItemSaveType.Room, Include, domainFileName)); } //break; } #endregion #region item tag parsing if (tag.Name == "directory" && tag.Attributes["name"] == "inventory") { foreach (Sluggy.Utility.Tag itemTag in tag.Children) { if (itemTag.Attributes.ContainsKey("name") && itemTag.Attributes.ContainsKey("class")) { string name = itemTag.Attributes["name"]; string itemClass = itemTag.Attributes["class"]; domRef.Inventory.Add(domRef.ConvertRoomNameToFullPath(name), new FileReferenceModel(name, Include.DetermineSaveType(itemClass), Include, domainFileName)); } } } #endregion //break; } } if (!validFile) { throw new DomainModelException("Invalid master XML file. Could not load domain."); } } catch (Sluggy.Utility.XMLParserException exception) { throw new DomainModelException("Failed to parse domain master XML file.\n\n" + exception.Message); } catch (System.IndexOutOfRangeException exception) { throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception); } catch (System.ArgumentOutOfRangeException exception) { throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception); } return(domRef); }