public static Audio GetMovieAudio(string format, string langue)
        {
            if (string.IsNullOrEmpty(format) == true || string.IsNullOrEmpty(langue))
            {
                return(null);
            }

            Audio audio = new Audio();

            audio.AudioType = AudioTypeServices.Get(format);
            audio.Language  = LanguageServices.GetLanguage(langue, false);

            return(audio);
        }
Beispiel #2
0
        public static void Add(IEnumerable <string> subs, IMyCollectionsData objEntity)
        {
            foreach (string item in subs)
            {
                string sub = item.Trim();
                if (string.IsNullOrWhiteSpace(sub) == false)
                {
                    Language lang = LanguageServices.GetLanguage(sub, true);

                    bool bFind = objEntity.Subtitles.Any(movieSub => movieSub.DisplayName == lang.DisplayName);

                    if (bFind == false)
                    {
                        lang             = new Language();
                        lang.ShortName   = sub;
                        lang.DisplayName = sub;

                        objEntity.Subtitles.Add(lang);
                    }
                }
            }
        }
Beispiel #3
0
        public static bool Fill(Hashtable objResults, Apps objEntity)
        {
            try
            {
                bool bAllfind = true;

                if (objResults != null)
                {
                    #region Background
                    if (objResults.ContainsKey("Background"))
                    {
                        if (objResults["Background"] != null)
                        {
                            RessourcesServices.AddBackground(Util.GetImage(objResults["Background"].ToString()), objEntity);
                        }
                    }
                    #endregion
                    #region BarCode
                    if (objResults.ContainsKey("BarCode"))
                    {
                        if (string.IsNullOrWhiteSpace(objEntity.BarCode) == true)
                        {
                            objEntity.BarCode = objResults["BarCode"].ToString().Trim();
                        }
                    }
                    if (string.IsNullOrEmpty(objEntity.BarCode) == true)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Comments
                    if (objResults.ContainsKey("Comments"))
                    {
                        if (string.IsNullOrWhiteSpace(objEntity.Comments))
                        {
                            objEntity.Comments = objResults["Comments"].ToString().Trim();
                        }
                    }
                    if (string.IsNullOrWhiteSpace(objEntity.Comments) == true)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Description
                    if (objResults.ContainsKey("Description"))
                    {
                        if (string.IsNullOrWhiteSpace(objEntity.Description) == true)
                        {
                            objEntity.Description = objResults["Description"].ToString().Trim();
                        }
                    }
                    if (string.IsNullOrWhiteSpace(objEntity.Description) == true)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Publisher
                    if (objResults.ContainsKey("Editor"))
                    {
                        bool isNew;
                        if (objEntity.Publisher == null)
                        {
                            objEntity.Publisher = PublisherServices.GetPublisher(objResults["Editor"].ToString().Trim(), out isNew, "App_Editor");
                        }
                    }
                    #endregion
                    #region Image
                    int index;
                    if (objResults.ContainsKey("Image"))
                    {
                        if (objResults["Image"] != null)
                        {
                            if (!string.IsNullOrWhiteSpace(objResults["Image"].ToString()))
                            {
                                byte[] objImage     = Util.GetImage(objResults["Image"].ToString());
                                byte[] defaultCover = RessourcesServices.GetDefaultCover(objEntity, out index);
                                if (objImage != null)
                                {
                                    if (defaultCover == null || objEntity.RemoveCover == true || defaultCover.LongLength < objImage.LongLength)
                                    {
                                        if (objResults["Image"] != null)
                                        {
                                            RessourcesServices.AddImage(Util.GetImage(objResults["Image"].ToString()), objEntity, true);
                                            objEntity.RemoveCover = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (RessourcesServices.GetDefaultCover(objEntity, out index) == null)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Language
                    if (objResults.ContainsKey("Language"))
                    {
                        if (objEntity.Language == null)
                        {
                            objEntity.Language = LanguageServices.GetLanguage(objResults["Language"].ToString().Trim(), false);
                        }
                    }
                    if (objEntity.Language == null)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Links
                    if (objResults.ContainsKey("Links"))
                    {
                        LinksServices.AddLinks(objResults["Links"].ToString().Trim(), objEntity, false);
                    }
                    if (objEntity.Links.Count == 0)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Rating
                    if (objResults.ContainsKey("Rating"))
                    {
                        if (objEntity.PublicRating == null)
                        {
                            objEntity.PublicRating = Convert.ToDouble(objResults["Rating"], CultureInfo.InvariantCulture);
                        }
                    }
                    if (objEntity.PublicRating == null)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Released
                    if (objResults.ContainsKey("Released"))
                    {
                        if (objEntity.ReleaseDate == null &&
                            objResults["Released"].ToString().Trim().IndexOf("inconnue",
                                                                             StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            string strDate = objResults["Released"].ToString().Trim();
                            if (strDate.Length < 10)
                            {
                                if (strDate.Length == 4)
                                {
                                    DateTime objTemp =
                                        new DateTime(Convert.ToInt32(strDate, CultureInfo.InvariantCulture), 1, 1);
                                    objEntity.ReleaseDate = objTemp;
                                }
                                else
                                {
                                    DateTime objTmp;
                                    if (DateTime.TryParse(objResults["Released"].ToString(), out objTmp) == true)
                                    {
                                        objEntity.ReleaseDate = objTmp;
                                    }
                                }
                            }
                            else
                            {
                                DateTime objTmp;
                                if (DateTime.TryParse(objResults["Released"].ToString(), out objTmp) == true)
                                {
                                    objEntity.ReleaseDate = objTmp;
                                }
                            }
                        }
                    }
                    if (objEntity.ReleaseDate == null)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Title
                    if (objResults.ContainsKey("Title") && (string.IsNullOrWhiteSpace(objEntity.Title) || MySettings.RenameFile == true))
                    {
                        objEntity.Title = objResults["Title"].ToString();
                        if (MySettings.RenameFile == true && string.IsNullOrWhiteSpace(objEntity.FileName) == false)
                        {
                            objEntity.FileName = Util.RenameFile(objEntity.Title, objEntity.FileName, objEntity.FilePath);
                        }
                    }
                    if (string.IsNullOrWhiteSpace(objEntity.Title))
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Type
                    if (objResults.ContainsKey("Types"))
                    {
                        GenreServices.AddGenres((List <string>)objResults["Types"], objEntity, false);
                    }
                    else
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Version
                    if (objResults.ContainsKey("Version"))
                    {
                        if (string.IsNullOrWhiteSpace(objEntity.Version) == true)
                        {
                            objEntity.Version = objResults["Version"].ToString();
                        }
                    }
                    if (string.IsNullOrWhiteSpace(objEntity.Version) == true)
                    {
                        bAllfind = false;
                    }
                    #endregion
                }
                else
                {
                    bAllfind = false;
                }

                objEntity.IsComplete = bAllfind;
                return(bAllfind);
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
                return(false);
            }
        }
        public static void ParseNfo(Nds objEntity, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (string.IsNullOrWhiteSpace(objEntity.FilePath))
            {
                errorMessage = "Nfo File not found";
            }
            else
            {
                string strFilePath;
                if (objEntity.FilePath.EndsWith(@"\", StringComparison.OrdinalIgnoreCase) == true)
                {
                    strFilePath = objEntity.FilePath + objEntity.FileName;
                }
                else
                {
                    strFilePath = objEntity.FilePath + @"\" + objEntity.FileName;
                }

                //FIX 2.82.0
                if (Directory.Exists(strFilePath))
                {
                    DirectoryInfo objFolder = new DirectoryInfo(strFilePath);

                    FileInfo[] lstFile = objFolder.GetFiles("*.nfo", SearchOption.AllDirectories);

                    if (lstFile.Any())
                    {
                        Hashtable objNfoValue = Dal.ParseNfo(lstFile[0].FullName);
                        #region Publisher

                        if (objEntity.Publisher == null)
                        {
                            if (objNfoValue.ContainsKey("Editor") == true)
                            {
                                Publisher objEditor = Dal.GetInstance.GetPublisher(objNfoValue["Editor"].ToString().Trim(), "App_Editor", "Name");
                                if (objEditor == null)
                                {
                                    objEditor      = new Publisher();
                                    objEditor.Name = objNfoValue["Editor"].ToString().Trim();
                                }
                                objEntity.Publisher = objEditor;
                            }
                        }

                        #endregion
                        #region Language

                        if (objEntity.Language == null)
                        {
                            if (objNfoValue.ContainsKey("Language") == true)
                            {
                                objEntity.Language = LanguageServices.GetLanguage(objNfoValue["Language"].ToString().Trim(), false);
                            }
                        }

                        #endregion
                        #region GamezType

                        if (objEntity.Genres == null || objEntity.Genres.Count == 0)
                        {
                            if (objNfoValue.ContainsKey("Type") == true)
                            {
                                Genre objGamezType = Dal.GetInstance.GetGenre(objNfoValue["Type"].ToString().Trim(), "GamezType");
                                if (objGamezType == null)
                                {
                                    objGamezType = new Genre(objNfoValue["Type"].ToString().Trim(), objNfoValue["Type"].ToString().Trim());
                                }

                                if (objEntity.Genres == null)
                                {
                                    objEntity.Genres = new List <Genre>();
                                }

                                objEntity.Genres.Add(objGamezType);
                            }
                        }

                        #endregion
                        #region Links
                        if (objNfoValue.ContainsKey("Links"))
                        {
                            LinksServices.AddLinks(objNfoValue["Links"].ToString().Trim(), objEntity, false);
                        }
                        #endregion
                        #region Released

                        if (objEntity.ReleaseDate == null)
                        {
                            if (objNfoValue.ContainsKey("Released") == true)
                            {
                                string strTempDate = objNfoValue["Released"].ToString().Trim();
                                if (strTempDate.Length == 8)
                                {
                                    strTempDate = strTempDate.Insert(2, @"/");
                                    strTempDate = strTempDate.Insert(5, @"/");
                                }
                                DateTime objDate;
                                if (DateTime.TryParse(strTempDate, out objDate) == true)
                                {
                                    objEntity.ReleaseDate = objDate;
                                }
                            }
                        }

                        #endregion
                    }
                    else
                    {
                        errorMessage = "Nfo File not found : " + strFilePath;
                    }
                }
                else
                {
                    errorMessage = "Nfo File not found : " + strFilePath;
                }
            }
        }
        public static void Update(IMyCollectionsData entity, string strLanguage, string strMedia, string studio, IEnumerable <string> lstGenres, IEnumerable objLinks,
                                  IEnumerable <string> artistName, string fileFormat, string aspectRatio, string platform, IEnumerable <string> metaData)
        {
            try
            {
                LinksServices.DeleteLinks(entity);
                entity.Media    = MediaServices.Get(strMedia, true);
                entity.Language = LanguageServices.GetLanguage(strLanguage, true);

                #region Publisher

                if (String.IsNullOrWhiteSpace(studio) == false)
                {
                    bool isNew;
                    switch (entity.ObjectType)
                    {
                    case EntityType.Nds:
                    case EntityType.Games:
                    case EntityType.Books:
                    case EntityType.Apps:
                        entity.Publisher = PublisherServices.GetPublisher(studio, out isNew, "App_Editor");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("App_Editor", entity.Publisher);
                        }
                        break;

                    case EntityType.Series:
                    case EntityType.Movie:
                        entity.Publisher = PublisherServices.GetPublisher(studio, out isNew, "Movie_Studio");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("Movie_Studio", entity.Publisher);
                        }
                        break;

                    case EntityType.Music:
                        entity.Publisher = PublisherServices.GetPublisher(studio, out isNew, "Music_Studio");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("Music_Studio", entity.Publisher);
                        }
                        break;

                    case EntityType.XXX:
                        entity.Publisher = PublisherServices.GetPublisher(studio, out isNew, "XXX_Studio");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("XXX_Studio", entity.Publisher);
                        }
                        break;
                    }
                }

                #endregion


                if (String.IsNullOrWhiteSpace(entity.FilePath))
                {
                    entity.FilePath = String.Empty;
                }

                switch (entity.ObjectType)
                {
                case EntityType.Apps:
                    Dal.GetInstance.AddApps(entity as Apps);
                    break;

                case EntityType.Books:
                    #region FileFormat
                    if (entity.FileFormat == null)
                    {
                        entity.FileFormat = BookServices.GetFormat(fileFormat, true);
                    }
                    else if (entity.FileFormat.Name != fileFormat)
                    {
                        entity.FileFormat = BookServices.GetFormat(fileFormat, true);
                    }
                    #endregion
                    Dal.GetInstance.AddBook(entity as Books);
                    break;

                case EntityType.Games:
                    entity.Platform = GameServices.GetPlatform(platform, true);
                    Dal.GetInstance.AddGame(entity as Gamez);
                    break;

                case EntityType.Movie:
                    #region FileFormat
                    if (entity.FileFormat == null)
                    {
                        entity.FileFormat = MovieServices.GetFormat(fileFormat);
                    }
                    else if (entity.FileFormat.Name != fileFormat)
                    {
                        entity.FileFormat = MovieServices.GetFormat(fileFormat);
                    }
                    #endregion
                    #region AspectRatio
                    if (entity.AspectRatio == null)
                    {
                        entity.AspectRatio = MovieServices.GetAspectRatio(aspectRatio);
                    }
                    else if (entity.AspectRatio.Name != aspectRatio)
                    {
                        entity.AspectRatio = MovieServices.GetAspectRatio(aspectRatio);
                    }
                    #endregion
                    Dal.GetInstance.AddMovie(entity as Movie);
                    break;

                case EntityType.Music:
                    if (MySettings.AutoUpdateID3 == true)
                    {
                        Task.Factory.StartNew(() => MusicServices.UpdateId3(entity as Music));
                    }
                    Dal.GetInstance.AddMusic(entity as Music);
                    Dal.GetInstance.AddTracks(entity as Music);
                    break;

                case EntityType.Nds:
                    Dal.GetInstance.AddNds(entity as Nds);
                    break;

                case EntityType.Series:
                    Dal.GetInstance.AddSeriesSeason(entity as SeriesSeason);
                    break;

                case EntityType.XXX:
                    Dal.GetInstance.AddXxx(entity as XXX);
                    break;
                }

                #region Genres
                Dal.GetInstance.UnlinkGenre(entity);

                GenreServices.AddGenres(lstGenres, entity, true);
                #endregion
                #region MetaData
                Dal.GetInstance.UnlinkMetaData(entity);
                MetaDataServices.Link(entity, metaData);
                #endregion

                LinksServices.AddLinks(objLinks.Cast <string>(), entity, true);
                RessourcesServices.UpdateRessources(entity);

                #region Artist

                if (entity.ObjectType != EntityType.Books && entity.ObjectType != EntityType.Music)
                {
                    Task.Factory.StartNew(() => UpdateArtist(entity, artistName));
                }
                else
                {
                    UpdateArtist(entity, artistName);
                }

                #endregion
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
                throw;
            }
        }
        public static Books Fill(Hashtable objResults, Books objEntity, ref bool bAllfind)
        {
            try
            {
                bAllfind = true;
                if (objResults != null)
                {
                    #region Author

                    if (objResults.ContainsKey("Author"))
                    {
                        Artist artist = (Artist)objResults["Author"];

                        if (objEntity.Artists == null)
                        {
                            objEntity.Artists = new List <Artist>();
                        }

                        if (objEntity.Artists.Count == 0 || objEntity.Artists.Any(x => x.IsOld == false) == false)
                        {
                            if (artist != null)
                            {
                                if (artist.Job == null)
                                {
                                    artist.Job = ArtistServices.GetJob("Author");
                                }

                                objEntity.Artists.Add(artist);
                            }
                        }
                    }

                    if (objEntity.Artists.Count == 0)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Background
                    if (objResults.ContainsKey("Background"))
                    {
                        if (objResults["Background"] != null)
                        {
                            RessourcesServices.AddBackground(Util.GetImage(objResults["Background"].ToString()), objEntity);
                        }
                    }
                    #endregion
                    #region BarCode
                    if (objResults.ContainsKey("BarCode"))
                    {
                        if (string.IsNullOrEmpty(objEntity.BarCode) == true)
                        {
                            objEntity.BarCode = objResults["BarCode"].ToString().Trim();
                        }
                    }
                    else if (string.IsNullOrEmpty(objEntity.BarCode) == true)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Comments

                    if (objResults.ContainsKey("Comments"))
                    {
                        if (string.IsNullOrEmpty(objEntity.Comments) == true)
                        {
                            objEntity.Comments = objResults["Comments"].ToString().Trim();
                        }
                    }
                    else if (string.IsNullOrEmpty(objEntity.Comments) == true)
                    {
                        bAllfind = false;
                    }

                    #endregion
                    #region Description
                    if (objResults.ContainsKey("Description"))
                    {
                        if (string.IsNullOrEmpty(objEntity.Description) == true)
                        {
                            objEntity.Description = objResults["Description"].ToString().Trim();
                        }
                    }
                    else if (string.IsNullOrEmpty(objEntity.Description) == true)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Format
                    if (objResults.ContainsKey("Format"))
                    {
                        if (objEntity.FileFormat == null)
                        {
                            objEntity.FileFormat = GetFormat(objResults["Format"].ToString().Trim(), false);
                        }
                    }
                    #endregion
                    #region Publisher
                    if (objResults.ContainsKey("Editor"))
                    {
                        bool isNew;
                        if (objEntity.Publisher == null)
                        {
                            objEntity.Publisher = PublisherServices.GetPublisher(objResults["Editor"].ToString().Trim(), out isNew, "App_Editor");
                        }
                    }
                    #endregion
                    #region Image
                    int index;
                    if (objResults.ContainsKey("Image"))
                    {
                        if (objResults["Image"] != null)
                        {
                            if (!string.IsNullOrWhiteSpace(objResults["Image"].ToString()))
                            {
                                byte[] objImage     = Util.GetImage(objResults["Image"].ToString());
                                byte[] defaultCover = RessourcesServices.GetDefaultCover(objEntity, out index);
                                if (objImage != null)
                                {
                                    if (defaultCover == null || objEntity.RemoveCover == true || defaultCover.LongLength < objImage.LongLength)
                                    {
                                        if (objResults["Image"] != null)
                                        {
                                            RessourcesServices.AddImage(Util.GetImage(objResults["Image"].ToString()), objEntity, true);
                                            objEntity.RemoveCover = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (RessourcesServices.GetDefaultCover(objEntity, out index) == null)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region ISBN
                    if (objResults.ContainsKey("ISBN"))
                    {
                        if (string.IsNullOrEmpty(objEntity.Isbn) == true)
                        {
                            objEntity.Isbn = objResults["ISBN"].ToString().Trim();
                        }
                    }
                    else if (string.IsNullOrEmpty(objEntity.Isbn) == true)
                    {
                        bAllfind = false;
                    }

                    #endregion
                    #region Language
                    if (objResults.ContainsKey("Language"))
                    {
                        if (objEntity.Language == null)
                        {
                            objEntity.Language = LanguageServices.GetLanguage(objResults["Language"].ToString().Trim(), false);
                        }
                    }
                    #endregion
                    #region Links
                    if (objResults.ContainsKey("Links"))
                    {
                        LinksServices.AddLinks(objResults["Links"].ToString().Trim(), objEntity, false);
                    }
                    else if (objEntity.Genres.Count == 0)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Pages
                    if (objResults.ContainsKey("Pages"))
                    {
                        if (objEntity.NbrPages == 0)
                        {
                            int intNbrPages;
                            if (int.TryParse(objResults["Pages"].ToString(), out intNbrPages) == true)
                            {
                                objEntity.NbrPages = intNbrPages;
                            }
                        }
                    }
                    #endregion
                    #region ReleaseDate
                    if (objResults.ContainsKey("Released"))
                    {
                        if (objEntity.ReleaseDate == null &&
                            objResults["Released"].ToString().Trim().IndexOf("inconnue",
                                                                             StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            string strDate = objResults["Released"].ToString().Trim();
                            if (strDate.Length < 10)
                            {
                                if (strDate.Length == 4)
                                {
                                    DateTime objTemp =
                                        new DateTime(Convert.ToInt32(strDate, CultureInfo.InvariantCulture), 1, 1);
                                    objEntity.ReleaseDate = objTemp;
                                }
                                else
                                {
                                    DateTime objTmp;
                                    if (DateTime.TryParse(objResults["Released"].ToString(), out objTmp) == true)
                                    {
                                        objEntity.ReleaseDate = objTmp;
                                    }
                                }
                            }
                            else
                            {
                                DateTime objTmp;
                                if (DateTime.TryParse(objResults["Released"].ToString(), out objTmp) == true)
                                {
                                    objEntity.ReleaseDate = objTmp;
                                }
                            }
                        }
                    }
                    else if (objEntity.ReleaseDate == null)
                    {
                        bAllfind = false;
                    }

                    #endregion
                    #region Rating

                    if (objResults.ContainsKey("Rating"))
                    {
                        if (objEntity.PublicRating == null)
                        {
                            double intRating;
                            if (double.TryParse(objResults["Rating"].ToString(), out intRating) == true)
                            {
                                objEntity.PublicRating = intRating;
                            }
                        }
                    }
                    if (objEntity.PublicRating == null)
                    {
                        bAllfind = false;
                    }

                    #endregion
                    #region Title
                    if (objResults.ContainsKey("Title") && (string.IsNullOrWhiteSpace(objEntity.Title) || MySettings.RenameFile == true))
                    {
                        objEntity.Title = objResults["Title"].ToString();
                        if (MySettings.RenameFile == true && string.IsNullOrWhiteSpace(objEntity.FileName) == false)
                        {
                            objEntity.FileName = Util.RenameFile(objEntity.Title, objEntity.FileName, objEntity.FilePath);
                        }
                    }
                    if (string.IsNullOrWhiteSpace(objEntity.Title))
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Types
                    if (objResults.ContainsKey("Types"))
                    {
                        GenreServices.AddGenres((IList <string>)objResults["Types"], objEntity, false);
                    }
                    if (objEntity.Genres.Count == 0)
                    {
                        bAllfind = false;
                    }
                    #endregion
                }
                else
                {
                    bAllfind = false;
                }

                objEntity.IsComplete = bAllfind;
                return(objEntity);
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
                return(objEntity);
            }
        }