Esempio n. 1
0
        public ActionResult UploadResult()
        {
            UploadStatus status     = SlickUpload.GetUploadStatus();
            decimal      totalCount = (decimal)status.GetUploadedFiles().Count;

            if (status != null && status.State == UploadState.Complete && 0 < totalCount)
            {
                //Post Processing Step: Update Screen to 0% Done
                UpdateProgressBarOnScreen(status, 0, false);

                //At this point, we know the file has been uploaded to the server
                //I think we can just kick off an async process to do the rest.
                ProcessTask processTask = new ProcessTask(this.PostProcessVideo);
                processTask.BeginInvoke(status, totalCount, null, processTask);

                UpdateProgressBarOnScreen(status, COMPLETE_PERCENTAGE, true);
            }
            else
            {
                ErrorLogRepository errorRepos = new ErrorLogRepository();
                errorRepos.SaveErrorToDB(null, "Video upload had issues. Upload Status = " + status.State.ToString() + " totalCount = " + totalCount.ToString() + ": " + Environment.NewLine + status.Reason + Environment.NewLine + status.ErrorMessage, User.Identity.Name);

                return(View("UploadFiles", new VideoUploadFilesViewModel(User.Identity.Name, status)));
            }

            return(RedirectToAction("UploadPending", new { contentLength = status.ContentLength }));
        }
Esempio n. 2
0
        protected void btnPostFile_Click(object sender, EventArgs e)
        {
            int          files        = 0;
            UploadStatus uploadstatus = HttpUploadModule.GetUploadStatus();
            bool         flag         = uploadstatus.Reason == UploadTerminationReason.NotTerminated;

            if (flag)
            {
                foreach (UploadedFile file in uploadstatus.GetUploadedFiles())
                {
                    string clientFileName = file.ClientName;
                    bool   flag2          = file.ContentLength.Equals(0L);
                    if (flag2)
                    {
                        base.PromptDialog(string.Format("[{0}]文件大小为0字节,系统不支持文件大小为0字节的文件上传,请重新选择文件上传。", clientFileName));
                        return;
                    }
                    bool flag3 = !this.filelist.MaxFileSize.Equals(0.0) && file.ContentLength > this.filelist.MaxFileSize;
                    if (flag3)
                    {
                        base.PromptDialog(string.Format("[{0}]文件大小已超出规定的 {1}上限,上传失败。", clientFileName, this.filelist.MaxFileSize.FormatFileSize()));
                        return;
                    }
                    DocFileInfo fileInfo = FileService.AddFile(file.ServerPath, clientFileName, file.ContentLength, this.hidFileGroup.Value.ToDouble());
                    this.hidFileGroup.Value   = fileInfo.FileGroupId.ToString();
                    this.filelist.FileGroupId = fileInfo.FileGroupId;
                    this.UpdateBusinessFileGroup();
                    files = this.UpdateBusinessFiles();
                }
            }
            this.UpdateTempletFileFieldRI(files);
            base.CurMaster_OnQuery(null, null);
        }
Esempio n. 3
0
        private string PostProcessVideo(UploadStatus status, decimal totalCount)
        {
            string resultMessage = String.Empty;
            string localFilePath = String.Empty;
            int    counter       = 0;

            //Setup the Azure Storage Container
            BlobContainer container = AzureUtility.GetAzureContainer(null);

            foreach (UploadedFile file in status.GetUploadedFiles())
            {
                try
                {
                    localFilePath = file.LocationInfo["fileName"].ToString();

                    //Save a skeleton record of the upload in the database
                    Video vid = _videoRepository.New();
                    _videoRepository.AddVideoToUser(vid, User.Identity.Name);
                    vid.Description         = file.FormValues["fileDescription"];
                    vid.StartProcessingDate = DateTime.Now;
                    vid.OriginalFileFormat  = file.ContentType;
                    vid.UploadSize          = file.ContentLength;
                    _videoRepository.Save();
                    Guid videoId = vid.Id;

                    string encodedFilePath = FFmpegEncoder.EncodeToWmv(localFilePath, file.ContentType);

                    if (!String.IsNullOrEmpty(encodedFilePath))
                    {
                        string fileNameOnly = encodedFilePath.Substring(encodedFilePath.LastIndexOf("Upload") + 7);

                        //TODO: Take a screenshot/Thumbnail of the video & upload it

                        BlobProperties properties = AzureUtility.CollectBlobMetadata(file, fileNameOnly, User.Identity.Name);

                        // Create the blob & Upload
                        long finalSize = 0;
                        using (FileStream uploadedFile = new FileStream(encodedFilePath, FileMode.Open, FileAccess.Read))
                        {
                            BlobContents fileBlob = new BlobContents(uploadedFile);
                            finalSize = fileBlob.AsStream.Length;
                            container.CreateBlob(properties, fileBlob, true);
                        }

                        //Create the database record for this video
                        vid = _videoRepository.GetById(videoId);
                        vid.CreationDate = DateTime.Now;
                        vid.FinalSize    = finalSize;
                        vid.Path         = String.Format("{0}/{1}", container.ContainerName, fileNameOnly);
                        _videoRepository.Save();

                        resultMessage = string.Format("Your video ({0}) is ready for you to use.", file.FormValues["fileDescription"]);

                        //Delete the local copy of the encoded file
                        System.IO.File.Delete(encodedFilePath);
                    }
                    else
                    {
                        resultMessage = "ERROR: video (" + file.FormValues["fileDescription"] + ") could not be converted to a recognizable video format.";
                    }

                    //Create a notification record so the user knows that processing is done for this video
                    Notification note = _notificationRepository.New();
                    _notificationRepository.AddNotificationToUser(note, User.Identity.Name);
                    note.UserNotified = false;
                    note.Message      = resultMessage;
                    note.CreationDate = DateTime.Now;
                    _notificationRepository.Save();
                }
                catch (Exception ex)
                {
                    resultMessage = string.Format("ERROR: we tried to process the video, {0}, but it did not finish.  You might want to try again.", file.FormValues["fileDescription"]);

                    //Create a notification record so the user knows that there was an error
                    Notification note = _notificationRepository.New();
                    _notificationRepository.AddNotificationToUser(note, User.Identity.Name);
                    note.UserNotified = false;
                    note.Message      = resultMessage;
                    note.CreationDate = DateTime.Now;
                    _notificationRepository.Save();

                    throw new Exception(resultMessage, ex);
                }
                finally
                {
                    //Delete the local copy of the original file
                    System.IO.File.Delete(localFilePath);

                    counter++;
                }
            }

            return(resultMessage);
        }