public static void Parse(IEnumerable <XElement> iRadioData, StreamWriter parsedElementsWriter, StreamWriter nonParsedElementsWriter, TextWriter stdOut, IShow Show) // System.Windows.Forms.Form form { foreach (XElement el in iRadioData) { // int timep; // using LINQ is not really more readable ... // XElement elem = el.DescendantsAndSelf("update").Where(r => r.Attribute("id").Value == "play").FirstOrDefault(); // == null || <update id="play"> < value id = "timep" min = "0" max = "65535" > 1698 </ value > // if ((elem = el.DescendantsAndSelf("update").Where(r => r.Attribute("id").Value == "play" && r.Element("value").Attribute("id").Value == "timep").FirstOrDefault()) != null) timep = int.Parse(elem.Value.Trim('\r', '\n', ' ')); if (Testmode) { Thread.Sleep(200); // 50ms used to delay parsing of Telnet.xml, otherwise it's over very quickly } Show.Log(parsedElementsWriter, stdOut, el); if (Macro != null) { Macro.Step(); // process macro, if any } switch (el.Name.ToString()) { case "update": if (el.Attribute("id").Value == "play") // <update id="play"> { if (el.Element("value") != null && el.Element("value").Attribute("id").Value == "timep") { Show.PlayingTime(el, Lines.PlayingTime); } else if (el.Element("value") != null && el.Element("value").Attribute("id").Value == "buflvl") { Show.Line("Buffer[%]", Lines.Buffer, el); } else if (el.Element("value") != null && el.Element("value").Attribute("id").Value == "wilvl") { Show.Line("WiFi[%]", Lines.WiFi, el); } else if (el.Element("value") != null && el.Element("value").Attribute("id").Value == "date") // <value id="date" { if (int.TryParse(el.Value, out int i) && i > 0) { Show.Line("Date", Lines.Status, el); } } else if (el.Element("text") != null && el.Element("text").Attribute("id").Value == "track") { Show.Line("Track", Lines.Track, el); } else if (el.Element("text") != null && el.Element("text").Attribute("id").Value == "artist") { Show.Line("Artist", Lines.Artist, el); currentArtist = Tools.Normalize(el); } else if (el.Element("text") != null && el.Element("text").Attribute("id").Value == "album") { Show.Line("Album", Lines.Album, el); } else { ConsoleProgram.LogElement(nonParsedElementsWriter, stdOut, el); } } else if (el.Attribute("id").Value == "status") // <update id="status"> { if (el.Element("icon") != null && el.Element("icon").Attribute("id").Value == "play") { Show.Line("Icon-Play", Lines.Icon, el, true); } if (el.Element("icon") != null && el.Element("icon").Attribute("id").Value == "shuffle") { Show.Line("Icon-Shuffle", Lines.Icon, el, true); } if (el.Element("icon") != null && el.Element("icon").Attribute("id").Value == "repeat") { Show.Line("Icon-Repeat", Lines.Icon, el, true); } if (el.Element("value") != null && el.Element("value").Attribute("id").Value == "busy") // <value id="busy" { Busy = false; if (int.TryParse(el.Value, out int busyval)) { Busy = busyval == 1; // el.Value = "\n 1\n" } Show.Line("Busy=", Lines.Busy, el, true); // System.Diagnostics.Debug.WriteLine("Status, busy = {0})", busy); } if (el.Element("value") != null && el.Element("value").Attribute("id").Value == "listpos") // <value id="listpos" { string min = el.Element("value").Attribute("min").Value; // <value id="listpos" min="1" max="26">23</value> string max = el.Element("value").Attribute("max").Value; string caption = " " + Tools.Normalize(el.Element("value")) + " [" + min + "..." + max + "]"; int.TryParse(min, out listposmin); int.TryParse(max, out listposmax); // System.Diagnostics.Debug.WriteLine("<update id='status'>< value id = 'listpos' min = {0} max = {1}>", listposmin, listposmax); Show.Line(caption, Lines.Status, el, true); } } else if (el.Attribute("id").Value == "config") // <update id="config"> { foreach (XElement e in el.Elements()) { if (e.Name == "text" && e.Attribute("id").Value == "title") { Show.Line("Title", Lines.Title, e); } else if (e.Name == "text" && e.Attribute("id").Value.Contains("line")) { Show.Browse(el, Lines.line0, false); } } } else if (el.Attribute("id").Value == "welcome") // <update id="welcome"> { // <icon id="welcome" text="wlan@ths / [email protected]">welcome</icon> if (el.Element("icon") != null && el.Element("icon").Attribute("id").Value == "welcome") { Show.Line("Welcome", Lines.Icon, el, true); } } else if (el.Attribute("id").Value == "browse") { Show.Browse(el, Lines.line0, true); } else { ConsoleProgram.LogElement(nonParsedElementsWriter, stdOut, el); } break; case "view": if (el.Attribute("id").Value == "play") { foreach (XElement e in el.Elements()) { if (e.Name == "text" && e.Attribute("id").Value == "title") { Show.Line("Title", Lines.Title, e); } else if (e.Name == "text" && e.Attribute("id").Value == "artist") { Show.Line("Artist", Lines.Artist, e); } else if (e.Name == "text" && e.Attribute("id").Value == "album") { Show.Line("Album", Lines.Album, e); } else if (e.Name == "text" && e.Attribute("id").Value == "track") { Show.Line("Track", Lines.Track, e); } else if (e.Name == "value" && e.Attribute("id").Value == "timep") { Show.PlayingTime(e, Lines.PlayingTime); } else if (e.Name == "value" && e.Attribute("id").Value == "buflvl") { Show.Line("Buffer[%]", Lines.Buffer, e); } else if (e.Name == "value" && e.Attribute("id").Value == "wilvl") { Show.Line("WiFi[%]", Lines.WiFi, e); } } } else if (el.Attribute("id").Value == "status") { // Console.WriteLine("Status, value = {0}", el.Element("value").Value); foreach (XElement e in el.Elements()) { if (e.Name == "icon" && e.Attribute("id").Value == "play") { Show.Status(e, Lines.Status); } if (e.Name == "icon" && e.Attribute("id").Value == "shuffle") { Show.Line("Icon-Shuffle", Lines.Icon, e, true); } if (e.Name == "icon" && e.Attribute("id").Value == "repeat") { Show.Line("Icon-Repeat", Lines.Icon, e, true); } } } else if (el.Attribute("id").Value == "msg") { if (el.Element("text") != null && el.Element("text").Attribute("id").Value == "scrid") { Show.Msg(el, Lines.line0); XElement elemline0 = el.DescendantsAndSelf("text").Where(r => r.Attribute("id").Value == "line0").FirstOrDefault(); // == null || <view id="msg"> <text id = "scrid" > 82 </text> <text id="line0"> Nicht verfügbar </text > XElement elemline1 = el.DescendantsAndSelf("text").Where(r => r.Attribute("id").Value == "line1").FirstOrDefault(); // == null || <view id="msg"> <text id = "scrid" >101 </text> <text id="line0"> Favoriten </text> <text id="line1">---- leer ----</text> if (elemline0 != null) { if (elemline0.Value == iRadioConsole.Properties.Resources.NoxonMessageToCloseStream) { Show.Line("CloseStream", Lines.Icon, el); // close stream if "Nicht verfügbar" return; } if (elemline0.Value == iRadioConsole.Properties.Resources.NoxonTitleFavorites && elemline1 != null && elemline1.Value == iRadioConsole.Properties.Resources.NoxonFavoritesEmpty) { Show.Line("CloseStream", Lines.Icon, el); // close stream if "Favoriten ---- leer ----" return; } } } foreach (XElement e in el.Elements()) { if (e.Name == "value" && e.Attribute("id").Value == "volume") { Show.Line("Volume", Lines.Status, e, true); } } } else if (el.Attribute("id").Value == "browse") { if (el.Element("text") != null && el.Element("text").Attribute("id").Value == "scrid") { Show.Browse(el, Lines.line0, true); } } else if (el.Attribute("id").Value == "config") { if (el.Element("text") != null && el.Element("text").Attribute("id").Value == "scrid") { Show.Browse(el, Lines.line0, false); } } else if (el.Attribute("id").Value == "welcome") // <view id="welcome"> { // <view id="welcome"> < icon id = "welcome" text = "wlan@ths / [email protected]" > welcome </ icon > </ view > if (el.Element("icon") != null && el.Element("icon").Attribute("id").Value == "welcome") { Show.Status(el, Lines.Status); } } else { ConsoleProgram.LogElement(nonParsedElementsWriter, stdOut, el); } break; case "CloseStream": Show.Line("CloseStreamAndReturn", Lines.Icon, el); return; default: ConsoleProgram.LogElement(nonParsedElementsWriter, stdOut, el); break; } } }