public void ProcessRequest(HttpContext context) { try { //上传路径 string uploadPathKey = WeiSha.Common.Request.QueryString["path"].String; string path = WeiSha.Common.Upload.Get[uploadPathKey].Virtual; string uid = WeiSha.Common.Request.QueryString["uid"].String; //全局唯一值 string file = WeiSha.Common.Request.QueryString["file"].String; //添加附件 Song.Entities.Accessory acc = new Song.Entities.Accessory(); //视频操作对象 string videoFile = HttpContext.Current.Server.MapPath(path + file); //上传后的视频文件 WeiSha.Common.VideoHandler handler = WeiSha.Common.VideoHandler.Hanlder(videoFile); if (handler.Width > 0) { acc = setAcc(acc, handler); } if (!string.IsNullOrWhiteSpace(uid)) { //参数 acc.As_Name = Path.GetFileName(file); acc.As_FileName = file; acc.As_Uid = uid; acc.As_IsOuter = false; //非外部链接 acc.As_Type = uploadPathKey; Business.Do <IAccessory>().Delete(uid, false); Business.Do <IAccessory>().Add(acc); } } catch { } }
/// <summary> /// 设置附件的各项参数 /// </summary> /// <param name="acc"></param> /// <param name="handler"></param> /// <returns></returns> Song.Entities.Accessory setAcc(Song.Entities.Accessory acc, WeiSha.Common.VideoHandler handler) { //视频时长 acc.As_Duration = (int)handler.Duration.TotalSeconds; acc.As_Duration = acc.As_Duration > 0 ? acc.As_Duration : 0; acc.As_Width = handler.Width; acc.As_Height = handler.Height; acc.As_Size = (int)handler.Size; return(acc); }
protected void Page_Load(object sender, EventArgs e) { if (Request.ServerVariables["REQUEST_METHOD"] == "GET") { Song.Entities.Accessory acc = Business.Do <IAccessory>().GetSingle(uid); if (acc == null) { return; } tbUrl.Text = acc.As_FileName; tbWidth.Text = acc.As_Width.ToString(); tbHeight.Text = acc.As_Height.ToString(); tbSpan.Text = (acc.As_Duration / 60).ToString(); //如果是外部链接,且不是第三方平台的 if (!(acc.As_IsOuter && !acc.As_IsOther)) { btnEnter.Visible = false; panleShow.Visible = true; } } //此页面的ajax提交,全部采用了POST方式 if (Request.ServerVariables["REQUEST_METHOD"] == "POST") { string url = WeiSha.Common.Request.Form["url"].UrlDecode; //视频链接 int height = WeiSha.Common.Request.Form["height"].Int32 ?? 0; //视频高 int width = WeiSha.Common.Request.Form["width"].Int32 ?? 0; //视频宽 int span = WeiSha.Common.Request.Form["span"].Int32 ?? 0; //视频时长 //添加附件信息 Song.Entities.Accessory acc = new Song.Entities.Accessory(); if (!string.IsNullOrWhiteSpace(uid)) { //参数 string name = url; if (name.IndexOf("/") > -1) { name = url.Substring(url.LastIndexOf("/") + 1); } acc.As_Name = System.Web.HttpUtility.UrlDecode(name); acc.As_FileName = url; acc.As_Uid = uid; acc.As_Type = pathkey; acc.As_Duration = span * 60; acc.As_Height = height; acc.As_Width = width; acc.As_IsOuter = true; //外部链接 Business.Do <IAccessory>().Delete(uid, false); Business.Do <IAccessory>().Add(acc); string json = "{\"success\":\"1\",\"name\":\"" + name + "\",\"url\":\"" + acc.As_FileName + "\"}"; Response.Write(json); Response.End(); } } }
/// <summary> /// 获取视频 /// </summary> /// <param name="couUID"></param> /// <returns></returns> public static Song.Entities.Accessory getVideo(string couUID) { //视频 List <Song.Entities.Accessory> videos = Business.Do <IAccessory>().GetAll(couUID, "CourseVideo"); if (videos.Count <= 0) { return(null); } Song.Entities.Accessory video = null; //如果是外部链接 if (videos[0].As_IsOuter) { video = videos[0]; } //如果是内部链接 if (!videos[0].As_IsOuter) { videos[0].As_FileName = Upload.Get[videos[0].As_Type].Virtual + videos[0].As_FileName; string fileHy = WeiSha.Common.Server.MapPath(videos[0].As_FileName); if (!System.IO.File.Exists(fileHy)) { string ext = System.IO.Path.GetExtension(fileHy).ToLower(); if (ext == ".mp4") { videos[0].As_FileName = Path.ChangeExtension(videos[0].As_FileName, ".flv"); } if (ext == ".flv") { videos[0].As_FileName = Path.ChangeExtension(videos[0].As_FileName, ".mp4"); } } video = videos[0]; } return(video); }
protected override void InitPageTemplate(HttpContext context) { //当前课程 Song.Entities.Course course = Business.Do <ICourse>().CourseSingle(couid); if (course == null || !course.Cou_IsUse) { return; } //是否免费,或是限时免费 if (course.Cou_IsLimitFree) { DateTime freeEnd = course.Cou_FreeEnd.AddDays(1).Date; if (!(course.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now)) { course.Cou_IsLimitFree = false; } } this.Document.Variables.SetValue("course", course); //是否学习当前课程,如果没有学习且课程处于免费,则创建关联 if (this.Account != null) { isStudy = Business.Do <ICourse>().Study(course.Cou_ID, this.Account.Ac_ID); isBuy = course.Cou_IsFree || course.Cou_IsLimitFree ? true : Business.Do <ICourse>().IsBuy(course.Cou_ID, this.Account.Ac_ID); } this.Document.Variables.SetValue("isStudy", isStudy); this.Document.Variables.SetValue("isBuy", isBuy); //记录学员当前学习的课程 if (isStudy) { Extend.LoginState.Accounts.Course(course); } //当前章节 Song.Entities.Outline ol = olid < 1 ? Business.Do <IOutline>().OutlineFirst(couid, true) : Business.Do <IOutline>().OutlineSingle(olid); if (ol == null) { return; } this.Document.Variables.SetValue("outline", ol); this.Document.Variables.SetValue("olid", ol.Ol_ID.ToString()); //入写章节id的cookie,当播放视频时会判断此处 Response.Cookies.Add(new HttpCookie("olid", ol.Ol_ID.ToString())); //是否可以学习,如果是免费或已经选修便可以学习,否则当前课程允许试用且当前章节是免费的,也可以学习 bool canStudy = isBuy || (isStudy && ol.Ol_IsUse && ol.Ol_IsFinish && course.Cou_IsTry && ol.Ol_IsFree); this.Document.Variables.SetValue("canStudy", canStudy); #region 章节输出 // 当前课程的所有章节 Song.Entities.Outline[] outlines = Business.Do <IOutline>().OutlineAll(ol.Cou_ID, true); //课程章节列表 this.Document.Variables.SetValue("outlines", outlines); //树形章节输出 if (outlines.Length > 0) { this.Document.Variables.SetValue("olTree", Business.Do <IOutline>().OutlineTree(outlines)); } #endregion //视频 Song.Entities.Accessory video = Song.Site.CourseStudy.getVideo(ol.Ol_UID); this.Document.Variables.SetValue("video", video); if (Extend.LoginState.Accounts.IsLogin) { Song.Entities.LogForStudentStudy studyLog = Business.Do <IStudent>().LogForStudySingle(this.Account.Ac_ID, ol.Ol_ID); if (studyLog != null) { this.Document.Variables.SetValue("studyLog", studyLog); double historyPlay = (double)studyLog.Lss_PlayTime / 1000; this.Document.Variables.SetValue("historyPlay", historyPlay); } } //附件 List <Song.Entities.Accessory> access = Business.Do <IAccessory>().GetAll(ol.Ol_UID, "Course"); if (access.Count > 0) { foreach (Accessory ac in access) { ac.As_FileName = Upload.Get["Course"].Virtual + ac.As_FileName; } this.Document.Variables.SetValue("access", access); } }
protected override void InitPageTemplate(HttpContext context) { //当前章节,如果章节id,则取课程第一个章节 Song.Entities.Outline ol = id < 1 ? Business.Do <IOutline>().OutlineFirst(couid, true) : Business.Do <IOutline>().OutlineSingle(id); couid = couid > 0 ? couid : (ol != null ? ol.Cou_ID : 0); //当前课程 Song.Entities.Course course = Business.Do <ICourse>().CourseSingle(couid); if (course == null || !course.Cou_IsUse) { return; } this.Document.Variables.SetValue("course", course); //如果章节为空,则不再后面的了 if (ol == null) { return; } this.Document.Variables.SetValue("outline", ol); this.Document.Variables.SetValue("olid", ol.Ol_ID.ToString()); //上级章节 this.Document.Variables.SetValue("pat", Business.Do <IOutline>().OutlineSingle(ol.Ol_PID)); Response.Cookies.Add(new HttpCookie("olid", ol.Ol_ID.ToString())); //当前课程 //Song.Entities.Course course = Business.Do<ICourse>().CourseSingle(couid >0 ? couid : ol.Cou_ID); //if (course == null || !course.Cou_IsUse) return; //是否免费,或是限时免费 if (course.Cou_IsLimitFree) { DateTime freeEnd = course.Cou_FreeEnd.AddDays(1).Date; if (!(course.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now)) { course.Cou_IsLimitFree = false; } } this.Document.Variables.SetValue("course", course); //判断是否允许在桌面应用中学习 this.Document.Variables.SetValue("StudyForDeskapp", getForDeskapp(course, ol)); //是否学习当前课程,如果没有学习且课程处于免费,则创建关联 if (this.Account != null) { isStudy = Business.Do <ICourse>().Study(course.Cou_ID, this.Account.Ac_ID); isBuy = course.Cou_IsFree || course.Cou_IsLimitFree ? true : Business.Do <ICourse>().IsBuy(course.Cou_ID, this.Account.Ac_ID); } this.Document.Variables.SetValue("isStudy", isStudy); this.Document.Variables.SetValue("isBuy", isBuy); //是否可以学习,如果是免费或已经选修便可以学习,否则当前课程允许试用且当前章节是免费的,也可以学习 bool canStudy = isBuy || (isStudy && ol.Ol_IsUse && ol.Ol_IsFinish && course.Cou_IsTry && ol.Ol_IsFree); this.Document.Variables.SetValue("canStudy", canStudy); //记录学员当前学习的课程 if (isStudy) { Extend.LoginState.Accounts.Course(course); } #region 章节输出 // 当前课程的所有章节 Song.Entities.Outline[] outlines = Business.Do <IOutline>().OutlineAll(ol.Cou_ID, true); //课程章节列表 this.Document.Variables.SetValue("outlines", outlines); //树形章节输出 if (outlines.Length > 0) { this.Document.Variables.SetValue("olTree", Business.Do <IOutline>().OutlineTree(outlines)); } #endregion #region 内容输出 CourseContext_State state = new CourseContext_State(); //视频 Song.Entities.Accessory video = getVideo(ol.Ol_UID); this.Document.Variables.SetValue("video", video); if (video != null) { state.Video = canStudy ? true : false; } if (Extend.LoginState.Accounts.IsLogin) { Song.Entities.LogForStudentStudy studyLog = Business.Do <IStudent>().LogForStudySingle(this.Account.Ac_ID, ol.Ol_ID); if (studyLog != null) { this.Document.Variables.SetValue("studyLog", studyLog); double historyPlay = (double)studyLog.Lss_PlayTime / 1000; this.Document.Variables.SetValue("historyPlay", historyPlay); } } //内容 if (!string.IsNullOrWhiteSpace(ol.Ol_Intro)) { state.Context = canStudy ? true : false; } //附件 List <Song.Entities.Accessory> access = Business.Do <IAccessory>().GetAll(ol.Ol_UID, "Course"); if (access.Count > 0) { foreach (Accessory ac in access) { ac.As_FileName = Upload.Get["Course"].Virtual + ac.As_FileName; } this.Document.Variables.SetValue("access", access); state.Attachment = canStudy ? true : false; } //当前章节是否有试题 if (canStudy) { bool isQues = Business.Do <IOutline>().OutlineIsQues(ol.Ol_ID, true); if (isQues) { state.Questions = canStudy ? true : false; } ; } state.JudgeNull(stateVal); this.Document.Variables.SetValue("state", state); #endregion //章节事件 OutlineEvent[] events = Business.Do <IOutline>().EventAll(-1, ol.Ol_ID, -1, true); this.Document.Variables.SetValue("events", events); this.Document.RegisterGlobalFunction(this.getEventQues); this.Document.RegisterGlobalFunction(this.getEventFeedback); this.Document.RegisterGlobalFunction(this.GetOrder); }
public void ProcessRequest(HttpContext context) { string serverFileName = "", path = ""; try { //上传路径 string uploadPath = WeiSha.Common.Request.QueryString["path"].String; path = WeiSha.Common.Upload.Get[uploadPath].Virtual; //全局唯一值 string uid = WeiSha.Common.Request.QueryString["uid"].String; HttpPostedFile file; for (int i = 0; i < context.Request.Files.Count; ++i) { file = context.Request.Files[i]; string ext = Path.GetExtension(file.FileName); if (file == null || file.ContentLength == 0 || string.IsNullOrEmpty(file.FileName)) { continue; } serverFileName = DateTime.Now.ToString("yyyyMMddhhmmss") + ext; //上传后的视频文件 string videoFile = HttpContext.Current.Server.MapPath(path + serverFileName); file.SaveAs(videoFile); if (!string.IsNullOrWhiteSpace(uid)) { //添加附件 Song.Entities.Accessory acc = new Song.Entities.Accessory(); //视频操作对象 WeiSha.Common.VideoHandler handler = WeiSha.Common.VideoHandler.Hanlder(videoFile); if (handler.Width > 0) { acc = setAcc(acc, handler); } //视频质量 Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent(); WeiSha.Common.CustomConfig config = CustomConfig.Load(org.Org_Config); int qscale = config["VideoConvertQscale"].Value.Int32 ?? 4; //先转为flv格式 string flvFile = handler.Convert().ToFlv(qscale); handler = WeiSha.Common.VideoHandler.Hanlder(flvFile); if (handler.Width > 0) { acc = setAcc(acc, handler); } string mp4File = handler.Convert().ToMP4(qscale, true); if (acc.As_Width <= 0) { handler = WeiSha.Common.VideoHandler.Hanlder(mp4File); if (handler.Width > 0) { acc = setAcc(acc, handler); } } //参数 acc.As_Name = Path.GetFileName(file.FileName); acc.As_FileName = System.IO.Path.ChangeExtension(serverFileName, ".flv"); acc.As_Uid = uid; acc.As_Type = uploadPath; // handler = WeiSha.Common.VideoHandler.Hanlder(videoFile); handler.Delete("flv,mp4"); Business.Do <IAccessory>().Add(acc); } } } catch (Exception ex) { context.Response.StatusCode = 700; context.Response.Write(ex.Message + " 详情请查看错误日志"); //写入Log string log = context.Server.MapPath(path) + "errorlog.txt"; using (System.IO.StreamWriter sw = new StreamWriter(log, true)) { sw.WriteLine("执行时间:" + DateTime.Now.ToString()); sw.WriteLine("错误信息:" + ex.Message); sw.WriteLine("堆栈信息:" + ex.StackTrace); sw.WriteLine(""); sw.Close(); } context.Response.End(); } finally { context.Response.Write(path + serverFileName); context.Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(uid)) { uid = WeiSha.Common.Request.Page.Name; } //提示消息 string msg = string.Empty; //是否要播放 bool isPlay = judge(uid, out msg); if (!isPlay) { Response.Write(msg); Response.End(); } else { //***************如果可以播放 Song.Entities.Accessory acc = Business.Do <IAccessory>().GetSingle(uid); if (acc == null) { Response.Write("视频不存在!"); Response.End(); } else { //视频文件 string video = string.Empty; //如果是系统内部文件 if (!acc.As_IsOuter) { video = Upload.Get[acc.As_Type].Physics + acc.As_FileName; //如果不是手机端 if (!WeiSha.Common.Browser.IsMobile) { //如果不存在,则后缀名改成mp4的试试 if (!System.IO.File.Exists(video)) { video = reExstname(video, "mp4"); } } else { video = reExstname(video, "mp4"); } } else { video = acc.As_FileName; //如果是外部视频链接; } HttpContext context = System.Web.HttpContext.Current; context.Response.Clear(); context.Response.ClearContent(); context.Response.ClearHeaders(); context.Response.AddHeader("Content-Disposition", "attachment;filename=" + acc.As_FileName); System.IO.FileInfo fi = new System.IO.FileInfo(video); context.Response.AddHeader("Content-Length", fi.Length.ToString()); context.Response.AddHeader("Content-Transfer-Encoding", "binary"); context.Response.ContentType = "application/octet-stream"; context.Response.ContentEncoding = System.Text.Encoding.Default; context.Response.WriteFile(video); context.Response.Flush(); context.Response.End(); } } }