Esempio n. 1
0
        private void worker_DoWork_XML(object sender, DoWorkEventArgs e)
        {
            try
            {
                Total = _selectedItems.Length;

                foreach (XElement node in _selectedItems)
                {
                    //exit if the user cancels
                    if (_isCancelationPending == true)
                    {
                        return;
                    }

                    Movie movie = new Movie();
                    movie.Title         = Util.GetElementValue(node, "TitreVF");
                    movie.OriginalTitle = Util.GetElementValue(node, "TitreVO");

                    int intValue;

                    if (int.TryParse(Util.GetElementValue(node, "Duree"), out intValue) == true)
                    {
                        movie.Runtime = intValue;
                    }

                    if (int.TryParse(Util.GetElementValue(node, "Note"), out intValue) == true)
                    {
                        movie.MyRating = intValue;
                    }

                    movie.Description = Util.GetElementValue(node, "Synopsis");
                    movie.Comments    = Util.GetElementValue(node, "Commentaires");
                    movie.FileFormat  = MovieServices.GetFormat(Util.GetElementValue(node, "Support"));
                    movie.FilePath    = Util.GetElementValue(node, "MediaChemin");
                    movie.Media       = MediaServices.Get("None", true);

                    DateTime dateValue;

                    if (DateTime.TryParse(Util.GetElementValue(node, "EntreeDate"), out dateValue) == true)
                    {
                        movie.AddedDate = dateValue;
                    }

                    if (Util.GetElementValue(node, "FilmVu") == "OUI")
                    {
                        movie.Watched = true;
                    }


                    #region Types
                    string   allType = Util.GetElementValue(node, "Genre");
                    string[] types   = allType.Split('/');


                    foreach (string type in types)
                    {
                        MovieServices.AddTypes(type, movie);
                    }
                    #endregion
                    #region Artist
                    string   allArtist = Util.GetElementValue(node, "Acteurs");
                    string[] artists   = allArtist.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                    foreach (string artist in artists)
                    {
                        string fullName = artist.Trim();
                        if (string.IsNullOrWhiteSpace(fullName) == false)
                        {
                            bool   isNew;
                            Artist newArtist = ArtistServices.Get(fullName, out isNew);
                            ArtistServices.SaveArtist(newArtist, movie);
                        }
                    }
                    #endregion
                    #region Director
                    string   allDirector = Util.GetElementValue(node, "Realisateurs");
                    string[] directors   = allDirector.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                    foreach (string director in directors)
                    {
                        string fullName = director.Trim();
                        if (string.IsNullOrWhiteSpace(fullName) == false)
                        {
                            bool   isNew;
                            Artist newArtist = ArtistServices.Get(fullName, out isNew);
                            ArtistServices.AddDirector(new[] { newArtist }, movie);
                        }
                    }
                    #endregion
                    #region Audio
                    string       allAudio  = Util.GetElementValue(node, "Audio");
                    string[]     audios    = allAudio.Split(',');
                    List <Audio> audioList = new List <Audio>();

                    foreach (string audio in audios)
                    {
                        string cleanAudio = audio.Trim();
                        if (string.IsNullOrWhiteSpace(cleanAudio) == false)
                        {
                            string[] detailAudio = cleanAudio.Split(' ');
                            audioList.Add(MovieServices.GetMovieAudio(detailAudio[0], detailAudio[1]));
                        }
                    }
                    AudioServices.Add(audioList, movie);
                    #endregion
                    #region Sub

                    string   allSubs = Util.GetElementValue(node, "SousTitres");
                    string[] subs    = allSubs.Split(',');

                    SubTitleServices.Add(subs, movie);

                    #endregion
                    #region Link
                    LinksServices.AddLinks(Util.GetElementValue(node, "BAChemin"), movie, true);
                    #endregion

                    Dal.GetInstance.AddMovie(movie);
                    _intAddedItem++;
                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }