private void btnAdd_Click(object sender, EventArgs e) { try { listStreams.add(new Stream(txtCaption.Text, txtURL.Text, txtQuality.Text)); listStreams.sort(); try { XMLPersist.saveStreamListConfig(listStreams); } catch (UnauthorizedAccessException) { MessageBox.Show(this, "Error: Unable to save the configuration. Check if you have write " + "permissions on the directory of the application.\n" + "Desktop Live Streamer may require administrative rights on some systems.", "Write permission required", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.GetType() + " " + ex.Message, "Erreur!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void loadStreamListConfig(ListStreams list) { XmlTextReader xr = null; int attributs_lus; Stream tmpStream = null; try { xr = new XmlTextReader(StreamXMLFile); while (xr.Read()) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "Stream") { tmpStream = new Stream(); attributs_lus = 0; while (xr.Read()) { // Lecture des attributs de personne if (xr.NodeType == XmlNodeType.Element && xr.Name == "Caption") { xr.Read(); tmpStream.Caption = xr.Value.Trim(); attributs_lus++; } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "URL") { xr.Read(); tmpStream.StreamUrl = xr.Value.Trim(); attributs_lus++; } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "Quality") { xr.Read(); tmpStream.Quality = xr.Value.Trim(); attributs_lus++; } // Sortie de while quand tous les attributs on été lu if (attributs_lus == 3) { list.add(tmpStream); break; } } } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "LiveStreamerExecutable") { xr.Read(); LiveStreamerExecutable = xr.Value.Trim(); } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "VLCExecutable") { xr.Read(); VLCExecutable = xr.Value.Trim(); } } } catch (Exception ex) { throw ex; } finally { if (xr != null) xr.Close(); } }
public static void loadStreamListConfig(ListStreams list) { XmlTextReader xr = null; int attributs_lus; Stream tmpStream = null; try { xr = new XmlTextReader(StreamXMLFile); while (xr.Read()) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "Stream") { tmpStream = new Stream(); attributs_lus = 0; while (xr.Read()) { // Lecture des attributs de personne if (xr.NodeType == XmlNodeType.Element && xr.Name == "Caption") { xr.Read(); tmpStream.Caption = xr.Value.Trim(); attributs_lus++; } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "URL") { xr.Read(); tmpStream.StreamUrl = xr.Value.Trim(); attributs_lus++; } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "Quality") { xr.Read(); tmpStream.Quality = xr.Value.Trim(); attributs_lus++; } // Sortie de while quand tous les attributs on été lu if (attributs_lus == 3) { list.add(tmpStream); break; } } } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "LiveStreamerExecutable") { xr.Read(); LiveStreamerExecutable = xr.Value.Trim(); } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "VLCExecutable") { xr.Read(); VLCExecutable = xr.Value.Trim(); } else if (xr.NodeType == XmlNodeType.Element && xr.Name == "PreferedQuality") { xr.Read(); PreferedQuality = xr.Value.Trim(); } } } catch (Exception ex) { throw ex; } finally { if (xr != null) { xr.Close(); } } }