Ejemplo n.º 1
0
        public async Task addCaptionAsyncTest_ReturnCaption()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "UserDatabase")
                          .Options;

            using (var context = new AppDbContext(options))
            {
                context.ct_captions.Add(new CaptionFile {
                    VideoID = "1", Caption = "String"
                });
                context.SaveChanges();
            }

            using (var context = new AppDbContext(options))
            {
                CaptionRepos captionrepos = new CaptionRepos(context);
                CaptionFile  captionfile  = new CaptionFile();
                captionfile.VideoID = "2";
                captionfile.Caption = "String2";
                await captionrepos.addCaptionAsync(captionfile);

                CaptionFile capget;
                capget = await captionrepos.getCaptionsAsync("2");

                Assert.AreEqual(captionfile.VideoID, capget.VideoID);
            }
        }
Ejemplo n.º 2
0
        public async Task <CaptionFile> addCaptionAsync(CaptionFile captions)
        {
            await _context.ct_captions.AddAsync(captions);

            await _context.SaveChangesAsync();

            return(captions);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <CaptionFile> > PostCaption([FromBody] CaptionFile caption)
        {
            var user = await _authLogic.GetUserFromToken(HttpContext.User.Identity as ClaimsIdentity);

            if (user == null)
            {
                return(Unauthorized());
            }

            return(await _captionsRepos.addCaptionAsync(caption));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <CaptionFile> > UpdateCaption([FromBody] CaptionFile caption)
        {
            var user = await _authLogic.GetUserFromToken(HttpContext.User.Identity as ClaimsIdentity);

            if (user == null)
            {
                return(Unauthorized());
            }

            await _captionsRepos.updateCaption(caption);

            return(Redirect($"{Request.Host}/StaticFiles/{caption.VideoID}.vtt"));
        }
Ejemplo n.º 5
0
        public void createStaticFile(string id, string filePath, CaptionFile caption)
        {
            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }

            string text = $"WEBVTT - This file has cues.\n\n{caption.Caption}";

            using (FileStream fs = System.IO.File.Create(filePath))
            {
                // Add some text to file
                Byte[] data = new UTF8Encoding(true).GetBytes(text);
                fs.Write(data, 0, text.Length);
            }
        }
Ejemplo n.º 6
0
        public async Task <CaptionFile> updateCaption(CaptionFile newcaption)
        {
            var caption = _context.Set <CaptionFile>()
                          .Local
                          .FirstOrDefault(entry => entry.Id.Equals(newcaption.Id));


            if (caption != null)
            {
                _context.Entry(caption).State = EntityState.Detached;
            }

            _context.Entry(newcaption).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(newcaption);
        }
Ejemplo n.º 7
0
        public async Task <CaptionFile> getCaptionsAsync(string videoid)
        {
            CaptionFile        caption  = null;
            List <CaptionFile> captions = await _context.ct_captions.ToListAsync();

            if (captions != null)
            {
                caption = captions.Last(v => v.VideoID == videoid);
            }

            if (caption != null)
            {
                return(caption);
            }

            else
            {
                return(null);
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <CaptionFile> > GetCaptions(string id)
        {
            var user = await _authLogic.GetUserFromToken(HttpContext.User.Identity as ClaimsIdentity);

            if (user == null)
            {
                return(Unauthorized());
            }

            CaptionFile caption = await _captionsRepos.getCaptionsAsync(id);

            if (caption == null)
            {
                return(NotFound());
            }

            var filePath = Path.Combine(Directory.GetCurrentDirectory(),
                                        "wwwroot", "StaticFiles", $"{id}.vtt");

            _captionLogic.createStaticFile(id, filePath, caption);


            return(caption);
        }