Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (!larga && cancionlarga is null) //caso normal
                {
                    min   = Convert.ToInt32(minTextBox.Text);
                    sec   = Convert.ToInt32(secsTextBox.Text);
                    title = tituloTextBox.Text;
                    bonus = checkBoxBonus.Checked;
                    if (editar) //si edita
                    {
                        cancion.Title   = title;
                        cancion.Length  = new TimeSpan(0, min, sec);
                        cancion.IsBonus = bonus;
                        DialogResult    = DialogResult.OK;
                        Close();
                    }
                    else
                    {
                        Song c = new Song(title, new TimeSpan(0, min, sec), ref album, bonus);
                        album.AddSong(c);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
                else if (larga && cancionlarga is null) //caso de que creemos una cancion larga, sin partes
                {
                    title = tituloTextBox.Text;
                    min   = sec = 0;
                    np    = Convert.ToInt32(textBoxNumPartes.Text);
                    LongSong longSong = new LongSong(title, album);

                    album.AddSong(longSong);
                    for (int i = 0; i < np; i++)
                    {
                        CreateSong addParte = new CreateSong(ref longSong, i + 1, ref album);
                        addParte.ShowDialog();
                        if (addParte.DialogResult == DialogResult.Cancel)
                        {
                            break;
                        }
                        else
                        {
                            DialogResult = DialogResult.OK;
                        }
                    }
                }
                else if (cancionlarga is not null && larga == true)//parte de una cancion normal
                {
                    title = tituloTextBox.Text;
                    min   = Convert.ToInt32(minTextBox.Text);
                    sec   = Convert.ToInt32(secsTextBox.Text);
                    TimeSpan dur = new TimeSpan(0, min, sec);
                    np = 0;
                    Song p = new Song(title, dur, ref album);
                    cancionlarga.AddPart(p);
                    DialogResult = DialogResult.OK;
                }
                Dispose();
            }
            catch (NullReferenceException ex)
            {
                Log.Instance.PrintMessage(ex.Message, MessageType.Error);

                MessageBox.Show(Kernel.LocalTexts.GetString("error_vacio1"));
            }

            catch (FormatException ex)
            {
                Log.Instance.PrintMessage(ex.Message, MessageType.Error);
                MessageBox.Show(Kernel.LocalTexts.GetString("error_formato"));
                //throw;
            }
        }
