ReadLine() public méthode

public ReadLine ( ) : string
Résultat string
Exemple #1
0
        private MpdResponse readResponse()
        {
            List <string> ret  = new List <string>();
            string        line = m_SocketManager.ReadLine();

            while (line != null && !(line.Equals(OK) || line.StartsWith(ACK)))
            {
                ret.Add(line);
                line = m_SocketManager.ReadLine();
            }
            if (line == null)
            {
                line = string.Empty;
            }

            if (line.Equals(OK))
            {
                return(new MpdResponse(new ReadOnlyCollection <string>(ret)));
            }
            else
            {
                Match match = ACK_REGEX.Match(line);

                if (match.Groups.Count != 5)
                {
                    throw new InvalidDataException("Error response not as expected");
                }

                return(new MpdResponse(
                           int.Parse(match.Result("${code}")),
                           int.Parse(match.Result("${nr}")),
                           match.Result("${command}"),
                           match.Result("${message}"),
                           new ReadOnlyCollection <string>(ret)
                           ));
            }
        }
Exemple #2
0
        /// <summary>
        /// Connects to the MPD server who's IPEndPoint was set in the Server property.
        /// </summary>
        /// <exception cref="InvalidOperationException">If no IPEndPoint was set to the Server property.</exception>
        public void Connect()
        {
            if (this.ipEndPoint == null)
            {
                throw new InvalidOperationException("Server IPEndPoint not set.");
            }

            if (this.Connected)
            {
                throw new AlreadyConnectedException();
            }

            if (m_SocketManager != null)
            {
                m_SocketManager.Dispose();
            }

            m_SocketManager = new SocketManager();
            m_SocketManager.Connect(ipEndPoint);

            string firstLine = m_SocketManager.ReadLine();

            if (!firstLine.StartsWith(FIRST_LINE_PREFIX))
            {
                this.Disconnect();
                throw new InvalidDataException("Response of mpd does not start with \"" + FIRST_LINE_PREFIX + "\".");
            }
            this.version = firstLine.Substring(FIRST_LINE_PREFIX.Length);

            //m_SocketManager.WriteLine(string.Empty);
            //this.readResponse();

            MpdResponse response = Exec("commands");

            m_Commands = response.getValueList();

            if (this.OnConnected != null)
            {
                this.OnConnected.Invoke(this);
            }
        }
Exemple #3
0
        /// <summary>
        /// Connects to the MPD server who's IPEndPoint was set in the Server property.
        /// </summary>
        /// <exception cref="InvalidOperationException">If no IPEndPoint was set to the Server property.</exception>
        public void Connect()
        {
            if (this.ipEndPoint == null)
            throw new InvalidOperationException("Server IPEndPoint not set.");

              if (this.Connected)
            throw new AlreadyConnectedException();

              if (m_SocketManager != null) {
            m_SocketManager.Dispose();
              }

              m_SocketManager = new SocketManager();
              m_SocketManager.Connect(ipEndPoint);

              string firstLine = m_SocketManager.ReadLine();
              if (!firstLine.StartsWith(FIRST_LINE_PREFIX)) {
            this.Disconnect();
            throw new InvalidDataException("Response of mpd does not start with \"" + FIRST_LINE_PREFIX + "\".");
              }
              this.version = firstLine.Substring(FIRST_LINE_PREFIX.Length);

              //m_SocketManager.WriteLine(string.Empty);
              //this.readResponse();

              MpdResponse response = Exec("commands");
              m_Commands = response.getValueList();

              if (this.OnConnected != null)
            this.OnConnected.Invoke(this);
        }