Beispiel #1
0
        private void AddGamez(string[] strTemp, string strTitle, string strFileName, string strFilePath)
        {
            Gamez objGames = new Gamez();

            objGames.Title      = strTitle;
            objGames.Ressources = new List <Ressource>();
            objGames.AddedDate  = DateTime.Now;
            #region File

            objGames.FileName = strFileName;
            objGames.FilePath = strFilePath;

            #endregion
            if (_mapping != null)
            {
                string strLanguage = Util.ConstructString(strTemp, (string[])_mapping["Language"], _nbrBaseParsing);
                objGames.Language = LanguageServices.GetLanguage(strLanguage, true);
            }

            objGames.Media = MediaServices.Get(_strMediaName.Trim(), _mediaType, _path,
                                               _cleanTitle, _entityType, _patternType, _useSubFolder, _bGetImage, _bParseNfo, true);
            #region Cover
            if (_bGetImage == true)
            {
                RessourcesServices.AddImage(Util.GetLocalImage(objGames.FilePath, objGames.FileName, _bFile), objGames, true);
            }
            #endregion
            if (string.IsNullOrEmpty(objGames.Title) == false)
            {
                bool bExist = false;
                if (Dal.GetInstance.GetGames(objGames.Media.Name, objGames.FilePath, objGames.FileName) != null)
                {
                    bExist = true;
                }


                if (bExist == false)
                {
                    #region ParseNfo

                    if (_bParseNfo == true)
                    {
                        string errorMessage;
                        GameServices.ParseNfo(objGames, out errorMessage);
                    }
                    #endregion
                    Dal.GetInstance.AddGame(objGames);

                    _intAddedItem++;
                }
                else
                {
                    _intNotAddedItem++;
                }
            }
        }
Beispiel #2
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, "Title");
                    movie.OriginalTitle = Util.GetElementValue(node, "OriginalTitle");
                    movie.BarCode       = Util.GetElementValue(node, "BarCode");
                    movie.Comments      = Util.GetElementValue(node, "Comments");
                    movie.Description   = Util.GetElementValue(node, "Description");
                    movie.FileName      = Util.GetElementValue(node, "FileName");
                    movie.FilePath      = Util.GetElementValue(node, "FilePath");
                    movie.Country       = Util.GetElementValue(node, "Country");
                    movie.AlloCine      = Util.GetElementValue(node, "AlloCine");
                    movie.Imdb          = Util.GetElementValue(node, "Imdb");
                    movie.Tagline       = Util.GetElementValue(node, "Tagline");

                    DateTime dateValue;

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

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

                    #region Bool
                    bool boolValue;

                    if (bool.TryParse(Util.GetElementValue(node, "IsComplete"), out boolValue) == true)
                    {
                        movie.IsComplete = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsDeleted"), out boolValue) == true)
                    {
                        movie.IsDeleted = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "Seen"), out boolValue) == true)
                    {
                        movie.Watched = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsWhish"), out boolValue) == true)
                    {
                        movie.IsWhish = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "ToBeDeleted"), out boolValue) == true)
                    {
                        movie.ToBeDeleted = boolValue;
                    }
                    #endregion
                    #region Int
                    int intValue;

                    if (int.TryParse(Util.GetElementValue(node, "Rated"), out intValue) == true)
                    {
                        movie.Rated = intValue.ToString(CultureInfo.InvariantCulture);
                    }

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

                    if (int.TryParse(Util.GetElementValue(node, "Runtime"), out intValue) == true)
                    {
                        movie.Runtime = intValue;
                    }
                    #endregion
                    #region Media
                    var query = from item in node.Descendants("Media")
                                select item;

                    XElement[] movieNode = query.ToArray();

                    foreach (XElement media in movieNode)
                    {
                        Media newMedia = MediaServices.Get(Util.GetElementValue(media, "Name"), true);
                        newMedia.Path = Util.GetElementValue(media, "Path");
                        movie.Media   = newMedia;
                    }
                    #endregion
                    #region AspectRatio
                    query = from item in node.Descendants("AspectRatio")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement aspectRatio in movieNode)
                    {
                        movie.AspectRatio = MovieServices.GetAspectRatio(Util.GetElementValue(aspectRatio, "Name"));
                    }
                    #endregion
                    #region FileFormat
                    query = from item in node.Descendants("FileFormat")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement format in movieNode)
                    {
                        movie.FileFormat = MovieServices.GetFormat(Util.GetElementValue(format, "Name"));
                    }
                    #endregion
                    #region Studio
                    query = from item in node.Descendants("Studio")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement studio in movieNode)
                    {
                        bool isNew;
                        movie.Publisher = PublisherServices.GetPublisher(Util.GetElementValue(studio, "Name"), out isNew, "Movie_Studio");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("Movie_Studio", movie.Publisher);
                        }
                    }
                    #endregion
                    #region Links
                    query = from item in node.Descendants("Link")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement link in movieNode)
                    {
                        LinksServices.AddLinks(Util.GetElementValue(link, "Path"), movie, true);
                    }

                    #endregion
                    #region Types
                    query = from item in node.Descendants("Type")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement type in movieNode)
                    {
                        MovieServices.AddTypes(Util.GetElementValue(type, "RealName"), movie);
                    }
                    #endregion
                    #region Image
                    query = from item in node.Descendants("Ressource")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement images in movieNode)
                    {
                        if (Util.GetElementValue(images, "ResourcesType") == "Image")
                        {
                            bool   isDefault = bool.Parse(Util.GetElementValue(images, "IsDefault"));
                            byte[] cover     = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddImage(cover, movie, isDefault);
                            }
                        }
                        if (Util.GetElementValue(images, "ResourcesType") == "Background")
                        {
                            byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddBackground(cover, movie);
                            }
                        }
                    }
                    #endregion
                    #region Artist
                    query = from item in node.Descendants("Artist")
                            select item;

                    XElement[] artistNode = query.ToArray();

                    foreach (XElement artist in artistNode)
                    {
                        bool   isNew;
                        string fullname  = Util.GetElementValue(artist, "FulleName");
                        Artist newArtist = ArtistServices.Get(fullname, out isNew);

                        if (string.IsNullOrWhiteSpace(newArtist.Aka))
                        {
                            newArtist.Aka = Util.GetElementValue(artist, "Aka");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Bio))
                        {
                            newArtist.Bio = Util.GetElementValue(artist, "Bio");
                        }

                        if (newArtist.BirthDay == null && DateTime.TryParse(Util.GetElementValue(artist, "BirthDay"), out dateValue) == true)
                        {
                            newArtist.BirthDay = dateValue;
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Breast))
                        {
                            newArtist.Breast = Util.GetElementValue(artist, "Breast");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Ethnicity))
                        {
                            newArtist.Ethnicity = Util.GetElementValue(artist, "Ethnicity");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.FirstName))
                        {
                            newArtist.FirstName = Util.GetElementValue(artist, "FirstName");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.LastName))
                        {
                            newArtist.LastName = Util.GetElementValue(artist, "LastName");
                        }

                        if (newArtist.Picture == null)
                        {
                            newArtist.Picture = Convert.FromBase64String(Util.GetElementValue(artist, "Picture"));
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.PlaceBirth))
                        {
                            newArtist.PlaceBirth = Util.GetElementValue(artist, "PlaceBirth");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.WebSite))
                        {
                            newArtist.WebSite = Util.GetElementValue(artist, "WebSite");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.YearsActive))
                        {
                            newArtist.YearsActive = Util.GetElementValue(artist, "YearsActive");
                        }

                        query = from item in artist.Descendants("Credit")
                                select item;

                        XElement[] creditsNode = query.ToArray();

                        foreach (XElement artistCredit in creditsNode)
                        {
                            ArtistCredits artistCredits = new ArtistCredits();

                            artistCredits.Title      = Util.GetElementValue(artistCredit, "Title");
                            artistCredits.BuyLink    = Util.GetElementValue(artistCredit, "BuyLink");
                            artistCredits.EntityType = EntityType.Movie;
                            artistCredits.Notes      = Util.GetElementValue(artistCredit, "Notes");

                            DateTime releaseDate;
                            if (DateTime.TryParse(Util.GetElementValue(artistCredit, "ReleaseDate"), out releaseDate) == true)
                            {
                                artistCredits.ReleaseDate = releaseDate;
                            }

                            if (string.IsNullOrWhiteSpace(artistCredits.Title) == false && string.IsNullOrWhiteSpace(newArtist.FulleName) == false)
                            {
                                if (Dal.GetInstance.GetArtistCredit(artistCredits.Title, newArtist.FulleName) == null)
                                {
                                    newArtist.ArtistCredits.Add(artistCredits);
                                }
                            }
                        }

                        ArtistServices.AddArtist(new[] { newArtist }, movie);
                    }


                    #endregion

                    Dal.GetInstance.AddMovie(movie);
                    _intAddedItem++;

                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }
