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; }
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); } }
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++; } } } }
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); } }
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); } }