コード例 #1
0
        public JsonResult CreateMultiple(List <PlaylistItemDto> playlistItemDtos)
        {
            List <PlaylistItemDto> savedPlaylistItemDtos;

            int count = playlistItemDtos.Count;

            if (count > 1000)
            {
                Session.SetBatchSize(count / 10);
            }
            else if (count > 3)
            {
                Session.SetBatchSize(count / 3);
            }

            using (ITransaction transaction = Session.BeginTransaction())
            {
                List <PlaylistItem> playlistItems = PlaylistItem.Create(playlistItemDtos, PlaylistManager);

                //  Split items into their respective playlists and then save on each.
                foreach (var playlistGrouping in playlistItems.GroupBy(i => i.Playlist))
                {
                    List <PlaylistItem> groupingItems = playlistGrouping.ToList();
                    playlistGrouping.Key.AddItems(groupingItems);
                    PlaylistItemManager.Save(groupingItems);
                }

                savedPlaylistItemDtos = PlaylistItemDto.Create(playlistItems);

                transaction.Commit();
            }

            return(Json(savedPlaylistItemDtos));
        }
コード例 #2
0
        public ActionResult UpdateMultiple(List <PlaylistItemDto> playlistItemDtos)
        {
            List <PlaylistItemDto> savedPlaylistItemDtos;

            int count = playlistItemDtos.Count;

            if (count > 1000)
            {
                Session.SetBatchSize(count / 10);
            }
            else if (count > 3)
            {
                Session.SetBatchSize(count / 3);
            }

            using (ITransaction transaction = Session.BeginTransaction())
            {
                List <PlaylistItem> playlistItems = PlaylistItem.Create(playlistItemDtos, PlaylistManager);

                PlaylistItemManager.Update(playlistItems);

                savedPlaylistItemDtos = PlaylistItemDto.Create(playlistItems);

                transaction.Commit();
            }

            return(Json(savedPlaylistItemDtos));
        }
コード例 #3
0
ファイル: Helpers.cs プロジェクト: donbing/StreamusServer
        /// <summary>
        ///     Create a new Playlist, save it to the DB, then generate N PlaylistItemDtos
        ///     which have the Playlist as their parent.
        /// </summary>
        public static List <PlaylistItemDto> CreatePlaylistItemsDto(int itemsToCreate, Guid playlistId = default(Guid))
        {
            if (playlistId == default(Guid))
            {
                User user = CreateUser();
                playlistId = user.Playlists.First().Id;
            }

            Video    video    = CreateUnsavedVideoWithId();
            VideoDto videoDto = VideoDto.Create(video);

            List <PlaylistItemDto> playlistItemDtos = new List <PlaylistItemDto>();

            for (int i = 0; i < itemsToCreate; i++)
            {
                var playlistItemDto = new PlaylistItemDto
                {
                    PlaylistId = playlistId,
                    Video      = videoDto
                };

                playlistItemDtos.Add(playlistItemDto);
            }

            return(playlistItemDtos);
        }
コード例 #4
0
        public ActionResult UpdateMultiple(List <PlaylistItemDto> playlistItemDtos)
        {
            List <PlaylistItem> playlistItems = PlaylistItem.Create(playlistItemDtos);

            PlaylistItemManager.Update(playlistItems);

            List <PlaylistItemDto> savedPlaylistItemDtos = PlaylistItemDto.Create(playlistItems);

            return(new JsonDataContractActionResult(savedPlaylistItemDtos));
        }
コード例 #5
0
        public ActionResult Update(PlaylistItemDto playlistItemDto)
        {
            PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto);

            PlaylistItemManager.Update(playlistItem);

            PlaylistItemDto updatedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

            return(new JsonDataContractActionResult(updatedPlaylistItemDto));
        }
コード例 #6
0
        public ActionResult Update(PlaylistItemDto playlistItemDto)
        {
            PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto);

            PlaylistItemManager.Update(playlistItem);

            PlaylistItemDto updatedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

            return(new JsonServiceStackResult(updatedPlaylistItemDto));
        }
コード例 #7
0
        public void Patch(Guid id, PlaylistItemDto playlistItemDto)
        {
            using (ITransaction transaction = Session.BeginTransaction())
            {
                PlaylistItem playlistItem = PlaylistItemManager.Get(id);
                playlistItemDto.SetPatchableProperties(playlistItem);
                PlaylistItemManager.Update(playlistItem);

                transaction.Commit();
            }
        }