Beispiel #3
0
        private void AddMusic(string[] strTemp, string strTitle, string strFileName, string strFilePath)
        {
            bool isFolder      = false;
            bool isEmptyFolder = false;

            FileInfo  file     = new FileInfo(Path.Combine(strFilePath, strFileName));
            Hashtable tags     = new Hashtable();
            Media     objMedia = MediaServices.Get(_strMediaName.Trim(), _mediaType, _path, _cleanTitle, _entityType, _patternType, _useSubFolder, _bGetImage, _bParseNfo, true);

            if (file.Exists == false && string.IsNullOrWhiteSpace(file.Extension))
            {
                if (Directory.Exists(file.FullName))
                {
                    DirectoryInfo folder = new DirectoryInfo(file.FullName);

                    FileInfo[] files = folder.GetFiles("*.mp3", SearchOption.TopDirectoryOnly);
                    files = files.Concat(folder.GetFiles("*.flc", SearchOption.TopDirectoryOnly)).ToArray();
                    files = files.Concat(folder.GetFiles("*.flac", SearchOption.TopDirectoryOnly)).ToArray();

                    if (files.Any())
                    {
                        file     = files[0];
                        isFolder = true;
                    }
                    else
                    {
                        isEmptyFolder = true;
                    }
                }
            }

            if (isEmptyFolder == false)
            {
                if (Dal.GetInstance.GetMusics(objMedia.Name, strFilePath, strFileName) == null)
                {
                    switch (file.Extension)
                    {
                    case ".mp3":
                        IID3v2 objMp3Tag = ID3v2Helper.CreateID3v2(file.FullName);

                        tags.Add("Title", objMp3Tag.Title);


                        if (string.IsNullOrWhiteSpace(objMp3Tag.Album) == false)
                        {
                            tags.Add("Album", objMp3Tag.Album);
                        }

                        if (isFolder == false && objMp3Tag.LengthMilliseconds != null)
                        {
                            tags.Add("Length", objMp3Tag.LengthMilliseconds);
                        }

                        if (objMp3Tag.PictureList.Count > 0)
                        {
                            tags.Add("Cover", objMp3Tag.PictureList[0].PictureData);
                        }

                        tags.Add("Genre", objMp3Tag.Genre);
                        tags.Add("Artist", objMp3Tag.Artist);
                        break;

                    case ".flac":
                    case ".flc":
                        try
                        {
                            FlacTagger objFlacTag = new FlacTagger(file.FullName);

                            tags.Add("Title", objFlacTag.Title);

                            if (string.IsNullOrWhiteSpace(objFlacTag.Album) == false)
                            {
                                tags.Add("Album", objFlacTag.Album);
                            }

                            if (isFolder == false)
                            {
                                tags.Add("Length", objFlacTag.Length);
                            }

                            if (objFlacTag.Arts.Count > 0)
                            {
                                tags.Add("Cover", objFlacTag.Arts[0].PictureData);
                            }

                            tags.Add("Genre", objFlacTag.Genre);
                            tags.Add("Artist", objFlacTag.Artist);
                            break;
                        }
                        //FIX 2.8.9.0
                        catch (FileFormatException)
                        {
                            break;
                        }
                    }

                    #region Title

                    if (tags.ContainsKey("Title") == false)
                    {
                        if (string.IsNullOrEmpty(strTitle) == false)
                        {
                            strTitle = strTitle.Replace('_', ' ');
                            strTitle = strTitle.Replace(".MP3", "");
                            strTitle = strTitle.Replace(".Mp3", "");
                            strTitle = strTitle.Replace(".flac", "");
                            strTitle = strTitle.Trim();
                            strTitle = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(strTitle);
                            tags.Add("Title", strTitle);
                        }
                    }

                    #endregion

                    Music objMusic = new Music();
                    objMusic.Ressources = new List <Ressource>();
                    objMusic.Genres     = new List <Genre>();
                    objMusic.Title      = strTitle;
                    objMusic.AddedDate  = DateTime.Now;
                    objMusic.FileName   = strFileName;
                    objMusic.FilePath   = strFilePath;

                    if (tags.ContainsKey("Album"))
                    {
                        objMusic.Album = tags["Album"].ToString();
                        if (isFolder == true && string.IsNullOrWhiteSpace(tags["Album"].ToString()) == false)
                        {
                            objMusic.Title = tags["Album"].ToString();
                        }
                    }

                    if (tags.ContainsKey("Length"))
                    {
                        objMusic.Runtime = tags["Length"] as int?;
                    }

                    objMusic.Media = objMedia;

                    #region Cover

                    if (_bGetImage == true)
                    {
                        RessourcesServices.AddImage(Util.GetLocalImage(objMusic.FilePath, objMusic.FileName, _bFile), objMusic,
                                                    true);
                    }
                    else
                    {
                        RessourcesServices.AddImage(tags["Cover"] as byte[], objMusic, true);
                    }

                    #endregion

                    bool bExist = false;
                    if (Dal.GetInstance.GetMusics(objMusic.Media.Name, objMusic.FilePath, objMusic.FileName) != null)
                    {
                        bExist = true;
                    }

                    if (bExist == false)
                    {
                        #region ParseNfo

                        if (_bParseNfo == true)
                        {
                            string errorMessage;
                            MusicServices.ParseNfo(objMusic, out errorMessage);
                        }
                        #endregion
                        #region Artist
                        string strArtistFullName = string.Empty;
                        if (tags.ContainsKey("Artist") == true)
                        {
                            if (tags["Artist"] == null)
                            {
                                if (_mapping != null)
                                {
                                    strArtistFullName = Util.ConstructString(strTemp, (string[])_mapping["Artist"], _nbrBaseParsing);
                                }
                            }
                            else
                            {
                                strArtistFullName = tags["Artist"] as string;
                            }
                        }
                        #endregion
                        Dal.GetInstance.AddMusic(objMusic);
                        if (tags.ContainsKey("Genre"))
                        {
                            GenreServices.AddGenres(new[] { tags["Genre"] as string }, objMusic, true);
                        }
                        if (strArtistFullName != null && string.IsNullOrWhiteSpace(strArtistFullName.Trim()) == false)
                        {
                            ArtistServices.AddArtist(strArtistFullName, objMusic);
                        }

                        _intAddedItem++;
                    }
                    else
                    {
                        _intNotAddedItem++;
                    }
                }
            }
        }
