public ActionResult AddGenre(GenreModel model)
        {
            _genreServices = new GenreServices();
            _genreServices.InsertGenre(model);

            return(RedirectToAction("ListGenre"));
        }
        public ActionResult EditGenre(int id)
        {
            _genreServices = new GenreServices();
            var model = _genreServices.GetGenreById(id);

            return(View(model));
        }
        public void AddNewGenre_WhenParametersAreCorrect(string genreName)
        {
            //Arrange
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var genreRepoMock  = new Mock <IRepository <Genre> >();

            var predifinedListOfGenres = new List <Genre>();
            var genreMock = new Mock <Genre>();

            //Setup
            unitOfWorkMock.Setup(unitOfWork => unitOfWork.Genres)
            .Returns(genreRepoMock.Object);

            genreRepoMock.Setup(repo => repo.Add(It.IsAny <Genre>()))
            .Callback <Genre>((genre) =>
            {
                predifinedListOfGenres.Add(genreMock.Object);
            });

            //Act
            var genreServices = new GenreServices(unitOfWorkMock.Object);

            genreServices.AddNewGenre(genreName);

            //Assert
            Assert.AreEqual(1, predifinedListOfGenres.Count);
        }
        public void AddGenre_WhenMethodIsCall_ShouldReturnGenre()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "AddGenre").Options;

            var validationMock = new Mock <IValidations>();

            string genre = "newGenre";

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unit = new UnitOfWork(actContext);

                var service = new GenreServices(unit, validationMock.Object);
                var result  = service.AddGenre(genre);
            }

            // Assert
            using (var assertContex = new LibrarySystemContext(contexInMemory))
            {
                int cont = assertContex.Genres.Count();
                Assert.AreEqual(1, cont);
                Assert.AreEqual(genre, assertContex.Genres.First().GenreName);
            }
        }
Beispiel #5
0
        public void DeleteGenre_WhenObjectExists()
        {
            //Arrange
            genre.IsDeleted = false;

            genreRepoMock
            .Setup(repo => repo.Delete(It.IsAny <Genre>()))
            .Callback <Genre>((genre) =>
            {
                predifinedListOfGenres.Remove(genre);
            });

            unitOfWork.Setup(x => x.Genres)
            .Returns(genreRepoMock.Object);

            genreRepoMock.Setup(repo => repo.AllAndDeleted())
            .Returns(predifinedListOfGenres.AsQueryable());

            //Act
            var command = new GenreServices(unitOfWork.Object);

            command.DeleteGenre(genre.Name);

            //Assert
            Assert.AreEqual(0, predifinedListOfGenres.Count);
        }
Beispiel #6
0
        private void cmdSave_Click(object sender, RoutedEventArgs e)
        {
            IList objSource = GenreServices.GetGenres(_itemsType);
            IList objTarget = (IList)dtgData.DataContext;

            if (objSource != null)
            {
                foreach (Genre item in objSource)
                {
                    Genre type = item;
                    if (!objTarget.Contains(type))
                    {
                        GenreServices.DeleteGenre(item, _itemsType);
                    }
                }
            }
            foreach (Genre item in objTarget)
            {
                if (string.IsNullOrWhiteSpace(item.RealName) == false || string.IsNullOrWhiteSpace(item.DisplayName) == false)
                {
                    if (string.IsNullOrWhiteSpace(item.RealName))
                    {
                        item.RealName = item.DisplayName;
                    }

                    if (string.IsNullOrWhiteSpace(item.RealName) == false && _added.Contains(item.RealName) == false)
                    {
                        new GenreServices().AddGenre(item, _itemsType);
                        _added.Add(item.RealName);
                    }
                }
            }

            Close();
        }
Beispiel #7
0
        public void GetAll_Should_GetAll()
        {
            var db            = new TFContext(this.DatabaseSimulator());
            var genreServices = new GenreServices(db);

            var genre = new Genre()
            {
                Name = genreNameToUse
            };
            var secondGenre = new Genre()
            {
                Name = "drama"
            };
            var thirdGenre = new Genre()
            {
                Name = "animation"
            };
            var deletedGenre = new Genre()
            {
                Name      = "comedy",
                IsDeleted = true
            };

            db.Genres.Add(genre);
            db.Genres.Add(secondGenre);
            db.Genres.Add(thirdGenre);
            db.Genres.Add(deletedGenre);
            db.SaveChanges();

            int getAllMethod = genreServices.GetAll().Count();

            Assert.AreEqual(3, getAllMethod);
        }
        public ActionResult ListGenre()
        {
            _genreServices = new GenreServices();
            var model = _genreServices.GetGenreList();

            return(View(model));
        }
