public void CanSaveAndGetInfoMOV_NoUserData() { // Arrange var form = new UploadForm(_inviteToOverrideAutoValues); using (var ms = new MemoryStream(TestFiles.sampleMOV)) { UploadedFile file = new UploadedVideoFile(form, _durationDetectorFactory); file.RawContentPath = _rawContentPath; file.ThumbnailAssetContentPath = _thumbnailAssetContentPath; file.UploadedStream = ms; // Act file.OriginalFileName = "Sample_MOV.mov"; file.SetDateIfUserHasNotProvidedOne("2011 7 8"); SaveThumbnail(file); // Assert Assert.AreEqual("Sample_MOV", file.Title); Assert.AreEqual(".mov", file.Extension); Assert.AreEqual(new DateTime(2011, 7, 8), file.Date); Assert.AreEqual(3284257, file.ContentLength); Assert.AreEqual(PreviewType.Video, file.PreviewType); AssertWithThreshold(85f, file.DisplayDuration, TIME_THRESHOLD_SECONDS); } }
public async Task <IActionResult> UploadAsync([FromForm] UploadForm upload) { var fileName = $"{HostingEnvironment.WebRootPath}\\files\\{upload.FormFile.FileName}"; using (var filestream = System.IO.File.Create(fileName)) { upload.FormFile.CopyTo(filestream); filestream.Flush(); } var uploadModel = this.UploadInDB(fileName); if (uploadModel.Any(u => u.Errors?.Count() > 0)) { var uploadModels = uploadModel.Where(u => u.Errors.Count() > 0); var errors = ""; foreach (var item in uploadModel) { errors = errors + item.Errors; } return(BadRequest(new Errors { Error = errors })); } var result = await SQLRepository.UploadDataAsync(uploadModel).ConfigureAwait(false); if (result == null) { return(BadRequest()); } return(Ok(result)); }
public void CanSaveVideoFileWithUserDataEmptyDateEmptyTitleEmptyDuration() { // Arrange var form = new UploadForm(_inviteToOverrideAutoValues); form.Title = ""; form.SetDateIfNotEmpty(""); form.SetDisplayDuration("", 1, 10); // Act using (var ms = new MemoryStream(TestFiles.sampleWMV)) { UploadedFile file = new UploadedVideoFile(form, _durationDetectorFactory); file.RawContentPath = _rawContentPath; file.ThumbnailAssetContentPath = _thumbnailAssetContentPath; file.UploadedStream = ms; // Act file.OriginalFileName = "Sample_WMV.wmv"; file.SetDateIfUserHasNotProvidedOne("2011 7 8"); SaveThumbnail(file); // Assert Assert.AreEqual("Sample_WMV", file.Title); Assert.AreEqual(".wmv", file.Extension); Assert.AreEqual(new DateTime(2011, 7, 8), file.Date); Assert.AreEqual(1030830, file.ContentLength); Assert.AreEqual(PreviewType.Video, file.PreviewType); AssertWithThreshold(34f, file.DisplayDuration, TIME_THRESHOLD_SECONDS); } }
public void CanSaveVideoFileWithUserData() { // Arrange var form = new UploadForm(_inviteToOverrideAutoValues); form.Title = "The Title"; form.SetDisplayDuration("100", 5, 200); form.SetDateIfNotEmpty("2011-12-20"); using (var ms = new MemoryStream(TestFiles.sampleWMV)) { UploadedFile file = new UploadedVideoFile(form, _durationDetectorFactory); file.RawContentPath = _rawContentPath; file.ThumbnailAssetContentPath = _thumbnailAssetContentPath; file.UploadedStream = ms; // Act file.OriginalFileName = "Sample_WMV.wmv"; file.SetDateIfUserHasNotProvidedOne("2011 7 8"); SaveThumbnail(file); // Assert Assert.AreEqual("The Title", file.Title); Assert.AreEqual(".wmv", file.Extension); Assert.AreEqual(new DateTime(2011, 12, 20), file.Date); Assert.AreEqual(1030830, file.ContentLength); Assert.AreEqual(PreviewType.Video, file.PreviewType); Assert.AreEqual(100f, file.DisplayDuration); } }
public void CanSaveAndGetInfoSWF_UserSetDateAndDuration_UserDateHonoured_DurationHonoured() { // Arrange var form = new UploadForm(_inviteToOverrideAutoValues); form.SetDisplayDuration("100", 5, 200); form.SetDateIfNotEmpty("2011-12-20"); // Act using (var ms = new MemoryStream(TestFiles.sampleSWF)) { UploadedFile file = new UploadedFlashFile(form, _durationDetectorFactory); file.RawContentPath = _rawContentPath; file.ThumbnailAssetContentPath = _thumbnailAssetContentPath; file.UploadedStream = ms; // Act file.OriginalFileName = "Sample_SWF.swf"; file.SetDateIfUserHasNotProvidedOne("2011 7 8"); SaveThumbnail(file); // Assert Assert.AreEqual("Sample_SWF", file.Title); Assert.AreEqual(".swf", file.Extension); Assert.AreEqual(new DateTime(2011, 12, 20), file.Date); Assert.AreEqual(115009, file.ContentLength); Assert.AreEqual(PreviewType.Flash, file.PreviewType); Assert.AreEqual(100f, file.DisplayDuration); } }
public void CanSaveAndGetInfoPNG_UserSetDateAndDuration_UserDateHonoured_DurationHonoured() { // Arrange var form = new UploadForm(_inviteToOverrideAutoValues); form.SetDisplayDuration("100", 5, 200); form.SetDateIfNotEmpty("2011-12-20"); using (var ms = new MemoryStream()) { TestFiles.SamplePNG.Save(ms, ImageFormat.Png); UploadedFile file = new UploadedImageFile(form, _durationDetectorFactory); file.RawContentPath = _rawContentPath; file.ThumbnailAssetContentPath = _thumbnailAssetContentPath; file.UploadedStream = ms; // Act file.OriginalFileName = "Sample_PNG.png"; file.SetDateIfUserHasNotProvidedOne("2011 7 8"); SaveThumbnail(file); // Assert Assert.AreEqual("Sample_PNG", file.Title); Assert.AreEqual(".png", file.Extension); Assert.AreEqual(new DateTime(2011, 12, 20), file.Date); Assert.AreEqual(PreviewType.Image, file.PreviewType); Assert.AreEqual(100, file.DisplayDuration); } }
public void CanSaveAndGetInfoJPG_NoUserData() { // Arrange var form = new UploadForm(_inviteToOverrideAutoValues); // Act using (var ms = new MemoryStream()) { TestFiles.sampleJPG.Save(ms, ImageFormat.Jpeg); UploadedFile file = new UploadedImageFile(form, _durationDetectorFactory); file.RawContentPath = _rawContentPath; file.ThumbnailAssetContentPath = _thumbnailAssetContentPath; file.UploadedStream = ms; // Act file.OriginalFileName = "Sample_JPG.jpg"; file.SetDateIfUserHasNotProvidedOne("2011 7 8"); SaveThumbnail(file); // Assert Assert.AreEqual("Sample_JPG", file.Title); Assert.AreEqual(".jpg", file.Extension); Assert.AreEqual(new DateTime(2011, 7, 8), file.Date); Assert.AreEqual(1184183, file.ContentLength); Assert.AreEqual(PreviewType.Image, file.PreviewType); Assert.AreEqual(-1, file.DisplayDuration); } }
private void dmButton1_exception_query_Click(object sender, EventArgs e) { dmButton1_exception_query.BackColor = Color.WhiteSmoke; UploadForm <CPKCheckUpload> ef = new UploadForm <CPKCheckUpload>(this); ef.ShowDialog(); }
public ActionResult _Upload(UploadForm form) { if (ModelState.IsValid) { byte[] file = new byte[form.File.ContentLength]; form.File.InputStream.Read(file, 0, file.Length); Document doc = new Document { Filename = Path.GetFileName(form.File.FileName), Body = file, AuthorEmployee = SessionUser.GetUser().Id }; if (form.PreviousVersionId.HasValue) { doc.Id = form.PreviousVersionId; } int?DocumentId = DocumentService.Create(doc); if (DocumentId != null) { if (form.DepartmentId != null) { DocumentService.AddToDepartment((int)DocumentId, (int)form.DepartmentId); return(RedirectToAction("Details", "Department", new { id = form.DepartmentId })); } else if (form.EventId != null) { DocumentService.AddToEvent((int)DocumentId, (int)form.EventId); return(RedirectToAction("Details", "Event", new { id = form.EventId })); } else if (form.MessageId != null) { DocumentService.AddToMessage((int)DocumentId, (int)form.MessageId); } else if (form.ProjectId != null) { DocumentService.AddToProject((int)DocumentId, (int)form.ProjectId); return(RedirectToAction("Details", "Project", new { projectId = form.ProjectId })); } else if (form.TaskId != null) { DocumentService.AddToTask((int)DocumentId, (int)form.TaskId); return(RedirectToAction("Details", "Task", new { taskId = form.TaskId })); } else if (form.TeamId != null) { DocumentService.AddToTeam((int)DocumentId, (int)form.TeamId); return(RedirectToAction("Details", "Team", new { teamId = form.TeamId })); } else if (form.PreviousVersionId != null) { return(RedirectToAction("Details", "Document", new { id = form.PreviousVersionId })); } } } return(RedirectToAction("Index", "Employee")); }
public async Task <IActionResult> Store([FromForm] UploadForm form) { PostType postType = form.GetPostType(); int postId = form.PostId; var attachments = new List <UploadFile>(); foreach (var file in form.Files) { if (file.Length > 0) { string fileName = file.FileName; var attachment = await GetUploadFileAsync(postType, postId, fileName); if (attachment == null) { throw new Exception(String.Format("attachmentService.FindByName({0},{1})", file.FileName, form.PostId)); } string folder = postType == PostType.Emoji ? "emoji" : ""; var upload = await SaveFile(file, folder); attachment.PostType = postType; attachment.Type = upload.Type; attachment.Path = upload.Path; switch (upload.Type) { case ".jpg": case ".jpeg": case ".png": case ".gif": var image = Image.Load(file.OpenReadStream()); attachment.Width = image.Width; attachment.Height = image.Height; attachment.PreviewPath = upload.Path; break; } attachments.Add(attachment); } } var addItems = attachments.Where(a => a.Id < 1).ToList(); var updateItems = attachments.Where(a => a.Id > 0).ToList(); foreach (var item in addItems) { await _attachmentsService.CreateAsync(item); } _attachmentsService.UpdateRange(updateItems); return(Ok(attachments)); }
public async Task <IActionResult> Store(UploadForm form) { foreach (var file in form.files) { if (file.Length > 0) { var attachment = attachmentService.FindByName(file.FileName, form.postId); if (attachment == null) { throw new Exception(String.Format("attachmentService.FindByName({0},{1})", file.FileName, form.postId)); } var upload = await SaveFile(file); attachment.Type = upload.Type; attachment.Path = upload.Path; switch (upload.Type) { case ".jpg": case ".jpeg": case ".png": case ".gif": var image = Image.FromStream(file.OpenReadStream()); attachment.Width = image.Width; attachment.Height = image.Height; attachment.PreviewPath = upload.Path; break; case ".mp4": //截取影片預覽圖 string imgPath = Path.ChangeExtension(upload.Path, ".jpg"); string videoFullPath = Path.Combine(this.UploadFilesPath, upload.Path); string imgFullPath = Path.Combine(this.UploadFilesPath, imgPath); SaveVideoImage(videoFullPath, imgFullPath); attachment.PreviewPath = imgPath; break; } attachmentService.Update(attachment); } } return(new NoContentResult()); }
public void DisplayDurationWithinBoundaries() { // Arrange UploadForm form = new UploadForm(_inviteToOverrideAutoValues); // Act form.SetDisplayDuration("120.2", 10, 200); // Assert Assert.AreEqual(form.DisplayDuration, 120.2F); Assert.IsTrue(form.UserHasProvidedDisplayDuration); }
public void DisplayDurationOutsideBoundariesShouldBeSetToMinusOne() { // Arrange UploadForm form = new UploadForm(_inviteToOverrideAutoValues); // Act form.SetDisplayDuration("120.2", 10, 20); // Assert Assert.AreEqual(form.DisplayDuration, -1); Assert.IsTrue(form.UserHasProvidedDisplayDuration); }
public void DisplayDurationShouldBeUserDefined() { // Arrange UploadForm form = new UploadForm(_inviteToOverrideAutoValues); // Act form.SetDisplayDuration("", 10, 20); // Assert Assert.AreEqual(form.DisplayDuration, -1); Assert.IsFalse(form.UserHasProvidedDisplayDuration); }
public void DateShouldBeNull() { // Arrange UploadForm form = new UploadForm(_inviteToOverrideAutoValues); // Act form.SetDateIfNotEmpty(""); // Assert Assert.IsNull(form.Date); Assert.IsFalse(form.UserHasProvidedDate); }
public void NonStringInputNullNonStringUserDataBoolsShouldBeFalse() { // Arrange UploadForm form = new UploadForm(_inviteToOverrideAutoValues); // Act form.SetDateIfNotEmpty(""); form.SetDisplayDuration("", 10, 20); // Assert Assert.IsFalse(form.UserHasProvidedDate); Assert.IsFalse(form.UserHasProvidedDisplayDuration); }
public ActionResult _Upload(int?DepartmentId, int?EventId, int?MessageId, int?ProjectId, int?TaskId, int?TeamId, int?DocumentId) { UploadForm form = new UploadForm { DepartmentId = DepartmentId, EventId = EventId, MessageId = MessageId, ProjectId = ProjectId, TaskId = TaskId, TeamId = TeamId, PreviousVersionId = DocumentId }; return(PartialView(form)); }
public IActionResult Upload(UploadForm form) { if (form.File is null) { return(RedirectToAction("Upload", new { id = form.Id })); } ; Speaker speaker = _speakerService.GetById(form.Id); byte[] audioFile = GetByteArray(form.File); _speechService.AddAudio(form.File.FileName, audioFile, speaker); return(RedirectToAction("View", "Speaker", new { Id = form.Id })); }
public async Task <IActionResult> Index(UploadForm model) { using (var memoryStream = new MemoryStream()) { await model.FormFile.CopyToAsync(memoryStream); var filename = await service.uploadAsync(memoryStream, model.FormFile.FileName); await this.imageRepo.addImage(filename, model.Description, model.Title, model.Tags); ViewBag.filename = filename; } return(View()); }
HtmlElement GetHtmlInput(string pId) { if (String.IsNullOrEmpty(pId)) { throw new ArgumentNullException("pId"); } var _ipt = Document.GetElementById(pId); if (_ipt == null) { _ipt = CreateHtmlHiddenInput(pId); UploadForm.AppendChild(_ipt); } return(_ipt); }
/// <summary> /// 用户执行上传功能 /// </summary> public static void Upload(string fileID = "") { OpenFileDialog dia = new OpenFileDialog(); dia.Filter = "*.*|*.*"; DialogResult dr = dia.ShowDialog(); if (dr == DialogResult.OK) { string strPath = dia.FileName; UploadForm frm = new UploadForm(); frm.fileID = fileID; frm.strUploadPath = strPath; frm.Show(); } }
public static UploadForm Instance(MAINFORM frmMain) { if (sForm == null) { sForm = new UploadForm(frmMain); } else { sForm.Close(); sForm = null; sForm = new UploadForm(frmMain); } return(sForm); }
public void StringInputNullUserDataBoolsShouldBeFalse() { // Arrange UploadForm form = new UploadForm(_inviteToOverrideAutoValues); // Act form.Title = ""; form.Description = ""; form.Creator = ""; form.Url = ""; // Assert Assert.IsFalse(form.UserHasProvidedDate); Assert.IsFalse(form.UserHasProvidedDisplayDuration); Assert.IsFalse(form.UserHasProvidedTitle); }
public void StringPropertiesShouldBeNull() { // Arrange UploadForm form = new UploadForm(_inviteToOverrideAutoValues); // Act form.Title = ""; form.Description = ""; form.Creator = ""; form.Url = ""; // Assert Assert.IsNull(form.Title); Assert.IsNull(form.Description); Assert.IsNull(form.Creator); Assert.IsNull(form.Url); }
public static void Upload(ClientPipelineArgs args, Edit fileEdit) { if (!args.IsPostBack) { UploadForm.Show(ApplicationContext.PackagePath, true); args.WaitForPostBack(); } else { if (!args.Result.StartsWith("ok:", StringComparison.InvariantCulture)) { return; } string[] strArray = args.Result.Substring("ok:".Length).Split('|'); if (strArray.Length < 1 || fileEdit == null) { return; } fileEdit.Value = strArray[0]; } }
public void CanGetDataFromAllFilledInAndLegit() { // Arrange UploadForm form = new UploadForm(_inviteToOverrideAutoValues); // Act form.Title = "Title"; form.Description = "Description"; form.Creator = "Creator"; form.Url = "url"; form.SetDateIfNotEmpty("11-01-2011"); form.SetDisplayDuration("12.5", 11, 13); // Assert Assert.AreEqual("Title", form.Title); Assert.AreEqual("Description", form.Description); Assert.AreEqual("Creator", form.Creator); Assert.AreEqual("url", form.Url); Assert.AreEqual(new DateTime(2011, 1, 11), form.Date); Assert.AreEqual(12.5, form.DisplayDuration); Assert.IsTrue(form.UserHasProvidedDate); Assert.IsTrue(form.UserHasProvidedDisplayDuration); Assert.IsTrue(form.UserHasProvidedTitle); }
private void button5_upload_Click(object sender, EventArgs e) { UploadForm <CDianShangOutCheckUploadData> uf = new UploadForm <CDianShangOutCheckUploadData>(this); uf.ShowDialog(); }