Beispiel #4
0
        private void AddMovies(string strTitle, string strFileName, string strFilePath)
        {
            try
            {
                Movie objMovie = new Movie();
                objMovie.Title      = strTitle;
                objMovie.Ressources = new List <Ressource>();
                objMovie.Artists    = new List <Artist>();
                objMovie.Audios     = new List <Audio>();
                objMovie.Subtitles  = new List <Language>();
                objMovie.Genres     = new List <Genre>();
                objMovie.Links      = new List <Links>();
                objMovie.AddedDate  = DateTime.Now;
                #region File

                objMovie.FileName = strFileName;
                objMovie.FilePath = strFilePath;

                #endregion
                objMovie.Media = MediaServices.Get(_strMediaName.Trim(), _mediaType, _path,
                                                   _cleanTitle, _entityType, _patternType, _useSubFolder, _bGetImage, _bParseNfo, true);
                #region Cover
                if (_bGetImage == true)
                {
                    RessourcesServices.AddImage(Util.GetLocalImage(objMovie.FilePath, objMovie.FileName, _bFile), objMovie, true);
                }
                #endregion
                if (string.IsNullOrEmpty(objMovie.Title) == false)
                {
                    bool bExist = false;
                    if (Dal.GetInstance.GetMovies(objMovie.Media.Name, objMovie.FilePath, objMovie.FileName) != null)
                    {
                        bExist = true;
                    }

                    if (bExist == false)
                    {
                        #region MediaInfo
                        FileInfo file = new FileInfo(Path.Combine(strFilePath, strFileName));
                        if (file.Attributes == FileAttributes.Directory)
                        {
                            DirectoryInfo objFolder = new DirectoryInfo(file.FullName);
                            if (objFolder.Exists == true)
                            {
                                FileInfo[] lstFile = objFolder.GetFiles("*.mkv", SearchOption.TopDirectoryOnly);

                                if (!lstFile.Any())
                                {
                                    lstFile = objFolder.GetFiles("*.avi", SearchOption.TopDirectoryOnly);
                                }

                                if (!lstFile.Any())
                                {
                                    lstFile = objFolder.GetFiles("*.divx ", SearchOption.TopDirectoryOnly);
                                }

                                if (lstFile.Any())
                                {
                                    MovieServices.Fill(MediaInfoService.getInfo(lstFile[0].FullName, objMovie.Id), objMovie);
                                }
                            }
                        }
                        else if (file.Attributes == FileAttributes.Normal)
                        {
                            MovieServices.Fill(MediaInfoService.getInfo(file.FullName, objMovie.Id), objMovie);
                        }

                        #endregion
                        #region ParseNfo

                        if (_bParseNfo == true)
                        {
                            string errorMessage;
                            MovieServices.ParseNfo(objMovie, out errorMessage);
                        }
                        #endregion
                        Dal.GetInstance.AddMovie(objMovie);
                        _intAddedItem++;
                    }
                    else
                    {
                        _intNotAddedItem++;
                    }
                }
            }
            catch (Exception exception)
            {
                Util.LogException(exception, strTitle);
            }
        }
