Ejemplo n.º 1
0
    private async Task <bool> UpdateVideoInfoAsync(Video video, long videoId, bool createThumbnails = true)
    {
        var archiveVideo = new ArchiveVideo
        {
            Title        = video.Name,
            DateCreated  = new DateTimeOffset(video.CreatedTime.ToUniversalTime()),
            DateUploaded = DateTimeOffset.UtcNow,
            Duration     = video.Duration,
            VideoId      = videoId.ToString(),
            Password     = video.Password,
            Description  = video.Description,
            VideoUrl     = video.Link
        };

        if (createThumbnails)
        {
            var getAnimatedThumbnailResult = await CreateAnimatedThumbnails(videoId);

            archiveVideo.AnimatedThumbnailUri = getAnimatedThumbnailResult.AnimatedThumbnailUri;
        }

        var videoInfoResponse = await _addVideoInfo.ExecuteAsync(archiveVideo);

        if (videoInfoResponse == null || videoInfoResponse.Code != System.Net.HttpStatusCode.OK)
        {
            _logger.LogError($"{video.Name} - {videoId} Add/Update info Error!");
            _logger.LogError($"Error: {videoInfoResponse?.Text}");
            return(false);
        }

        _logger.LogInformation($"{video.Name} - {videoId} Add/Update info Done.");
        return(true);
    }
