예제 #1
0
        public override void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse)
        {
            var videoJson = string.Format("{0}/{1}", Dir, config.Video);
            var video     = File.Exists(videoJson)
                                ? JsonConvert.DeserializeObject <Video>(File.ReadAllText(videoJson))
                                : new Video {
                Records = new Record[0]
            };

            VideoHistory.UpdateHistory(Dir, video);
            var guids = Guids == null ? null : Guids.Split(',').Select(Utils.GetNormalizedGuid).ToList();

            if (config.Video != null && File.Exists(string.Format("{0}/{1}", Dir, config.Video)))
            {
                var videoComponents = video
                                      .Records
                                      .Where(x => guids == null || guids.Contains(Utils.GetNormalizedGuid(x.Guid)))
                                      .Select(x => new VideoComponent(Utils.GetNormalizedGuid(x.Guid), x.Data.Name, x.Data.Id));

                patcher.PatchComponents(
                    edxCourse,
                    videoComponents,
                    guids != null || !SkipExistingGuids
                    );
            }
        }
        public async Task AddVideoToHistoryAsync(string videoId, string userId)
        {
            var videoHistory = this.videoHistoryRepository.AllWithDeleted()
                               .FirstOrDefault(h => h.VideoId == videoId && h.UserId == userId);

            if (videoHistory != null)
            {
                if (videoHistory.IsDeleted == true)
                {
                    videoHistory.IsDeleted = false;
                    videoHistory.DeletedOn = null;
                }

                videoHistory.CreatedOn = DateTime.UtcNow;
            }
            else
            {
                videoHistory = new VideoHistory
                {
                    UserId  = userId,
                    VideoId = videoId,
                };

                await this.videoHistoryRepository.AddAsync(videoHistory);
            }

            await this.videoHistoryRepository.SaveChangesAsync();
        }
 private void ClearHistoryBtn_Click(object sender, EventArgs e)
 {
     if (top != null)
     {
         top = null;
         PrintHistory();
     }
 }
예제 #4
0
        public override void DoExecute()
        {
            var profile = Config.GetProfile(Profile);

            Console.WriteLine("Please, download course from Edx (tar.gz from Tools - Export menu) and save it in working directory");


            var tarGzPath = Dir.GetSingleFile(CourseTarGz ?? "*.tar.gz");

            EdxInteraction.ExtractEdxCourseArchive(Dir, tarGzPath);

            Console.WriteLine("Loading edx course...");
            var edxCourse = EdxCourse.Load(Dir + "/olx");

            if (edxCourse.CourseWithChapters.Chapters.Length != 0)
            {
                Console.WriteLine("List of chapters to be removed or replaced:");
                foreach (var chapterName in edxCourse.CourseWithChapters.Chapters.Select(x => x.DisplayName))
                {
                    Console.WriteLine("\t" + chapterName);
                }
                while (true)
                {
                    Console.WriteLine("Do you want to proceed? (y/n)");
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Y)
                    {
                        break;
                    }
                    if (key.Key == ConsoleKey.N)
                    {
                        return;
                    }
                }
            }
            var video = LoadVideoInfo();

            VideoHistory.UpdateHistory(Dir, video);

            Console.WriteLine($"Loading ulearn course from {Config.ULearnCourseId}");
            var course = new CourseLoader().LoadCourse(new DirectoryInfo(Path.Combine(Dir, Config.ULearnCourseId)));

            Console.WriteLine($"Converting ulearn course \"{course.Id}\" to edx course");
            Converter.ToEdxCourse(
                course,
                Config,
                profile.UlearnUrl + SlideUrlFormat,
                profile.UlearnUrl + SolutionsUrlFormat,
                video.Records.ToDictionary(x => x.Data.Id, x => x.Guid.GetNormalizedGuid())
                ).Save(Dir + "/olx");

            EdxInteraction.CreateEdxCourseArchive(Dir, course.Id);

            Console.WriteLine($"Now you can upload {course.Id}.tar.gz to edx via Tools - Import menu");
        }
        public void PrintHistory()
        {
            VideoHistory cur            = top;
            string       currentHistory = "";
            int          videoNumber    = 1;

            while (cur != null)
            {
                currentHistory += videoNumber + ": " + cur.data + Environment.NewLine;
                videoNumber++;
                cur = cur.next;
            }

            browserHistoryBox.Text = currentHistory;
        }
        public void AddToHistory(string videoToAdd)
        {
            if (top == null)
            {
                VideoHistory newVideo = new VideoHistory(videoToAdd);
                top = newVideo;
            }
            else
            {
                VideoHistory newVideo = new VideoHistory(videoToAdd);

                newVideo.next = top;
                top           = newVideo;
            }
        }