コード例 #8
0
        /// <summary>
        ///     Create a new Playlist, save it to the DB, then generate a PlaylistItemDto
        ///     which has the Playlist as its parent.
        /// </summary>
        public PlaylistItemDto CreatePlaylistItemDto()
        {
            User user = CreateUser();

            PlaylistItem playlistItem = CreateUnsavedPlaylistItem();

            var playlistItemDto = PlaylistItemDto.Create(playlistItem);

            playlistItemDto.PlaylistId = user.Playlists.First().Id;

            return(playlistItemDto);
        }
コード例 #9
0
        public JsonDataContractActionResult Create(PlaylistItemDto playlistItemDto)
        {
            PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto);

            playlistItem.Playlist.AddItem(playlistItem);

            PlaylistItemManager.Save(playlistItem);

            PlaylistItemDto savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

            return(new JsonDataContractActionResult(savedPlaylistItemDto));
        }
コード例 #10
0
        public JsonServiceStackResult Create(PlaylistItemDto playlistItemDto)
        {
            PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto);

            playlistItem.Playlist.AddItem(playlistItem);

            PlaylistItemManager.Save(playlistItem);

            PlaylistItemDto savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

            return(new JsonServiceStackResult(savedPlaylistItemDto));
        }
コード例 #11
0
        public IEnumerable <PlaylistItemDto> CreateMultiple(List <PlaylistItemDto> playlistItemDtos)
        {
            List <PlaylistItemDto> savedPlaylistItemDtos;

            int count = playlistItemDtos.Count;

            if (count > 1000)
            {
                Session.SetBatchSize(count / 10);
            }
            else if (count > 500)
            {
                Session.SetBatchSize(count / 5);
            }
            else if (count > 2)
            {
                Session.SetBatchSize(count / 2);
            }

            using (ITransaction transaction = Session.BeginTransaction())
            {
                List <PlaylistItem> savedPlaylistItems = new List <PlaylistItem>();

                //  Split items into their respective playlists and then save on each.
                foreach (var playlistGrouping in playlistItemDtos.GroupBy(pid => pid.PlaylistId))
                {
                    List <PlaylistItemDto> groupedPlaylistItemDtos = playlistGrouping.ToList();
                    Playlist playlist = PlaylistManager.Get(playlistGrouping.Key);

                    foreach (var playlistItemDto in groupedPlaylistItemDtos)
                    {
                        SongDto songDto = playlistItemDto.Song;

                        PlaylistItem playlistItem = new PlaylistItem(playlistItemDto.Id, playlistItemDto.Title, playlistItemDto.Cid, songDto.Id, songDto.Type, songDto.Title, songDto.Duration, songDto.Author);
                        playlistItemDto.SetPatchableProperties(playlistItem);

                        playlist.AddItem(playlistItem);

                        savedPlaylistItems.Add(playlistItem);
                    }
                }

                PlaylistItemManager.Save(savedPlaylistItems);

                savedPlaylistItemDtos = PlaylistItemDto.Create(savedPlaylistItems);

                transaction.Commit();
            }

            return(savedPlaylistItemDtos);
        }
コード例 #12
0
        public void CreatePlaylistItem_PlaylistItemDoesntExist_PlaylistItemCreated()
        {
            PlaylistItemDto playlistItemDto = Helpers.CreatePlaylistItemDto();

            var createdPlaylistItemDto = PlaylistItemController.Create(playlistItemDto);

            //  Make sure we actually get a PlaylistItem DTO back from the Controller.
            Assert.NotNull(createdPlaylistItemDto);

            Playlist playlist = PlaylistManager.Get(createdPlaylistItemDto.PlaylistId);

            //  Make sure that the created playlistItem was cascade added to the Playlist
            Assert.That(playlist.Items.Count(i => i.Id == createdPlaylistItemDto.Id) == 1);
        }
コード例 #13
0
        public static PlaylistItem Create(PlaylistItemDto playlistItemDto, IPlaylistManager playlistManager)
        {
            PlaylistItem playlistItem = new PlaylistItem
            {
                Cid      = playlistItemDto.Cid,
                Id       = playlistItemDto.Id,
                Playlist = playlistManager.Get(playlistItemDto.PlaylistId),
                Sequence = playlistItemDto.Sequence,
                Title    = playlistItemDto.Title,
                Video    = Video.Create(playlistItemDto.Video)
            };

            return(playlistItem);
        }