Ejemplo n.º 2
0
        public static void PopulateTestData(AppDbContext dbContext)
        {
            if (dbContext.ArchiveVideos.Any())
            {
                return;
            }

            var vid1 = new ArchiveVideo()
            {
                Title       = "Video One",
                ShowNotes   = @"
# Video about using markdown in ASP.NET Core

In this video we talk about some stuff. In this video we talk about some stuff. In this video we talk about some stuff. In this video we talk about some stuff. In this video we talk about some stuff. In this video we talk about some stuff. 

<a href="" "" class=""ts"" data-time=""20"">00:20</a>

<a href = "" "" class=""ts"" data-time=""40"">00:40</a>

<a href = "" "" class=""ts"" data-time=""60"">00:60</a>

## References

- [Steve's Blog](https://ardalis.com)
- [Google](https://google.com)
",
                DateCreated = new DateTime(2019, 3, 8),
                VideoUrl    = "2019-05-17-3.mp4"
            };
            var vid2 = new ArchiveVideo()
            {
                Title       = "Video Two",
                DateCreated = new DateTime(2019, 3, 15)
            };
            var questionA = new Question()
            {
                QuestionText     = "How do I A?",
                TimestampSeconds = 30
            };
            var questionB = new Question()
            {
                QuestionText     = "How do I B?",
                TimestampSeconds = 245
            };

            vid1.Questions.Add(questionA);
            vid1.Questions.Add(questionB);

            dbContext.ArchiveVideos.Add(vid1);
            dbContext.ArchiveVideos.Add(vid2);
            dbContext.SaveChanges();

            //dbContext.ArchiveVideos.Add(new ArchiveVideo()
            //{
            //    DateCreated = DateTime.Now,
            //    Title = "Test Video",
            //    VideoUrl = "http://youtube.com"
            //});
            //dbContext.SaveChanges();
        }
        public void DoesNothingGivenNullQuestion()
        {
            var video = new ArchiveVideo();

            video.AddQuestion(null);

            Assert.Empty(video.Questions);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(List <IFormFile> files)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var videoEntity = new ArchiveVideo()
            {
                DateCreated = ArchiveVideoModel.DateCreated,
                ShowNotes   = ArchiveVideoModel.ShowNotes,
                Title       = ArchiveVideoModel.Title,
                VideoUrl    = ""
            };

            _repository.Add(videoEntity);

            var uploadSuccess = false;

            string dateString = videoEntity.DateCreated.ToString(Constants.FILE_DATE_FORMAT_STRING);
            string fileName   = "";

            foreach (var formFile in files)
            {
                if (formFile.Length <= 0)
                {
                    continue;
                }

                // NOTE: uncomment either OPTION A or OPTION B to use one approach over another

                // OPTION A: convert to byte array before upload
                //using (var ms = new MemoryStream())
                //{
                //    formFile.CopyTo(ms);
                //    var fileBytes = ms.ToArray();
                //    uploadSuccess = await UploadToBlob(formFile.FileName, fileBytes, null);
                //}

                // OPTION B: read directly from stream for blob upload
                using (var stream = formFile.OpenReadStream())
                {
                    string extension = formFile.FileName.Split(".").Last();
                    fileName      = $"{dateString}-{videoEntity.Id}.{extension}";
                    uploadSuccess = await UploadToBlob(fileName, null, stream);
                }
            }

            if (uploadSuccess)
            {
                videoEntity.VideoUrl = fileName;
                _repository.Update(videoEntity);
                return(RedirectToPage("/ArchivedVideos/Index"));
            }


            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 5
0
    public MemberVideoProgress(int memberId, ArchiveVideo archiveVideo, int secondWatched)
    {
        MemberId = memberId;

        ArchiveVideo   = archiveVideo;
        ArchiveVideoId = ArchiveVideo.Id;

        SecondWatched = secondWatched;
    }
        public void AddsQuestionToQuestionsList()
        {
            var video    = new ArchiveVideo();
            var question = new Question();

            video.AddQuestion(question);

            Assert.Same(question, video.Questions.First());
        }
    public void ShouldRemoveFavoriteArchiveVideoGivenExistingFavoriteArchiveVideo()
    {
        var member       = MemberHelpers.CreateWithInternalConstructor();
        var archiveVideo = new ArchiveVideo
        {
            Id = _validArchiveVideoId,
        };

        member.AddFavoriteArchiveVideo(archiveVideo);

        member.RemoveFavoriteArchiveVideo(archiveVideo);

        member.FavoriteArchiveVideos.Should().BeEmpty();
    }
    public void ShouldDoNothingGivenDuplicateArchiveVideo()
    {
        var member = MemberHelpers.CreateWithInternalConstructor();

        var archiveVideo = new ArchiveVideo
        {
            Id = _validArchiveVideoId,
        };

        member.AddFavoriteArchiveVideo(archiveVideo);
        member.AddFavoriteArchiveVideo(archiveVideo);

        member.FavoriteArchiveVideos.Count().Should().Be(1);
    }
    public void ShouldAddFavoriteArchiveVideoGivenArchiveVideo()
    {
        var member = MemberHelpers.CreateWithInternalConstructor();

        var archiveVideo = new ArchiveVideo
        {
            Id = _validArchiveVideoId,
        };

        member.AddFavoriteArchiveVideo(archiveVideo);

        using (new AssertionScope())
        {
            member.FavoriteArchiveVideos.Single().ArchiveVideoId.Should().Be(_validArchiveVideoId);
            member.FavoriteArchiveVideos.Single().MemberId.Should().Be(member.Id);
        }
    }
Ejemplo n.º 10
0
        private void CreateaArchivedVideos(IEnumerable <FileInfo> filesInfo)
        {
            foreach (var file in filesInfo)
            {
                var archivedVideo = new ArchiveVideo
                {
                    Fullname     = file.FullName,
                    Name         = file.Name.Split('.').First(),
                    CreationDate = file.Name.GetDateFromFileName()
                };

                ShellFile thumbNail  = ShellFile.FromFilePath(archivedVideo.Fullname);
                var       thumbLarge = thumbNail.Thumbnail.LargeBitmap;
                archivedVideo.PreviewImage = thumbLarge.ToBitmapImage();

                ArchivedVideos.Add(archivedVideo);

                RaisePropertyChanged("ArchivedVideos");
            }
        }
    public void ShouldDoNothingGivenFavoriteArchiveVideoNotInFavoriteArchiveVideos()
    {
        var member = MemberHelpers.CreateWithInternalConstructor();
        var existingArchiveVideo = new ArchiveVideo
        {
            Id = _validArchiveVideoId,
        };

        member.AddFavoriteArchiveVideo(existingArchiveVideo);
        int expectedCount = member.FavoriteArchiveVideos.Count();

        var nonexistingArchiveVideo = new ArchiveVideo
        {
            Id = _validArchiveVideoId + 1,
        };

        member.RemoveFavoriteArchiveVideo(nonexistingArchiveVideo);

        member.FavoriteArchiveVideos.Count().Should().Be(expectedCount);
    }
Ejemplo n.º 12
0
    public async Task UpdateAnimatedThumbnailsAsync(string vimeoId)
    {
        _logger.LogInformation("UpdateAnimatedThumbnailsAsync Started");

        var response = await _getVideoService.ExecuteAsync(vimeoId);

        if (response?.Code != HttpStatusCode.OK)
        {
            _logger.LogInformation("Video Does Not Exist on Vimeo!");
            _logger.LogError($"Vimeo ID: {vimeoId} Update Animated Thumbnails getVideoService Error!");
            _logger.LogError($"Error: HTTP {response?.Code} {response?.Text}");
            return;
        }

        var archiveVideo = new ArchiveVideo
        {
            VideoId = vimeoId
        };

        var getAnimatedThumbnailResult = await CreateAnimatedThumbnails(long.Parse(vimeoId));

        _logger.LogDebug($"AnimatedThumbnailUri: {getAnimatedThumbnailResult.AnimatedThumbnailUri}");

        archiveVideo.AnimatedThumbnailUri = getAnimatedThumbnailResult.AnimatedThumbnailUri;

        var updateVideoThumbnailsResponse = await _updateVideoThumbnails.ExecuteAsync(archiveVideo);

        if (updateVideoThumbnailsResponse == null || updateVideoThumbnailsResponse.Code != HttpStatusCode.OK)
        {
            _logger.LogError($"{vimeoId} Update Animated Thumbnails _updateVideoThumbnails Error!");
            _logger.LogError($"Error: HTTP {updateVideoThumbnailsResponse?.Code} {updateVideoThumbnailsResponse?.Text}");
            return;
        }

        _logger.LogInformation($"{vimeoId} Is Updated.");
    }
Ejemplo n.º 13
0
    public static void PopulateTestData(AppDbContext dbContext,
                                        UserManager <ApplicationUser> userManager)
    {
        if (dbContext.ArchiveVideos !.Any())
        {
            return;
        }

        var vid1 = new ArchiveVideo()
        {
            Title       = "Video One",
            Description = @"
# Video about using markdown in ASP.NET Core

In this video we talk about some stuff. In this video we talk about some stuff. In this video we talk about some stuff. In this video we talk about some stuff. In this video we talk about some stuff. In this video we talk about some stuff. 

<a href="" "" class=""ts"" data-time=""20"">00:20</a>

<a href = "" "" class=""ts"" data-time=""40"">00:40</a>

<a href = "" "" class=""ts"" data-time=""60"">00:60</a>

## References

- [Steve's Blog](https://ardalis.com)
- [Google](https://google.com)
",
            DateCreated = new DateTime(2019, 3, 8),
            VideoUrl    = "2019-05-17-3.mp4"
        };
        var vid2 = new ArchiveVideo()
        {
            Title       = "Video Two",
            DateCreated = new DateTime(2019, 3, 15)
        };
        var questionA = new Question()
        {
            QuestionText     = "How do I A?",
            TimestampSeconds = 30
        };
        var questionB = new Question()
        {
            QuestionText     = "How do I B?",
            TimestampSeconds = 245
        };

        vid1.Questions.Add(questionA);
        vid1.Questions.Add(questionB);

        dbContext.ArchiveVideos !.Add(vid1);
        dbContext.ArchiveVideos.Add(vid2);

        dbContext.Books !.Add(new Book
        {
            Author      = "Steve Smith",
            Title       = "ASP.NET By Example",
            PurchaseUrl = "https://ardalis.com",
            Details     = "A classic."
        });
        dbContext.SaveChanges();

        AddMembers(dbContext, userManager);
    }
Ejemplo n.º 14
0
        public void InitializesListOfQuestions()
        {
            var video = new ArchiveVideo();

            Assert.NotNull(video.Questions);
        }
        public void ThrowsArgumentNullExceptionGivenNullQuestion()
        {
            var video = new ArchiveVideo();

            var exception = Assert.Throws <ArgumentNullException>(() => video.AddQuestion(null !));
        }
Ejemplo n.º 16
0
    public void AddVideoProgress(ArchiveVideo archiveVideo, int secondWatch)
    {
        var video = new MemberVideoProgress(Id, archiveVideo, secondWatch);

        Videos.Add(video);
    }
Ejemplo n.º 17
0
 public VideoAddedEvent(ArchiveVideo video)
 {
     Video = video;
 }