Exemplo n.º 2
0
        public static void LoadCSVAlbums(string file)
        {
            Log.Instance.PrintMessage("Loading CSV albums stored at " + file, MessageType.Info, "cargarAlbumesLegacy(string)");
            Stopwatch crono = Stopwatch.StartNew();
            //cargando CSV a lo bestia
            int lineaC = 1;

            using (StreamReader lector = new StreamReader(file))
            {
                string linea;
                while (!lector.EndOfStream)
                {
                    linea = lector.ReadLine();
                    while (linea == "")
                    {
                        linea = lector.ReadLine();
                        lineaC++;
                    }

                    if (linea == null)
                    {
                        continue;                //si no hay nada tu sigue, que hemos llegado al final del fichero, después del nulo porque siempre al terminar un disco pongo línea nueva.
                    }
                    string[] datos = linea.Split(';');
                    if (datos.Length == 8) //need to convert
                    {
                        Log.Instance.PrintMessage("Adding Studio type to album", MessageType.Info);
                    }
                    else if (datos.Length != 9)
                    {
                        SendErrorLoading(lineaC, file);
                        Environment.Exit(-1);
                    }
                    short nC  = 0;
                    int   gen = FindGenre(datos[(int)CSV_Albums.Genre]);
                    Genre g   = Genres[gen];
                    if (string.IsNullOrEmpty(datos[(int)CSV_Albums.Cover_PATH]))
                    {
                        datos[(int)CSV_Albums.Cover_PATH] = string.Empty;
                    }
                    AlbumData a = null;
                    try
                    {
                        nC = Convert.ToInt16(datos[(int)CSV_Albums.NumSongs]);
                        string CoverPath = String.Empty;
                        if (!string.IsNullOrEmpty(datos[(int)CSV_Albums.Cover_PATH]))
                        {
                            CoverPath = Environment.CurrentDirectory + "\\" + datos[(int)CSV_Albums.Cover_PATH];
                        }
                        a      = new AlbumData(g, datos[(int)CSV_Albums.Title], datos[(int)CSV_Albums.Artist], Convert.ToInt16(datos[(int)CSV_Albums.Year]), CoverPath);
                        a.Type = (AlbumType)Convert.ToInt32(datos[(int)CSV_Albums.Type]);
                    }
                    catch (FormatException)
                    {
                        SendErrorLoading(lineaC, file);
                        Environment.Exit(-1);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        a.Type = AlbumType.Studio;
                    }
                    if (!string.IsNullOrEmpty(datos[(int)CSV_Albums.SpotifyID]))
                    {
                        a.IdSpotify = datos[(int)CSV_Albums.SpotifyID];
                    }
                    if (!string.IsNullOrEmpty(datos[(int)CSV_Albums.SongFiles_DIR]))
                    {
                        a.SoundFilesPath = datos[(int)CSV_Albums.SongFiles_DIR];
                    }
                    bool exito = true;
                    for (int i = 0; i < nC; i++)
                    {
                        exito = false;
                        linea = lector.ReadLine();
                        lineaC++;
                        if (string.IsNullOrEmpty(linea))
                        {
                            /*System.Windows.Forms.MessageBox.Show("mensajeError"+Environment.NewLine
                             + a.nombre + " - " + a.nombre + Environment.NewLine
                             + "saltarAlSiguiente", "error", System.Windows.Forms.MessageBoxButtons.OK);*/
                            break; //no sigue cargando el álbum
                        }
                        else
                        {
                            try
                            {
                                exito = true;
                                string[] datosCancion = linea.Split(';');
                                if (datosCancion.Length == 3)
                                {
                                    byte bonus = Convert.ToByte(datosCancion[(int)CSV_Songs.IsBonus]);
                                    Song c     = new Song(datosCancion[(int)CSV_Songs.Title], TimeSpan.FromSeconds(Convert.ToInt32(datosCancion[(int)CSV_Songs.TotalSeconds])), ref a, Convert.ToBoolean(bonus));
                                    a.AddSong(c, i);
                                }
                                else
                                {
                                    LongSong cl = new LongSong(datosCancion[(int)CSV_Songs.Title], a);
                                    int      np = Convert.ToInt32(datosCancion[(int)CSV_Songs.TotalSeconds]);
                                    for (int j = 0; j < np; j++)
                                    {
                                        linea = lector.ReadLine();
                                        lineaC++;
                                        datosCancion = linea.Split(';');
                                        Song c = new Song(datosCancion[0], TimeSpan.FromSeconds(Convert.ToInt32(datosCancion[(int)CSV_Songs.TotalSeconds])), ref a);
                                        cl.AddPart(c);
                                    }
                                    a.AddSong(cl, i);
                                }
                            }
                            catch (FormatException)
                            {
                                SendErrorLoading(lineaC, file);
                                Environment.Exit(-1);
                            }
                        }
                    }
                    //We won't check repeated albums because there shouldn't be any
                    //if (Collection.IsInCollection(a))
                    //{
                    //    exito = false; //pues ya está repetido.
                    //    Log.Instance.PrintMessage("Repeated album -> " + a.Artist + " - " + a.Title, MessageType.Warning);
                    //}

                    if (exito)
                    {
                        Collection.AddAlbum(ref a);
                    }
                    else
                    {
                        Log.Instance.PrintMessage("Couldn't add the album", MessageType.Error);
                    }

                    a.CanBeRemoved = true;
                    lineaC++;
                }
            }
            crono.Stop();
            Log.Instance.PrintMessage("Cargados " + Collection.Albums.Count + " álbumes correctamente", MessageType.Correct, crono, TimeType.Milliseconds);
            ReloadView();
        }