Пример #1
0
        /// <summary>Loads the specified <see cref="MDBPlayListItem"/>.</summary>
        /// <param name="mdb">The <see cref="MusicDataBase"/> instance.</param>
        /// <param name="item">The <see cref="MDBPlayListItem"/>.</param>
        /// <returns></returns>
        public static MDBFileSelection Load(MusicDataBase mdb, MDBPlayListItem item)
        {
            var result = new MDBFileSelection();

            result.AudioFile    = mdb.AudioFiles.TryGetStruct(item.AudioFileID);
            result.File         = mdb.Files.TryGetStruct(result.AudioFile.FileID);
            result.NowPlaying   = MDBNowPlaying.Create(mdb, item.StreamID, item.OwnerID, item.SubsetID, DateTime.MinValue, result.AudioFile);
            result.PlayListItem = item;
            return(result);
        }
Пример #2
0
        public void AddToPlaylist(WebData webData, long audioFileID, long streamID = 0)
        {
            if (streamID == 0)
            {
                streamID = (long)MDBStreamType.JukeBob;
            }
            lock (mdb.PlayListItems)
            {
                var settings     = mdb.GetStreamSettings(streamID);
                var presentCount = mdb.PlayListItems.Count(nameof(MDBNowPlaying.StreamID), MDBStreamType.JukeBob);
                if (settings.MaximumTitleCount > 0 && presentCount > settings.MaximumTitleCount)
                {
                    throw new WebServerException(WebError.DatasetAlreadyPresent, "Already {0} titles present at playlist!", presentCount);
                }

                bool exist =
                    //if is in nowplaying (file, JukeBob)
                    mdb.NowPlaying.Exist(
                        Search.FieldEquals(nameof(MDBNowPlaying.AudioFileID), audioFileID) &
                        Search.FieldEquals(nameof(MDBNowPlaying.StreamID), MDBStreamType.JukeBob)
                        ) ||
                    //or is in playlist (file, JukeBob)
                    mdb.PlayListItems.Exist(
                        Search.FieldEquals(nameof(MDBPlayListItem.AudioFileID), audioFileID) &
                        Search.FieldEquals(nameof(MDBPlayListItem.StreamID), MDBStreamType.JukeBob)
                        );
                if (exist)
                {
                    throw new WebServerException(WebError.DatasetAlreadyPresent, "Title is already present at playlist!");
                }

                var item = new MDBPlayListItem()
                {
                    AudioFileID = audioFileID,
                    StreamID    = streamID,
                    Added       = DateTime.UtcNow.AddTicks(DefaultRNG.Int8),
                };

                item.OwnerID = webData.Session.GetUser().ID;
                long titleCount = mdb.PlayListItems.Count(Search.FieldEquals(nameof(MDBPlayListItem.OwnerID), item.OwnerID));

                if (settings.TitlesPerUser > 0 && titleCount + 1 > settings.TitlesPerUser)
                {
                    throw new WebServerException(WebError.MissingRights, 0, string.Format("You already have {0} titles at the playlist.", titleCount));
                }
                mdb.PlayListItems.Insert(item);
            }
        }