private void SaveMediaItems(IAudio audio) { try { var artist = audio.GetArtist(securityContext, mediaFactory, mediaItemRepository); mediaItemRepository.Save(new List<IArtist> { artist }); tagRepository.Save(artist.GetTags()); var album = audio.GetAlbum(securityContext, mediaFactory, mediaItemRepository, artist); mediaItemRepository.Save(new List<IAlbum> { album }); tagRepository.Save(album.GetTags()); var track = audio.GetTrack(securityContext, mediaFactory, mediaItemRepository, audioStreamFactory, artist, album); mediaItemRepository.Save(new List<ITrack> { track }); tagRepository.Save(track.GetTags()); var trackDate = track.FromDate > DateTime.MinValue ? track.FromDate : track.ToDate; if (album.FromDate == DateTime.MinValue && trackDate != DateTime.MinValue) { var identityInfo = new IdentityInfo(album.Location, album.Type, album.Name, album.Summary, trackDate, trackDate, album.Number); var sizeInfo = new SizeInfo(album.Duration, album.Height, album.Width); var creatorInfo = new CreatorInfo(album.Creator, album.CreatorName); var catalogInfo = new CatalogInfo(album.Catalog, album.CatalogName); var targetInfo = new TargetInfo(album.Target, album.TargetType); var userInfo = new UserInfo(album.User, album.UserName); var thumbnailInfo = new ThumbnailInfo(album.Thumbnail, album.ThumbnailData); album = new Album(identityInfo, sizeInfo, creatorInfo, catalogInfo, targetInfo, userInfo, thumbnailInfo); mediaItemRepository.Save(new List<IAlbum> { album }); } //if (album.ToDate == DateTime.MinValue && track.ToDate != DateTime. if (!HasDefaultThumbnail(track)) { if (HasDefaultThumbnail(album)) { //var fromDate = album.FromDate; //if (album.FromDate == DateTime.MinValue || album.FromDate == DateTime.MaxValue) //{ // fromDate = track.ToDate != DateTime.MinValue && track.ToDate != DateTime.MaxValue ? // track.ToDate // : track.FromDate; //} var number = album.Number; if (album.Name.Contains("#") && !album.Name.EndsWith("#")) { var suffix = album.Name.Substring(album.Name.LastIndexOf('#') + 1).Trim(); uint.TryParse(suffix, out number); } else if (album.Name.Contains("(") && !album.Name.EndsWith("(")) { var suffix = album.Name.Substring(album.Name.LastIndexOf("(") + 1); var cleaned = System.Text.RegularExpressions.Regex.Replace(suffix, "[^0-9]", string.Empty); uint.TryParse(cleaned, out number); } var identityInfo = new IdentityInfo(album.Location, album.Type, album.Name, album.Summary, album.FromDate, album.ToDate, number); var sizeInfo = new SizeInfo(album.Duration, album.Height, album.Width); var creatorInfo = new CreatorInfo(album.Creator, album.CreatorName); var catalogInfo = new CatalogInfo(album.Catalog, album.CatalogName); var targetInfo = new TargetInfo(album.Target, album.TargetType); var userInfo = new UserInfo(album.User, album.UserName); var thumbnailInfo = new ThumbnailInfo(track.Thumbnail, track.ThumbnailData); var updated = new Album(identityInfo, sizeInfo, creatorInfo, catalogInfo, targetInfo, userInfo, thumbnailInfo); mediaItemRepository.Save(new List<IAlbum> { updated }); } } } catch (Exception ex) { logger.Error(" SaveMediaItems", ex); } }
private void SaveMediaItems(IAudio audio) { try { var artist = audio.GetArtist(securityContext, mediaFactory, mediaItemRepository); mediaItemRepository.Save(new List <IArtist> { artist }); tagRepository.Save(artist.GetTags()); var album = audio.GetAlbum(securityContext, mediaFactory, mediaItemRepository, artist); mediaItemRepository.Save(new List <IAlbum> { album }); tagRepository.Save(album.GetTags()); var track = audio.GetTrack(securityContext, mediaFactory, mediaItemRepository, audioStreamFactory, artist, album); mediaItemRepository.Save(new List <ITrack> { track }); tagRepository.Save(track.GetTags()); var trackDate = track.FromDate > DateTime.MinValue ? track.FromDate : track.ToDate; if (album.FromDate == DateTime.MinValue && trackDate != DateTime.MinValue) { var identityInfo = new IdentityInfo(album.Location, album.Type, album.Name, album.Summary, trackDate, trackDate, album.Number); var sizeInfo = new SizeInfo(album.Duration, album.Height, album.Width); var creatorInfo = new CreatorInfo(album.Creator, album.CreatorName); var catalogInfo = new CatalogInfo(album.Catalog, album.CatalogName); var targetInfo = new TargetInfo(album.Target, album.TargetType); var userInfo = new UserInfo(album.User, album.UserName); var thumbnailInfo = new ThumbnailInfo(album.Thumbnail, album.ThumbnailData); album = new Album(identityInfo, sizeInfo, creatorInfo, catalogInfo, targetInfo, userInfo, thumbnailInfo); mediaItemRepository.Save(new List <IAlbum> { album }); } //if (album.ToDate == DateTime.MinValue && track.ToDate != DateTime. if (!HasDefaultThumbnail(track)) { if (HasDefaultThumbnail(album)) { //var fromDate = album.FromDate; //if (album.FromDate == DateTime.MinValue || album.FromDate == DateTime.MaxValue) //{ // fromDate = track.ToDate != DateTime.MinValue && track.ToDate != DateTime.MaxValue ? // track.ToDate // : track.FromDate; //} var number = album.Number; if (album.Name.Contains("#") && !album.Name.EndsWith("#")) { var suffix = album.Name.Substring(album.Name.LastIndexOf('#') + 1).Trim(); uint.TryParse(suffix, out number); } else if (album.Name.Contains("(") && !album.Name.EndsWith("(")) { var suffix = album.Name.Substring(album.Name.LastIndexOf("(") + 1); var cleaned = System.Text.RegularExpressions.Regex.Replace(suffix, "[^0-9]", string.Empty); uint.TryParse(cleaned, out number); } var identityInfo = new IdentityInfo(album.Location, album.Type, album.Name, album.Summary, album.FromDate, album.ToDate, number); var sizeInfo = new SizeInfo(album.Duration, album.Height, album.Width); var creatorInfo = new CreatorInfo(album.Creator, album.CreatorName); var catalogInfo = new CatalogInfo(album.Catalog, album.CatalogName); var targetInfo = new TargetInfo(album.Target, album.TargetType); var userInfo = new UserInfo(album.User, album.UserName); var thumbnailInfo = new ThumbnailInfo(track.Thumbnail, track.ThumbnailData); var updated = new Album(identityInfo, sizeInfo, creatorInfo, catalogInfo, targetInfo, userInfo, thumbnailInfo); mediaItemRepository.Save(new List <IAlbum> { updated }); } } } catch (Exception ex) { logger.Error(" SaveMediaItems", ex); } }