Beispiel #5
0
        private void AddSeries(string strTitle, string strFileName, string strFilePath)
        {
            if (IsRootFolder(strFileName, strFilePath) == false)
            {
                bool         create;
                SeriesSeason objEntity = IsSeasonFolder(strFileName, strFilePath, out create);
                if (create == true)
                {
                    if (objEntity == null)
                    {
                        objEntity         = new SeriesSeason();
                        objEntity.SerieId = SerieServices.GetSerieId(strTitle);
                        objEntity.Title   = strTitle;
                        objEntity.Season  = 1;
                    }

                    Media objMedia = MediaServices.Get(_strMediaName.Trim(), _mediaType, _path, _cleanTitle, _entityType, _patternType, _useSubFolder, _bGetImage, _bParseNfo, true);

                    objEntity.Media       = objMedia;
                    objEntity.Watched     = false;
                    objEntity.IsComplete  = false;
                    objEntity.ToBeDeleted = false;
                    objEntity.ToWatch     = false;
                    objEntity.AddedDate   = DateTime.Now;
                    objEntity.Ressources  = new List <Ressource>();
                    objEntity.Genres      = new List <Genre>();
                    objEntity.Audios      = new List <Audio>();
                    objEntity.Subtitles   = new List <Language>();


                    #region File

                    objEntity.FilePath = Path.Combine(strFilePath, strFileName);

                    #endregion

                    #region Cover

                    if (_bGetImage == true)
                    {
                        RessourcesServices.AddImage(Util.GetLocalImage(objEntity.FilePath, string.Empty, _bFile), objEntity,
                                                    true);
                    }

                    #endregion

                    if (string.IsNullOrEmpty(objEntity.Title) == false)
                    {
                        bool bExist = false;
                        if (Dal.GetInstance.GetSeriesSeason(objEntity.Media.Name, objEntity.FilePath, objEntity.Season) != null)
                        {
                            bExist = true;
                        }

                        if (bExist == false)
                        {
                            #region MediaInfo
                            FileInfo file = new FileInfo(Path.Combine(strFilePath, strFileName));
                            if (file.Attributes == FileAttributes.Directory)
                            {
                                if (Directory.Exists(file.FullName) == true)
                                {
                                    string[] lstFile = Util.GetFiles(file.FullName, new[] { "*.mkv", "*.mp4", "*.avi", "*.divx" });

                                    if (lstFile.Any())
                                    {
                                        SerieServices.Fill(MediaInfoService.getInfo(lstFile[0], objEntity.Id), objEntity);
                                    }
                                }
                            }
                            else if (file.Attributes == FileAttributes.Normal)
                            {
                                SerieServices.Fill(MediaInfoService.getInfo(file.FullName, objEntity.Id), objEntity);
                            }

                            #endregion

                            #region ParseNfo

                            if (_bParseNfo == true)
                            {
                                string errorMessage;
                                SerieServices.ParseNfo(objEntity, out errorMessage);
                            }
                            #endregion
                            Dal.GetInstance.AddSeriesSeason(objEntity);
                            _intAddedItem++;
                        }
                        else
                        {
                            _intNotAddedItem++;
                        }
                    }
                }
            }
        }
