コード例 #1
0
ファイル: MPDClient.cs プロジェクト: pietvanvliet/mpdcwp
 // Next task after successful connection
 private void MPDClient_NextTaskToPorform(object sender, NextEventArgs e)
 {
     this.SendCommand(e.Command, e.Attributes);
 }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: pietvanvliet/mpdcwp
 // If not connected, but needs to play
 // After successfull connection this method is being called
 private void mpdclient_nextEventToPorform(object sender, NextEventArgs e)
 {
     Connection.SendCommand(MPDClient.PLAY);
 }
コード例 #3
0
ファイル: MPDClient.cs プロジェクト: pietvanvliet/mpdcwp
        /// <summary>
        /// Send given command and parameters to the server
        /// </summary>
        /// <param name="command">Command</param>
        /// <param name="attributes">Attributes</param>
        public void SendCommand(string command, string[] attributes = null)
        {
            if (this.IsConnected)
            {
                StringBuilder sb = new StringBuilder(command);
                string space = "";
                if (attributes != null)
                {
                    sb.Append(" \"");
                    foreach (string attr in attributes)
                    {
                        sb.Append(space + attr);
                        space = " ";
                    }
                    sb.Append("\"");
                }
                SocketAsyncEventArgs asyncEvent = new SocketAsyncEventArgs { RemoteEndPoint = new DnsEndPoint(this.Server, this.Port) };

                byte[] buffer = Encoding.UTF8.GetBytes(sb.ToString() + Environment.NewLine);

                asyncEvent.Completed += asyncEvent_Completed;
                asyncEvent.SetBuffer(buffer, 0, buffer.Length);
                connection.SendAsync(asyncEvent);
            }
            else
            {
                this.nextArgs = new NextEventArgs(command, attributes);
                this.NextTaskToPorform += MPDClient_NextTaskToPorform;
                this.Connect();
            }
        }