public static NamingRules LoadRules(string xmlPath) { NamingRules namingRules = new NamingRules(); namingRules.rules = new List <NamingRule>(); using (XmlReader reader = new XmlTextReader(xmlPath)) { reader.ReadStartElement("Rules"); reader.ReadStartElement("GeneralSettings"); reader.ReadStartElement("FilenameRegex"); namingRules.filenameRegex = reader.ReadString(); reader.ReadEndElement(); reader.ReadStartElement("ContextDepth"); namingRules.contextDepth = reader.ReadContentAsInt(); if (namingRules.ContextDepth < 1 || namingRules.ContextDepth > 4) { throw new FormatException("Context Depth must be between 1 and 4"); } reader.ReadEndElement(); reader.ReadStartElement("ContextSeparator"); namingRules.contextSeparator = reader.ReadString(); reader.ReadEndElement(); reader.ReadEndElement(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.EndElement) { System.Diagnostics.Debug.Assert(reader.Name == "Rules"); break; } //if (reader.IsStartElement()) // System.Diagnostics.Debug.Assert(reader.Name == "Rule"); reader.ReadStartElement("Rule"); //reader.Read(); reader.ReadStartElement("SearchString"); string regex = reader.ReadString(); reader.ReadEndElement(); reader.ReadStartElement("Replacement"); string replacement = reader.ReadString(); reader.ReadEndElement(); reader.ReadEndElement(); namingRules.rules.Add(new NamingRule(regex, replacement)); } reader.ReadEndElement(); } return(namingRules); }
private void MainForm_Load(object sender, EventArgs args) { string executableFolder = Path.GetDirectoryName(Application.ExecutablePath); try { namingRules = NamingRules.LoadRules(Path.Combine(executableFolder, "NamingRules.xml")); } catch (Exception e) { MessageBox.Show(String.Format("Error reading NamingRules.xml\r\n{0}", e.ToString()), Application.ProductName); Close(); } }
public static NamingRules LoadRules(string xmlPath) { NamingRules namingRules = new NamingRules(); namingRules.rules = new List<NamingRule>(); using (XmlReader reader = new XmlTextReader(xmlPath)) { reader.ReadStartElement("Rules"); reader.ReadStartElement("GeneralSettings"); reader.ReadStartElement("FilenameRegex"); namingRules.filenameRegex = reader.ReadString(); reader.ReadEndElement(); reader.ReadStartElement("ContextDepth"); namingRules.contextDepth = reader.ReadContentAsInt(); if (namingRules.ContextDepth < 1 || namingRules.ContextDepth > 4) throw new FormatException("Context Depth must be between 1 and 4"); reader.ReadEndElement(); reader.ReadStartElement("ContextSeparator"); namingRules.contextSeparator = reader.ReadString(); reader.ReadEndElement(); reader.ReadEndElement(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.EndElement) { System.Diagnostics.Debug.Assert(reader.Name == "Rules"); break; } //if (reader.IsStartElement()) // System.Diagnostics.Debug.Assert(reader.Name == "Rule"); reader.ReadStartElement("Rule"); //reader.Read(); reader.ReadStartElement("SearchString"); string regex = reader.ReadString(); reader.ReadEndElement(); reader.ReadStartElement("Replacement"); string replacement = reader.ReadString(); reader.ReadEndElement(); reader.ReadEndElement(); namingRules.rules.Add(new NamingRule(regex, replacement)); } reader.ReadEndElement(); } return namingRules; }
public MidiConverter(NamingRules namingRules) { settings = Properties.Settings.Default; this.namingRules = namingRules; ezdFileName = new Regex(namingRules.FilenameRegex); }