예제 #7
0
        public override void DoExecute()
        {
            var profile     = Config.GetProfile(Profile);
            var credentials = Credentials.GetCredentials(Dir, Profile);

            EdxInteraction.Download(Dir, Config, profile.EdxStudioUrl, credentials);

            var edxCourse = EdxCourse.Load(Dir + "/olx");

            if (edxCourse.CourseWithChapters.Chapters.Length != 0)
            {
                Console.WriteLine("List of chapters to be removed or replaced:");
                foreach (var chapterName in edxCourse.CourseWithChapters.Chapters.Select(x => x.DisplayName))
                {
                    Console.WriteLine("\t" + chapterName);
                }
                while (true)
                {
                    Console.WriteLine("Do you want to proceed? (y/n)");
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Y)
                    {
                        break;
                    }
                    if (key.Key == ConsoleKey.N)
                    {
                        return;
                    }
                }
            }
            var video = LoadVideoInfo();

            VideoHistory.UpdateHistory(Dir, video);

            Console.WriteLine("Loading uLearn course from {0}", Config.ULearnCourseId);
            var course = new CourseLoader().LoadCourse(new DirectoryInfo(Path.Combine(Dir, Config.ULearnCourseId)));

            Console.WriteLine("Converting uLearn course \"{0}\" to Edx course", course.Id);
            Converter.ToEdxCourse(
                course,
                Config,
                profile.UlearnUrl + SlideUrlFormat,
                profile.UlearnUrl + SolutionsUrlFormat,
                video.Records.ToDictionary(x => x.Data.Id, x => Utils.GetNormalizedGuid(x.Guid))
                ).Save(Dir + "/olx");

            EdxInteraction.Upload(Dir, course.Id, Config, profile.EdxStudioUrl, credentials);
        }
        public HistoriesServiceTests()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            this.historyRepository = new EfDeletableEntityRepository <VideoHistory>(new ApplicationDbContext(options.Options));

            this.service = new HistoriesService(this.historyRepository);

            this.videoHistory = new VideoHistory
            {
                Id      = 1,
                UserId  = "user1",
                VideoId = "video1",
            };
        }
        public async Task PostShouldAddAnalysisAsync()
        {
            //arrange
            var mockRepo          = new Mock <IRepository>();
            var inputVideoHistory = new VideoHistory()
            {
                Email    = "*****@*****.**",
                VideoUrl = "ABC",
                AverageSentimentScore = 0.5,
                ChannelName           = "Mathemars"
            };
            var controller = new UserSentimentHistoryController(mockRepo.Object);

            //act
            var result = await controller.PostAsync(inputVideoHistory);

            //assert
            Assert.IsAssignableFrom <CreatedAtActionResult>(result);
        }
        public async Task PostShouldHandleRequestsAsync()
        {
            //arrange
            var mockRepo = new Mock <IRepository>();

            mockRepo.Setup(x => x.AddAnalysisAsync(It.IsAny <AverageSentiment>(), It.IsAny <Creator>())).Throws(new Persistence.CreatorDoesNotExistException());
            var inputVideoHistory = new VideoHistory()
            {
                Email    = "*****@*****.**",
                VideoUrl = "ABC",
                AverageSentimentScore = 0.5,
                ChannelName           = "Mathemars"
            };
            var controller = new UserSentimentHistoryController(mockRepo.Object);

            //act
            var result = await controller.PostAsync(inputVideoHistory);

            //assert
            Assert.IsAssignableFrom <BadRequestResult>(result);
        }
예제 #11
0
        public override void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse)
        {
            var ulearnDir = new DirectoryInfo(string.Format("{0}/{1}", Dir, config.ULearnCourseId));

            Console.WriteLine("Loading Ulearn course from {0}", ulearnDir.Name);
            var ulearnCourse = new CourseLoader().Load(ulearnDir);

            Console.WriteLine("Patching");
            var videoJson = string.Format("{0}/{1}", Dir, config.Video);
            var video     = File.Exists(videoJson)
                                ? JsonConvert.DeserializeObject <Video>(File.ReadAllText(videoJson))
                                : new Video {
                Records = new Record[0]
            };
            var videoHistory = VideoHistory.UpdateHistory(Dir, video);
            var videoGuids   = videoHistory.Records
                               .SelectMany(x => x.Data.Select(y => Tuple.Create(y.Id, x.Guid.GetNormalizedGuid())))
                               .ToDictionary(x => x.Item1, x => x.Item2);

            var guids = Guids?.Split(',').Select(Utils.GetNormalizedGuid).ToList();

            patcher.PatchVerticals(
                edxCourse,
                ulearnCourse.Slides
                .Where(s => !config.IgnoredUlearnSlides.Select(Guid.Parse).Contains(s.Id))
                .Where(s => guids == null || guids.Contains(s.NormalizedGuid))
                .Select(s => s.ToVerticals(
                            ulearnCourse.Id,
                            profile.UlearnUrl,
                            videoGuids,
                            config.LtiId,
                            CoursePackageRoot
                            ).ToArray()),
                guids != null || !SkipExistingGuids
                );
            if (Config.EmitSequentialsForInstructorNotes)
            {
                PatchInstructorsNotes(edxCourse, ulearnCourse, patcher.OlxPath);
            }
        }
        public async Task <IActionResult> PostAsync([FromBody] VideoHistory inputVideo)
        {
            try
            {
                AverageSentiment inputAnalysis = new AverageSentiment()
                {
                    VideoURL = inputVideo.VideoUrl,
                    AverageSentimentScore = inputVideo.AverageSentimentScore
                };
                Creator inputCreator = new Creator()
                {
                    Email       = inputVideo.Email,
                    ChannelName = inputVideo.ChannelName
                };
                await _repository.AddAnalysisAsync(inputAnalysis, inputCreator);

                return(CreatedAtAction("Post", inputVideo));
            }
            catch
            {
                return(BadRequest());
            }
        }