Beispiel #9
0
        public void GetGenre_WhenMethodIsCall_ShouldReturnGenre()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "GetGenre").Options;

            var validationMock = new Mock <IValidations>();

            string genreName = "Genre";
            string book1     = "book1";
            string book2     = "book2";

            var authorBooks = new List <Book>();

            authorBooks.Add(new Book()
            {
                Title = book1
            });
            authorBooks.Add(new Book()
            {
                Title = book2
            });

            var genre = new Genre()
            {
                Id        = 1,
                GenreName = genreName,
                Books     = authorBooks
            };

            using (var arrangeContext = new LibrarySystemContext(contexInMemory))
            {
                arrangeContext.Genres.Add(genre);
                arrangeContext.SaveChanges();
            }

            GenreViewModel result;

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unitOfWork = new UnitOfWork(actContext);
                var service    = new GenreServices(unitOfWork, validationMock.Object);

                result = service.GetGenre(genreName);
            }

            // Assert
            Assert.AreEqual(genreName, result.GenreName);
            Assert.AreEqual(2, result.BooksByGenre.Count);
        }
Beispiel #10
0
        public void Add_Should_AddCorrect()
        {
            var db            = new TFContext(this.DatabaseSimulator());
            var genreServices = new GenreServices(db);

            var genre = new Genre()
            {
                Name = genreNameToUse
            };

            genreServices.Add(genre);

            Assert.AreEqual(1, db.Genres.Count());
        }
Beispiel #11
0
        public void ThrowEntityDoesntExistException_WhenGenreDoesNotExist()
        {
            //Act
            var genreServices = new GenreServices(unitOfWork.Object);

            unitOfWork.Setup(x => x.Genres)
            .Returns(genreRepoMock.Object);

            genreRepoMock.Setup(repo => repo.AllAndDeleted())
            .Returns(resultFromGenreRepo.AsQueryable());

            //Assert
            Assert.ThrowsException <EntityDoesntExistException>(()
                                                                => genreServices.GetID("NonExistingGenre"));
        }
Beispiel #12
0
        public void ReturnCorrectGenreId_WhenGenreExists()
        {
            //Arrange
            unitOfWork.Setup(x => x.Genres)
            .Returns(genreRepoMock.Object);

            genreRepoMock.Setup(repo => repo.AllAndDeleted())
            .Returns(resultFromGenreRepo.AsQueryable());

            //Act
            var genreServices = new GenreServices(unitOfWork.Object);
            int result        = genreServices.GetID(testGenreName);

            //Assert
            Assert.AreEqual(genre.Id, result);
        }
Beispiel #13
0
        public void Add_Should_ThrowWhenGenreAlreadyExists()
        {
            var db            = new TFContext(this.DatabaseSimulator());
            var genreServices = new GenreServices(db);

            var genre = new Genre()
            {
                Name = genreNameToUse
            };

            db.Genres.Add(genre);
            db.SaveChanges();

            Assert.ThrowsException <EntityAlreadyExistingException>
                (() => genreServices.Add(genre));
        }
        private void cmdUpdate_Click(object sender, RoutedEventArgs e)
        {
            Cursor = Cursors.Wait;
            List <string> lstGenres = (from CheckBox item in RootPanel.Children
                                       where item.IsChecked == true
                                       select item.Content.ToString()).ToList();

            foreach (ThumbItem item in _items)
            {
                IMyCollectionsData entity = _service.Get(item.Id);
                GenreServices.UnlinkGenre(entity);
                GenreServices.AddGenres(lstGenres, entity, true);
            }

            Close();
            Cursor = null;
        }
Beispiel #15
0
        public void GetGenre_WhenGenreDontExist_ThrowException()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "GetGenreDontExist").Options;

            var validationMock = new Mock <IValidations>();

            string genreName = "Genre";

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unitOfWork = new UnitOfWork(actContext);
                var service    = new GenreServices(unitOfWork, validationMock.Object);

                service.GetGenre(genreName);
            }
        }