Beispiel #6
0
        private void AddBooks(string[] strTemp, string strTitle, string strFileName, string strFilePath)
        {
            Media objMedia = MediaServices.Get(_strMediaName.Trim(), _mediaType, _path,
                                               _cleanTitle, _entityType, _patternType, _useSubFolder, _bGetImage, _bParseNfo, true);

            const string strBookFormat = "Unknown";
            FileFormat   objFormat     = BookServices.GetFormat(strBookFormat, true);

            //Fix since 2.7.12.0
            strTitle = strTitle.Replace("EPub", "");
            strTitle = strTitle.Replace("Epub", "");
            strTitle = strTitle.Replace("Mobi", "");
            strTitle = strTitle.Replace("epub", "");
            strTitle = strTitle.Replace("mobi", "");
            strTitle = strTitle.Replace(".", " ");
            strTitle = strTitle.Trim();


            Books objBooks = new Books();

            objBooks.Ressources = new List <Ressource>();
            objBooks.Title      = strTitle;
            objBooks.AddedDate  = DateTime.Now;
            #region File

            objBooks.FileName = strFileName;
            objBooks.FilePath = strFilePath;

            #endregion
            if (_mapping != null)
            {
                string strLanguage = Util.ConstructString(strTemp, (string[])_mapping["Language"], _nbrBaseParsing);
                objBooks.Language = LanguageServices.GetLanguage(strLanguage, true);
            }

            objBooks.FileFormat = objFormat;
            objBooks.Media      = objMedia;
            #region Cover

            if (_bGetImage == true)
            {
                RessourcesServices.AddImage(Util.GetLocalImage(objBooks.FilePath, objBooks.FileName, _bFile), objBooks, true);
            }
            int index;
            if (RessourcesServices.GetDefaultCover(objBooks, out index) == null)
            {
                DirectoryInfo objFolder;

                if (_bFile == false)
                {
                    objFolder = new DirectoryInfo(objBooks.FilePath + @"\" + objBooks.FileName);
                }
                else
                {
                    objFolder = new DirectoryInfo(objBooks.FilePath);
                }

                FileInfo[] lstPdf = objFolder.GetFiles("*.pdf", SearchOption.AllDirectories);

                if (lstPdf.Any())
                {
                    RessourcesServices.AddImage(Util.GetImageFromPdf(lstPdf[0].FullName), objBooks, true);
                }
            }

            #endregion
            if (string.IsNullOrEmpty(objBooks.Title) == false)
            {
                bool bExist = false;
                if (Dal.GetInstance.GetBooks(objBooks.Media.Name, objBooks.FilePath, objBooks.FileName) != null)
                {
                    bExist = true;
                }

                if (bExist == false)
                {
                    #region ParseNfo

                    if (_bParseNfo == true)
                    {
                        string errorMessage;
                        BookServices.ParseNfo(objBooks, out errorMessage);
                    }
                    #endregion
                    Dal.GetInstance.AddBook(objBooks);
                    _intAddedItem++;
                }
                else
                {
                    _intNotAddedItem++;
                }
            }
        }
Beispiel #7
0
        private void AddXxx(string[] strTemp, string strTitle,
                            string strFileName,
                            string strFilePath)
        {
            Media objMedia = MediaServices.Get(_strMediaName.Trim(), _mediaType, _path,
                                               _cleanTitle, _entityType, _patternType, _useSubFolder, _bGetImage, _bParseNfo, true);

            XXX objEntity = new XXX();

            objEntity.Ressources = new List <Ressource>();
            objEntity.Media      = objMedia;
            objEntity.Title      = strTitle;
            objEntity.FilePath   = strFilePath;
            objEntity.AddedDate  = DateTime.Now;
            objEntity.Ressources = new List <Ressource>();
            objEntity.Genres     = new List <Genre>();
            objEntity.Audios     = new List <Audio>();
            objEntity.Subtitles  = new List <Language>();
            objEntity.Artists    = new List <Artist>();


            #region File

            objEntity.FileName = strFileName;

            #endregion
            #region Language

            if (_mapping != null)
            {
                string strLanguage = Util.ConstructString(strTemp, (string[])_mapping["Language"], _nbrBaseParsing);
                objEntity.Language = LanguageServices.GetLanguage(strLanguage, true);
            }

            #endregion

            if (_bGetImage == true)
            {
                RessourcesServices.AddImage(Util.GetLocalImage(objEntity.FilePath, objEntity.FileName, _bFile), objEntity, true);
            }

            if (string.IsNullOrEmpty(objEntity.Title) == false)
            {
                bool bExist = false;
                if (Dal.GetInstance.GetXxXs(objEntity.Media.Name, objEntity.FilePath, objEntity.FileName) != null)
                {
                    bExist = true;
                }

                if (bExist == false)
                {
                    #region MediaInfo
                    FileInfo file = new FileInfo(Path.Combine(strFilePath, strFileName));
                    if (file.Attributes == FileAttributes.Directory)
                    {
                        if (Directory.Exists(file.FullName) == true)
                        {
                            string[] lstFile = Util.GetFiles(file.FullName, new [] { "*.mkv", "*.mp4", "*.avi", "*.divx" });

                            if (lstFile.Any())
                            {
                                XxxServices.Fill(MediaInfoService.getInfo(lstFile[0], objEntity.Id), objEntity);
                            }
                        }
                    }
                    else if (file.Attributes == FileAttributes.Normal)
                    {
                        XxxServices.Fill(MediaInfoService.getInfo(file.FullName, objEntity.Id), objEntity);
                    }

                    #endregion

                    #region ParseNfo

                    if (_bParseNfo == true)
                    {
                        string errorMessage;
                        XxxServices.ParseNfo(objEntity, out errorMessage);
                    }
                    #endregion
                    Dal.GetInstance.AddXxx(objEntity);

                    _intAddedItem++;
                }
                else
                {
                    _intNotAddedItem++;
                }
            }
        }
Beispiel #8
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;
                    }

                    Apps apps = new Apps();
                    apps.Title       = Util.GetElementValue(node, "Title");
                    apps.BarCode     = Util.GetElementValue(node, "BarCode");
                    apps.Comments    = Util.GetElementValue(node, "Comments");
                    apps.Description = Util.GetElementValue(node, "Description");
                    apps.FileName    = Util.GetElementValue(node, "FileName");
                    apps.FilePath    = Util.GetElementValue(node, "FilePath");
                    apps.Version     = Util.GetElementValue(node, "Version");

                    #region DateTime
                    DateTime dateValue;

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

                    if (DateTime.TryParse(Util.GetElementValue(node, "ReleaseDate"), out dateValue) == true)
                    {
                        apps.ReleaseDate = dateValue;
                    }
                    #endregion
                    #region Bool
                    bool boolValue;

                    if (bool.TryParse(Util.GetElementValue(node, "IsComplete"), out boolValue) == true)
                    {
                        apps.IsComplete = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsDeleted"), out boolValue) == true)
                    {
                        apps.IsDeleted = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsTested"), out boolValue) == true)
                    {
                        apps.Watched = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsWhish"), out boolValue) == true)
                    {
                        apps.IsWhish = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "ToBeDeleted"), out boolValue) == true)
                    {
                        apps.ToBeDeleted = boolValue;
                    }
                    #endregion
                    #region Long
                    int longValue;

                    if (int.TryParse(Util.GetElementValue(node, "Rating"), out longValue) == true)
                    {
                        apps.MyRating = longValue;
                    }
                    #endregion
                    #region Media
                    var query = from item in node.Descendants("Media")
                                select item;

                    XElement[] bookNode = query.ToArray();

                    foreach (XElement media in bookNode)
                    {
                        Media newMedia = MediaServices.Get(Util.GetElementValue(media, "Name"), true);
                        newMedia.Path = Util.GetElementValue(media, "Path");
                        apps.Media    = newMedia;
                    }
                    #endregion
                    #region Publisher
                    query = from item in node.Descendants("Editor")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement editor in bookNode)
                    {
                        bool isNew;
                        apps.Publisher = PublisherServices.GetPublisher(Util.GetElementValue(editor, "Name"), out isNew, "App_Editor");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("App_Editor", apps.Publisher);
                        }
                    }
                    #endregion
                    #region Language
                    query = from item in node.Descendants("Language")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement languages in bookNode)
                    {
                        apps.Language = LanguageServices.GetLanguage(Util.GetElementValue(languages, "DisplayName"), true);
                    }
                    #endregion
                    #region Links
                    query = from item in node.Descendants("Link")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement link in bookNode)
                    {
                        LinksServices.AddLinks(Util.GetElementValue(link, "Path"), apps, true);
                    }

                    #endregion
                    #region Types
                    query = from item in node.Descendants("Type")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement type in bookNode)
                    {
                        GenreServices.AddGenres(new [] { Util.GetElementValue(type, "RealName") }, apps, true);
                    }
                    #endregion
                    #region Image
                    query = from item in node.Descendants("Ressource")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement images in bookNode)
                    {
                        if (Util.GetElementValue(images, "ResourcesType") == "Image")
                        {
                            bool   isDefault = bool.Parse(Util.GetElementValue(images, "IsDefault"));
                            byte[] cover     = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddImage(cover, apps, isDefault);
                            }
                        }
                        if (Util.GetElementValue(images, "ResourcesType") == "Background")
                        {
                            byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddBackground(cover, apps);
                            }
                        }
                    }
                    #endregion

                    Dal.GetInstance.AddApps(apps);
                    _intAddedItem++;

                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }
        private void worker_DoWork_XML(object sender, DoWorkEventArgs e)
        {
            try
            {
                Total = _selectedNodes.Length;

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

                    Music music = new Music();
                    music.Title    = Util.GetElementValue(node, "Title");
                    music.Album    = Util.GetElementValue(node, "Album");
                    music.BarCode  = Util.GetElementValue(node, "BarCode");
                    music.Comments = Util.GetElementValue(node, "Comments");
                    music.FileName = Util.GetElementValue(node, "FileName");
                    music.FilePath = Util.GetElementValue(node, "FilePath");

                    #region DateTime
                    DateTime dateValue;

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

                    if (DateTime.TryParse(Util.GetElementValue(node, "ReleaseDate"), out dateValue) == true)
                    {
                        music.ReleaseDate = dateValue;
                    }
                    #endregion
                    #region Bool
                    bool boolValue;

                    if (bool.TryParse(Util.GetElementValue(node, "IsComplete"), out boolValue) == true)
                    {
                        music.IsComplete = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsDeleted"), out boolValue) == true)
                    {
                        music.IsDeleted = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsHear"), out boolValue) == true)
                    {
                        music.Watched = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsWhish"), out boolValue) == true)
                    {
                        music.IsWhish = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "ToBeDeleted"), out boolValue) == true)
                    {
                        music.ToBeDeleted = boolValue;
                    }
                    #endregion
                    #region int
                    int intValue;

                    if (int.TryParse(Util.GetElementValue(node, "BitRate"), out intValue) == true)
                    {
                        music.BitRate = intValue;
                    }

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

                    if (int.TryParse(Util.GetElementValue(node, "Rating"), out intValue) == true)
                    {
                        music.MyRating = intValue;
                    }
                    #endregion
                    #region Media
                    var query = from item in node.Descendants("Media")
                                select item;

                    XElement[] musicNode = query.ToArray();

                    foreach (XElement media in musicNode)
                    {
                        Media newMedia = MediaServices.Get(Util.GetElementValue(media, "Name"), true);
                        newMedia.Path = Util.GetElementValue(media, "Path");
                        music.Media   = newMedia;
                    }
                    #endregion
                    #region Studio
                    query = from item in node.Descendants("Studio")
                            select item;

                    musicNode = query.ToArray();

                    foreach (XElement editor in musicNode)
                    {
                        bool isNew;
                        music.Publisher = PublisherServices.GetPublisher(Util.GetElementValue(editor, "Name"), out isNew, "Music_Studio");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("Music_Studio", music.Publisher);
                        }
                    }
                    #endregion
                    #region Track
                    query = from item in node.Descendants("Track")
                            select item;

                    musicNode = query.ToArray();

                    foreach (XElement track in musicNode)
                    {
                        MusicServices.AddTracks(new [] { Util.GetElementValue(track, "Title") }, music);
                    }
                    #endregion
                    #region Links
                    query = from item in node.Descendants("Link")
                            select item;

                    musicNode = query.ToArray();

                    foreach (XElement link in musicNode)
                    {
                        LinksServices.AddLinks(Util.GetElementValue(link, "Path"), music, true);
                    }

                    #endregion
                    #region Types
                    query = from item in node.Descendants("Type")
                            select item;

                    musicNode = query.ToArray();

                    foreach (XElement type in musicNode)
                    {
                        GenreServices.AddGenres(new[] { Util.GetElementValue(type, "RealName") }, music, true);
                    }
                    #endregion
                    #region Image
                    query = from item in node.Descendants("Ressource")
                            select item;

                    musicNode = query.ToArray();

                    foreach (XElement images in musicNode)
                    {
                        if (Util.GetElementValue(images, "ResourcesType") == "Image")
                        {
                            bool   isDefault = bool.Parse(Util.GetElementValue(images, "IsDefault"));
                            byte[] cover     = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddImage(cover, music, isDefault);
                            }
                        }
                        if (Util.GetElementValue(images, "ResourcesType") == "Background")
                        {
                            byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddBackground(cover, music);
                            }
                        }
                    }
                    #endregion
                    #region Artist
                    query = from item in node.Descendants("Artist")
                            select item;

                    XElement[] artistNode = query.ToArray();

                    foreach (XElement artist in artistNode)
                    {
                        bool   isNew;
                        string fullname  = Util.GetElementValue(artist, "FulleName");
                        Artist newArtist = ArtistServices.Get(fullname, out isNew);

                        if (string.IsNullOrWhiteSpace(newArtist.Aka))
                        {
                            newArtist.Aka = Util.GetElementValue(artist, "Aka");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Bio))
                        {
                            newArtist.Bio = Util.GetElementValue(artist, "Bio");
                        }

                        if (newArtist.BirthDay == null && DateTime.TryParse(Util.GetElementValue(artist, "BirthDay"), out dateValue) == true)
                        {
                            newArtist.BirthDay = dateValue;
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Breast))
                        {
                            newArtist.Breast = Util.GetElementValue(artist, "Breast");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Ethnicity))
                        {
                            newArtist.Ethnicity = Util.GetElementValue(artist, "Ethnicity");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.FirstName))
                        {
                            newArtist.FirstName = Util.GetElementValue(artist, "FirstName");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.LastName))
                        {
                            newArtist.LastName = Util.GetElementValue(artist, "LastName");
                        }

                        if (newArtist.Picture == null)
                        {
                            newArtist.Picture = Convert.FromBase64String(Util.GetElementValue(artist, "Picture"));
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.PlaceBirth))
                        {
                            newArtist.PlaceBirth = Util.GetElementValue(artist, "PlaceBirth");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.WebSite))
                        {
                            newArtist.WebSite = Util.GetElementValue(artist, "WebSite");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.YearsActive))
                        {
                            newArtist.YearsActive = Util.GetElementValue(artist, "YearsActive");
                        }

                        query = from item in artist.Descendants("Credit")
                                select item;

                        XElement[] creditsNode = query.ToArray();

                        foreach (XElement artistCredit in creditsNode)
                        {
                            ArtistCredits artistCredits = new ArtistCredits();

                            artistCredits.Title      = Util.GetElementValue(artistCredit, "Title");
                            artistCredits.BuyLink    = Util.GetElementValue(artistCredit, "BuyLink");
                            artistCredits.EntityType = EntityType.Movie;
                            artistCredits.Notes      = Util.GetElementValue(artistCredit, "Notes");

                            DateTime releaseDate;
                            if (DateTime.TryParse(Util.GetElementValue(artistCredit, "ReleaseDate"), out releaseDate) == true)
                            {
                                artistCredits.ReleaseDate = releaseDate;
                            }

                            if (string.IsNullOrWhiteSpace(artistCredits.Title) == false && string.IsNullOrWhiteSpace(newArtist.FulleName) == false)
                            {
                                if (Dal.GetInstance.GetArtistCredit(artistCredits.Title, newArtist.FulleName) == null)
                                {
                                    newArtist.ArtistCredits.Add(artistCredits);
                                }
                            }
                        }

                        ArtistServices.SaveArtist(newArtist, music);
                    }

                    #endregion

                    Dal.GetInstance.AddMusic(music);
                    _intAddedItem++;

                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }
