Esempio n. 1
0
        private void dGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            cancionSelect[0] = dGV.Rows[e.RowIndex].Cells["Artista"].Value.ToString();
            cancionSelect[1] = dGV.Rows[e.RowIndex].Cells["Canción"].Value.ToString();

            Console.WriteLine(cancionSelect[0] + cancionSelect[1]);

            for (int i = 0; i < CancionesDGV.Length; i++)
            {
                if (CancionesDGV[i].artista.Equals(cancionSelect[0]) &&
                    CancionesDGV[i].nombreCancion.Equals(cancionSelect[1]))
                {
                    AddDatoMensaje mensajeCancion = new AddDatoMensaje();
                    mensajeCancion.cancion    = new Canciones[1];
                    mensajeCancion.cancion[0] = CancionesDGV[i];
                    mensajeCancion.OpCod      = "04";

                    socketPrincipal = new SocketCliente(mensajeCancion);
                    MessageBox.Show("Canción disponible");
                    selectDVG[0] = CancionesDGV[i];
                    cargarArchivo(socketPrincipal.ListaRecibida[0].bytesSong);
                    break;
                }
            }
        }
Esempio n. 2
0
        private AddDatoMensaje mensajeCancion(String codigoOp, Canciones[] cancion)
        {
            AddDatoMensaje mensaje = new AddDatoMensaje();

            mensaje.OpCod   = codigoOp;
            mensaje.cancion = cancion;
            //  mensaje.cancion.PRUEBAA = "212";
            return(mensaje);
        }
Esempio n. 3
0
        private void eliminarbtn_Click(object sender, EventArgs e)
        {
            AddDatoMensaje mensajeCancion = new AddDatoMensaje();

            mensajeCancion.cancion = selectDVG;
            mensajeCancion.OpCod   = "05";
            mensajeCancion.cancion[0].bytesSong = null;
            socketPrincipal = new SocketCliente(mensajeCancion);
            loadDataGridView();
        }
Esempio n. 4
0
        private void loadDataGridView()
        {
            if (lazyLoadingPos.Equals(1))
            {
                anteriorbutton.Enabled = false;
                // buttonStop.Enabled = isPlaying;
            }
            else if (!lazyLoadingPos.Equals(1))
            {
                anteriorbutton.Enabled = true;
            }
            dGV.Rows.Clear();
            AddDatoMensaje mensajeCancion = new AddDatoMensaje();

            mensajeCancion.OpCod             = "03";
            mensajeCancion.cantidadTotalSong = lazyLoadingPos;


            SocketCliente socketis = new SocketCliente(mensajeCancion);

            CancionesDGV = socketis.listaRecibida();
            double rangoNumeros = socketis.cantidadTotal / 3;

            Console.WriteLine(rangoNumeros);

            rangoNumeros = Math.Round(rangoNumeros);

            pageLabel.Text = string.Format("Pág. {0}/{1}", pageNumber, rangoNumeros);
            int num = 0;

            dGV.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dGV.Columns[4].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

            for (int i = 0; i < CancionesDGV.Length; i++)
            {
                dGV.Rows.Add(new object[] { CancionesDGV[i].artista, CancionesDGV[i].album,
                                            CancionesDGV[i].nombreCancion, CancionesDGV[i].genero, CancionesDGV[i].letra });
            }
        }
Esempio n. 5
0
        public SocketCliente(AddDatoMensaje mensajeEntrante)
        {
            //http://www.srikanthtechnologies.com/blog/java/java_cs_xml.aspx

            /**
             * El codigo de operacion se asigan al momento de crear el AddDatoMensaje en el metodo seleccionado, aqui solamente invoca la funcion usarSocket
             */
            //Enviar el mensaje tipo AddDatoMensaje y listo.
            //new ThreadExceptionDialog (new )
            if (mensajeEntrante.OpCod.Equals("01"))
            {
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    /* run your code here */
                    usarSocket(mensajeEntrante);
                }).Start();
            }
            else
            {
                usarSocket(mensajeEntrante);
            }
        }
Esempio n. 6
0
        private void Agregar_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog CajaBsuquedaArchivos = new OpenFileDialog();
                CajaBsuquedaArchivos.Multiselect = true;
                if (CajaBsuquedaArchivos.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //String[] ArchivosMP3;
                    String[] rutasMP3;
                    // ArchivosMP3 = CajaBsuquedaArchivos.SafeFileNames;
                    rutasMP3 = CajaBsuquedaArchivos.FileNames;
                    int cantidadMp3       = 0;
                    int largoCancionesMp3 = rutasMP3.Length;
                    //Array que va a tener las canciones insertadas
                    Canciones[] CancionesTotal = new Canciones[largoCancionesMp3];


                    while (cantidadMp3 < largoCancionesMp3)
                    {
                        Canciones   cancionEntrante = new Canciones();
                        TagLib.File tagFile         = TagLib.File.Create(rutasMP3[cantidadMp3].ToString());
                        //  Console.WriteLine("------------"+ tagFile.Tag.FirstArtist.ToString());
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                        cancionEntrante.artista = tagFile.Tag.FirstArtist.ToString();
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos

                        cancionEntrante.album         = tagFile.Tag.Album;
                        cancionEntrante.nombreCancion = tagFile.Tag.Title;
                        cancionEntrante.genero        = tagFile.Tag.FirstGenre;
                        cancionEntrante.letra         = tagFile.Tag.Comment;
                        byte[] bytesCancionSelect = ReadAllBytes(rutasMP3[cantidadMp3].ToString());
                        Console.WriteLine("largo de bytes es" + bytesCancionSelect.Length);
                        cancionEntrante.bytesSong   = bytesCancionSelect;
                        CancionesTotal[cantidadMp3] = cancionEntrante;


                        //CancionesTotal[1] = cancionEntrante;

                        //  CancionesTotal[1] = cancionEntrante;


                        ///https://stackoverflow.com/questions/1003275/how-to-convert-utf-8-byte-to-string
                        cantidadMp3++;
                    }

                    //  cargarArchivo(CancionesTotal[0].bytesSong);


                    //  CancionesDGV = CancionesTotal;
                    //loadDataGridView();
                    AddDatoMensaje mensajeCancion = new AddDatoMensaje();
                    mensajeCancion.cancion = CancionesTotal;
                    mensajeCancion.OpCod   = "01";


                    socketPrincipal = new SocketCliente(mensajeCancion);
                    loadDataGridView();
                }
            }
            catch (Exception error)
            {
                Console.WriteLine(error);
            }
        }
Esempio n. 7
0
        private void usarSocket(AddDatoMensaje mensaje)
        {
            Console.WriteLine("entro a usarSockets");

            string ObjectXML = ObjectToXml(mensaje);

            //de xml a object
            //   Canciones XMLObject = XMLtoObject<Canciones>(ObjectXML);
            ObjectXML = ObjectXML.Replace("\n", "").Replace("\r", "");
            Console.WriteLine(ObjectXML.ToString());
            // Console.WriteLine(XMLObject.nombreCancion);


            //IMPORTANTE

            TcpClient     tcpClient     = new TcpClient("localhost", 5001);
            NetworkStream networkStream = tcpClient.GetStream();

            byte[] datoByte;

            string datoEnviar = ObjectXML;

            datoByte = Encoding.UTF8.GetBytes(datoEnviar + "\n");
            //Envia al servidor
            networkStream.Write(datoByte, 0, datoEnviar.Length + 1);

            Console.WriteLine("Se envio la vara");

            networkStream.Close();



            /**AQUI SE DEBE IMPLEMENTAR LO QUE SE VE HACER CON LO QUE HIZO EL SERVER*/
            //Leer del servidor
            //  ReceiveAll(networkStream);


            // Do something with the resultStream, like resultStream.ToArray() ...

            StreamReader data_in = new StreamReader(tcpClient.GetStream());
            //  Console.WriteLine(data_in.ReadToEnd());
            //  data_in.ToString();

            String datorecibido = data_in.ReadToEnd();

            tcpClient.Close();
            networkStream.Close();
            data_in.Close();
            // networkStream.Read(datoByte, 0, 99999999);
            // 444448847

            //El dato que se va a obtener
            //    String datorecibido = Encoding.UTF8.GetString(bytecito);

            //Quita los bytes sobrantes
            //  datorecibido = datorecibido.Replace("\0", string.Empty);
            // datorecibido = datorecibido.Substring(0, datorecibido.IndexOf(char.ConvertFromUtf32(0)));
            //Console.WriteLine(datorecibido);
            if (mensaje.OpCod.Equals("01"))
            {
                MessageBox.Show(datorecibido);
            }
            else if (mensaje.OpCod.Equals("03"))
            {
                Console.WriteLine("entro");
                if (!mensaje.cantidadTotalSong.Equals(0))
                {
                    Canciones[] datoServer = XMLtoObject <Canciones[]>(datorecibido);
                    ListaRecibida = datoServer;
                    cantidadTotal = datoServer.Length;
                }
            }
            //Para solicitar los bytes y reproducir
            else if (mensaje.OpCod.Equals("04"))
            {
                Console.WriteLine("CancionRecibida");
                Canciones[] datoServer = XMLtoObject <Canciones[]>(datorecibido);
                ListaRecibida = datoServer;
                cantidadTotal = datoServer.Length;
            }
            networkStream.Close();

            tcpClient.Close();
        }
Esempio n. 8
0
 public Canciones[] SocketClienteSong(AddDatoMensaje mensajeEntrante)
 {
     usarSocket(mensajeEntrante);
     return(new Canciones[2]);
 }