Exemple #1
0
 // Test messages received
 private void TestMessagesReceived(object sender, MessageArrayEventArgs e)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() =>
     {
         if (listBoxTestOutput.Items.Count > 500)
         {
             for (int i = 0; i < 100; i++)
             {
                 listBoxTestOutput.Items.RemoveAt(0);
             }
         }
         foreach (string item in e.MessageArray)
         {
             listBoxTestOutput.Items.Add(item);
         }
     });
 }
Exemple #2
0
 // When all tracks is fetched
 private void AllTracksFetched(object sender, MessageArrayEventArgs e)
 {
     lines.AddRange(e.MessageArray);
     if (e.MessageArray.Contains("OK"))
     {
         List<Track> tracks = ParseAllTracks(lines);
         Deployment.Current.Dispatcher.BeginInvoke(() =>
         {
             foreach (Track track in tracks)
             {
                 AllTracks.Add(track);
             }
         });
         Connection.MessagePass -= AllTracksFetched;
         Loading(false);
         Deployment.Current.Dispatcher.BeginInvoke(() =>
         {
             listBoxSearch.ItemsSource = null;
             listBoxSearch.ItemsSource = AllTracks;
             DivideTracks();
             listBoxBrowse.ItemsSource = Artists.Values;
         });
     }
 }
Exemple #3
0
 // After playlist is fetched
 // TODO Entä jos on tyhjä? Tällöin palautetaan pelkkä OK. Mutta jos palautetaankin jonkun muun komenonn tulokset välissä.
 // TODO Null check
 private void PlaylistFetched(object sender, MessageArrayEventArgs e)
 {
     playlistLines.AddRange(e.MessageArray);
     if (e.MessageArray.Contains("OK"))
     {
         List<Track> tracks = ParseTracks(playlistLines);
         Deployment.Current.Dispatcher.BeginInvoke(() =>
         {
             Playlist.Clear();
             foreach (Track track in tracks)
             {
                 Playlist.Add(track);
             }
         });
         Connection.MessagePass -= PlaylistFetched;
         Loading(false);
         if (getAllTracksEvent != null)
             getAllTracksEvent(this, new EventArgs());
     }
 }
Exemple #4
0
        // When message received from server
        private void OnMessageReceivedFromServer(object sender, SocketAsyncEventArgs e)
        {
            string message = Encoding.UTF8.GetString(e.Buffer, 0, e.BytesTransferred);

            if (!string.IsNullOrWhiteSpace(trailingMessage))
            {
                message = trailingMessage + message;
                trailingMessage = null;
            }

            if (string.IsNullOrWhiteSpace(message))
            {
                // Connection lost
                return;
            }

            // Convert the received string into a string array
            List<string> lines = new List<string>(message.Split("\n\r".ToCharArray(), StringSplitOptions.None));

            if (lines.Count > 0)
            {
                string lastLine = lines[lines.Count - 1];
                bool isBufferFull = !string.IsNullOrWhiteSpace(lastLine);
                if (isBufferFull)
                {
                    trailingMessage = lastLine;
                    lines.Remove(lastLine);
                }

                MessageArrayEventArgs args = new MessageArrayEventArgs(lines.ToArray());
                if (MessagePass != null)
                {
                    MessagePass(this, args);
                }
                if (MessageReceived != null)
                {
                    MessageReceived(this, args);
                }
                if (TestMessagesReceived != null)
                {
                    TestMessagesReceived(this, args);
                }

            }
            // Start listening for the next message
            StartReceivingMessages();
        }