コード例 #14
0
        /// <summary>
        ///     Create a new Folder and Playlist, save them to the DB, then generate a PlaylistItemDto
        ///     which has those entities as its parents.
        /// </summary>
        public static PlaylistItemDto CreatePlaylistItemDto()
        {
            Guid playlistId = UserManager.CreateUser().Folders.First().Playlists.First().Id;

            Video    video    = CreateUnsavedVideoWithId();
            VideoDto videoDto = VideoDto.Create(video);

            var playlistItemDto = new PlaylistItemDto
            {
                PlaylistId = playlistId,
                Video      = videoDto
            };

            return(playlistItemDto);
        }
コード例 #15
0
        private async Task <PlaylistItem> GetPlaylistItem(PlaylistItemDto playlistItemDto)
        {
            var contentId = new ContentId(
                playlistItemDto.ExternalId,
                playlistItemDto.ContentSource,
                playlistItemDto.ContentType);

            var content = await _contentRepository.GetAsync(contentId, CancellationToken.None);

            return(new PlaylistItem(
                       contentId,
                       playlistItemDto.PlaylistItemIndex,
                       content.Title,
                       content.Description));
        }
コード例 #16
0
        public ActionResult Update(PlaylistItemDto playlistItemDto)
        {
            PlaylistItemDto updatedPlaylistItemDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto, PlaylistManager);
                PlaylistItemManager.Update(playlistItem);

                updatedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);
                transaction.Commit();
            }

            return(Json(updatedPlaylistItemDto));
        }
コード例 #17
0
        public void PatchPlaylistItem_SequenceProvided_SequenceModified()
        {
            PlaylistItemDto playlistItemDto        = Helpers.CreatePlaylistItemDto();
            var             createdPlaylistItemDto = PlaylistItemController.Create(playlistItemDto);

            const double newSequence = 5;

            PlaylistItemDto patchedPlaylistItemDto = new PlaylistItemDto {
                Sequence = newSequence
            };

            PlaylistItem playlistItem = PlaylistItemManager.Get(createdPlaylistItemDto.Id);

            PlaylistItemController.Patch(playlistItem.Id, patchedPlaylistItemDto);

            Assert.AreEqual(playlistItem.Sequence, newSequence);
        }
コード例 #18
0
        /// <summary>
        ///     Create a new Playlist, save it to the DB, then generate a PlaylistItemDto
        ///     which has the Playlist as its parent.
        /// </summary>
        public PlaylistItemDto CreatePlaylistItemDto()
        {
            User user = CreateUser();

            Guid playlistId = user.Playlists.First().Id;

            Video    video    = CreateUnsavedVideoWithId();
            VideoDto videoDto = VideoDto.Create(video);

            var playlistItemDto = new PlaylistItemDto
            {
                PlaylistId = playlistId,
                Video      = videoDto
            };

            return(playlistItemDto);
        }
コード例 #19
0
        public void CreatePlaylistItem_PlaylistItemDoesntExist_PlaylistItemCreated()
        {
            PlaylistItemDto playlistItemDto = Helpers.CreatePlaylistItemDto();

            var result = PlaylistItemController.Create(playlistItemDto);

            var createdPlaylistItemDto = (PlaylistItemDto)result.Data;

            //  Make sure we actually get a PlaylistItem DTO back from the Controller.
            Assert.NotNull(createdPlaylistItemDto);

            NHibernateSessionManager.Instance.Clear();

            Playlist playlist = PlaylistDao.Get(createdPlaylistItemDto.PlaylistId);

            //  Make sure that the created playlistItem was cascade added to the Playlist
            Assert.That(playlist.Items.Count(i => i.Id == createdPlaylistItemDto.Id) == 1);
        }
コード例 #20
0
        public void DeletePlaylistItem_ItemExistsInPlaylist_DeletedSuccessfully()
        {
            PlaylistItemDto playlistItemDto = Helpers.CreatePlaylistItemDto();

            var result = PlaylistItemController.Create(playlistItemDto);

            var createdPlaylistItemDto = (PlaylistItemDto)result.Data;

            //  Make sure we actually get a PlaylistItem DTO back from the Controller.
            Assert.NotNull(createdPlaylistItemDto);

            Playlist playlist = PlaylistManager.Get(createdPlaylistItemDto.PlaylistId);

            //  Make sure that the created playlistItem was cascade added to the Playlist
            Assert.That(playlist.Items.Count(i => i.Id == createdPlaylistItemDto.Id) == 1);

            PlaylistItemController.Delete(createdPlaylistItemDto.Id);
        }
