public static RSS Read(XmlNode xml) { RSS result = new RSS(); result.ID = xml.Attributes["id"].Value; result.Description = xml.Attributes["description"].Value; result.Address = xml.Attributes["address"].Value; result.Interval = int.Parse(xml.Attributes["interval"].Value); result.OneString = bool.Parse(xml.Attributes["oneString"].Value); return(result); }
void Button1Click(object sender, EventArgs e) { // zapisanie kanałów List <RSS> rss = new List <RSS>(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].IsNewRow) { continue; } RSS r = new RSS(); r.ID = (string)dataGridView1.Rows[i].Cells[_id.Index].Value; if (string.IsNullOrEmpty(r.ID) || r.ID.Trim().Length == 0) { MessageBox.Show(this, "Wprowadzono błędny identyfikator.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); dataGridView1.CurrentCell = dataGridView1.Rows[i].Cells[_id.Index]; return; } if (rss.Find(delegate(RSS o) { return(o.ID == r.ID); }) != null) { MessageBox.Show(this, string.Format("Identyfikator '{0}' jest użyty co najmniej dwa razy. Identyfikator musi być unikalny.", r.ID), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); dataGridView1.CurrentCell = dataGridView1.Rows[i].Cells[_id.Index]; return; } r.Description = (string)dataGridView1.Rows[i].Cells[_opis.Index].Value; r.Address = (string)dataGridView1.Rows[i].Cells[_address.Index].Value; if (string.IsNullOrEmpty(r.Address) || r.Address.Trim().Length == 0) { MessageBox.Show(this, string.Format("Nie podano adresu kanału RSS '{0}'.", r.ID), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); dataGridView1.CurrentCell = dataGridView1.Rows[i].Cells[_address.Index]; return; } r.Interval = int.Parse((string)dataGridView1.Rows[i].Cells[_interval.Index].Value ?? "1"); r.OneString = (bool)(dataGridView1.Rows[i].Cells[_oneString.Index].Value ?? false); rss.Add(r); } Configuration.RSSs = rss.ToArray(); DialogResult = DialogResult.OK; Close(); }
public static ModuleConfiguration Load(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException(fileName); } ModuleConfiguration c = new ModuleConfiguration(); XmlDocument xml = new XmlDocument(); xml.Load(fileName); XmlNodeList nodes = xml.SelectNodes("configuration/input/rss"); if (nodes != null && nodes.Count > 0) { List <RSS> rsss = new List <RSS>(); foreach (XmlNode node in nodes) { rsss.Add(RSS.Read(node)); } c.RSSs = rsss.ToArray(); } return(c); }
private ModuleConfiguration() { RSSs = new RSS[0]; }