protected void btnNewCategory_Click(object sender, EventArgs e) { // Parse the new category string CatName = Sanitizers.SanitizeGeneralInputString(txtNewCategoryName.Text); string Parent = Sanitizers.SanitizeGeneralInputString(drpParent.SelectedValue); bool Hidden = chkHidden.Checked; bool Private = chkPrivate.Checked; if ((!string.IsNullOrEmpty(CatName)) && (CatName.Length > 2)) { VideoCategory NewCategory = new VideoCategory() { Name = CatName, ParentCategoryID = Parent, IsHidden = Hidden, IsPrivate = Private }; VideoCategoryRepository videoCategoryRepository = new VideoCategoryRepository(); videoCategoryRepository.Insert(NewCategory); txtNewCategoryName.Text = ""; chkHidden.Checked = false; chkPrivate.Checked = false; refreshCategoryList(); } }
private void displayVideo(Video video) { lblID.Text = video.ID; txtTitle.Text = video.Name; txtAuthor.Text = video.Author; txtDescription.Text = video.Description; txtTags.Text = video.Tags.ToSpaceSeparatedString(); txtWidth.Text = video.Width.ToString(); txtHeight.Text = video.Height.ToString(); txtDuration.Text = video.DurationInSeconds.ToString(); txtYoutubeURL.Text = video.YoutubeURL; txtYoutubeStartTime.Text = video.YoutubeStartTimeInSeconds.ToString(); txtMP4URL.Text = video.FileURL_H264; txtOGVURL.Text = video.FileURL_THEORA; txtWEBM.Text = video.FileURL_VP8; txtDownloadURL.Text = video.DownloadURL; chkhidden.Checked = video.IsHidden; chkPrivate.Checked = video.IsPrivate; // Category VideoCategoryRepository videoCategoryRepo = new VideoCategoryRepository(); drpCategory.Items.Clear(); drpCategory.Items.Add(new ListItem() { Text = " - No Category -", Value = "0" }); foreach (VideoCategory category in videoCategoryRepo.GetAll().OrderBy(c => c.FullName)) { bool selected = video.CategoryID == category.ID; drpCategory.Items.Add(new ListItem() { Selected = selected, Text = category.FullName, Value = category.ID }); } // Thumbnail imgThumbnail.ImageUrl = "/thumbnails/videos/" + video.ThumbnailURL; DirectoryInfo ThumbnailDirectory = new DirectoryInfo(Server.MapPath("/thumbnails/videos")); foreach (FileInfo file in ThumbnailDirectory.GetFiles()) { if ( (file.Extension.ToLower() == ".png") || (file.Extension.ToLower() == ".jpg") || (file.Extension.ToLower() == ".gif") ) { ListItem Thumb = new ListItem(file.Name, file.Name); if (video.ThumbnailURL == file.Name) { Thumb.Selected = true; } drpThumbnail.Items.Add(Thumb); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Populate thumbnail dropdown DirectoryInfo ThumbnailDirectory = new DirectoryInfo(Server.MapPath("/thumbnails/videos")); foreach (FileInfo file in ThumbnailDirectory.GetFiles()) { if ( (file.Extension.ToLower() == ".png") || (file.Extension.ToLower() == ".jpg") || (file.Extension.ToLower() == ".gif") ) { ListItem Thumb = new ListItem(file.Name, file.Name); if (file.Name == "blank.png") { Thumb.Selected = true; } drpThumbnail.Items.Add(Thumb); } } // Populate list of categories VideoCategoryRepository videoCategoryRepository = new VideoCategoryRepository(); List <VideoCategory> VideoCategories = videoCategoryRepository.GetAll(); drpCategory.Items.Clear(); drpCategory.Items.Add(new ListItem(" - No Category -", string.Empty)); foreach (VideoCategory cat in VideoCategories.OrderBy(c => c.FullName).ToList <VideoCategory>()) { drpCategory.Items.Add(new ListItem(cat.FullName, cat.ID)); } } }
protected void Page_Load(object sender, EventArgs e) { // If the user hasn't selected a category, display a list of categories // If the user has selected a category, display all videos in that category // Always list categories VideoCategoryRepository videoCategoryRepo = new VideoCategoryRepository(); List <VideoCategory> VideoCategories = videoCategoryRepo.GetTopLevel(); litCategories.Text = addMenuChildren(VideoCategories); // If given a category ID, display all videos from that category if (!string.IsNullOrEmpty(Request.QueryString["category"])) { string parsedCatID = Sanitizers.SanitizeGeneralInputString(Request.QueryString["category"].ToString().Trim()); if (!string.IsNullOrEmpty(parsedCatID)) { VideoCategory selectedCategory = videoCategoryRepo.Get(parsedCatID); if (selectedCategory != null) { // Determine if the viewer is viewing from inside the network string clientIP = Request.ServerVariables["REMOTE_ADDR"]; bool canUserAccessPrivateContent = Config.CanAccessPrivate(clientIP); VideoRepository videoRepository = new VideoRepository(); List <Video> CategoryVideos = videoRepository.GetFromCategory(selectedCategory, canUserAccessPrivateContent); StringBuilder VideoListHTML = new StringBuilder(); foreach (Video video in CategoryVideos) { VideoListHTML.Append(videoListItem(video)); } litVideos.Text = VideoListHTML.ToString(); } } } }
private void refreshCategoryList() { VideoCategoryRepository videoCategoryRepo = new VideoCategoryRepository(); List <VideoCategory> AllCategories = videoCategoryRepo.GetAll(); tblCategories.Rows.Clear(); tblCategories.Rows.Add(AddVideoCategoryTableHeadings()); drpParent.Items.Clear(); drpParent.Items.Add(new ListItem(" - No Parent Category -", string.Empty)); foreach (VideoCategory cat in AllCategories.OrderBy(c => c.FullName).ToList <VideoCategory>()) { tblCategories.Rows.Add(AddVideoCategoryTableRow(cat, false)); // Add categories to the dropdown list if (!IsPostBack) { ListItem newCategoryItem = new ListItem(cat.FullName, cat.ID); drpParent.Items.Add(newCategoryItem); } } }
private Video parseVideo() { string title = txtTitle.Text; string author = txtAuthor.Text; string description = txtDescription.Text; string id = lblID.Text; string tagsRaw = txtTags.Text; List <string> tags = new List <string>(); foreach (string tag in tagsRaw.Split(' ')) { string tagSanitized = tag.Trim(); if (!string.IsNullOrEmpty(tagSanitized)) { if (!tags.Contains(tagSanitized)) { tags.Add(tagSanitized); } } } int width = Parsers.ParseInt(txtWidth.Text); int height = Parsers.ParseInt(txtHeight.Text); string thumbnail = drpThumbnail.SelectedValue; int durationInSeconds = Parsers.ParseInt(txtDuration.Text); string youtubeURL = txtYoutubeURL.Text; int youtubeStartTimeInSeconds = Parsers.ParseInt(txtYoutubeStartTime.Text); string file_mp4 = txtMP4URL.Text; string file_ogg = txtOGVURL.Text; string file_webm = txtWEBM.Text; string downloadURL = txtDownloadURL.Text; bool ishidden = chkhidden.Checked; bool isprivate = chkPrivate.Checked; // Category string cateogryID = string.Empty; VideoCategoryRepository videoCategoryRepo = new VideoCategoryRepository(); VideoCategory category = videoCategoryRepo.Get(drpCategory.SelectedValue); if (category != null) { cateogryID = category.ID; } // Validate if (string.IsNullOrEmpty(title)) { throw new Exception("Title cannot be empty."); } if (width <= 0) { throw new Exception("Width must be greater than zero"); } if (height <= 0) { throw new Exception("Height must be greater than zero"); } return(new Video() { ID = id, Name = title, Author = author, Description = description, Width = width, Height = height, DateAdded = DateTime.Now, DurationInSeconds = durationInSeconds, FileURL_H264 = file_mp4, FileURL_THEORA = file_ogg, FileURL_VP8 = file_webm, DownloadURL = downloadURL, YoutubeURL = youtubeURL, YoutubeStartTimeInSeconds = youtubeStartTimeInSeconds, IsHidden = ishidden, IsPrivate = isprivate, Tags = tags, ThumbnailURL = thumbnail, CategoryID = cateogryID, }); }