protected void LastChangeSink(CpRenderingControl sender, string LC) { if (LC == "") { return; } if (LC.Substring(0, 1) != "<") { LC = UPnPStringFormatter.UnEscapeString(LC); } if (LC.Substring(0, 1) != "<") { LC = UPnPStringFormatter.UnEscapeString(LC); } /* * if(LC.StartsWith("<?")==true) * { * int dx = LC.IndexOf(">"); * LC = LC.Substring(0,dx+1) + "<MYROOT>" + LC.Substring(dx+1) + "</MYROOT>"; * } * else * { * LC = "<MYROOT>" + LC + "</MYROOT>"; * }*/ StringReader MyString = new StringReader(LC); XmlTextReader XMLDoc = new XmlTextReader(MyString); Hashtable T = new Hashtable(); int ID = -1; string VarName = ""; string VarValue = ""; string AttrName = ""; string AttrValue = ""; XMLDoc.Read(); XMLDoc.MoveToContent(); XMLDoc.Read(); XMLDoc.MoveToContent(); while ((XMLDoc.LocalName != "Event") && (XMLDoc.EOF == false)) { // At Start, should be InstanceID if (XMLDoc.LocalName == "InstanceID") { XMLDoc.MoveToAttribute("val"); ID = int.Parse(XMLDoc.GetAttribute("val")); if (T.ContainsKey(ID) == false) { T[ID] = new Hashtable(); } XMLDoc.MoveToContent(); XMLDoc.Read(); XMLDoc.MoveToContent(); while (XMLDoc.LocalName != "InstanceID") { VarName = XMLDoc.LocalName; VarValue = ""; AttrName = ""; AttrValue = ""; for (int a_idx = 0; a_idx < XMLDoc.AttributeCount; ++a_idx) { XMLDoc.MoveToAttribute(a_idx); if (XMLDoc.LocalName == "val") { VarValue = XMLDoc.GetAttribute(a_idx); } else { AttrName = XMLDoc.LocalName; AttrValue = XMLDoc.GetAttribute(a_idx); } } XMLDoc.MoveToContent(); if (AttrName == "") { ((Hashtable)T[ID])[VarName] = VarValue; } else { if (((Hashtable)T[ID]).ContainsKey(VarName) == false) { ((Hashtable)T[ID])[VarName] = new Hashtable(); } if (((Hashtable)((Hashtable)T[ID])[VarName]).ContainsKey(AttrName) == false) { ((Hashtable)((Hashtable)T[ID])[VarName])[AttrName] = new Hashtable(); } ((Hashtable)((Hashtable)((Hashtable)T[ID])[VarName])[AttrName])[AttrValue] = VarValue; } XMLDoc.Read(); XMLDoc.MoveToContent(); } } else { XMLDoc.Skip(); } XMLDoc.Read(); XMLDoc.MoveToContent(); } XMLDoc.Close(); IDictionaryEnumerator inEn = T.GetEnumerator(); IDictionaryEnumerator EvEn; Hashtable TT; while (inEn.MoveNext()) { if ((int)inEn.Key == InstanceID) { TT = (Hashtable)inEn.Value; EvEn = TT.GetEnumerator(); while (EvEn.MoveNext()) { switch ((string)EvEn.Key) { case "Mute": if (EvEn.Value.GetType().FullName == "System.String") { MuteByChannel["MASTER"] = (bool)UPnPService.CreateObjectInstance(typeof(bool), (string)EvEn.Value); } else { IDictionaryEnumerator E2 = ((Hashtable)EvEn.Value).GetEnumerator(); while (E2.MoveNext()) { IDictionaryEnumerator E3 = ((Hashtable)((Hashtable)E2.Value)).GetEnumerator(); while (E3.MoveNext()) { MuteByChannel[E3.Key.ToString()] = (bool)UPnPService.CreateObjectInstance(typeof(bool), E3.Value.ToString()); } } } if (OnMuteChanged != null) { OnMuteChanged(this); } break; case "Volume": if (EvEn.Value.GetType().FullName == "System.String") { VolumeByChannel["MASTER"] = UInt16.Parse((string)EvEn.Value); } else { IDictionaryEnumerator E2 = ((Hashtable)EvEn.Value).GetEnumerator(); while (E2.MoveNext()) { IDictionaryEnumerator E3 = ((Hashtable)((Hashtable)E2.Value)).GetEnumerator(); while (E3.MoveNext()) { VolumeByChannel[E3.Key.ToString()] = UInt16.Parse(E3.Value.ToString()); } } } //_Volume = UInt16.Parse((string)EvEn.Value); if (OnVolumeChanged != null) { OnVolumeChanged(this); } break; } } } } }
protected void LastChangeSink(CpAVTransport sender, string LC) { if (LC == "") { return; } //LC = UPnPStringFormatter.UnEscapeString(LC); if (LC.Substring(0, 1) != "<") { LC = UPnPStringFormatter.UnEscapeString(LC); } if (LC.Substring(0, 1) != "<") { LC = UPnPStringFormatter.UnEscapeString(LC); } StringReader MyString = new StringReader(LC); XmlTextReader XMLDoc = new XmlTextReader(MyString); Hashtable T = new Hashtable(); int ID = -1; string VarName = ""; string VarValue = ""; string AttrName = ""; string AttrValue = ""; XMLDoc.Read(); XMLDoc.MoveToContent(); XMLDoc.Read(); XMLDoc.MoveToContent(); while ((XMLDoc.LocalName != "Event") && (XMLDoc.EOF == false)) { // At Start, should be InstanceID if (XMLDoc.LocalName == "InstanceID") { XMLDoc.MoveToAttribute("val"); ID = int.Parse(XMLDoc.GetAttribute("val")); if (T.ContainsKey(ID) == false) { T[ID] = new Hashtable(); } XMLDoc.MoveToContent(); XMLDoc.Read(); XMLDoc.MoveToContent(); while (XMLDoc.LocalName != "InstanceID") { if (XMLDoc.IsStartElement() == true) { VarName = XMLDoc.LocalName; VarValue = ""; AttrName = ""; AttrValue = ""; for (int a_idx = 0; a_idx < XMLDoc.AttributeCount; ++a_idx) { XMLDoc.MoveToAttribute(a_idx); if (XMLDoc.LocalName == "val") { VarValue = UPnPStringFormatter.UnEscapeString(XMLDoc.GetAttribute(a_idx)); } else { AttrName = XMLDoc.LocalName; AttrValue = XMLDoc.GetAttribute(a_idx); } } XMLDoc.MoveToContent(); if (AttrName == "") { ((Hashtable)T[ID])[VarName] = VarValue; } else { if (((Hashtable)T[ID]).ContainsKey(VarName) == false) { ((Hashtable)T[ID])[VarName] = new Hashtable(); } if (((Hashtable)((Hashtable)T[ID])[VarName]).ContainsKey(AttrName) == false) { ((Hashtable)((Hashtable)T[ID])[VarName])[AttrName] = new Hashtable(); } ((Hashtable)((Hashtable)((Hashtable)T[ID])[VarName])[AttrName])[AttrValue] = VarValue; } } XMLDoc.Read(); XMLDoc.MoveToContent(); } } else { XMLDoc.Skip(); } XMLDoc.Read(); XMLDoc.MoveToContent(); } XMLDoc.Close(); IDictionaryEnumerator inEn = T.GetEnumerator(); IDictionaryEnumerator EvEn; Hashtable TT; string TempString; DText TempParser = new DText(); while (inEn.MoveNext()) { if (inEn.Key.ToString() == InstanceID) { TT = (Hashtable)inEn.Value; EvEn = TT.GetEnumerator(); while (EvEn.MoveNext()) { switch ((string)EvEn.Key) { case "AVTransportURI": _AVTransportURI = (string)EvEn.Value; if (OnAVTransportURIChanged != null) { OnAVTransportURIChanged(this); } break; case "TransportState": _PlayState = (string)EvEn.Value; if (OnPlayStateChanged != null) { OnPlayStateChanged(this); } break; case "CurrentTrackDuration": TempString = (string)EvEn.Value; TempParser.ATTRMARK = ":"; TempParser[0] = TempString; try { this._CurrentDuration = new TimeSpan(int.Parse(TempParser[1]), int.Parse(TempParser[2]), int.Parse(TempParser[3])); } catch (Exception) {} if (this.OnCurrentPositionChanged != null) { this.OnCurrentPositionChanged(this); } break; case "RelativeTimePosition": TempString = (string)EvEn.Value; TempParser.ATTRMARK = ":"; TempParser[0] = TempString; this._CurrentPosition = new TimeSpan(int.Parse(TempParser[1]), int.Parse(TempParser[2]), int.Parse(TempParser[3])); if (this.OnCurrentPositionChanged != null) { this.OnCurrentPositionChanged(this); } break; case "NumberOfTracks": try { _NumberOfTracks = UInt32.Parse((string)EvEn.Value); if (OnNumberOfTracksChanged != null) { OnNumberOfTracksChanged(this); } } catch (Exception) {} break; case "CurrentTrack": try { _CurrentTrack = UInt32.Parse((string)EvEn.Value); if (OnCurrentTrackChanged != null) { OnCurrentTrackChanged(this); } } catch (Exception) {} break; case "CurrentTrackURI": _TrackURI = (string)EvEn.Value; if (OnTrackURIChanged != null) { OnTrackURIChanged(this); } break; case "TransportStatus": _TransportStatus = (string)EvEn.Value; if (OnTransportStatusChanged != null) { OnTransportStatusChanged(this); } break; case "AVTransportURIMetaData": _AVTransportMetaData = (string)EvEn.Value; if (this.OnCurrentURIMetaDataChanged != null) { OnCurrentURIMetaDataChanged(this); } break; case "CurrentPlayMode": _CurrentPlayMode = (string)EvEn.Value; if (this.OnCurrentPlayModeChanged != null) { OnCurrentPlayModeChanged(this); } break; } } } } }