コード例 #21
0
        public JsonDataContractActionResult CreateMultiple(List <PlaylistItemDto> playlistItemDtos)
        {
            List <PlaylistItem> playlistItems = PlaylistItem.Create(playlistItemDtos);

            //  Split items into their respective playlists and then save on each.
            foreach (var playlistGrouping in playlistItems.GroupBy(i => i.Playlist))
            {
                List <PlaylistItem> groupingItems = playlistGrouping.ToList();

                Playlist playlist = groupingItems.First().Playlist;
                playlist.AddItems(groupingItems);

                PlaylistItemManager.Save(groupingItems);
            }

            List <PlaylistItemDto> savedPlaylistItemDtos = PlaylistItemDto.Create(playlistItems);

            return(new JsonDataContractActionResult(savedPlaylistItemDtos));
        }
コード例 #22
0
        public JsonResult Create(PlaylistItemDto playlistItemDto)
        {
            PlaylistItemDto savedPlaylistItemDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto, PlaylistManager);

                playlistItem.Playlist.AddItem(playlistItem);

                PlaylistItemManager.Save(playlistItem);

                savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

                transaction.Commit();
            }

            return(Json(savedPlaylistItemDto));
        }
コード例 #23
0
        public async Task <HttpResponseMessage> PostAsync(int playlistId, [FromBody] PlaylistItemDto model, CancellationToken cancellationToken)
        {
            var playlist = await _services.Media.FindByIdAsync(playlistId, cancellationToken);

            if (playlist == null)
            {
                return(Request.CreateFaultResponse(HttpStatusCode.NotFound, "Playlist was not found."));
            }
            if (ProjectIdentity == null || ProjectIdentity.Id != playlist.ContactId)
            {
                return(Request.CreateFaultResponse(HttpStatusCode.Forbidden, "Playlist has already been taken."));
            }
            if (ModelState.IsValid)
            {
                var entity = new MediaPlaylistItem
                {
                    PlaylistId  = playlistId,
                    Name        = model.Name,
                    MediaType   = model.MediaType,
                    MediaId     = model.MediaId,
                    Duration    = model.Duration,
                    PublishDate = model.PublishDate
                };
                await _services.Media.AddItemAsync(entity, cancellationToken);

                await _services.SaveAsync(cancellationToken);

                var result = new MediaPlaylistItemResult
                {
                    Id          = entity.Id,
                    SortOrderId = entity.SortOrderId,
                    Name        = entity.Name,
                    MediaType   = entity.MediaType,
                    MediaId     = entity.MediaId,
                    Duration    = entity.Duration,
                    PublishDate = entity.PublishDate
                };
                return(Request.CreateResponse(HttpStatusCode.Created, result));
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
コード例 #24
0
        /// <summary>
        ///     Create a new Playlist, save it to the DB, then generate N PlaylistItemDtos
        ///     which have the Playlist as their parent.
        /// </summary>
        public List <PlaylistItemDto> CreatePlaylistItemsDto(int itemsToCreate, Guid playlistId = default(Guid))
        {
            if (playlistId == default(Guid))
            {
                User user = CreateUser();
                playlistId = user.Playlists.First().Id;
            }

            PlaylistItem playlistItem = CreateUnsavedPlaylistItem();

            List <PlaylistItemDto> playlistItemDtos = new List <PlaylistItemDto>();

            for (int i = 0; i < itemsToCreate; i++)
            {
                var playlistItemDto = PlaylistItemDto.Create(playlistItem);
                playlistItemDto.PlaylistId = playlistId;

                playlistItemDtos.Add(playlistItemDto);
            }

            return(playlistItemDtos);
        }
コード例 #25
0
        public PlaylistItemDto Create(PlaylistItemDto playlistItemDto)
        {
            PlaylistItemDto savedPlaylistItemDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                Playlist playlist = PlaylistManager.Get(playlistItemDto.PlaylistId);

                SongDto songDto = playlistItemDto.Song;

                PlaylistItem playlistItem = new PlaylistItem(playlistItemDto.Id, playlistItemDto.Title, playlistItemDto.Cid, songDto.Id, songDto.Type, songDto.Title, songDto.Duration, songDto.Author);
                playlistItemDto.SetPatchableProperties(playlistItem);

                playlist.AddItem(playlistItem);

                PlaylistItemManager.Save(playlistItem);

                savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

                transaction.Commit();
            }

            return(savedPlaylistItemDto);
        }
コード例 #26
0
        public static PlaylistItem Create(PlaylistItemDto playlistItemDto)
        {
            PlaylistItem playlistItem = Mapper.Map <PlaylistItemDto, PlaylistItem>(playlistItemDto);

            return(playlistItem);
        }