Beispiel #10
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;
                    }

                    Books books = new Books();
                    books.Title       = Util.GetElementValue(node, "Title");
                    books.BarCode     = Util.GetElementValue(node, "BarCode");
                    books.Comments    = Util.GetElementValue(node, "Comments");
                    books.Description = Util.GetElementValue(node, "Description");
                    books.FileName    = Util.GetElementValue(node, "FileName");
                    books.FilePath    = Util.GetElementValue(node, "FilePath");
                    books.Isbn        = Util.GetElementValue(node, "ISBN");

                    #region DateTime
                    DateTime dateValue;

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

                    if (DateTime.TryParse(Util.GetElementValue(node, "ReleaseDate"), out dateValue) == true)
                    {
                        books.ReleaseDate = dateValue;
                    }
                    #endregion
                    #region Bool
                    bool boolValue;

                    if (bool.TryParse(Util.GetElementValue(node, "IsComplete"), out boolValue) == true)
                    {
                        books.IsComplete = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsDeleted"), out boolValue) == true)
                    {
                        books.IsDeleted = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsRead"), out boolValue) == true)
                    {
                        books.Watched = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsWhish"), out boolValue) == true)
                    {
                        books.IsWhish = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "ToBeDeleted"), out boolValue) == true)
                    {
                        books.ToBeDeleted = boolValue;
                    }
                    #endregion
                    #region Long
                    int longValue;

                    if (int.TryParse(Util.GetElementValue(node, "NbrPages"), out longValue) == true)
                    {
                        books.NbrPages = longValue;
                    }

                    if (int.TryParse(Util.GetElementValue(node, "Rated"), out longValue) == true)
                    {
                        books.Rated = longValue.ToString(CultureInfo.InvariantCulture);
                    }

                    if (int.TryParse(Util.GetElementValue(node, "Rating"), out longValue) == true)
                    {
                        books.MyRating = longValue;
                    }
                    #endregion
                    #region Media
                    var query = from item in node.Descendants("Media")
                                select item;

                    XElement[] bookNode = query.ToArray();

                    foreach (XElement media in bookNode)
                    {
                        Media newMedia = MediaServices.Get(Util.GetElementValue(media, "Name"), true);
                        newMedia.Path = Util.GetElementValue(media, "Path");
                        books.Media   = newMedia;
                    }
                    #endregion
                    #region Format
                    query = from item in node.Descendants("Format")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement format in bookNode)
                    {
                        books.FileFormat = BookServices.GetFormat(Util.GetElementValue(format, "Name"), true);
                    }
                    #endregion
                    #region Artist
                    query = from item in node.Descendants("Artist")
                            select item;

                    XElement[] artistNode = query.ToArray();

                    Job objJob = ArtistServices.GetJob("Author");
                    foreach (XElement artist in artistNode)
                    {
                        bool   isNew;
                        string fullname  = Util.GetElementValue(artist, "FulleName");
                        Artist newArtist = ArtistServices.Get(fullname, out isNew);

                        if (string.IsNullOrWhiteSpace(newArtist.Aka))
                        {
                            newArtist.Aka = Util.GetElementValue(artist, "Aka");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Bio))
                        {
                            newArtist.Bio = Util.GetElementValue(artist, "Bio");
                        }

                        if (newArtist.BirthDay == null && DateTime.TryParse(Util.GetElementValue(artist, "BirthDay"), out dateValue) == true)
                        {
                            newArtist.BirthDay = dateValue;
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Breast))
                        {
                            newArtist.Breast = Util.GetElementValue(artist, "Breast");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Ethnicity))
                        {
                            newArtist.Ethnicity = Util.GetElementValue(artist, "Ethnicity");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.FirstName))
                        {
                            newArtist.FirstName = Util.GetElementValue(artist, "FirstName");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.LastName))
                        {
                            newArtist.LastName = Util.GetElementValue(artist, "LastName");
                        }

                        if (newArtist.Picture == null)
                        {
                            newArtist.Picture = Convert.FromBase64String(Util.GetElementValue(artist, "Picture"));
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.PlaceBirth))
                        {
                            newArtist.PlaceBirth = Util.GetElementValue(artist, "PlaceBirth");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.WebSite))
                        {
                            newArtist.WebSite = Util.GetElementValue(artist, "WebSite");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.YearsActive))
                        {
                            newArtist.YearsActive = Util.GetElementValue(artist, "YearsActive");
                        }

                        query = from item in artist.Descendants("Credit")
                                select item;

                        XElement[] creditsNode = query.ToArray();

                        foreach (XElement artistCredit in creditsNode)
                        {
                            ArtistCredits artistCredits = new ArtistCredits();

                            artistCredits.Title      = Util.GetElementValue(artistCredit, "Title");
                            artistCredits.BuyLink    = Util.GetElementValue(artistCredit, "BuyLink");
                            artistCredits.EntityType = EntityType.Movie;
                            artistCredits.Notes      = Util.GetElementValue(artistCredit, "Notes");

                            DateTime releaseDate;
                            if (DateTime.TryParse(Util.GetElementValue(artistCredit, "ReleaseDate"), out releaseDate) == true)
                            {
                                artistCredits.ReleaseDate = releaseDate;
                            }

                            if (string.IsNullOrWhiteSpace(artistCredits.Title) == false && string.IsNullOrWhiteSpace(newArtist.FulleName) == false)
                            {
                                if (Dal.GetInstance.GetArtistCredit(artistCredits.Title, newArtist.FulleName) == null)
                                {
                                    newArtist.ArtistCredits.Add(artistCredits);
                                }
                            }
                        }
                        newArtist.Job = objJob;
                        books.Artists.Add(newArtist);
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddArtist(newArtist, books);
                        }
                    }


                    #endregion
                    #region Editor
                    query = from item in node.Descendants("Editor")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement editor in bookNode)
                    {
                        bool isNew;
                        books.Publisher = PublisherServices.GetPublisher(Util.GetElementValue(editor, "Name"), out isNew, "App_Editor");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("App_Editor", books.Publisher);
                        }
                    }
                    #endregion
                    #region Language
                    query = from item in node.Descendants("Language")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement languages in bookNode)
                    {
                        books.Language = LanguageServices.GetLanguage(Util.GetElementValue(languages, "DisplayName"), true);
                    }
                    #endregion
                    #region Links
                    query = from item in node.Descendants("Link")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement link in bookNode)
                    {
                        LinksServices.AddLinks(Util.GetElementValue(link, "Path"), books, true);
                    }

                    #endregion
                    #region Types
                    query = from item in node.Descendants("Type")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement type in bookNode)
                    {
                        GenreServices.AddGenre(Util.GetElementValue(type, "RealName"), books, true);
                    }
                    #endregion
                    #region Image
                    query = from item in node.Descendants("Ressource")
                            select item;

                    bookNode = query.ToArray();

                    foreach (XElement images in bookNode)
                    {
                        if (Util.GetElementValue(images, "ResourcesType") == "Image")
                        {
                            bool   isDefault = bool.Parse(Util.GetElementValue(images, "IsDefault"));
                            byte[] cover     = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddImage(cover, books, isDefault);
                            }
                        }
                        if (Util.GetElementValue(images, "ResourcesType") == "Background")
                        {
                            byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddBackground(cover, books);
                            }
                        }
                    }
                    #endregion

                    Dal.GetInstance.AddBook(books);
                    _intAddedItem++;

                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }
