public int AddVideo(string Title, VideoStatus Status, string Object, string Description, int?CategoryId, int?CreatorId, string Image, bool?AutoResize, Languages?lan) { int videoID = AddVideo(Title, Status, Object, Description, CategoryId, CreatorId, null, AutoResize, lan, null); WebClient webClient = new WebClient(); string ImageName = Path.GetFileNameWithoutExtension(Image); ImageName = string.Format("{0}_{1}{2}", ImageName, videoID, Path.GetExtension(Image)); string path = WebContext.Server.MapPath("~/" + Folders.VideoThumbsFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, ImageName); webClient.DownloadFile(Image, path); if (AutoResize != null && AutoResize.Value == true) { VideoCategory cat = GetVideoCategory(CategoryId.Value); if (cat.ThumbWidth > 0 && cat.ThumbHeight > 0) { //ImageUtils.Resize(path, path, (int)cat.ThumbWidth, (int)cat.ThumbHeight); ImageUtils.CropImage(path, path, (int)cat.ThumbWidth, (int)cat.ThumbHeight, ImageUtils.AnchorPosition.Default); } else { Config cfg = new Config(); Dimension dim = new Dimension(cfg.GetKey(lw.CTE.parameters.VideoThumbSize)); if (dim.Width > 0 && dim.Height > 0) { ImageUtils.CropImage(path, path, (int)dim.Width, (int)dim.Height, ImageUtils.AnchorPosition.Default); } } } Video thisVideo = this.GetVideo(videoID); thisVideo.ThumbImage = ImageName; MediaData.SubmitChanges(); return(videoID); }
public int AddVideoCategory(string Title, short?ThumbWidth, short?ThumbHeight, bool Status) { if (StringUtils.IsNullOrWhiteSpace(Title)) { return(-1); } VideoCategory videocat = new VideoCategory { Title = Title, ThumbWidth = ThumbWidth, ThumbHeight = ThumbHeight, Status = Status, UniqueName = StringUtils.ToURL(Title) }; MediaData.VideoCategories.InsertOnSubmit(videocat); MediaData.SubmitChanges(); return(videocat.CategoryId); }
partial void DeleteVideoCategory(VideoCategory instance);
partial void UpdateVideoCategory(VideoCategory instance);
partial void InsertVideoCategory(VideoCategory instance);
public int AddVideo(string Title, VideoStatus Status, string Object, string Description, int?CategoryId, int?CreatorId, HttpPostedFile Image, bool?AutoResize, Languages?lan, HttpPostedFile VideoFile) { if (StringUtils.IsNullOrWhiteSpace(Title)) { return(-1); } if (lan == null) { lan = Languages.Default; } Video video = new Video { Title = Title, Status = (byte)Status, Object = Object, Description = Description, CategoryId = CategoryId, CreatorId = CreatorId.Value, DateCreated = DateTime.Now, DateModified = DateTime.Now, UniqueName = StringUtils.ToURL(Title), ModifierId = CreatorId, Language = (short)lan }; MediaData.Videos.InsertOnSubmit(video); MediaData.SubmitChanges(); bool generateThumb = Image != null && Image.ContentLength > 0; if (VideoFile != null && VideoFile.ContentLength > 0) { string videoName = Path.GetFileNameWithoutExtension(VideoFile.FileName); videoName = string.Format("{0}_{1}{2}", videoName, video.VideoId, Path.GetExtension(VideoFile.FileName)); string path = WebContext.Server.MapPath("~/" + Folders.VideosFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, videoName); VideoFile.SaveAs(path); //ShellFile so = ShellFile.FromFilePath(path); //decimal nanoseconds; //decimal.TryParse(so.Properties.System.Media.Duration.Value.ToString(), out nanoseconds); //decimal seconds = nanoseconds * (decimal)0.0000001; //video.VideoLength = seconds; //if (!generateThumb) //{ // string imageName = Path.GetFileNameWithoutExtension(videoName) + ".Jpg"; // string thumbImagePath = WebContext.Server.MapPath("~/" + Folders.VideoThumbsFolder); // if (!Directory.Exists(thumbImagePath)) // { // Directory.CreateDirectory(thumbImagePath); // } // string imagePath = Path.Combine(thumbImagePath, imageName); // //so.Thumbnail.Bitmap.Save (imagePath); // System.Drawing.Bitmap image; // //force the actual thumbnail, not the icon // //so.Thumbnail.FormatOption = ShellThumbnailFormatOptions.ThumbnailOnly; // //image = so.Thumbnail.ExtraLargeBitmap; // image.Save(imagePath); // VideoCategory cat = GetVideoCategory(CategoryId.Value); // if (cat.ThumbWidth > 0 && cat.ThumbHeight > 0) // { // ImageUtils.CropImage(imagePath, imagePath, (int)cat.ThumbWidth, (int)cat.ThumbHeight, ImageUtils.AnchorPosition.Default); // } // else // { // Config cfg = new Config(); // Dimension dim = new Dimension(cfg.GetKey(lw.CTE.parameters.VideoThumbSize)); // if (dim.Width > 0 && dim.Height > 0) // { // ImageUtils.CropImage(imagePath, imagePath, (int)dim.Width, (int)dim.Height, ImageUtils.AnchorPosition.Default); // } // } // video.ThumbImage = imageName; //} video.VideoFile = videoName; MediaData.SubmitChanges(); } if (Image != null && Image.ContentLength > 0) { string ImageName = Path.GetFileNameWithoutExtension(Image.FileName); ImageName = string.Format("{0}_{1}{2}", ImageName, video.VideoId, Path.GetExtension(Image.FileName)); string path = WebContext.Server.MapPath("~/" + Folders.VideoThumbsFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, ImageName); Image.SaveAs(path); if (AutoResize != null && AutoResize.Value == true) { VideoCategory cat = GetVideoCategory(CategoryId.Value); if (cat.ThumbWidth > 0 && cat.ThumbHeight > 0) { //ImageUtils.Resize(path, path, (int)cat.ThumbWidth, (int)cat.ThumbHeight); ImageUtils.CropImage(path, path, (int)cat.ThumbWidth, (int)cat.ThumbHeight, ImageUtils.AnchorPosition.Default); } else { Config cfg = new Config(); Dimension dim = new Dimension(cfg.GetKey(lw.CTE.parameters.VideoThumbSize)); if (dim.Width > 0 && dim.Height > 0) { ImageUtils.CropImage(path, path, (int)dim.Width, (int)dim.Height, ImageUtils.AnchorPosition.Default); } } } video.ThumbImage = ImageName; MediaData.SubmitChanges(); } return(video.VideoId); }
public int UpdateVideoWithImage(int VideoId, string Title, VideoStatus Status, string Object, string Description, int?CategoryId, int ModifierId, HttpPostedFile Image, bool?AutoResize, bool DeleteOldImage, Languages?lan, bool?Crop) { if (lan == null) { lan = Languages.Default; } var video = GetVideo(VideoId); video.Title = Title; video.Status = (byte)Status; video.Object = Object; video.Description = Description; video.CategoryId = CategoryId; video.DateModified = DateTime.Now; video.UniqueName = StringUtils.ToURL(Title); video.ModifierId = ModifierId; video.Language = (short)lan; MediaData.SubmitChanges(); string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.VideoThumbsFolder)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var oldImage = video.ThumbImage; DeleteOldImage = DeleteOldImage || (Image != null && Image.ContentLength > 0); if (DeleteOldImage && !StringUtils.IsNullOrWhiteSpace(video.ThumbImage)) { if (File.Exists(Path.Combine(path, oldImage))) { File.Delete(Path.Combine(path, oldImage)); } video.ThumbImage = ""; } if (Image != null && Image.ContentLength > 0) { string ImageName = Path.GetFileNameWithoutExtension(Image.FileName); ImageName = string.Format("{0}_{1}{2}", ImageName, video.VideoId, Path.GetExtension(Image.FileName)); string _path = Path.Combine(path, ImageName); Image.SaveAs(_path); if (AutoResize != null && AutoResize.Value) { VideoCategory cat = GetVideoCategory(CategoryId.Value); if (cat.ThumbWidth > 0 && cat.ThumbHeight > 0) { if (Crop != null && Crop == true) { ImageUtils.CropImage(_path, _path, (int)cat.ThumbWidth, (int)cat.ThumbHeight, ImageUtils.AnchorPosition.Default); } else { ImageUtils.Resize(_path, _path, (int)cat.ThumbWidth, (int)cat.ThumbHeight); } } else { Config cfg = new Config(); Dimension dim = new Dimension(cfg.GetKey(lw.CTE.parameters.VideoThumbSize)); if (dim.Width > 0 && dim.Height > 0) { ImageUtils.CropImage(_path, _path, (int)dim.Width, (int)dim.Height, ImageUtils.AnchorPosition.Default); } } } video.ThumbImage = ImageName; } MediaData.SubmitChanges(); return(VideoId); }
public int UpdateVideo(int VideoId, string Title, VideoStatus Status, string Object, string Description, int?CategoryId, int ModifierId, HttpPostedFile Image, bool?AutoResize, bool DeleteOldImage, Languages?lan, HttpPostedFile VideoFile) { if (lan == null) { lan = Languages.Default; } var video = GetVideo(VideoId); video.Title = Title; video.Status = (byte)Status; video.Object = Object; video.Description = Description; video.CategoryId = CategoryId; video.DateModified = DateTime.Now; video.UniqueName = StringUtils.ToURL(Title); video.ModifierId = ModifierId; video.Language = (short)lan; MediaData.SubmitChanges(); string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.VideosFolder)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var oldImage = video.ThumbImage; bool generateThumb = Image != null && Image.ContentLength > 0; if (VideoFile != null && VideoFile.ContentLength > 0) { string videoName = Path.GetFileNameWithoutExtension(VideoFile.FileName); videoName = string.Format("{0}_{1}{2}", videoName, video.VideoId, Path.GetExtension(VideoFile.FileName)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, videoName); VideoFile.SaveAs(path); //ShellFile so = ShellFile.FromFilePath(path); //decimal nanoseconds; //decimal.TryParse(so.Properties.System.Media.Duration.Value.ToString(), out nanoseconds); //decimal seconds = nanoseconds * (decimal)0.0000001; //video.VideoLength = seconds; if (!generateThumb) { string imageName = Path.GetFileNameWithoutExtension(videoName) + ".Jpg"; string imagePath = Path.Combine(WebContext.Server.MapPath("~/" + Folders.VideoThumbsFolder), imageName); //so.Thumbnail.Bitmap.Save(imagePath); VideoCategory cat = GetVideoCategory(CategoryId.Value); if (cat.ThumbWidth > 0 && cat.ThumbHeight > 0) { ImageUtils.CropImage(imagePath, imagePath, (int)cat.ThumbWidth, (int)cat.ThumbHeight, ImageUtils.AnchorPosition.Default); } else { Config cfg = new Config(); Dimension dim = new Dimension(cfg.GetKey(lw.CTE.parameters.VideoThumbSize)); if (dim.Width > 0 && dim.Height > 0) { ImageUtils.CropImage(imagePath, imagePath, (int)dim.Width, (int)dim.Height, ImageUtils.AnchorPosition.Default); } } video.ThumbImage = imageName; } video.VideoFile = videoName; MediaData.SubmitChanges(); } DeleteOldImage = DeleteOldImage || (Image != null && Image.ContentLength > 0); if (DeleteOldImage && !StringUtils.IsNullOrWhiteSpace(video.ThumbImage)) { if (File.Exists(Path.Combine(path, oldImage))) { File.Delete(Path.Combine(path, oldImage)); } video.ThumbImage = ""; } if (AutoResize != null && AutoResize.Value == true) { VideoCategory cat = GetVideoCategory(CategoryId.Value); if (cat.ThumbWidth > 0 && cat.ThumbHeight > 0) { //ImageUtils.Resize(path, path, (int)cat.ThumbWidth, (int)cat.ThumbHeight); ImageUtils.CropImage(path, path, (int)cat.ThumbWidth, (int)cat.ThumbHeight, ImageUtils.AnchorPosition.Default); } else { Config cfg = new Config(); Dimension dim = new Dimension(cfg.GetKey(lw.CTE.parameters.VideoThumbSize)); if (dim.Width > 0 && dim.Height > 0) { ImageUtils.CropImage(path, path, (int)dim.Width, (int)dim.Height, ImageUtils.AnchorPosition.Default); } } } MediaData.SubmitChanges(); return(VideoId); }