Beispiel #16
0
        public void GenreExist_Should_ReturnTrueWhenExistAndNoWhenDoesNot()
        {
            var db            = new TFContext(this.DatabaseSimulator());
            var genreServices = new GenreServices(db);

            var genre = new Genre()
            {
                Name = genreNameToUse
            };
            bool doNotExist = genreServices.GenreExists(genreNameToUse);

            db.Genres.Add(genre);
            db.SaveChanges();


            bool exist = genreServices.GenreExists(genreNameToUse);

            Assert.IsFalse(doNotExist);
            Assert.IsTrue(exist);
        }
        public void AddGenre_WhenAuthorExist_ShouldReturnAddToDatabase()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "AddGenreExist").Options;

            var validationMock = new Mock <IValidations>();

            string genre = "newAuthor";

            var existingGenre = new Genre()
            {
                Id        = 1,
                GenreName = genre
            };
            int result;

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unit = new UnitOfWork(actContext);
                var test = actContext.Genres.Add(existingGenre).Entity;
                actContext.SaveChanges();

                var service = new GenreServices(unit, validationMock.Object);
                result = service.AddGenre(genre);
            }

            // Assert
            using (var assertContext = new LibrarySystemContext(contexInMemory))
            {
                var toAssert = assertContext.Genres
                               .SingleOrDefault(g => g.GenreName == genre);

                int count = assertContext.Genres.Count();

                Assert.AreEqual(1, count);
                Assert.AreEqual(toAssert.Id, result);
            }
        }
        private void addCustomeType_Click(object sender, RoutedEventArgs e)
        {
            AddLink addlink = new AddLink();

            addlink.ShowDialog();
            if (string.IsNullOrWhiteSpace(addlink.Link) == false)
            {
                string newtype = addlink.Link;
                GenreServices.GetGenre(newtype, _objEntity.ObjectType);
                bool bExist = RootPanel.Children.Cast <CheckBox>().Any(item => item.Content.ToString() == newtype);

                if (bExist == false)
                {
                    CheckBox objCheckBox = new CheckBox();
                    objCheckBox.Margin = new Thickness(5, 0, 0, 0);

                    objCheckBox.Content   = newtype;
                    objCheckBox.IsChecked = true;
                    RootPanel.Children.Add(objCheckBox);
                }
            }
        }
        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;
                    }

                    SeriesSeason seriesSeason = new SeriesSeason();
                    seriesSeason.BarCode         = Util.GetElementValue(node, "BarCode");
                    seriesSeason.Comments        = Util.GetElementValue(node, "Comments");
                    seriesSeason.Description     = Util.GetElementValue(node, "Description");
                    seriesSeason.FilePath        = Util.GetElementValue(node, "FilePath");
                    seriesSeason.Country         = Util.GetElementValue(node, "Country");
                    seriesSeason.OfficialWebSite = Util.GetElementValue(node, "OfficialWebSite");

                    DateTime dateValue;

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if (int.TryParse(Util.GetElementValue(node, "RunTime"), out longValue) == true)
                    {
                        seriesSeason.Runtime = longValue;
                    }

                    if (int.TryParse(Util.GetElementValue(node, "TotalEpisodes"), out longValue) == true)
                    {
                        seriesSeason.TotalEpisodes = longValue;
                    }
                    #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");
                        seriesSeason.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"), seriesSeason, 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") }, seriesSeason, 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, seriesSeason, isDefault);
                            }
                        }
                        if (Util.GetElementValue(images, "ResourcesType") == "Background")
                        {
                            byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

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

                    XElement[] studioNode = query.ToArray();

                    foreach (XElement editor in studioNode)
                    {
                        bool isNew;
                        seriesSeason.Publisher = PublisherServices.GetPublisher(Util.GetElementValue(editor, "Name"), out isNew, "Movie_Studio");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("Movie_Studio", seriesSeason.Publisher);
                        }
                    }
                    #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 }, seriesSeason);
                    }


                    #endregion
                    Dal.GetInstance.AddSeriesSeason(seriesSeason);
                    _intAddedItem++;

                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }
Beispiel #20
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 #21
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);
            }
        }
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                Total = _selectedItems.Count;

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


                    if (string.IsNullOrWhiteSpace(item) == false)
                    {
                        string[] attributes = item.Split(';');

                        if (string.IsNullOrWhiteSpace(attributes[1]) == false)
                        {
                            Music music = new Music();
                            music.Title     = attributes[1];
                            music.Media     = new Media();
                            music.Media.Id  = _mediaId;
                            music.AddedDate = DateTime.Now;

                            ArtistServices.AddArtist(attributes[0], music);
                            GenreServices.AddGenres(new List <string> {
                                attributes[2]
                            }, music, true);

                            music.Comments = attributes[4];

                            List <string> tracks = new List <string>();
                            for (int i = 5; i < attributes.Length; i++)
                            {
                                if (string.IsNullOrWhiteSpace(attributes[i]) == false)
                                {
                                    tracks.Add(attributes[i]);
                                }
                            }

                            MusicServices.AddTracks(tracks, music);

                            Music bExist = null;
                            if (music.Artists != null && music.Artists.Count > 0)
                            {
                                bExist = Dal.GetInstance.GetMusics(_mediaName, music.Title, music.Artists.First().FirstName, music.Artists.First().LastName);
                            }

                            if (bExist == null)
                            {
                                Dal.GetInstance.AddMusic(music);
                                _intAddedItem++;
                            }
                            else
                            {
                                _intNotAddedItem++;
                            }
                        }
                    }
                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }
