public HttpResponseMessage CreateEmployee() { var modelJson = HttpContext.Current.Request.Form["Model"]; EmployeeModel model = JsonConvert.DeserializeObject <EmployeeModel>(modelJson); HttpFileCollection hfc = HttpContext.Current.Request.Files; string pathFolder = "fileUpload/" + Constants.FolderEmployee + "/"; string pathFolderServer = HostingEnvironment.MapPath("~/" + pathFolder); string imageLink = string.Empty; try { if (hfc.Count > 0) { for (int i = 0; i < hfc.Count; i++) { if (i == 0) { // imageLink = Task.Run(async () => { return wait UploadPhotoAsync(hfc[i], hfc[i].FileName); }).Result; imageLink = Task.Run(async() => { return(await AzureStorageUploadFiles.GetInstance().UploadPhotoAsync(hfc[i], hfc[i].FileName, Constants.FolderEmployee)); }).Result; } else { imageLink += ";" + Task.Run(async() => { return(await AzureStorageUploadFiles.GetInstance().UploadPhotoAsync(hfc[i], hfc[i].FileName, Constants.FolderEmployee)); }).Result; } } } model.LinkImage = imageLink; _userBusiness.CreateEmployee(model); return(Request.CreateResponse(HttpStatusCode.OK, string.Empty)); } catch (Exception ex) { logger.Error(ex.Message, ex.InnerException); //Xóa file trên server nếu cập nhật lỗi string[] mangErro = imageLink.Split(';'); for (int i = 0; i < mangErro.Length; i++) { UploadFileServer.DeleteFile(mangErro[i]); } return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <Stream> MergingImage(string imageUrl, int imageWidth, int imageHeight, IEnumerable <FaceBox> listFaces) { AzureStorageUploadFiles azureStorageUploadFiles = AzureStorageUploadFiles.GetInstance(); if (azureStorageUploadFiles.CheckExitPhotoAsync(imageUrl) && listFaces != null && listFaces.Count() > 0) { Bitmap imgCrop = new Bitmap(azureStorageUploadFiles.ReadFileToStream(imageUrl)); List <ImageCropModel> listImageCrop = new List <ImageCropModel>(); foreach (FaceBox face in listFaces) { int width, height, xStartPosition, yStartPosition; EnlargeFaceBoxSize(face, imageWidth, imageHeight, out width, out height, out xStartPosition, out yStartPosition); Image imageFace = imgCrop.Clone(new Rectangle(xStartPosition, yStartPosition, width, height), imgCrop.PixelFormat); listImageCrop.Add(new ImageCropModel() { ImageCrop = imageFace, Width = width, Height = height }); } Bitmap imgMerging = new Bitmap(listImageCrop.Sum(r => r.Width) + (listImageCrop.Count() - 1) * 5, listImageCrop.Max(r => r.Height)); Graphics grpMerging = Graphics.FromImage(imgMerging); int startPoint = 0; foreach (var itemImage in listImageCrop) { grpMerging.DrawImage(itemImage.ImageCrop, new Point(startPoint, 0)); //Giữa 2 Face cách nhau 5px startPoint += itemImage.Width + 5; } grpMerging.Save(); Stream imageStream = new MemoryStream(); imgMerging.Save(imageStream, ImageFormat.Jpeg); imageStream.Position = 0; await azureStorageUploadFiles.UploadImageStreamAsync(imageStream, "ImageFace", "jpg"); return(imageStream); } return(null); }
public SettingConfig() { this.InitializeComponent(); LoadData(); try { AzureStorageUploadFiles.GetInstance(); } catch (Exception ex) { new MessageDialog("Thông tin cấu hình Azure Storage không đúng.").ShowAsync(); } //if (!ServiceBusSetting.CheckServiceBus()) //{ // new MessageDialog("Thông tin cấu hình Service Bus không đúng.").ShowAsync(); //} }
//[NTSAuthorize(AllowFeature = "SY0002")] public HttpResponseMessage UpdateUser() { var modelJson = HttpContext.Current.Request.Form["Model"]; UserModel model = JsonConvert.DeserializeObject <UserModel>(modelJson); HttpFileCollection hfc = HttpContext.Current.Request.Files; string imageLink = string.Empty; string imageLinkOld = string.Empty; try { if (hfc.Count > 0) { imageLink = Task.Run(async() => { return(await AzureStorageUploadFiles.GetInstance().UploadPhotoAsync(hfc[0], hfc[0].FileName, Constants.FolderImageUser)); }).Result; //Upload file lên server // imageLink = UploadFileServer.UploadFile(hfc[0], Constants.FolderImageUser); imageLinkOld = model.ImageLink; } model.ImageLink = !string.IsNullOrEmpty(imageLink) ? imageLink : model.ImageLink; _userBusiness.UpdateUser(model); if (!string.IsNullOrEmpty(imageLinkOld)) { //Xóa file cũ nếu cập nhật thành công UploadFileServer.DeleteFile(imageLinkOld); } return(Request.CreateResponse(HttpStatusCode.OK, string.Empty)); } catch (Exception ex) { logger.Error(ex.Message, ex.InnerException); //Xóa file upload nếu cập nhật lỗi UploadFileServer.DeleteFile(imageLink); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }