Пример #1
0
        private void HandshakeResponseCallback(IAsyncResult aResult)
        {
            WebResponse  response   = null;
            StreamReader readStream = null;

            try
            {
                WebResponseState state = aResult.AsyncState as WebResponseState;
                response = state.WebRequest.EndGetResponse(aResult);
                Stream   stream = response.GetResponseStream();
                Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                readStream = new StreamReader(stream, encode);

                string result      = "OK";
                string streamUrl   = "";
                string frameHack   = "";
                string infoMsg     = "";
                string fingerPrint = "";
                iSession = NextParameter(readStream);           // session
                if (iSession == "FAILED")
                {
                    result = NextParameter(readStream);         // msg
                }
                else
                {
                    streamUrl   = NextParameter(readStream);            // stream url
                    iSubscriber = NextParameter(readStream) == "1";     // subscriber
                    frameHack   = NextParameter(readStream);            // frame hack
                    iBaseUrl    = NextParameter(readStream);            // base url
                    iBasePath   = NextParameter(readStream);            // base path
                    infoMsg     = NextParameter(readStream);            // info message
                    fingerPrint = NextParameter(readStream);            // finger print upload url
                }
                if (EventHandshakeCompleted != null)
                {
                    EventHandshakeCompleted(this, new EventArgsHandshakeCompleted(result, iSession, streamUrl, iSubscriber, frameHack, iBaseUrl, iBasePath, infoMsg, fingerPrint));
                }
            }
            catch (WebException e)
            {
                if (EventHandshakeCompleted != null)
                {
                    EventHandshakeCompleted(this, new EventArgsHandshakeCompleted(e));
                }
            }
            finally
            {
                if (readStream != null)
                {
                    readStream.Close();
                }
                if (response != null)
                {
                    response.Close();
                }
            }
        }
Пример #2
0
        private void PlaylistResponseCallback(IAsyncResult aResult)
        {
            WebResponse  response   = null;
            StreamReader readStream = null;

            try
            {
                WebResponseState state = aResult.AsyncState as WebResponseState;
                response = state.WebRequest.EndGetResponse(aResult);
                Stream   stream = response.GetResponseStream();
                Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                readStream = new StreamReader(stream, encode);

                XmlTextReader reader = new XmlTextReader(readStream);
                XmlDocument   xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNodeList list  = xmlDoc.DocumentElement.SelectNodes("/playlist/trackList/track");
                string      skips = xmlDoc.DocumentElement.SelectSingleNode("/playlist/link[@rel=\"http://www.last.fm/skipsLeft\"]").InnerText;
                Console.WriteLine("skips=" + skips);
                List <ITrack> playlist = new List <ITrack>();
                foreach (XmlNode node in list)
                {
                    string title    = node.SelectSingleNode("title").InnerText;
                    string album    = node.SelectSingleNode("album").InnerText;
                    string artist   = node.SelectSingleNode("creator").InnerText;
                    string url      = node.SelectSingleNode("location").InnerText;
                    string image    = node.SelectSingleNode("image").InnerText;
                    int    duration = int.Parse(node.SelectSingleNode("duration").InnerText) / 1000;
                    playlist.Add(new Track(title, album, artist, url, image, duration));
                }
                if (EventPlaylistCompleted != null)
                {
                    EventPlaylistCompleted(this, new EventArgsPlaylistCompleted("OK", playlist));
                }
            }
            catch (WebException e)
            {
                if (EventPlaylistCompleted != null)
                {
                    EventPlaylistCompleted(this, new EventArgsPlaylistCompleted(e));
                }
            }
            finally
            {
                if (readStream != null)
                {
                    readStream.Close();
                }
                if (response != null)
                {
                    response.Close();
                }
            }
        }
Пример #3
0
        private void ChangeStationResponseCallback(IAsyncResult aResult)
        {
            WebResponse  response   = null;
            StreamReader readStream = null;

            try
            {
                WebResponseState state = aResult.AsyncState as WebResponseState;
                response = state.WebRequest.EndGetResponse(aResult);
                Stream   stream = response.GetResponseStream();
                Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                readStream = new StreamReader(stream, encode);

                string result = NextParameter(readStream);
                if (EventChangeStationCompleted != null)
                {
                    EventChangeStationCompleted(this, new EventArgsChangeStationCompleted(result));
                }
            }
            catch (WebException e)
            {
                if (EventChangeStationCompleted != null)
                {
                    EventChangeStationCompleted(this, new EventArgsChangeStationCompleted(e));
                }
            }
            finally
            {
                if (readStream != null)
                {
                    readStream.Close();
                }
                if (response != null)
                {
                    response.Close();
                }
            }
        }