Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public static bool Fill(Hashtable objResults, Music objEntity)
        {
            try
            {
                bool bAllfind = true;
                if (objResults != null)
                {
                    #region Artist

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

                        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("Singer");
                                }

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

                    if (objEntity.Artists.Count == 0)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Album
                    if (objResults.ContainsKey("Album"))
                    {
                        if (string.IsNullOrWhiteSpace(objEntity.Album))
                        {
                            objEntity.Album = objResults["Album"].ToString();
                        }
                    }
                    #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();
                        }
                    }
                    #endregion
                    #region Cdart
                    if (objResults.ContainsKey("Cdart"))
                    {
                        if (objResults["Cdart"] != null)
                        {
                            RessourcesServices.AddImage(Util.GetImage(objResults["Cdart"].ToString()), objEntity, false);
                        }
                    }
                    #endregion
                    #region Description
                    if (objResults.ContainsKey("Description"))
                    {
                        if (string.IsNullOrWhiteSpace(objEntity.Comments))
                        {
                            objEntity.Comments = Util.PurgeHtml(objResults["Description"].ToString());
                        }
                    }
                    #endregion
                    #region Publisher
                    if (objResults.ContainsKey("Editor"))
                    {
                        bool isNew;
                        if (objEntity.Publisher == null)
                        {
                            objEntity.Publisher = PublisherServices.GetPublisher((string)objResults["Editor"], out isNew, "Music_Studio");
                        }
                    }
                    #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 Links
                    if (objResults.ContainsKey("Links"))
                    {
                        if (objResults["Links"].GetType() == typeof(List <string>))
                        {
                            LinksServices.AddLinks((List <string>)objResults["Links"], objEntity, false);
                        }
                        else
                        {
                            LinksServices.AddLinks(objResults["Links"].ToString().Trim(), objEntity, false);
                        }
                    }
                    #endregion
                    #region Rating
                    if (objResults.ContainsKey("Rating"))
                    {
                        if (objEntity.PublicRating == null)
                        {
                            objEntity.PublicRating = Convert.ToDouble(objResults["Rating"], CultureInfo.InvariantCulture);
                        }
                    }

                    #endregion
                    #region Released
                    if (objResults.ContainsKey("Released"))
                    {
                        if (objEntity.ReleaseDate == null && objResults["Released"] != 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 objTemp;
                                    if (DateTime.TryParse(objResults["Released"].ToString(), out objTemp) == true)
                                    {
                                        objEntity.ReleaseDate = objTemp;
                                    }
                                }
                            }
                            else if (objResults["Released"] is DateTime)
                            {
                                objEntity.ReleaseDate = objResults["Released"] as DateTime?;
                            }
                            else
                            {
                                DateTime objTemp;
                                if (DateTime.TryParse(objResults["Released"].ToString(), out objTemp) == true)
                                {
                                    objEntity.ReleaseDate = objTemp;
                                }
                            }
                        }
                    }
                    if (objEntity.ReleaseDate == null)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Runtime
                    if (objResults.ContainsKey("Runtime"))
                    {
                        if (objEntity.Runtime == null)
                        {
                            objEntity.Runtime = Convert.ToInt32(objResults["Runtime"]);
                        }
                    }
                    #endregion
                    #region Title
                    if (objResults.ContainsKey("Title") && string.IsNullOrWhiteSpace(objEntity.Title))
                    {
                        objEntity.Title = objResults["Title"].ToString();
                    }
                    if (string.IsNullOrWhiteSpace(objEntity.Title))
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Tracks
                    if (objResults.ContainsKey("Tracks"))
                    {
                        if (objEntity.Tracks.Count == 0)
                        {
                            AddTracks((List <string>)objResults["Tracks"], objEntity);
                        }
                    }
                    if (objEntity.Tracks.Count == 0)
                    {
                        bAllfind = false;
                    }
                    #endregion
                    #region Types
                    if (objResults.ContainsKey("Types"))
                    {
                        GenreServices.AddGenres((List <string>)objResults["Types"], objEntity, false);
                    }
                    if (objEntity.Genres.Count == 0)
                    {
                        bAllfind = false;
                    }
                    #endregion
                }
                else
                {
                    bAllfind = false;
                }

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