Beispiel #11
0
        private void worker_DoWork_XML(object sender, DoWorkEventArgs e)
        {
            try
            {
                Total = _selectedItems.Length;

                foreach (XElement node in _selectedItems)
                {
                    Gamez games = new Gamez();
                    games.Title       = Util.GetElementValue(node, "Title");
                    games.BarCode     = Util.GetElementValue(node, "BarCode");
                    games.Comments    = Util.GetElementValue(node, "Comments");
                    games.Description = Util.GetElementValue(node, "Description");
                    games.FileName    = Util.GetElementValue(node, "FileName");
                    games.FilePath    = Util.GetElementValue(node, "FilePath");

                    DateTime dateValue;

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

                    if (DateTime.TryParse(Util.GetElementValue(node, "ReleaseDate"), out dateValue) == true)
                    {
                        games.ReleaseDate = dateValue;
                    }

                    #region Bool
                    bool boolValue;

                    if (bool.TryParse(Util.GetElementValue(node, "IsComplete"), out boolValue) == true)
                    {
                        games.IsComplete = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsDeleted"), out boolValue) == true)
                    {
                        games.IsDeleted = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsTested"), out boolValue) == true)
                    {
                        games.Watched = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsWhish"), out boolValue) == true)
                    {
                        games.IsWhish = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "ToBeDeleted"), out boolValue) == true)
                    {
                        games.ToBeDeleted = boolValue;
                    }

                    #endregion
                    #region Long
                    int longValue;

                    if (int.TryParse(Util.GetElementValue(node, "Price"), out longValue) == true)
                    {
                        games.Price = longValue;
                    }

                    if (int.TryParse(Util.GetElementValue(node, "Rated"), out longValue) == true)
                    {
                        games.Rated = longValue.ToString(CultureInfo.InvariantCulture);
                    }

                    #endregion
                    #region int
                    int intValue;

                    if (int.TryParse(Util.GetElementValue(node, "Rating"), out intValue) == true)
                    {
                        games.MyRating = intValue;
                    }
                    #endregion
                    #region Media
                    var query = from item in node.Descendants("Media")
                                select item;

                    XElement[] mediaNode = query.ToArray();

                    foreach (XElement media in mediaNode)
                    {
                        Media newMedia = MediaServices.Get(Util.GetElementValue(media, "Name"), true);
                        newMedia.Path = Util.GetElementValue(media, "Path");
                        games.Media   = newMedia;
                    }
                    #endregion
                    #region Links
                    query = from item in node.Descendants("Link")
                            select item;

                    XElement[] linksNode = query.ToArray();

                    foreach (XElement link in linksNode)
                    {
                        LinksServices.AddLinks(Util.GetElementValue(link, "Path"), games, true);
                    }
                    #endregion
                    #region Types
                    query = from item in node.Descendants("Type")
                            select item;

                    XElement[] typekNode = query.ToArray();

                    foreach (XElement type in typekNode)
                    {
                        GenreServices.AddGenres(new[] { Util.GetElementValue(type, "RealName") }, games, true);
                    }
                    #endregion
                    #region Platform
                    query = from item in node.Descendants("Platform")
                            select item;

                    XElement[] platformNode = query.ToArray();

                    foreach (XElement type in platformNode)
                    {
                        games.Platform = GameServices.GetPlatform(Util.GetElementValue(type, "Name"), true);
                    }
                    #endregion
                    #region Image
                    query = from item in node.Descendants("Ressource")
                            select item;

                    XElement[] imagesNode = query.ToArray();

                    foreach (XElement images in imagesNode)
                    {
                        if (Util.GetElementValue(images, "ResourcesType") == "Image")
                        {
                            bool   isDefault = bool.Parse(Util.GetElementValue(images, "IsDefault"));
                            byte[] cover     = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddImage(cover, games, isDefault);
                            }
                        }
                        if (Util.GetElementValue(images, "ResourcesType") == "Background")
                        {
                            byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddBackground(cover, games);
                            }
                        }
                    }
                    #endregion
                    #region Publisher
                    query = from item in node.Descendants("Editor")
                            select item;

                    XElement[] editorNode = query.ToArray();

                    foreach (XElement editor in editorNode)
                    {
                        bool isNew;
                        games.Publisher = PublisherServices.GetPublisher(Util.GetElementValue(editor, "Name"), out isNew, "App_Editor");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("App_Editor", games.Publisher);
                        }
                    }
                    #endregion
                    #region Language
                    query = from item in node.Descendants("Language")
                            select item;

                    XElement[] languageNode = query.ToArray();

                    foreach (XElement languages in languageNode)
                    {
                        games.Language = LanguageServices.GetLanguage(Util.GetElementValue(languages, "DisplayName"), true);
                    }
                    #endregion
                    Dal.GetInstance.AddGame(games);
                    _intAddedItem++;

                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }