public bool SaveFileFromStream(Stream inputStream, string path, string filename) { bool result = false; if (inputStream != null) { try { AmazonS3.UploadFile(inputStream, path, filename); result = true; } catch (Exception ex) { result = false; } } return(result); }
public bool SaveFile(HttpPostedFileBase file, string path, string filename) { bool result = false; if (file != null) { try { //file.SaveAs(HttpContext.Current.Server.MapPath("~" + path) + filename); AmazonS3.UploadFile(file.InputStream, path, filename); result = true; } catch (Exception ex) { result = false; } } return(result); }
protected void UploadScreenSplashButton_Click(object sender, EventArgs e) { Util util = new Util(); Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID]; if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return; if (UploadScreenSplash.UploadedFiles.Count > 0) { repeaterResultsScreenSplash.DataSource = UploadScreenSplash.UploadedFiles; repeaterResultsScreenSplash.DataBind(); repeaterResultsScreenSplash.Visible = true; string targetFolder = Server.MapPath(UploadScreenSplash.TargetFolder); foreach (UploadedFile file in UploadScreenSplash.UploadedFiles) { string name = file.GetName(); string file_path = targetFolder + @"\" + name; if (System.IO.File.Exists(file_path)) { byte[] image_data = File.ReadAllBytes(file_path); ImageConverter ic = new ImageConverter(); System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(image_data); Bitmap bitmap = new Bitmap(img); int expected_width = Constants.IPHONE_DISPLAY_WIDTH; int expected_height = Constants.IPHONE_SCROLL_HEIGHT; switch (State["SelectedDeviceType"].ToString()) { case Constants.IPAD: expected_width = Constants.IPAD_DISPLAY_WIDTH; expected_height = Constants.IPAD_SCROLL_HEIGHT; break; case Constants.ANDROID_TABLET: expected_width = Constants.ANDROID_TABLET_DISPLAY_WIDTH; expected_height = Constants.ANDROID_TABLET_SCROLL_HEIGHT; break; case Constants.IPHONE: expected_width = Constants.IPHONE_DISPLAY_WIDTH; expected_height = Constants.IPHONE_SCROLL_HEIGHT; break; case Constants.ANDROID_PHONE: expected_width = Constants.ANDROID_PHONE_DISPLAY_WIDTH; expected_height = Constants.ANDROID_PHONE_SCROLL_HEIGHT; break; } if (bitmap.Width != expected_width || bitmap.Height != expected_height) { SplashUploadMessage.Text = "The image '" + name + "' is not the right size"; return; } AmazonS3 s3 = new AmazonS3(); string file_name = name.Replace(" ", "_"); string url = s3.UploadFile(State, file_name, file_path); if (!url.StartsWith("http")) return; if (File.Exists(file_path)) File.Delete(file_path); util.SetApplicationSplashImage(State, State["ApplicationID"].ToString(), url); ScreenSplashButton.Visible = true; DeleteSplashImage.Visible = true; } } } else { repeaterResultsScreenSplash.Visible = false; SplashUploadMessage.Text = "Browse for a file"; } }
protected void UploadButton_Click(object sender, EventArgs e) { Util util = new Util(); Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID]; if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return; if (UploadMessage.Text.Length > 0) return; int width = Convert.ToInt32(Width.Text); int height = Convert.ToInt32(Height.Text); if (UploadBackground.UploadedFiles.Count > 0) { string targetFolder = Server.MapPath(UploadBackground.TargetFolder); foreach (UploadedFile file in UploadBackground.UploadedFiles) { string name = file.GetName(); if (!name.EndsWith(".png") && !name.EndsWith(".jpg") && !name.EndsWith(".gif")) { UploadMessage.Text = "The image format for '" + name + "' is not allowed"; return; } string file_path = targetFolder + @"\" + name; if (System.IO.File.Exists(file_path)) { byte[] image_data = File.ReadAllBytes(file_path); ImageConverter ic = new ImageConverter(); System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(image_data); Bitmap bitmap = new Bitmap(img); if (bitmap.Width != width || bitmap.Height != height) { UploadMessage.Text = "The image '" + name + "' is not " + Width.Text + " X " + Height.Text; return; } string file_name = util.FilterWebFileName(name); string save_file_path = HttpRuntime.Cache["TempFilesPath"].ToString() + State["Username"].ToString() + "." + file_name; try { if (File.Exists(save_file_path)) File.Delete(save_file_path); File.WriteAllBytes(save_file_path, image_data); File.Delete(file_path); } catch { //Trying to overwrite the same file } AmazonS3 s3 = new AmazonS3(); string url = s3.UploadFile(State, file_name, save_file_path); if (!url.StartsWith("http")) return ; if (File.Exists(save_file_path)) File.Delete(save_file_path); ImageSource.Text = url; UploadMessage.Text = "Upload Successful. Click Close."; } } } else { UploadMessage.Text = "Browse for a file"; } }
public async Task <IActionResult> UpdateNRICDetails([FromHeader(Name = "Grid-Authorization-Token")] string token, [FromForm] NRICDetails request) { try { if (string.IsNullOrEmpty(token)) { return(Ok(new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = true, Message = EnumExtensions.GetDescription(CommonErrors.TokenEmpty) })); } AdminUsersDataAccess _adminUsersDataAccess = new AdminUsersDataAccess(_iconfiguration); DatabaseResponse tokenAuthResponse = await _adminUsersDataAccess.AuthenticateAdminUserToken(token); if (tokenAuthResponse.ResponseCode == (int)DbReturnValue.AuthSuccess) { if (!((AuthTokenResponse)tokenAuthResponse.Results).IsExpired) { if (!ModelState.IsValid) { return(StatusCode((int)HttpStatusCode.OK, new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = true, Message = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)) })); } if (!string.IsNullOrEmpty(request.IdentityCardNumber)) { EmailValidationHelper _helper = new EmailValidationHelper(); if (!_helper.NRICValidation(null, request.IdentityCardNumber, out string _warningmsg)) { LogInfo.Warning("NRIC Validation with type: " + _warningmsg); return(Ok(new OperationResponse { HasSucceeded = false, Message = "Document details are invalid", IsDomainValidationErrors = false })); } } int deliveryStatusNumber = request.IDVerificationStatus; var authToken = (AuthTokenResponse)tokenAuthResponse.Results; MiscHelper configHelper = new MiscHelper(); CommonDataAccess _commonDataAccess = new CommonDataAccess(_iconfiguration); NRICDetailsRequest personalDetails = new NRICDetailsRequest { OrderID = request.OrderID, IdentityCardNumber = request.IdentityCardNumber, IdentityCardType = request.IdentityCardType, Nationality = request.Nationality, NameInNRIC = request.NameInNRIC, DOB = request.DOB, Expiry = request.Expiry, Remarks = request.Remarks, IDVerificationStatus = request.IDVerificationStatus, }; if (request.FrontImage != null || request.BackImage != null) { string IDCardNumberForImage = string.Empty; DatabaseResponse awsConfigResponse = await _commonDataAccess.GetConfiguration(ConfiType.AWS.ToString()); if (awsConfigResponse != null && awsConfigResponse.ResponseCode == (int)DbReturnValue.RecordExists) { GridAWSS3Config awsConfig = configHelper.GetGridAwsConfig((List <Dictionary <string, string> >)awsConfigResponse.Results); // Check for IdentityCardNumber //Start if (string.IsNullOrEmpty(request.IdentityCardNumber)) { var orderDetailsForIDCard = await _commonDataAccess.GetOrderDetails(request.OrderID); IDCardNumberForImage = orderDetailsForIDCard.IdentityCardNumber; } else { IDCardNumberForImage = request.IdentityCardNumber; } //End AmazonS3 s3Helper = new AmazonS3(awsConfig); if (request.FrontImage != null) { string fileNameFront = IDCardNumberForImage.Substring(1, IDCardNumberForImage.Length - 2) + "_Front_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(request.FrontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension UploadResponse s3UploadResponse = await s3Helper.UploadFile(request.FrontImage, fileNameFront); if (s3UploadResponse.HasSucceed) { personalDetails.FrontImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName; } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed)); } } if (request.BackImage != null) { string fileNameBack = IDCardNumberForImage.Substring(1, IDCardNumberForImage.Length - 2) + "_Back_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(request.BackImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension UploadResponse s3UploadResponse = await s3Helper.UploadFile(request.BackImage, fileNameBack); if (s3UploadResponse.HasSucceed) { personalDetails.BackImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName; } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed)); } } } else { // unable to get aws config LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetConfiguration)); } } var returnResponse = await _commonDataAccess.UpdateNRICDetails(authToken.CustomerID, deliveryStatusNumber, personalDetails); if (returnResponse.ResponseCode == (int)DbReturnValue.UpdateSuccessSendEmail) { var emailDetails = (EmailResponse)returnResponse.Results; DatabaseResponse configResponse = new DatabaseResponse(); DatabaseResponse tokenCreationResponse = new DatabaseResponse(); string finalURL = string.Empty; // Fetch the URL if (emailDetails.VerificationStatus == 2) // Rejected then token { configResponse = ConfigHelper.GetValueByKey(ConfigKeys.NRICReUploadLink.GetDescription(), _iconfiguration); tokenCreationResponse = await _adminOrderDataAccess.CreateTokenForVerificationRequests(request.OrderID); var tokenCreation = (VerificationRequestResponse)tokenCreationResponse.Results; finalURL = configResponse.Results.ToString() + tokenCreation.RequestToken; } else { var result = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID); } //Sending message start // Send email to customer email ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration); DatabaseResponse registrationResponse = await _adminOrderDataAccess.GetEmailNotificationTemplate(emailDetails.VerificationStatus == 2?NotificationEvent.ICValidationReject.GetDescription() : NotificationEvent.ICValidationChange.GetDescription()); string[] changelog = emailDetails.ChangeLog.Split(";"); string finallog = ""; foreach (string log in changelog) { if (!string.IsNullOrWhiteSpace(log)) { finallog = finallog + "• " + log.Trim() + "<br/>"; } } var notificationMessage = MessageHelper.GetMessage(emailDetails.Email, emailDetails.Name, emailDetails.VerificationStatus == 2 ? NotificationEvent.ICValidationReject.GetDescription() : NotificationEvent.ICValidationChange.GetDescription(), ((EmailTemplate)registrationResponse.Results).TemplateName, _iconfiguration, string.IsNullOrWhiteSpace(finalURL) ? "-" : finalURL, string.IsNullOrWhiteSpace(emailDetails.Remark) ? "-" : emailDetails.Remark.Replace(";", "<br />"), string.IsNullOrWhiteSpace(emailDetails.ChangeLog) ? "-" : finallog); var notificationResponse = await _adminOrderDataAccess.GetConfiguration(ConfiType.Notification.ToString()); MiscHelper parser = new MiscHelper(); var notificationConfig = parser.GetNotificationConfig((List <Dictionary <string, string> >)notificationResponse.Results); Publisher customerNotificationPublisher = new Publisher(_iconfiguration, notificationConfig.SNSTopic); await customerNotificationPublisher.PublishAsync(notificationMessage); try { DatabaseResponse notificationLogResponse = await _adminOrderDataAccess.CreateEMailNotificationLogForDevPurpose( new NotificationLogForDevPurpose { EventType = NotificationEvent.OrderSuccess.ToString(), Message = JsonConvert.SerializeObject(notificationMessage) }); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); } //Sending message Stop return(Ok(new ServerResponse { HasSucceeded = true, Message = StatusMessages.SuccessMessage, Result = null })); } else if (returnResponse.ResponseCode == (int)DbReturnValue.UpdateSuccess) { var emailDetails = (EmailResponse)returnResponse.Results; DatabaseResponse configResponse = new DatabaseResponse(); DatabaseResponse tokenCreationResponse = new DatabaseResponse(); string finalURL = string.Empty; if (emailDetails.VerificationStatus == 2) // Rejected then token { configResponse = ConfigHelper.GetValueByKey(ConfigKeys.NRICReUploadLink.GetDescription(), _iconfiguration); tokenCreationResponse = await _adminOrderDataAccess.CreateTokenForVerificationRequests(request.OrderID); var tokenCreation = (VerificationRequestResponse)tokenCreationResponse.Results; finalURL = configResponse.Results.ToString() + tokenCreation.RequestToken; DatabaseResponse registrationResponse = await _adminOrderDataAccess.GetEmailNotificationTemplate(NotificationEvent.ICValidationReject.GetDescription()); var notificationMessage = MessageHelper.GetMessage(emailDetails.Email, emailDetails.Name, NotificationEvent.ICValidationReject.GetDescription(), ((EmailTemplate)registrationResponse.Results).TemplateName, _iconfiguration, string.IsNullOrWhiteSpace(finalURL) ? "-" : finalURL, string.IsNullOrWhiteSpace(emailDetails.Remark) ? "-" : emailDetails.Remark.Replace(";", "<br />"), string.IsNullOrWhiteSpace(emailDetails.ChangeLog) ? "-" : emailDetails.ChangeLog); var notificationResponse = await _adminOrderDataAccess.GetConfiguration(ConfiType.Notification.ToString()); MiscHelper parser = new MiscHelper(); var notificationConfig = parser.GetNotificationConfig((List <Dictionary <string, string> >)notificationResponse.Results); Publisher customerNotificationPublisher = new Publisher(_iconfiguration, notificationConfig.SNSTopic); await customerNotificationPublisher.PublishAsync(notificationMessage); try { DatabaseResponse notificationLogResponse = await _adminOrderDataAccess.CreateEMailNotificationLogForDevPurpose( new NotificationLogForDevPurpose { EventType = NotificationEvent.OrderSuccess.ToString(), Message = JsonConvert.SerializeObject(notificationMessage) }); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); } } else { var result = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID); } //Sending message start // Send email to customer email ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration); return(Ok(new ServerResponse { HasSucceeded = true, Message = StatusMessages.SuccessMessage, Result = null })); } else { LogInfo.Error("UpdateNRICDetails failed for " + request.OrderID + " Order Id " + DbReturnValue.UpdationFailed); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(DbReturnValue.UpdationFailed), IsDomainValidationErrors = false })); } } else { //Token expired LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.ExpiredToken)); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(DbReturnValue.TokenExpired), IsDomainValidationErrors = true })); } } else { // token auth failure LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed)); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed), IsDomainValidationErrors = false })); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(Ok(new OperationResponse { HasSucceeded = false, Message = StatusMessages.ServerError, IsDomainValidationErrors = false })); } }
public string ConvertToImageLink(Hashtable State,string page_name, string html) { //fill in link prefixes where they are left out int start = 0; string search = " src=\""; int end = 0; StringBuilder sb_html = new StringBuilder(); if (State["BackgroundColor"] == null && State["BackgroundHtml"] != null) { string html_and_back = State["BackgroundHtml"].ToString() + html; sb_html.Append(html_and_back); } else { sb_html.Append(html); } do { end = sb_html.ToString().ToLower().IndexOf(search, start); if (end > 0) { end += search.Length; start = end ; if (sb_html.ToString().Substring(start, 4) != "http") { sb_html.Insert(start, HttpRuntime.Cache["PublicViziAppsUrl"].ToString() + "/"); } } }while(end >=0); //filter for table images start = 0; search = "url("; do { end = sb_html.ToString().ToLower().IndexOf(search, start); if (end > 0) { end += search.Length ; string quote_type = "none"; if (sb_html[end] == '&') { start = end + 6; quote_type = "encoded"; } else if (sb_html[end] == '"') { start = end + 1; quote_type = "quote"; } else start = end; if (sb_html.ToString().Substring(start, 4) != "http") { sb_html.Insert(start, HttpRuntime.Cache["PublicViziAppsUrl"].ToString() + "/"); } //get image url switch (quote_type) { case "none": end = sb_html.ToString().IndexOf(")", start); break; case "encoded": end = sb_html.ToString().IndexOf(""", start); break; case "quote": end = sb_html.ToString().IndexOf("\"", start); break; } string image_url = sb_html.ToString().Substring(start, end - start); start = end + 1; end = sb_html.ToString().IndexOf(">", start); start = end + 1; sb_html.Insert(start, " <img src=\"" + image_url + "\"/>"); sb_html.Insert(end, " style=\"overflow:hidden\" "); } } while (end >= 0); Util util = new Util(); string file_name = State["SelectedApp"].ToString() + "." + page_name + ".jpg"; file_name = file_name.Replace(" ","_"); string save_file_path = HttpRuntime.Cache["TempFilesPath"].ToString() + State["Username"].ToString() + "." + file_name; int browserWidth = Constants.IPHONE_DISPLAY_WIDTH; int browserHeight = Convert.ToInt32(Constants.IPHONE_SCROLL_HEIGHT_S); int thumbnailWidth = browserWidth; int thumbnailHeight = browserHeight; if (State["SelectedDeviceType"].ToString() == Constants.IPAD) { browserWidth = Constants.IPAD_DISPLAY_WIDTH; browserHeight = Constants.IPAD_DISPLAY_HEIGHT; thumbnailWidth = browserWidth; thumbnailHeight = browserHeight; } else if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_TABLET) { browserWidth = Constants.ANDROID_TABLET_DISPLAY_WIDTH; browserHeight = Constants.ANDROID_TABLET_DISPLAY_HEIGHT; thumbnailWidth = browserWidth; thumbnailHeight = browserHeight; } string whole_html = HttpRuntime.Cache["CanvasHtml"].ToString().Replace("<REPLACE>", sb_html.ToString()); string temp_store_path = HttpRuntime.Cache["TempFilesPath"].ToString() + "canvas.htm"; File.WriteAllText(temp_store_path, whole_html.Replace("iframe","div")); string siteurl = "file:///" + temp_store_path; System.Drawing.Image img = (System.Drawing.Image)PAB.WebControls.WebSiteThumbnail.GetSiteThumbnail(siteurl, browserWidth, browserHeight, thumbnailWidth, thumbnailHeight, save_file_path); if (!File.Exists(save_file_path)) return null; try { if (File.Exists(temp_store_path)) File.Delete(temp_store_path); } catch{ //file access issues }; string url = null; try{ AmazonS3 s3 = new AmazonS3(); url = s3.UploadFile(State, file_name, save_file_path); if (!url.StartsWith("http")) return null; if (File.Exists(save_file_path)) File.Delete(save_file_path); } catch{ //file access issues }; return url; }
public async Task <IActionResult> UpdateNRICIDDetails([FromHeader(Name = "Grid-General-Token")] string Token, [FromForm] UpdateOrderPersonalIDDetailsPublicRequest request) { try { if (!ModelState.IsValid) { return(Ok(new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = true, Message = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)) })); } TokenValidationHelper tokenValidationHelper = new TokenValidationHelper(); if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration)) { return(Ok(new OperationResponse { HasSucceeded = false, Message = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed), IsDomainValidationErrors = true })); } CommonDataAccess commonDataAccess = new CommonDataAccess(_iconfiguration); var tokenResult = await commonDataAccess.ValidateVerificationToken(request.RequestToken); if (tokenResult.ResponseCode != (int)DbReturnValue.RecordExists) { return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(DbReturnValue.RequestTokenExpired), IsDomainValidationErrors = false })); } AccountDataAccess _AccountAccess = new AccountDataAccess(_iconfiguration); CommonDataAccess _commonDataAccess = new CommonDataAccess(_iconfiguration); DatabaseResponse customerResponse = await _commonDataAccess.GetCustomerIdFromOrderId(request.OrderID); if (customerResponse.ResponseCode == (int)DbReturnValue.RecordExists) { IFormFile frontImage = request.IDImageFront; IFormFile backImage = request.IDImageBack; BSSAPIHelper bsshelper = new BSSAPIHelper(); MiscHelper configHelper = new MiscHelper(); OrderDetails customerOrderDetails = await _commonDataAccess.GetOrderDetails(request.OrderID); NRICDetailsRequest personalDetails = new NRICDetailsRequest { OrderID = request.OrderID, IdentityCardNumber = customerOrderDetails.IdentityCardNumber, IdentityCardType = customerOrderDetails.IdentityCardType, Nationality = customerOrderDetails.Nationality, NameInNRIC = customerOrderDetails.Name, DOB = customerOrderDetails.DOB, Expiry = customerOrderDetails.ExpiryDate, }; //process file if uploaded - non null if (frontImage != null && backImage != null) { DatabaseResponse awsConfigResponse = await _commonDataAccess.GetConfiguration(ConfiType.AWS.ToString()); if (awsConfigResponse != null && awsConfigResponse.ResponseCode == (int)DbReturnValue.RecordExists) { GridAWSS3Config awsConfig = configHelper.GetGridAwsConfig((List <Dictionary <string, string> >)awsConfigResponse.Results); AmazonS3 s3Helper = new AmazonS3(awsConfig); string fileNameFront = customerOrderDetails.IdentityCardNumber.Substring(1, customerOrderDetails.IdentityCardNumber.Length - 2) + "_Front_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(frontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension UploadResponse s3UploadResponse = await s3Helper.UploadFile(frontImage, fileNameFront); if (s3UploadResponse.HasSucceed) { personalDetails.FrontImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName; } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed)); } string fileNameBack = customerOrderDetails.IdentityCardNumber.Substring(1, customerOrderDetails.IdentityCardNumber.Length - 2) + "_Back_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(frontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension s3UploadResponse = await s3Helper.UploadFile(backImage, fileNameBack); if (s3UploadResponse.HasSucceed) { personalDetails.BackImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName; } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed)); } } else { // unable to get aws config LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetConfiguration)); } } //file //update ID ReUpload details DatabaseResponse updateNRICResponse = await _commonDataAccess.UpdateNRICDetails(null, 0, personalDetails); if (updateNRICResponse.ResponseCode == (int)DbReturnValue.UpdateSuccess) { DatabaseResponse updateTokenStatus = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID); // EmailResponse emailResponse = (EmailResponse)updateNRICResponse.Results; // string emailStatus= await SendAdminEmailNotificationOnIDReUpload(emailResponse.Email, emailResponse.OrderNumber); return(Ok(new OperationResponse { HasSucceeded = true, Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccess), IsDomainValidationErrors = false })); } else if (updateNRICResponse.ResponseCode == (int)DbReturnValue.UpdateSuccessSendEmail) { DatabaseResponse updateTokenStatus = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID); // EmailResponse emailResponse = (EmailResponse)updateNRICResponse.Results; // string emailStatus = await SendAdminEmailNotificationOnIDReUpload(emailResponse.Email, emailResponse.OrderNumber); // LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.UpdateSuccessSendEmail) + "for " + request.OrderID + "Order"); return(Ok(new OperationResponse { HasSucceeded = true, Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccessSendEmail), IsDomainValidationErrors = false })); } else if (updateNRICResponse.ResponseCode == (int)DbReturnValue.NotExists) { LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.NotExists) + " " + EnumExtensions.GetDescription(CommonErrors.ImageAlreadyUploaded) + " Order" + request.OrderID); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(CommonErrors.ImageAlreadyUploaded), IsDomainValidationErrors = false })); } else { LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.UpdationFailed)); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(DbReturnValue.UpdationFailed), IsDomainValidationErrors = false })); } } else { // failed to locate customer LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetCustomer)); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(CommonErrors.FailedToGetCustomer), IsDomainValidationErrors = false })); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(Ok(new OperationResponse { HasSucceeded = false, Message = StatusMessages.ServerError, IsDomainValidationErrors = false })); } }
protected void UploadButton_Click(object sender, EventArgs e) { Util util = new Util(); Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID]; if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return; if (UploadBackground.UploadedFiles.Count > 0) { string targetFolder = Server.MapPath(UploadBackground.TargetFolder); foreach (UploadedFile file in UploadBackground.UploadedFiles) { string name = file.GetName(); string file_path = targetFolder + @"\" + name; if (file_path.Contains(".wav") && file_path.Contains(".mp3")) { UploadMessage.Text = name + "' is not a .mp3 or .wav file"; return; } if (System.IO.File.Exists(file_path)) { byte[] audio_data = File.ReadAllBytes(file_path); string file_name = name.Replace(" ", "_").Replace("%20", "_"); string save_file_path = HttpRuntime.Cache["TempFilesPath"].ToString() + State["Username"].ToString() + "." + file_name; try { if (File.Exists(save_file_path)) File.Delete(save_file_path); File.WriteAllBytes(save_file_path, audio_data); File.Delete(file_path); } catch { //Trying to overwrite the same file } AmazonS3 s3 = new AmazonS3(); string url = s3.UploadFile(State, file_name, save_file_path); if (!url.StartsWith("http")) return; try { if (File.Exists(save_file_path)) File.Delete(save_file_path); } catch (Exception ex) { } ImageSource.Value = url; UploadMessage.Text = "Upload Successful. Click Close."; } } } else { UploadMessage.Text = "Browse for a file"; } }
public void SetApplicationLargeIcon(Hashtable State, string application_id, Bitmap bitmap, string file_name, string file_path) { DeleteLargeIcon(State, application_id); AmazonS3 s3 = new AmazonS3(); string url = s3.UploadFile(State, file_name, file_path); if (!url.StartsWith("http")) throw new Exception("Error in SetApplicationLargeIcon: s3.UploadFile failed."); if (File.Exists(file_path)) File.Delete(file_path); string[] icon_sizes = { "114", "72", "58", "57", "48", "36", "29" }; DB db = new DB(); StringBuilder b_sql = new StringBuilder("INSERT INTO branding_images SET "); b_sql.Append("branding_image_id='" + Guid.NewGuid().ToString() + "'"); b_sql.Append(",application_id='" + application_id + "'"); b_sql.Append(",width=512,height=512,type='icon'"); b_sql.Append(",url='" + url + "'"); db.ViziAppsExecuteNonQuery(State, b_sql.ToString()); //do all the other sizes foreach (string icon_size in icon_sizes) { int size = Convert.ToInt32(icon_size); Bitmap resized_bitmap = (Bitmap)ResizeImage(bitmap, new Size(size, size)); resized_bitmap.Save(file_path); url = s3.UploadFile(State, file_name.Insert(file_name.Length - 4, "_" + icon_size), file_path); if (!url.StartsWith("http")) throw new Exception("Error in SetApplicationLargeIcon: s3.UploadFile failed."); if (File.Exists(file_path)) File.Delete(file_path); b_sql = new StringBuilder("INSERT INTO branding_images SET "); b_sql.Append("branding_image_id='" + Guid.NewGuid().ToString() + "'"); b_sql.Append(",application_id='" + application_id + "'"); b_sql.Append(",width=" + icon_size + ",height=" + icon_size + ",type='icon'"); b_sql.Append(",url='" + url + "'"); db.ViziAppsExecuteNonQuery(State, b_sql.ToString()); } db.CloseViziAppsDatabase(State); }
protected void UploadScreenSplashButton_Click(object sender, EventArgs e) { Util util = new Util(); Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID]; if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return; if (UploadScreenSplash.UploadedFiles.Count > 0) { repeaterResultsScreenSplash.DataSource = UploadScreenSplash.UploadedFiles; repeaterResultsScreenSplash.DataBind(); repeaterResultsScreenSplash.Visible = true; string targetFolder = Server.MapPath(UploadScreenSplash.TargetFolder); foreach (UploadedFile file in UploadScreenSplash.UploadedFiles) { string name = file.GetName(); if (!name.ToLower().EndsWith(".jpg")) { SplashUploadMessage.Text = "File must be .jpg file"; return; } string file_path = targetFolder + @"\" + name; if (System.IO.File.Exists(file_path)) { byte[] image_data = File.ReadAllBytes(file_path); ImageConverter ic = new ImageConverter(); System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(image_data); Bitmap bitmap = new Bitmap(img); if (bitmap.Width != 320 || bitmap.Height != 460) { SplashUploadMessage.Text = "The image '" + name + "' is not 320 X 460"; return; } AmazonS3 s3 = new AmazonS3(); string file_name = name.Replace(" ", "_"); string url = s3.UploadFile(State, file_name, file_path); if (!url.StartsWith("http")) return; if (File.Exists(file_path)) File.Delete(file_path); util.SetApplicationSplashImage(State, State["ApplicationID"].ToString(), url); ScreenSplashButton.Visible = true; DeleteSplashImage.Visible = true; } } } else { repeaterResultsScreenSplash.Visible = false; SplashUploadMessage.Text = "Browse for a file"; } }