Exemple #1
0
        public async Task <PositionInfoResponse> GetPositionInfo()
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add(SoapActionHeader, GetPositionInfoSoapAction);
                HttpContent         postContent = new StringContent(GetPositionInfoBody, Encoding.UTF8, "text/xml");
                HttpResponseMessage response    = await client.PostAsync(BaseUrl + "/" + MediaRendererAVTransportUrl, postContent);

                if (response.IsSuccessStatusCode)
                {
                    //Set proper content encoding without quotes
                    response.Content.Headers.Remove("CONTENT-TYPE");
                    response.Content.Headers.Add("CONTENT-TYPE", "text/xml; charset=UTF-8");
                    var content = await response.Content.ReadAsStringAsync();

                    content = SonosUtils.CleanSonosResponse(content);

                    var settings   = new XmlReaderSettings();
                    var obj        = new Envelope();
                    var serializer = new XmlSerializer(typeof(Envelope));
                    obj = (Envelope)serializer.Deserialize(new StringReader(content));

                    return(obj.Body.PositionInfoResponse);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #2
0
        public async Task <Event> ParseNotification(string notification)
        {
            try
            {
                notification = SonosUtils.CleanSonosNotification(notification);

                var settings   = new XmlReaderSettings();
                var obj        = new Event();
                var serializer = new XmlSerializer(typeof(Event));
                obj = (Event)serializer.Deserialize(new StringReader(notification));

                try
                {
                    obj.InstanceID.CurrentTrackMetaData.TrackMeta = await GetTrackMetaData(obj.InstanceID.CurrentTrackMetaData.Val);
                }
                catch (Exception e) { }
                try
                {
                    obj.InstanceID.NextTrackMetaData.TrackMeta = await GetTrackMetaData(obj.InstanceID.NextTrackMetaData.Val);
                }
                catch (Exception e) { }

                OnNotificationEvent(obj);

                return(obj);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemple #3
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task <Event> ParseNotification(string notification)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            try
            {
                notification = SonosUtils.CleanSonosNotification(notification);

                var settings   = new XmlReaderSettings();
                var obj        = new Event();
                var serializer = new XmlSerializer(typeof(Event));
                obj = (Event)serializer.Deserialize(new StringReader(notification));

                try
                {
                    obj.InstanceID.CurrentTrackMetaData.TrackMeta = GetTrackMetaData(obj.InstanceID.CurrentTrackMetaData.Val);
                }
                catch (Exception e) { e.ToString(); }
                try
                {
                    obj.InstanceID.NextTrackMetaData.TrackMeta = GetTrackMetaData(obj.InstanceID.NextTrackMetaData.Val);
                }
                catch (Exception e) { e.ToString(); }

                OnNotificationEvent(obj);

                return(obj);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(null);
            }
        }
Exemple #4
0
        private async Task <TrackMeta> GetTrackMetaData(string metaData)
        {
            try
            {
                metaData = SonosUtils.CleanSonosResponse(metaData);

                var       trackMetaSerializer = new XmlSerializer(typeof(TrackMeta));
                TrackMeta trackMeta           = (TrackMeta)trackMetaSerializer.Deserialize(new StringReader(metaData));

                return(trackMeta);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemple #5
0
        private TrackMeta GetTrackMetaData(string metaData)
        {
            try
            {
                metaData = SonosUtils.CleanSonosResponse(metaData);

                var       trackMetaSerializer = new XmlSerializer(typeof(TrackMeta));
                TrackMeta trackMeta           = (TrackMeta)trackMetaSerializer.Deserialize(new StringReader(metaData));

                return(trackMeta);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(null);
            }
        }