public Artist(string name) { Albums = new AlbumCollection(); Identifier = Guid.NewGuid(); Name = name; }
public Library() { _artists = new ArtistCollection(); _albums = new AlbumCollection(); _tracks = new TrackCollection(); _trackDict = new Dictionary<string, Track>(); }
public void Init() { //the first line of config file is the login, //and the second one is the password using (StreamReader sr = new StreamReader ("config")) { login_config [0] = sr.ReadLine (); login_config [1] = sr.ReadLine (); } fotki = new FotkiService (login_config [0], login_config [1]); albums = fotki.GetAlbums (); }
protected void CacheAlbums(AlbumCollection model) { foreach (var albumContainer in model.Albums) { var albumCached = _cache.TryGetValue(albumContainer.Album.Id, out _); if (!albumCached) { _cache.Set(albumContainer.Album.Id, albumContainer.Album, new MemoryCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.UtcNow.AddHours(5), AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(5), SlidingExpiration = TimeSpan.FromHours(1), }); } } }
private AlbumViewModel LookupAlbum(AlbumModel album) { if (AlbumLookupMap.ContainsKey(album.AlbumId)) { return(AlbumLookupMap[album.AlbumId]); } else { ArtistViewModel artist = LookupArtistById(album.ArtistId); AlbumViewModel newAlbumViewModel = new AlbumViewModel(album, artist); AlbumLookupMap.Add(newAlbumViewModel.AlbumId, newAlbumViewModel); AlbumCollection.Add(newAlbumViewModel, newAlbumViewModel.SortName); return(newAlbumViewModel); } }
private void Timer_Tick(object sender, EventArgs e) { if (AlbumCollection.Count >= 5000) { Stop(); } var newAlbum = new Album { Title = SampleData.Albums.ElementAt(random.Next(0, SampleData.Albums.Count - 1)).Title, Genre = SampleData.Genres.ElementAt(random.Next(0, SampleData.Genres.Count - 1)), Price = (decimal)random.NextDouble() * random.Next(1, 100), Artist = SampleData.Artists.ElementAt(random.Next(0, SampleData.Artists.Count - 1)), AlbumArtUrl = "/Content/Images/placeholder.gif" }; Action action = () => { AlbumCollection.Add(newAlbum); }; Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(action)); }
public async Task GetLikedAlbumIdsByUserIdAsyncTest_UserIdNoLikedArtists_EmptyArray() { // Arrange var albumRepoMock = new Mock <IAlbumRepository>(); albumRepoMock.Setup(mock => mock.GetLikedAlbumIdsByUserIdAsync(1)) .ReturnsAsync(new int[] { }) .Verifiable(); var albumCollection = new AlbumCollection(albumRepoMock.Object, _dependencyMapper); // Act var likedAlbums = (await albumCollection.GetLikedAlbumIdsByUserIdAsync(1)).ToArray(); // Assert albumRepoMock.Verify(); Assert.AreEqual(0, likedAlbums.Length); }
public async Task GetAlbumByIdAsyncTest_InvalidId_Null() { // Arrange var albumRepoMock = new Mock <IAlbumRepository>(); albumRepoMock.Setup(mock => mock.GetAlbumByIdAsync(1)) .ReturnsAsync(null as AlbumDataDto) .Verifiable(); var albumCollection = new AlbumCollection(albumRepoMock.Object, _dependencyMapper); // Act var album = await albumCollection.GetAlbumByIdAsync(1); // Assert albumRepoMock.Verify(); Assert.AreEqual(null, album); }
public async Task GetAllAlbumsAsyncTest_NoAlbums_EmptyArray() { // Arrange var albumRepoMock = new Mock <IAlbumRepository>(); albumRepoMock.Setup(mock => mock.GetAllAlbumsAsync(0, 4)) .ReturnsAsync(new AlbumDataDto[] { }) .Verifiable(); var albumCollection = new AlbumCollection(albumRepoMock.Object, _dependencyMapper); // Act var albums = (await albumCollection.GetAllAlbumsAsync(0, 4)).ToArray(); // Assert albumRepoMock.Verify(); Assert.AreEqual(0, albums.Length); }
internal void RemoveAlbumIfNeeded(AlbumViewModel albumViewModel) { if (albumViewModel.Songs.Count == 0) { if (albumViewModel.Artist.Albums.Contains(albumViewModel)) { albumViewModel.Artist.Albums.Remove(albumViewModel); RemoveArtistIfNeeded(albumViewModel.Artist); AlbumCollection.Remove(albumViewModel, albumViewModel.SortName); AlbumLookupMap.Remove(albumViewModel.AlbumId); albumViewModel.IsBeingDeleted = true; LibraryModel.Current.DeleteAlbum(albumViewModel.AlbumId); } } }
private async void AllMusic_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: MusicCollection.AddRange(e.NewItems.Cast <LocalMusic>()); // ArtistCollection.AddRange(e.NewItems.Cast<LocalMusic>()); AlbumCollection.AddRange(e.NewItems.Cast <LocalMusic>()); break; case NotifyCollectionChangedAction.Remove: foreach (LocalMusic item in e.OldItems) { MusicCollection.Remove(item); // ArtistCollection.Remove(item); AlbumCollection.Remove(item); } await ArtistCollection.AddRangeAsync(AllMusic.GroupBy(x => x.ArtistsName?.FirstOrDefault() ?? "未知艺术家").ToDictionary(x => x.Key, x => x.ToArray()) .Select(x => new LocalArtist { Name = x.Key, PicPath = x.Value.First().Id3Pic, LocalMusics = x.Value })); break; case NotifyCollectionChangedAction.Replace: break; case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Reset: MusicCollection.Clear(); ArtistCollection.Clear(); AlbumCollection.Clear(); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Gets the albums for artist async. /// </summary> /// <param name="artistId">The artist id.</param> /// <param name="locale">sets the locale to do the search on. If null or empty, it uses what's set for Locale</param> /// <returns></returns> /// <exception cref="System.NullReferenceException">Artist Id cannot be null or empty</exception> public async Task <AlbumCollection> GetAlbumsForArtistAsync(string artistId, string locale = null) { if (string.IsNullOrEmpty(artistId)) { throw new NullReferenceException("Artist Id cannot be null or empty"); } locale = string.IsNullOrEmpty(locale) ? Locale : locale; var url = string.Format(Constants.ArtistUrlFormat, locale, artistId, "albums"); var xml = await HttpClient.GetStringAsync(url); var result = ParseXml <ZuneAlbumSearch.albumFeed>(xml); var returnList = new AlbumCollection(result.entry.Select(r => new Album(r)).ToList()); return(returnList); }
private static AlbumsViewModel AlbumsViewModel(AlbumCollection model) { return(new AlbumsViewModel { Album = model.Albums.Select(x => new AlbumViewModel { AddedAt = x.AddedAt, Name = x.Album.Name, Genres = x.Album.Genres, Id = x.Album.Id, Uri = x.Album.Uri, Label = x.Album.Label, Popularity = x.Album.Popularity, Image = x.Album.Images.Select(x => new Image { Url = x.Url, Width = x.Width, Height = x.Height }).FirstOrDefault(), Artists = x.Album.Artists.Select(s => new ArtistViewModel { Name = s.Name }), Tracks = new TracksViewModel { Href = x.Album.Tracks?.Href, SongsList = x.Album.Tracks?.SongsList.Select(p => new TrackViewModel { Name = p.Name, DurationMs = p.DurationMs, Id = p.Id, Artists = p.Artists.Select(s => new ArtistViewModel { Name = s.Name }), Uri = p.Uri }).ToList(), }, ReleaseDate = x.Album.ReleaseDate, AlbumType = x.Album.AlbumType }).ToList() }); }
private void songsOfAlbum_Loaded(object sender, RoutedEventArgs e) { string _albumName = NavigationContext.QueryString["albumName"]; MediaLibrary medialib = new MediaLibrary(); AlbumCollection albumCollection = medialib.Albums; Microsoft.Xna.Framework.Media.Album album = albumCollection.Single(al => al.Name == _albumName); songCollection = album.Songs; songs.Clear(); foreach (Song so in album.Songs) { songs.Add(so); } loadList.Begin(); }
public async Task GetAllAlbumsAsyncTest_MoreThanCount_MultipleSections() { // Arrange AlbumDataDto[] result = { new AlbumDataDto { Id = 1, Name = "Test", CoverArt = "", }, new AlbumDataDto { Id = 2, Name = "Test 2", CoverArt = "test2.mp3", }, }; var albumRepoMock = new Mock <IAlbumRepository>(); albumRepoMock.Setup(mock => mock.GetAllAlbumsAsync(0, 1)) .ReturnsAsync(new[] { result[0] }) .Verifiable(); albumRepoMock.Setup(mock => mock.GetAllAlbumsAsync(1, 1)) .ReturnsAsync(new[] { result[1] }) .Verifiable(); var albumCollection = new AlbumCollection(albumRepoMock.Object, _dependencyMapper); // Act var section1 = (await albumCollection.GetAllAlbumsAsync(0, 1)).ToArray(); var section2 = (await albumCollection.GetAllAlbumsAsync(1, 1)).ToArray(); // Assert albumRepoMock.Verify(); Assert.AreEqual(1, section1.Length); Assert.AreEqual(1, section2.Length); Assert.AreEqual(1, section1[0].Id); Assert.AreEqual(2, section2[0].Id); }
protected override void OnNavigatedTo(NavigationEventArgs e) { try { string _albumName = NavigationContext.QueryString["albumName"]; MediaLibrary medialib = new MediaLibrary(); AlbumCollection albumCollection = medialib.Albums; Microsoft.Xna.Framework.Media.Album album = albumCollection.Single(al => al.Name == _albumName); songCollection = album.Songs; if (album.HasArt) { BitmapImage bmpImage = new BitmapImage(); bmpImage.SetSource(album.GetAlbumArt()); albumArt.Source = bmpImage; } albumName.Text = album.Name; AlbumArtist.Text = album.Artist.Name; if (album.Duration.Days > 0) { albumDuration.Text = string.Format("Duration: {0:D1}:{1:D2}:{2:D2}:{3:D2}", album.Duration.Days , album.Duration.Hours, album.Duration.Minutes, album.Duration.Minutes); } else { albumDuration.Text = string.Format("Duration: {0:D2}:{1:D2}:{2:D2}", album.Duration.Hours, album.Duration.Minutes, album.Duration.Minutes); } songsNumbers.Text = "Songs numbers: " + album.Songs.Count; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static AlbumCollection SelectByPid(SqlConnection con, string PID) { var List = new AlbumCollection(); var obj = new SqlParameter[1]; if (!string.IsNullOrEmpty(PID)) { obj[0] = new SqlParameter("PID", PID); } else { obj[0] = new SqlParameter("PID", DBNull.Value); } using (IDataReader rd = SqlHelper.ExecuteReader(con, CommandType.StoredProcedure, "sp_tblAlbum_Select_SelectByPid_linhnx", obj)) { while (rd.Read()) { List.Add(getFromReader(rd)); } } return(List); }
public async Task GetAlbumsByArtistIdAsyncTest_ValidId_MultipleAlbums() { // Arrange AlbumDataDto[] result = { new AlbumDataDto { Id = 1, Name = "Test", CoverArt = "", }, new AlbumDataDto { Id = 2, Name = "Test 2", CoverArt = "test2.mp3", }, }; var albumRepoMock = new Mock <IAlbumRepository>(); albumRepoMock.Setup(mock => mock.GetAlbumsByArtistIdAsync(1)) .ReturnsAsync(result) .Verifiable(); var albumCollection = new AlbumCollection(albumRepoMock.Object, _dependencyMapper); // Act var albums = (await albumCollection.GetAlbumsByArtistIdAsync(1)).ToArray(); // Assert albumRepoMock.Verify(); Assert.AreEqual(2, albums.Length); for (int i = 0; i < 2; ++i) { Assert.AreEqual(result[i].Id, albums[i].Id); Assert.AreEqual(result[i].Name, albums[i].Name); Assert.AreEqual(result[i].CoverArt, albums[i].CoverArt); } }
public override bool BeforeExecute(int operatorUserID, string param, ref long offset, ref int totalCount, out string title) { StringList paramData = StringList.Parse(param); AdminAlbumFilter filter = AdminAlbumFilter.Parse(paramData[0]); //只取一条数据测试下就可以 filter.PageSize = 1; AlbumCollection albums = AlbumBO.Instance.GetAlbumsForAdmin(operatorUserID, filter, 1); if (albums == null || albums.Count == 0) { title = "没有数据可以删除"; return(false); } totalCount = albums.TotalRecords; title = "将删除 " + totalCount + " 个相册"; return(true); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // set to be 30 fps TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0); // load the media library and initialize a media queue MediaLibrary mediaLibrary = new MediaLibrary(); albumCollection = mediaLibrary.Albums; wasPausePressed = false; // initialize the member variables currentAlbum = "Shuffle by Album"; currentArtist = "version 1.1 - XNA 3.1.10527.0"; currentSong = "press play to begin"; currentVolume = ""; currentElapsedTime = "00:00"; currentRemianingTime = "-00:00"; currentTrack = ""; currentState = ""; // set to null and 0 since there's no song playing yet currentIndex = 0; nextIndex = -1; currentAlbumArt = null; previousAlbumArt = null; nextAlbumArt = null; songCollection = null; // seed with a random number random = new Random((int)DateTime.Now.Ticks); // make sure the player is stopped MediaPlayer.Stop(); base.Initialize(); }
public override AlbumCollection GetFriendAlbums(int userID, int pageNumber, int pageSize) { using (SqlQuery query = new SqlQuery()) { query.Pager.TableName = "bx_Albums"; query.Pager.SortField = "UpdateDate"; query.Pager.PrimaryKey = "AlbumID"; query.Pager.PageNumber = pageNumber; query.Pager.PageSize = pageSize; query.Pager.IsDesc = true; query.Pager.SelectCount = true; query.Pager.Condition = "[UserID] IN (SELECT [FriendUserID] FROM [bx_Friends] WHERE [UserID] = @UserID) AND ([PrivacyType] IN (0,1,3))"; query.CreateParameter<int>("@UserID", userID, SqlDbType.Int); using (XSqlDataReader reader = query.ExecuteReader()) { AlbumCollection albums = new AlbumCollection(reader); if (reader.NextResult()) { if (reader.Read()) { albums.TotalRecords = reader.Get<int>(0); } } return albums; } } }
public AlbumCollection GetAlbums() { if (albums == null) { var albums_xml = request_manager.GetString (link_albums); albums = new AlbumCollection (this, albums_xml); } return albums; }
/// <summary> /// Load content for the screen. /// </summary> /// <param name="GraphicInfo"></param> /// <param name="factory"></param> /// <param name="contentManager"></param> protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { base.LoadContent(GraphicInfo, factory, contentManager); { ///Create the xml file model extractor ///Loads a XML file that was export by our 3DS MAX plugin ExtractXmlModelLoader ext = new ExtractXmlModelLoader("Content//ModelInfos//", "Model//", "Textures//"); this.AttachCleanUpAble(ext); ///Extract all the XML info (Model,Cameras, ...) ModelLoaderData data = ext.Load(factory, GraphicInfo, "ilha"); ///Create the WOrld Loader ///Convert the ModelLoaderData in World Entities WorldLoader wl = new WorldLoader(); ///all default wl.LoadWorld(factory, GraphicInfo, World, data); } ///Create and add a sound to the SoundAudioPlayer ap = new SoundAudioPlayer(factory); ap.AddSoundToRepository("Songs/bye", "bye"); ///Create a sound effect without the SoundAudioPlayer (internaly the SoundAudioPlayer is a container of SimpleSoundEffect -- and some stuffs more) se = new SimpleSoundEffect(factory, "Songs/alarm"); ///Load the Sounds that you hear in your Microsoft Media Player ///Just loading the first album found =P lm = new LocalMediaAudioPlayer(); AlbumCollection ac = lm.MediaLibrary.Albums; lm.PlayAlbum(ac[0]); ///Creating a static 3D sound in the 0,0,0 (Bellow the island tree, go there and hear the sound getting louder) sound = new Static3DSound(factory, "Songs/pianosong", Vector3.Zero); this.World.AddSoundEmitter(sound, true); #region NormalLight DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White); DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White); DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White); DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White); DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White); float li = 0.5f; ld1.LightIntensity = li; ld2.LightIntensity = li; ld3.LightIntensity = li; ld4.LightIntensity = li; ld5.LightIntensity = li; this.World.AddLight(ld1); this.World.AddLight(ld2); this.World.AddLight(ld3); this.World.AddLight(ld4); this.World.AddLight(ld5); #endregion CameraFirstPerson cam = new CameraFirstPerson(MathHelper.ToRadians(30), MathHelper.ToRadians(-10), new Vector3(200, 150, 250), GraphicInfo); this.World.CameraManager.AddCamera(cam); SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//grassCube"); CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc); }
public AlbumsModel(AlbumCollection ac, IHostingEnvironment environment, ImageProcessor processor) { _ac = ac; _environment = environment; _processor = processor; }
/// <summary> /// Get an album from with the specified name, artist name and library /// </summary> /// <param name="albumName"></param> /// <param name="artistName"></param> /// <param name="libraryId"></param> /// <returns></returns> public static Album GetAlbumInLibrary(string albumName, string artistName, int libraryId) => AlbumCollection.Where(album => (album.LibraryId == libraryId) && (album.Name == albumName) && (album.ArtistName == artistName)).FirstOrDefault();
public AlbumsController(AlbumCollection albums = null) { _albums = albums ?? AlbumCollection.Default(); }
internal void AlertAlbumNameChanged(AlbumViewModel albumViewModel, string oldName) { AlbumCollection.Remove(albumViewModel, oldName); AlbumCollection.Add(albumViewModel, albumViewModel.SortName); }
protected void Page_Load(object sender, EventArgs e) { int pageNumber = _Request.Get<int>("page", Method.Get, 1); m_AlbumListPageSize = 20; m_View = _Request.Get("view", Method.Get, ""); if (IsSpace) { m_AlbumList = AlbumBO.Instance.GetUserAlbums(MyUserID, AppOwnerUserID, pageNumber, m_AlbumListPageSize); m_AlbumTotalCount = m_AlbumList.TotalRecords; m_CommentList = CommentBO.Instance.GetLastestCommentsForSomeone(AppOwnerUserID, CommentType.Photo, 10); UserBO.Instance.WaitForFillSimpleUsers<Album>(m_AlbumList); UserBO.Instance.WaitForFillSimpleUsers<Comment>(m_CommentList); } else { if (SelectedMy) { m_AlbumList = AlbumBO.Instance.GetUserAlbums(MyUserID, MyUserID, pageNumber, m_AlbumListPageSize); m_AlbumTotalCount = m_AlbumList.TotalRecords; m_CommentList = CommentBO.Instance.GetLastestCommentsForSomeone(MyUserID, CommentType.Photo, 10); UserBO.Instance.WaitForFillSimpleUsers<Album>(m_AlbumList); UserBO.Instance.WaitForFillSimpleUsers<Comment>(m_CommentList); } else if (SelectedFriend) { m_AlbumList = AlbumBO.Instance.GetFriendAlbums(MyUserID, pageNumber, m_AlbumListPageSize); m_AlbumTotalCount = m_AlbumList.TotalRecords; UserBO.Instance.WaitForFillSimpleUsers<Album>(m_AlbumList); } else if (SelectedEveryone) { m_AlbumList = AlbumBO.Instance.GetEveryoneAlbums(pageNumber, m_AlbumListPageSize); m_AlbumTotalCount = m_AlbumList.TotalRecords; UserBO.Instance.WaitForFillSimpleUsers<Album>(m_AlbumList); } } SetPager("pager1", null, pageNumber, AlbumListPageSize, AlbumTotalCount); if (IsSpace == false) { AddNavigationItem(FunctionName, BbsRouter.GetUrl("app/album/index")); if (SelectedMy) AddNavigationItem(string.Concat("我的", FunctionName)); else if (SelectedFriend) AddNavigationItem(string.Concat("好友的", FunctionName)); else if (SelectedEveryone) AddNavigationItem(string.Concat("大家的", FunctionName)); } else { AddNavigationItem(string.Concat(AppOwner.Username, "的空间"),UrlHelper.GetSpaceUrl(AppOwner.UserID)); AddNavigationItem(string.Concat("主人的", FunctionName)); } }
public void setSongList(MediaLibrary library) { albumCollection = library.Albums; }
protected void Page_Load(object sender, EventArgs e) { int pageNumber = _Request.Get <int>("page", Method.Get, 1); m_AlbumListPageSize = 20; m_View = _Request.Get("view", Method.Get, ""); if (IsSpace) { m_AlbumList = AlbumBO.Instance.GetUserAlbums(MyUserID, AppOwnerUserID, pageNumber, m_AlbumListPageSize); m_AlbumTotalCount = m_AlbumList.TotalRecords; m_CommentList = CommentBO.Instance.GetLastestCommentsForSomeone(AppOwnerUserID, CommentType.Photo, 10); UserBO.Instance.WaitForFillSimpleUsers <Album>(m_AlbumList); UserBO.Instance.WaitForFillSimpleUsers <Comment>(m_CommentList); } else { if (SelectedMy) { m_AlbumList = AlbumBO.Instance.GetUserAlbums(MyUserID, MyUserID, pageNumber, m_AlbumListPageSize); m_AlbumTotalCount = m_AlbumList.TotalRecords; m_CommentList = CommentBO.Instance.GetLastestCommentsForSomeone(MyUserID, CommentType.Photo, 10); UserBO.Instance.WaitForFillSimpleUsers <Album>(m_AlbumList); UserBO.Instance.WaitForFillSimpleUsers <Comment>(m_CommentList); } else if (SelectedFriend) { m_AlbumList = AlbumBO.Instance.GetFriendAlbums(MyUserID, pageNumber, m_AlbumListPageSize); m_AlbumTotalCount = m_AlbumList.TotalRecords; UserBO.Instance.WaitForFillSimpleUsers <Album>(m_AlbumList); } else if (SelectedEveryone) { m_AlbumList = AlbumBO.Instance.GetEveryoneAlbums(pageNumber, m_AlbumListPageSize); m_AlbumTotalCount = m_AlbumList.TotalRecords; UserBO.Instance.WaitForFillSimpleUsers <Album>(m_AlbumList); } } SetPager("pager1", null, pageNumber, AlbumListPageSize, AlbumTotalCount); if (IsSpace == false) { AddNavigationItem(FunctionName, BbsRouter.GetUrl("app/album/index")); if (SelectedMy) { AddNavigationItem(string.Concat("我的", FunctionName)); } else if (SelectedFriend) { AddNavigationItem(string.Concat("好友的", FunctionName)); } else if (SelectedEveryone) { AddNavigationItem(string.Concat("大家的", FunctionName)); } } else { AddNavigationItem(string.Concat(AppOwner.Username, "的空间"), UrlHelper.GetSpaceUrl(AppOwner.UserID)); AddNavigationItem(string.Concat("主人的", FunctionName)); } }
public override AlbumCollection GetAlbumsBySearch(int operatorID, IEnumerable<Guid> excludeRoleIDs, AdminAlbumFilter filter, int pageNumber) { using (SqlQuery query = new SqlQuery()) { string sqlCondition = BuildConditionsByFilter(query, filter, operatorID, excludeRoleIDs, false); query.Pager.TableName = "bx_Albums"; query.Pager.SortField = filter.Order.ToString(); if (filter.Order != AdminAlbumFilter.OrderBy.AlbumID) { query.Pager.PrimaryKey = "AlbumID"; } query.Pager.PageNumber = pageNumber; query.Pager.PageSize = filter.PageSize; query.Pager.SelectCount = true; query.Pager.IsDesc = filter.IsDesc; query.Pager.Condition = sqlCondition; using (XSqlDataReader reader = query.ExecuteReader()) { AlbumCollection albums = new AlbumCollection(reader); if (reader.NextResult()) { if (reader.Read()) { albums.TotalRecords = reader.Get<int>(0); } } return albums; } } }
/// <summary> /// Searches through the users collections with different possible parameters and returns a new AlbumCollection model that contains the albums that meet the parameters and pagination object /// </summary> /// <param name="term">The string instance of what was searched</param> /// <param name="id">The unique Id of the collection being searched</param> /// <param name="searchGenres">A list of strings for the genres that are selected</param> /// <param name="perPage">The integer representing the number of results contained on each page</param> /// <param name="currentPage">The integer representing the current page being viewed</param> /// <param name="sortBy">The string dictating which category {Artist, Title, Year} to sort by</param> /// <param name="direction">The string {ASC, DESC} which determines which way to sort the results</param> /// <returns>An AlbumCollection data model that fits the required parameters</returns> public AlbumCollection SearchThruCollection(string term, Guid id, string[] searchGenres, int perPage, int currentPage, string sortBy, string direction) { using (var db = new SqlConnection(_connectionString)) { // finds the current first item to show on the page var currentStartNumber = ((perPage * currentPage) - perPage); // creates the new collection to return var collection = new AlbumCollection(); var sql = @"SELECT DISTINCT a.* FROM [CollectionAlbum] ca JOIN [Album] a ON ca.AlbumId = a.Id"; // generic where statement var whereStatement = " WHERE ca.CollectionId = @id "; var regex = "%"; // if some genres were selected if (searchGenres.Length != 0) { sql += @" JOIN AlbumGenre ag ON a.Id = ag.AlbumId JOIN Genre g ON g.Id = ag.GenreId"; whereStatement += "AND g.id in @searchGenres"; } // if something was searched for add regex to where statement if (term != null) { char[] charArr = term.ToCharArray(); foreach (char ch in charArr) { regex += "[" + ch + "]"; } regex += "%"; // if no genres were specified if (searchGenres.Length == 0) { whereStatement = " WHERE ca.CollectionId = @id AND ([Title] LIKE @regex OR [Artist] LIKE @regex)"; } // if some genres were specified adds to where statment else { whereStatement = @" WHERE ca.CollectionId = @id AND ([Title] LIKE @regex OR [Artist] LIKE @regex) AND g.id in @searchGenres"; } } // adds the where statement to the end of the sql call sql += whereStatement; collection.Id = id; collection.Name = GetCollectionNameById(id); var parameters = new { regex, id, searchGenres, currentStartNumber, perPage }; // returns all the albums in a list before offset is added in to get total in search var totalAlbumsForSearch = db.Query <Album>(sql, parameters).ToList(); // creates the order by statement from parameters given var orderByStatement = " ORDER by"; if (sortBy == "Artist") { orderByStatement += " a.Artist"; } if (sortBy == "Title") { orderByStatement += " a.Title"; } if (sortBy == "Year") { orderByStatement += " a.ReleaseYear"; } if (direction == "ASC") { orderByStatement += " ASC"; } if (direction == "DESC") { orderByStatement += " DESC"; } orderByStatement += @" OFFSET @currentStartNumber ROWS FETCH NEXT @perPage ROWS ONLY"; // adds the order by statement to the sql call sql += orderByStatement; // returns the list AFTER the offset and orderby to display correctly var albums = db.Query <Album>(sql, parameters).ToList(); // adds the genre and style string for each album in the collection foreach (Album album in albums) { album.Genre = _genreRepo.GetListOfGenreNamesForAlbum(album.Id); album.Style = _styleRepo.GetListOfStyleNamesForAlbum(album.Id); } // gets the genre total results for the search parameters var genreTotalResults = _genreRepo.GetAlbumsInCategories(regex, id); // fills in the collection object collection.Albums = albums; collection.NumberInCollection = totalAlbumsForSearch.Count; collection.TotalForEachGenre = genreTotalResults; collection.Pagination = CreatePagination(currentPage, totalAlbumsForSearch.Count, perPage); return(collection); } }
public void Dispose() { AlbumCollection.Clear(); }
public override AlbumCollection GetUserAlbums(int userID, DataAccessLevel dataAccessLevel, int pageNumber, int pageSize, ref int? totalCount) { using (SqlQuery query = new SqlQuery()) { query.Pager.TableName = "[bx_Albums]"; query.Pager.SortField = "[UpdateDate]"; query.Pager.PrimaryKey = "AlbumID"; query.Pager.IsDesc = true; query.Pager.PageNumber = pageNumber; query.Pager.PageSize = pageSize; query.Pager.TotalRecords = totalCount; query.Pager.SelectCount = true; query.Pager.Condition = "[UserID] = @UserID"; query.CreateParameter<int>("@UserID", userID, SqlDbType.Int); if (dataAccessLevel == DataAccessLevel.Normal) { query.Pager.Condition += " AND [PrivacyType] IN (0, 3)"; } else if (dataAccessLevel == DataAccessLevel.Friend) { query.Pager.Condition += " AND [PrivacyType] IN (0, 1, 3)"; } using (XSqlDataReader reader = query.ExecuteReader()) { AlbumCollection albums = new AlbumCollection(reader); if (totalCount == null && reader.NextResult() && reader.Read()) { totalCount = reader.Get<int>(0); } albums.TotalRecords = totalCount.GetValueOrDefault(); return albums; } } }
public override AlbumCollection GetEveryoneAlbums(int pageNumber, int pageSize, ref int? totalCount) { using (SqlQuery query = new SqlQuery()) { query.Pager.TableName = "[bx_Albums]"; query.Pager.SortField = "[UpdateDate]"; query.Pager.PrimaryKey = "[AlbumID]"; query.Pager.PageNumber = pageNumber; query.Pager.PageSize = pageSize; query.Pager.TotalRecords = totalCount; query.Pager.IsDesc = true; query.Pager.SelectCount = true; query.Pager.Condition = " ([PrivacyType] IN (0,3))"; using (XSqlDataReader reader = query.ExecuteReader()) { AlbumCollection albums = new AlbumCollection(reader); if (totalCount == null && reader.NextResult() && reader.Read()) { totalCount = reader.Get<int>(0); } albums.TotalRecords = totalCount.GetValueOrDefault(); return albums; } } }
public PhotoModel(AlbumCollection ac, IHostingEnvironment environment) { _ac = ac; _environment = environment; }
private MusicSessionImpl(ISessionBuilder isb,IMainWindowHwndProvider mp) { _IMW = mp; _AllAlbums = new AlbumCollection(this); _AllArtists = new ArtistCollection(this); _AllTracks = new TrackCollection(this); _MusicFolderHelper = isb.Folders; _ISF = isb.GetNhibernateConfiguration(DBFactoryBuilder.GetConfiguration).BuildSessionFactory(); _ISFact = isb.SettingFactory; _CleanOnOpen = isb.DBCleanOnOpen; _SessionCose = isb.OnSessionClose; this.Dependencies = isb.InfraTools; TraceListener = new ApplicationTraceListener(); _MusicConverter = new Lazy<IMusicConverter>(isb.MusicConverterBuilder); Trace.Listeners.Add(TraceListener); }