public Set Copy() { Set tSet = new Set(); foreach (Song tS in SongList) tSet.AddSong(tS); tSet.Name = Name; return tSet; }
private Set getSetFromFile(string aFile) { Set tSet = new Set(); using (System.IO.StreamReader tFile = new System.IO.StreamReader(aFile)) { using (XmlReader tReader = XmlReader.Create(tFile)) { XmlDocument xml = new XmlDocument(); xml.Load(tReader); tSet = new Set(); XmlNode xSet = xml.SelectSingleNode("Set"); if (xSet.Attributes.Count > 0) { XmlAttribute tAt = xSet.Attributes["Name"]; tSet.Name = tAt.Value; } XmlNodeList tList = xml.SelectNodes("/Set/Song"); foreach (XmlNode xSong in tList) { Song tS = new Song(); if (xSong.Attributes.Count > 0) tS.Name = xSong.Attributes["Name"].Value; foreach (XmlNode xTrig in xSong.ChildNodes) { TriggerData tData = new TriggerData(); tData.Filename = xTrig["Filename"].InnerText; TriggerMessage tTrig = new TriggerMessage(); XmlNode xMes = xTrig["Message"]; tTrig.stEvent = xMes["Event"].InnerText; tTrig.stRawMessage = Convert.ToInt32(xMes["RawMessage"].InnerText); tData.Message = tTrig; tS.TriggerDataList.Add(tData); } tSet.SongList.Add(tS); } } } return tSet; }
public void OpenSetFromFile() { if (CheckForSave() == MessageBoxResult.Cancel) return; OpenFileDialog tDial = new OpenFileDialog(); tDial.DefaultExt = ".xml"; tDial.Title = "Open set xml file"; bool? result = tDial.ShowDialog(mWindow); if (!(bool)result) return; string tFilename = tDial.FileName; Set tSet = getSetFromFile(tFilename); mSet = tSet; mWindow.dontUpdate = true; mWindow.SongListComboBox.Items.Clear(); foreach (Song tS in mSet.SongList) mWindow.SongListComboBox.Items.Add(tS.Name); mWindow.SongListComboBox.SelectedIndex = 0; LoadSong(mSet.SongList[0]); mWindow.dontUpdate = false; AppController.Instance().ChangesMade = false; }
public XmlDocument CreateXML(Set aSet) { XmlDocument tDoc = new XmlDocument(); XmlElement tSet = tDoc.CreateElement("Set"); foreach (Song tS in aSet.SongList) { XmlElement tSong = tDoc.CreateElement("Song"); tSong.SetAttribute("Name", tS.Name); foreach (TriggerData tD in tS.TriggerDataList) { XmlElement tTrigData = tDoc.CreateElement("TriggerData"); XmlElement tFilename = tDoc.CreateElement("Filename"); tFilename.InnerText = tD.Filename; tTrigData.AppendChild(tFilename); XmlElement tMsg = tDoc.CreateElement("Message"); XmlElement tEvent = tDoc.CreateElement("Event"); if (tD.Message.stEvent != null) tEvent.InnerText = tD.Message.stEvent.ToString(); XmlElement tRaw = tDoc.CreateElement("RawMessage"); tRaw.InnerText = tD.Message.stRawMessage.ToString(); tMsg.AppendChild(tEvent); tMsg.AppendChild(tRaw); tTrigData.AppendChild(tMsg); tSong.AppendChild(tTrigData); } tSet.AppendChild(tSong); } tDoc.AppendChild(tSet); return tDoc; }