protected void Page_Load(object sender, EventArgs e)
        {
            string requestArticleGuid = Request.QueryString["ArticleGuid"];
            if (string.IsNullOrEmpty(requestArticleGuid) || !Wis.Toolkit.Validator.IsGuid(requestArticleGuid))
            {
                throw new System.ArgumentNullException("ArticleGuid");
            }
            Guid articleGuid = new Guid(requestArticleGuid);
            if (System.Web.HttpContext.Current.Items["VideoArticle"] == null)
            {
                Response.Redirect(string.Format("ArticleAddVideo.aspx?ArticleGuid={0}", articleGuid));
                return;
            }
            VideoArticle videoArticle = System.Web.HttpContext.Current.Items["VideoArticle"] as VideoArticle;

            // 转换视频格式
            // 输出进度条
            string content;
            using (System.IO.StreamReader reader = new System.IO.StreamReader(Page.MapPath("Progressbar.htm"), System.Text.Encoding.UTF8))
            {
                content = reader.ReadToEnd();
                System.Text.RegularExpressions.Regex.Replace(content, "", this.TotalSeconds.ToString(), System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            }
            Context.Response.Write(content);
            Context.Response.Flush();

            string inFile = Page.MapPath(videoArticle.VideoPath);
            string outFile = Page.MapPath(videoArticle.FlvVideoPath);

            string ffmpegFile = Page.MapPath("Tools/ffmpeg.exe");
            MediaHandler mediaHandler = new MediaHandler();
            this.TotalSeconds = mediaHandler.GetTotalSeconds(ffmpegFile, inFile);

            outFile = Page.MapPath(videoArticle.FlvVideoPath);
            mediaHandler.ConvertingVideo(ffmpegFile, inFile, outFile, new DataReceivedEventHandler(ConvertingVideo_DataReceived));

            System.Threading.Thread.Sleep(1000);
            string flvtool2File = Page.MapPath("Tools/flvtool2.exe");
            mediaHandler.InjectMetadata(flvtool2File, outFile, new DataReceivedEventHandler(ConvertingVideo_DataReceived));

            content = "<script type='text/javascript' language='javascript'>AddLog('转换成功。');SetProgressbar('100');</script>\n";
            Response.Write(content);
            Response.Flush();

            // 视频信息入库
            Wis.Website.DataManager.VideoArticleManager videoArticleManager = new Wis.Website.DataManager.VideoArticleManager();
            int videoArticleCount = videoArticleManager.Count(videoArticle.Article.ArticleGuid);
            if (videoArticleCount == 0)
                videoArticle.VideoArticleId = videoArticleManager.AddNew(videoArticle);
            else
                videoArticle.VideoArticleId = videoArticleManager.Update(videoArticle);

            System.Web.HttpContext.Current.Items.Remove("VideoArticle");

            // 下一步
            Wis.Toolkit.ClientScript.Window.Redirect(string.Format("ArticleRelease.aspx?ArticleGuid={0}", videoArticle.Article.ArticleGuid));
            //Response.Redirect(string.Format("ArticleRelease.aspx?ArticleGuid={0}", this.ArticleGuid));
        }
        protected void ImageButtonNext_Click(object sender, ImageClickEventArgs e)
        {
            #warning 最大允许上传的文件尺寸
            // DJUploadController1.Status.LengthExceeded
            // The maximum upload size was exceeded

            // Uploads were not processed via the module
            if (!UploadManager.Instance.ModuleInstalled)
            {
                Warning.InnerHtml = "请配置文件上传的 Module";
                return;
            }

            // Files uploaded
            if (DJUploadController1.Status == null ||
                DJUploadController1.Status.ErrorFiles.Count > 0 ||  // Files with errors
                DJUploadController1.Status.UploadedFiles.Count != 1)
            {
                Warning.InnerHtml = "上传文件错误";
                return;
            }

            // 获得文件名
            UploadedFile videoUploadedFile = DJUploadController1.Status.UploadedFiles[0];
            //// Exception
            //if (f.Exception != null)
            //{
            //    Warning.InnerHtml = string.Format("文件上传发生异常:{0}", f.Exception.Message);
            //    return;
            //}
            if (videoUploadedFile == null)
            {
                Warning.InnerHtml = "未正确获取上传的控件对象";
                return;
            }

            #warning TODO:Uploads 作为配置项
            string uploadsDirectory = "Uploads";
            uploadsDirectory.Trim('/'); // 去除前后的 /

            // 获得视频临时路径
            string inFile = Server.MapPath(string.Format("/{0}/Temp/{1}", uploadsDirectory, System.IO.Path.GetFileName(videoUploadedFile.FileName)));
            System.IO.FileInfo tempFileInfo = new System.IO.FileInfo(inFile);
            if (!tempFileInfo.Exists)
            {
                Warning.InnerHtml = "上传文件错误,请重新上传";
                return;
            }

            // 视频信息
            Wis.Website.DataManager.VideoArticle videoArticle = null;
            Wis.Website.DataManager.VideoArticleManager videoArticleManager = new Wis.Website.DataManager.VideoArticleManager();
            int videoArticleCount = videoArticleManager.Count(this.ArticleGuid);
            if (videoArticleCount == 0)
            {
                videoArticle = new Wis.Website.DataManager.VideoArticle();
                videoArticle.VideoArticleGuid = Guid.NewGuid();
                videoArticle.Article.ArticleGuid = article.ArticleGuid;
            }
            else
            {
                videoArticle = videoArticleManager.GetVideoArticle(this.ArticleGuid);

                // 删除已存在的文件
                if(System.IO.File.Exists(Page.MapPath(videoArticle.VideoPath)))
                    System.IO.File.Delete(Page.MapPath(videoArticle.VideoPath));
                if(System.IO.File.Exists(Page.MapPath(videoArticle.FlvVideoPath)))
                    System.IO.File.Delete(Page.MapPath(videoArticle.FlvVideoPath));
                if(System.IO.File.Exists(Page.MapPath(videoArticle.PreviewFramePath)))
                    System.IO.File.Delete(Page.MapPath(videoArticle.PreviewFramePath));
            }

            // 视频星级 Star
            byte star;
            if (byte.TryParse(RequestManager.Request("Star"), out star))
                if (star != 0) videoArticle.Star = star;

            // Videos 目录
            string path = Server.MapPath(string.Format("/{0}/Videos/{1}/", uploadsDirectory, article.DateCreated.ToShortDateString()));
            if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path);

            // 视频,Flv视频,预览帧 路径
            videoArticle.VideoPath = string.Format("/{0}/Videos/{1}/{2}{3}", uploadsDirectory, article.DateCreated.ToShortDateString(), this.ArticleGuid, tempFileInfo.Extension);
            videoArticle.FlvVideoPath = Regex.Replace(videoArticle.VideoPath, tempFileInfo.Extension, ".swf", RegexOptions.IgnoreCase);
            videoArticle.PreviewFramePath = Regex.Replace(videoArticle.VideoPath, tempFileInfo.Extension, ".jpg", RegexOptions.IgnoreCase);

            // 3 创建缩微图 88x66
            string ffmpegFile = Page.MapPath("Tools/ffmpeg.exe");
            MediaHandler mediaHandler = new MediaHandler();
            this.TotalSeconds = mediaHandler.GetTotalSeconds(ffmpegFile, inFile);
            int timeOffset = (this.TotalSeconds % 2 == 0) ? (int)(this.TotalSeconds / 2) : ((int)(this.TotalSeconds / 2) + 1);
            string outFile = Page.MapPath(videoArticle.PreviewFramePath);
            mediaHandler.CreatePreviewFrame(ffmpegFile, timeOffset, inFile, outFile, this.ThumbnailWidth, this.ThumbnailHeight, new DataReceivedEventHandler(MediaHandler_DataReceived));

            // 视频文件转移到 Videos 目录
            tempFileInfo.MoveTo(Server.MapPath(videoArticle.VideoPath));

            // 转换视频
            if (tempFileInfo.Extension.ToLower() == ".flv" || tempFileInfo.Extension.ToLower() == ".swf")
            {
                outFile = Page.MapPath(videoArticle.FlvVideoPath);
                if (tempFileInfo.Extension.ToLower() == ".flv")
                {
                    tempFileInfo.MoveTo(outFile);
                    videoArticle.VideoPath = videoArticle.FlvVideoPath;
                }
                // 添加 Meta Data信息 InjectMetadata
                string flvtool2File = Page.MapPath("Tools/flvtool2.exe");
                mediaHandler.InjectMetadata(flvtool2File, outFile, new DataReceivedEventHandler(MediaHandler_DataReceived));

                // 视频信息入库
                if (videoArticleCount == 0)
                    videoArticle.VideoArticleId = videoArticleManager.AddNew(videoArticle);
                else
                    videoArticle.VideoArticleId = videoArticleManager.Update(videoArticle);

                // 下一步
                //Wis.Toolkit.ClientScript.Window.Redirect(string.Format("ArticleRelease.aspx?ArticleGuid={0}", this.ArticleGuid));
                Response.Redirect(string.Format("ArticleRelease.aspx?ArticleGuid={0}", this.ArticleGuid));
            }
            else
            {
                System.Web.HttpContext.Current.Items.Add("VideoArticle", videoArticle);
                Server.Transfer(string.Format("ArticleConvertingVideo.aspx?ArticleGuid={0}", this.ArticleGuid));
                return;
            }
        }