Exemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "Id,Name,TotalDuration, Videos")] PlaylistViewModel playList)
        {
            using (SignageContainer db = new SignageContainer())
            {
                if (ModelState.IsValid)
                {
                    var videos = db.Videos
                                 .Where(v => playList.Videos.Contains(v.Id))
                                 .ToArray();

                    var totalDuration = TimeSpan.FromSeconds(videos.Sum(v => v.Duration.TotalSeconds));

                    var pl = db.Playlists.Find(playList.Id);
                    pl.Videos.Clear();
                    //db.SaveChanges();

                    //foreach(var v in pl.Videos.ToArray())
                    //{
                    //    pl.Videos.Remove(v);
                    //}

                    pl.Name          = playList.Name;
                    pl.TotalDuration = totalDuration;
                    foreach (var v in videos)
                    {
                        pl.Videos.Add(v);
                    }

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(Edit(playList.Id));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Name,TotalDuration, Videos")] PlaylistViewModel playList)
        {
            using (SignageContainer db = new SignageContainer())
            {
                if (ModelState.IsValid)
                {
                    var videos = db.Videos
                                 .Where(v => playList.Videos.Contains(v.Id))
                                 .ToArray();

                    var totalDuration = TimeSpan.FromSeconds(videos.Sum(v => v.Duration.TotalSeconds));

                    var p = new Playlist
                    {
                        Name          = playList.Name,
                        TotalDuration = totalDuration,
                        Videos        = videos
                    };
                    db.Playlists.Add(p);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(Create());
        }
Exemplo n.º 3
0
        public ActionResult Play(int id)
        {
            using (SignageContainer db = new SignageContainer())
            {
                var v = db.Videos.Find(id);

                var url = String.Format("{0}/{1}",
                                        @Url.Content("~/" + ConfigurationManager.AppSettings["VideoFolder"]),
                                        v.FileName);
                return(Json(new { name = v.Name, url = url }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 4
0
 public ActionResult Play(int id, string from)
 {
     using (SignageContainer db = new SignageContainer())
     {
         if (from.Equals("playlist"))
         {
             var pl = db.Playlists.Find(id);
             return(View(pl.Videos));
         }
         ViewBag.Video = db.Videos.Find(id);
         return(View());
     }
 }
Exemplo n.º 5
0
 public ActionResult Edit(int id)
 {
     BindDropDown();
     using (var db = new SignageContainer())
     {
         var pl = db.Playlists.Find(id);
         pl.Videos = db.Playlists.Find(id).Videos;
         if (pl == null)
         {
             return(HttpNotFound());
         }
         return(View(pl));
     }
 }
Exemplo n.º 6
0
        public void BindDropDown()
        {
            using (var db = new SignageContainer())
            {
                ViewBag.Videos = db.Videos
                                 .ToArray()
                                 .Select(v => new SelectListItem()
                {
                    Text = v.Name, Value = v.Id.ToString()
                });

                // return View(new Playlist());
            }
        }
Exemplo n.º 7
0
        public ActionResult Index(int pageNo = 1)
        {
            using (SignageContainer db = new SignageContainer())
            {
                var pageSize = Int32.Parse(ConfigurationManager.AppSettings["PageSize"]);
                int skipRows = (pageNo - 1) * pageSize;

                var data = db.Playlists.Include("Videos").OrderBy(v => v.Name).Skip(skipRows).Take(pageSize).ToArray();
                db.Videos.Include("PlayLists");
                var totalRecCount = db.Playlists.Count();
                ViewBag.Paging = new PageList(pageSize, totalRecCount, pageNo);
                return(View(data));
            }
        }
Exemplo n.º 8
0
        // GET: /Video/
        public ActionResult Index(int?page)
        {
            using (var db = new SignageContainer())
            {
                int pageSize  = 10;
                int curPageNo = page.HasValue ? Convert.ToInt32(page) : 1;
                int skipRows  = (curPageNo - 1) * pageSize;
                int noOfLinks = 10;

                var data             = db.Videos.OrderBy(v => v.Name).Skip(skipRows).Take(pageSize).ToArray();
                var totalRecordCount = db.Videos.Count();
                ViewBag.Paging = new Paging(pageSize, totalRecordCount, curPageNo, noOfLinks);
                return(View(data));
            }
        }
Exemplo n.º 9
0
        void DeleteFile(int id)
        {
            using (var db = new SignageContainer())
            {
                var fileName = (from p in db.Videos
                                where p.Id == id
                                select p).First().FileName;

                var filePath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings["VideoFolder"] + "/")) + fileName;

                FileInfo file = new FileInfo(filePath);
                if (file.Exists)    //check file exsit or not
                {
                    file.Delete();
                }
            }
        }
Exemplo n.º 10
0
        public ActionResult IndexPost(IEnumerable <int> deleteInputs)
        {
            using (var db = new SignageContainer())
            {
                foreach (var item in deleteInputs)
                {
                    var video = db.Videos.Find(item);
                    if (video == null)
                    {
                        return(HttpNotFound());
                    }

                    // Delete File from Folder
                    DeleteFile(item);
                    // Delete File Record from Database
                    db.Videos.Remove(video);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 11
0
        public ActionResult DeleteSelected(int[] IdsToDelete)
        {
            if (IdsToDelete != null && IdsToDelete.Length > 0)
            {
                List <Playlist> allSelected = new List <Playlist>();
                using (SignageContainer db = new SignageContainer())
                {
                    allSelected = db.Playlists.Where(p => IdsToDelete.Contains(p.Id)).ToList();
                    foreach (var i in allSelected)
                    {
                        //foreach (var v in i.Videos.ToArray()) Delete is original , loop is copy
                        //{
                        //    i.Videos.Remove(v);
                        //}

                        db.Playlists.Remove(i);
                    }

                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
        public ActionResult UploadFile()

        {
            var statuses = new List <FilesStatus>();

            for (int i = 0; i < Request.Files.Count; i++)
            {
                var file = Request.Files[i];

                //using (MediaFile mf = new MediaFile(file.InputStream))
                //{
                double durationinNanoSecond = 10000;
                //if (durationinNanoSecond > 0 && mf.Video.Count > 0)
                //{
                Guid NewGuid = Guid.NewGuid();

                var fullPath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings["VideoFolder"] + "/")
                                            , Path.GetFileNameWithoutExtension(file.FileName).Replace(" ", "_")
                                            + "_" + NewGuid.ToString() + Path.GetExtension(file.FileName));

                file.SaveAs(fullPath);

                Process.Start(new ProcessStartInfo(
                                  Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/" + "FFmpeg/ffmpeg.exe"))
                                  , "-ss 10"
                                  + " -i " + fullPath
                                  + @" -vf " + @"scale=100:-1,select='eq(pict_type,PICT_TYPE_I)'"
                                  + " -frames:v 1"
                                  + " " + Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/"
                                                                                                     + ConfigurationManager.AppSettings["ThumbnailFolder"] + "/")
                                                       , Path.GetFileNameWithoutExtension(file.FileName).Replace(" ", "_")
                                                       + "_" + NewGuid.ToString() + ConfigurationManager.AppSettings["ThumbnailImageExtension"])))
                .WaitForExit(3000);


                string fullName = Path.GetFileName(file.FileName);

                statuses.Add(new FilesStatus(fullName, file.ContentLength, fullPath));
                double   durationinSecond = durationinNanoSecond / 1000;
                TimeSpan ts = TimeSpan.FromSeconds(durationinSecond);

                decimal MediaInfoDotnetsizeonByte = Convert.ToDecimal(120.0);
                Video   Newvideo = new Video();
                Newvideo.Name     = Path.GetFileNameWithoutExtension(file.FileName);
                Newvideo.Duration = ts;
                Newvideo.Size     = MediaInfoDotnetsizeonByte.ToString();
                Newvideo.FileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + NewGuid.ToString() + Path.GetExtension(file.FileName);

                using (var db = new SignageContainer())
                {
                    db.Videos.Add(Newvideo);

                    db.SaveChanges();
                }
                //    }
                //    else
                //    {
                //        statuses[i].error = "File Format Not Support ";
                //        return Json(statuses);
                //    }
                //}
            }

            JsonResult result = Json(statuses);

            result.ContentType = "application/json";

            return(Json(statuses));
        }