Beispiel #24
0
 public ManageItems(EntityType itemsType)
 {
     InitializeComponent();
     _itemsType  = itemsType;
     DataContext = GenreServices.GetGenres(_itemsType);
 }
 public ActionResult DeleteGenre(int id)
 {
     _genreServices = new GenreServices();
     _genreServices.DeleteGenre(id);
     return(RedirectToAction("ListGenre"));
 }
 public ActionResult EditGenre(GenreModel model)
 {
     _genreServices = new GenreServices();
     _genreServices.UpdateGenre(model);
     return(RedirectToAction("ListGenre"));
 }
Beispiel #27
0
        public static Hashtable Parse(string strUrl, string strSearch)
        {
            Hashtable objResults = new Hashtable();

            try
            {
                string strResults = Util.GetHtmlPage(strUrl, Encoding.UTF8);

                if (strResults == null)
                {
                    return(null);
                }

                objResults.Add("Title", strSearch);
                objResults.Add("Links", strUrl);

                #region Description
                string strParsing = @"Descriptif :";
                int    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @"</li>";
                    objResults.Add("Description", Util.PurgeHtml(HttpUtility.HtmlDecode(strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim())));
                }
                #endregion
                #region Editor
                strParsing = @"Editeur :";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @""">";
                    strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                    strParsing = @"</a>";
                    objResults.Add("Editor", strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim());
                }
                else
                {
                    strParsing = @"<strong>D&amp;eacute;veloppeur :</strong>";
                    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                    if (intTmp1 > -1)
                    {
                        strResults = strResults.Substring(intTmp1 + strParsing.Length);
                        strParsing = @""">";
                        strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                        strParsing = @"</a>";
                        objResults.Add("Editor", strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim());
                    }
                }
                #endregion
                #region Types
                strParsing = @"<strong>Type :</strong>";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @"</li>";
                    string types = strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim();
                    if (types.Contains(@""">"))
                    {
                        string[]     lstTypes   = Regex.Split(types, @""">");
                        List <Genre> gamesTypes = new List <Genre>();
                        foreach (string lstType in lstTypes)
                        {
                            if (lstType.StartsWith("<") == false)
                            {
                                strParsing = @"<";
                                string item     = lstType.Substring(0, lstType.IndexOf(strParsing, StringComparison.Ordinal));
                                Genre  gametype = GenreServices.GetGenre(item, EntityType.Games);
                                gamesTypes.Add(gametype);
                            }
                        }

                        objResults.Add("Types", gamesTypes);
                    }
                    else
                    {
                        objResults.Add("Types", new List <string> {
                            types
                        });
                    }
                }
                #endregion
                #region Released Date
                strParsing = @"<strong>Sortie France :</strong>";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @"</li>";

                    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                    strParsing = @"<br";
                    int intTmp2 = strResults.IndexOf(strParsing, StringComparison.Ordinal);

                    if (intTmp2 == -1 || intTmp2 > intTmp1)
                    {
                        objResults.Add("Released", strResults.Substring(0, intTmp1).Trim());
                    }
                    else
                    {
                        objResults.Add("Released", strResults.Substring(0, intTmp2).Trim());
                    }
                }
                #endregion
                strParsing = @"note_redac";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @":";
                    strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                    strParsing = @"<";

                    string strTemp = strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal));
                    if (string.IsNullOrEmpty(strTemp) == false)
                    {
                        strTemp = strTemp.Trim().Split('/')[0];
                        if (Util.IsNumeric(strTemp) == true)
                        {
                            int intTmp = Convert.ToInt32(strTemp, CultureInfo.InvariantCulture);
                            objResults.Add("Rating", intTmp);
                        }
                    }

                    strParsing = @"<li>";
                    strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                    strParsing = @"</li>";

                    objResults.Add("Comments", Util.PurgeHtml(strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.InvariantCultureIgnoreCase)).Trim()));
                }
                if (objResults.ContainsKey("Rating") == false)
                {
                    strParsing = @"Note moyenne des Lecteurs :";
                    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                    if (intTmp1 > -1)
                    {
                        strResults = strResults.Substring(intTmp1 + strParsing.Length);
                        strParsing = @"<";

                        string strTemp = strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal));
                        if (string.IsNullOrEmpty(strTemp) == false)
                        {
                            strTemp = strTemp.Trim().Split('/')[0];
                            if (Util.IsNumeric(strTemp) == true)
                            {
                                int intTmp = Convert.ToInt32(strTemp, CultureInfo.InvariantCulture);
                                objResults.Add("Rating", intTmp);
                            }
                        }
                    }
                }
                if (objResults.ContainsKey("Comments") == false)
                {
                    strParsing = @"Dernier avis :";
                    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                    if (intTmp1 > -1)
                    {
                        strResults = strResults.Substring(intTmp1 + strParsing.Length);
                        strParsing = @">";
                        strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                        strParsing = @"<";

                        objResults.Add("Comments", Util.PurgeHtml(strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.InvariantCultureIgnoreCase)).Trim()));
                    }
                }
                #region Image
                strParsing = @"li class=""recto_verso"">";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @"<a href=""";
                    strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                    strParsing = @"""";
                    strResults = strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim();
                    strParsing = @"affpic.htm?";

                    if (strResults.Contains(strParsing))
                    {
                        strResults = strResults.Replace(strParsing, "");
                    }

                    if (strResults.Contains(".htm") == false)
                    {
                        objResults.Add("Image", strResults);
                    }
                    else
                    {
                        string pageimage = Util.GetHtmlPage(strResults, Encoding.GetEncoding("iso-8859-1"));
                        strParsing = strResults;
                        pageimage  = pageimage.Substring(pageimage.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                        strParsing = @"src='";
                        pageimage  = pageimage.Substring(pageimage.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                        strParsing = @"'";
                        pageimage  = pageimage.Substring(0, pageimage.IndexOf(strParsing, StringComparison.Ordinal)).Trim();
                        objResults.Add("Image", pageimage);
                    }
                }
                #endregion
                objResults.Add("Platform", GetPlateform(strUrl));

                return(objResults);
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
                return(null);
            }
        }
Beispiel #28
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 #29
0
        public static Hashtable Parse(string strId)
        {
            Hashtable objResults = new Hashtable();

            try
            {
                const string imageUrl = @"http://thegamesdb.net/banners/";
                Uri          strUrl   = new Uri(string.Format(Url + @"/GetGame.php?id={0}", strId));
                string       results  = Util.GetRest(strUrl);

                if (string.IsNullOrWhiteSpace(results))
                {
                    return(null);
                }

                XElement restResponse = XElement.Parse(results);

                TheGamesDb game = TheGamesDb.GamesToObject(restResponse);
                if (game != null)
                {
                    if (string.IsNullOrWhiteSpace(game.Background) == false)
                    {
                        objResults.Add("Background", imageUrl + game.Background);
                    }

                    if (string.IsNullOrWhiteSpace(game.Cover) == false)
                    {
                        objResults.Add("Image", imageUrl + game.Cover);
                    }

                    if (string.IsNullOrWhiteSpace(game.Description) == false)
                    {
                        objResults.Add("Description", game.Description);
                    }

                    if (string.IsNullOrWhiteSpace(game.Platform) == false)
                    {
                        objResults.Add("Platform", game.Platform);
                    }

                    if (string.IsNullOrWhiteSpace(game.Rating) == false)
                    {
                        double intTmp;
                        if (double.TryParse(game.Rating, NumberStyles.Any, new CultureInfo("en-US", true), out intTmp))
                        {
                            objResults.Add("Rating", intTmp * 2);
                        }
                    }

                    if (game.Released != null)
                    {
                        objResults.Add("Released", game.Released);
                    }

                    if (string.IsNullOrWhiteSpace(game.Studio) == false)
                    {
                        objResults.Add("Editor", game.Studio);
                    }

                    if (string.IsNullOrWhiteSpace(game.Title) == false)
                    {
                        objResults.Add("Title", game.Title);
                    }

                    if (string.IsNullOrWhiteSpace(game.Link) == false)
                    {
                        objResults.Add("Links", game.Link);
                    }

                    List <Genre> gamesTypes = new List <Genre>();
                    foreach (string item in game.Types)
                    {
                        Genre gametype = GenreServices.GetGenre(item, EntityType.Games);
                        gamesTypes.Add(gametype);
                    }

                    objResults.Add("Types", gamesTypes);
                }

                return(objResults);
            }
            catch (Exception ex)
            {
                Util.LogException(ex, strId);
                return(null);
            }
        }
Beispiel #30
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);
            }
        }