public static string CreateFolder(string baseDirectory) { string theNewFolderName = ""; string currentPath; bool useAttachmentsRelativePath = false; string sUseAttachmentsRelativePath = AppSettings.Get <string>("UseAttachmentsRelativePath"); if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath)) { useAttachmentsRelativePath = bUseAttachmentsRelativePath; } do { DateTime date = DateTime.Now; theNewFolderName = date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); if (useAttachmentsRelativePath) { currentPath = "~/".MapHostAbsolutePath() + baseDirectory + theNewFolderName; } else { currentPath = baseDirectory + theNewFolderName; } } while (Directory.Exists(currentPath)); Directory.CreateDirectory(currentPath); return(theNewFolderName); }
public async Task <string> AuthorizePlayerAsync(Guid gameId, string password, User user) { var game = await _gameStorage.GetByIdAsync(gameId); if (game is null) { return("GAME_NOT_FOUND"); } if (game.IsPrivate()) { if (string.IsNullOrEmpty(password)) { return("PASSWORD_REQUIRED"); } var passwordHash = MD5HashGenerator.GenerateHash(password); if (!game.Password.Equals(passwordHash)) { return("INCORRECT_PASSWORD"); } } game.AuthorizeUser(user.Id); await _gameStorage.EditAsync(game); return("OK"); }
public Token GetNew(string ForeignType, long ForeignKey) { var token = new Token { ForeignKey = ForeignKey, ForeignType = ForeignType, Value = MD5HashGenerator.GenerateKey(DateTime.Now), ExpiresAt = DateTimeOffset.Now.AddMinutes(40) }; return(Add(token)); }
public static string ComputeHash(this object sourceObject, ObjectHasherAlgorithmTypeEnum algorithm = ObjectHasherAlgorithmTypeEnum.MD5) { IObjectHasher objectHasher = null; switch (algorithm) { case ObjectHasherAlgorithmTypeEnum.MD5: objectHasher = new MD5HashGenerator(); break; } return(objectHasher.ComputeHash(sourceObject)); }
/// <summary> /// Serves as a hash function for a particular type. /// </summary> /// <returns> /// A hash code for the current <see cref="T:System.Object"/>. /// </returns> public override int GetHashCode() { string hashString = MD5HashGenerator.GenerateKey(this); try { return(Convert.ToInt32(hashString, CultureInfo.InvariantCulture)); } catch (FormatException fe) { this.logger.Debug("Couldn't transform the hash string: " + hashString + " to an Integer. Cause: " + fe.Message); return(base.GetHashCode()); } }
public static string CreateFolder(string baseDirectory) { string theNewFolderName = ""; string currentPath; do { DateTime date = DateTime.Now; theNewFolderName = date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); currentPath = baseDirectory + theNewFolderName; } while (Directory.Exists(currentPath)); Directory.CreateDirectory(currentPath); return(theNewFolderName); }
public async Task <Game> CreateAsync(User user, string name, string password, GameOptions options) { if (!string.IsNullOrEmpty(password)) { password = MD5HashGenerator.GenerateHash(password); } var game = new Game(name, password, options); game.AuthorizeUser(user.Id); await _gameStorage.AddAsync(game); var player = Player.CreateAsAdmin(game.Id, user); await _playerStorage.AddAsync(player); return(game); }
public void GetMD5Hash_Test() { ReferencesData data1; ReferencesData data2; using (EventLogReader reader = EventLogReader.CreateReader(_sampleDatabaseFileLGF)) { data1 = ReferencesData.CreateFromReader(reader); } using (EventLogReader reader = EventLogReader.CreateReader(_sampleDatabaseFileLGF)) { data2 = ReferencesData.CreateFromReader(reader); } string hashMD51 = MD5HashGenerator.GetMd5Hash(data1); string hashMD52 = MD5HashGenerator.GetMd5Hash(data2); Assert.Equal(hashMD51, hashMD52); }
public bool getPostedAttachmentsToBuyer() { HttpPostedFile file = Request.Files["myfile"]; HttpFileCollection fileCollection = Request.Files; if (file != null) { string fileName = file.FileName; HttpPostedFile postedFile = file; string baseAttachmentsPath = ConfigurationManager.AppSettings["RFQAttachmentsInbox"]; string currentPathAttachments; string folderName = Request["RFQATTACHMENTSFOLDERINBOX"]; if (folderName != null && folderName.Trim() != "") { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; } else { do { DateTime date = DateTime.Now; folderName = date.Year.ToString() + date.Month.ToString() + date.Day.ToString() + "_" + MD5HashGenerator.GenerateKey(date); currentPathAttachments = baseAttachmentsPath + folderName; } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); currentPathAttachments += @"\"; } if (postedFile.ContentLength > 0) { postedFile.SaveAs(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } Response.Clear(); Response.Write("[{\"FolderName\":\"" + folderName + "\"}," + JsonConvert.SerializeObject(getAttachmentsFromFolder(folderName)) + "]"); Response.End(); return(true); } return(false); }
public object attachmentsPost() { CommonResponse response = new CommonResponse(); try { string attachmentKind = HttpContext.Current.Request["attachmentKind"]; if (attachmentKind == null || attachmentKind == "") { response.ErrorThrown = true; response.ResponseDescription = "Attachment Kind was not specified."; return(response); } var postedFile = HttpContext.Current.Request.Files["file"]; if (postedFile != null) { string fileName = postedFile.FileName; string baseAttachmentsPath = ConfigurationManager.AppSettings[attachmentKind]; bool useAttachmentsRelativePath = false; string sUseAttachmentsRelativePath = ConfigurationManager.AppSettings["UseAttachmentsRelativePath"]; if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath)) { useAttachmentsRelativePath = bUseAttachmentsRelativePath; } string currentPathAttachments; string folderName = HttpContext.Current.Request["targetFolder"]; if (folderName != null && folderName.Trim() != "") { if (useAttachmentsRelativePath) { currentPathAttachments = HostingEnvironment.MapPath("~/" + baseAttachmentsPath + folderName + @"/"); } else { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; } if (!Directory.Exists(currentPathAttachments)) { Directory.CreateDirectory(currentPathAttachments); } } else { string folderPrefix = HttpContext.Current.Request["folderPrefix"]; if (string.IsNullOrWhiteSpace(folderPrefix) || folderPrefix == "undefined" || folderPrefix == "null") { folderPrefix = ""; } do { DateTime date = DateTime.Now; folderName = folderPrefix + date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); if (useAttachmentsRelativePath) { currentPathAttachments = HostingEnvironment.MapPath("~/" + baseAttachmentsPath + folderName); } else { currentPathAttachments = baseAttachmentsPath + folderName; } } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); if (useAttachmentsRelativePath) { currentPathAttachments += @"/"; } else { currentPathAttachments += @"\"; } } if (postedFile.ContentLength > 0) { postedFile.SaveAs(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } List <Attachment> attachmentsResult = AttachmentsIO.getAttachmentsFromFolder(folderName, attachmentKind); response.ErrorThrown = false; response.ResponseDescription = folderName; response.Result = attachmentsResult; } } catch (Exception e) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: " + e.Message; response.Result = e; } return(response); }
public string sendRFQ() { List <RFQ> resultRFQs = new List <RFQ>(); GatewayResponse response = new GatewayResponse(); String s; NewRFQScreen newRFQScreen; try { s = new StreamReader(Request.InputStream).ReadToEnd(); newRFQScreen = JsonConvert.DeserializeObject <NewRFQScreen>(s); } catch (Exception ex) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: When trying to parse JSON in server. " + ex.Message; return(JsonConvert.SerializeObject(response)); } RFQNumberCRUD rfqNumberCRUD = new RFQNumberCRUD(); bomDetailCRUD bomDetail_CRUD = new bomDetailCRUD(); UserCRUD user_CRUD = new UserCRUD(); string baseBOMAttachmentsPath = ConfigurationManager.AppSettings["BOMLineAttachments"]; string baseRFQAttachmentsPath = ConfigurationManager.AppSettings["RFQAttachmentsSent"]; string strAuthUser = HttpContext.Current.User.Identity.Name; User user = user_CRUD.readById(strAuthUser); List <SIFDetail> EAUsList = newRFQScreen.SIFVolumesList; if (EAUsList.Count == 0) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: Cannot create RFQ without EAU specified."; return(JsonConvert.SerializeObject(response)); } List <RFQEAV> newEAUList = new List <RFQEAV>(); foreach (SIFDetail eau in EAUsList) { RFQEAV eauParsed = new RFQEAV(); eauParsed.Volume = eau.ProjectedAnnualVolume; eauParsed.Year = eau.ProgramYear; RFQEAV alreadyExists = newEAUList.Find(eauInternal => eauInternal.Volume == eauParsed.Volume); if (alreadyExists == null) { newEAUList.Add(eauParsed); } else { alreadyExists.Year = alreadyExists.Year.Trim() + ", " + eauParsed.Year.Trim(); } } List <BOMDetail> bomDetailList = newRFQScreen.BomDetailList; ConnectionManager CM = new ConnectionManager(); Data_Base_MNG.SQL DM = CM.getDataManager(); if (newRFQScreen.SupplierList.Count > 0) { foreach (Supplier supplier in newRFQScreen.SupplierList) { foreach (BOMDetail component in bomDetailList) { RFQNumberEntity rfqNumber = new RFQNumberEntity(); rfqNumber.BOMDetailKey = component.Id; rfqNumber.SifHeaderKey = newRFQScreen.SIFHeaderID; rfqNumber.RFQNumber = rfqNumberCRUD.generateNewRFQNumber(rfqNumber.SifHeaderKey); if (rfqNumber.RFQNumber == -1) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: There was an error generating a new RFQ number."; return(JsonConvert.SerializeObject(response)); } CM = new ConnectionManager(); DM = CM.getDataManager(); /*Begin Transaction*/ DM.Open_Connection("Send New RFQ"); RFQ rfq = new RFQ(); RFQNumberEntity rfqNumberGenereated = rfqNumberCRUD.create_return_object(rfqNumber, ref DM); if (rfqNumberCRUD.ErrorOccur) { response.ErrorThrown = true; response.ResponseDescription = "ERROR:" + rfqNumberCRUD.ErrorMessage; return(JsonConvert.SerializeObject(response)); } else { //rfq.SentAttachmentsFolder = newRFQScreen.FolderAttachments; newRFQScreen.FolderAttachments = newRFQScreen.FolderAttachments.Trim(); if (newRFQScreen.FolderAttachments != "") { if (System.IO.Directory.Exists((baseRFQAttachmentsPath + newRFQScreen.FolderAttachments))) { DirectoryInfo directory = new DirectoryInfo((baseRFQAttachmentsPath + newRFQScreen.FolderAttachments)); if (directory.GetFiles().Length > 0) { string folderName = ""; do { DateTime date = DateTime.Now; folderName = date.Year.ToString() + date.Month.ToString() + date.Day.ToString() + "_" + MD5HashGenerator.GenerateKey(date); } while (Directory.Exists((baseRFQAttachmentsPath + folderName))); Directory.CreateDirectory((baseRFQAttachmentsPath + folderName)); rfq.SentAttachmentsFolder = folderName; foreach (FileInfo file in directory.GetFiles()) { try { File.Copy(file.FullName, (baseRFQAttachmentsPath + rfq.SentAttachmentsFolder + @"\" + file.Name), true); } catch (Exception ex) { response.ErrorThrown = true; response.ResponseDescription = "ERROR:" + ex.Message; return(JsonConvert.SerializeObject(response)); } } } } } foreach (Attachment bomAttachment in component.AttachmentsList) { if (rfq.SentAttachmentsFolder.Trim() == "") { string folderName = ""; do { DateTime date = DateTime.Now; folderName = date.Year.ToString() + date.Month.ToString() + date.Day.ToString() + "_" + MD5HashGenerator.GenerateKey(date); } while (Directory.Exists((baseRFQAttachmentsPath + folderName))); Directory.CreateDirectory((baseRFQAttachmentsPath + folderName)); rfq.SentAttachmentsFolder = folderName; } string currentPathAttachmentSource = baseBOMAttachmentsPath + bomAttachment.Directory + @"\" + bomAttachment.FileName; string currentPathAttachmentTarget = baseRFQAttachmentsPath + rfq.SentAttachmentsFolder + @"\" + bomAttachment.FileName; try { File.Copy(currentPathAttachmentSource, currentPathAttachmentTarget, true); } catch (Exception e) { response.ErrorThrown = true; response.ResponseDescription = "ERROR:" + e.Message; return(JsonConvert.SerializeObject(response)); } } RfqCRUD rfqCRUD = new RfqCRUD(); rfq.SupplierId = supplier.Id; rfq.SupplierName = supplier.SupplierName; rfq.SentToVendor = DateTime.Now; rfq.LastEmail = supplier.ContactEmail; rfq.Status = "PENDING"; rfq.BomDetailId = component.Id; rfq.Um = component.Um; rfq.RfqNumberKey = rfqNumberGenereated.Id; rfq.RfqGenerated = rfqNumberGenereated.RfqGenerated; rfq.DueDate = newRFQScreen.DueDate; rfq.MarketSectorID = newRFQScreen.MarketSectorID; rfq.DrawingLevel = newRFQScreen.DrawingLevel; rfq.TargetPrice = newRFQScreen.TargetPrice; rfq.CommentsToVendor = newRFQScreen.CommentsToVendor; rfq.CreatedBy = strAuthUser; string idGenerated = rfqCRUD.createAndReturnIdGenerated(rfq, component, ref DM); if (!rfqCRUD.ErrorOccur) { rfq.Id = long.Parse(idGenerated); foreach (RFQEAV eau in newEAUList) { RFQEAVCRUD rfqEAV_CRUD = new RFQEAVCRUD(); RFQEAV rfqEAV_toPersist = new RFQEAV(); rfqEAV_toPersist.RfqHeaderKey = long.Parse(idGenerated); rfqEAV_toPersist.Volume = eau.Volume * component.Qty; rfqEAV_toPersist.Year = eau.Year; rfqEAV_toPersist.Status = "CREATED"; rfqEAV_CRUD.createAndReturnIdGenerated(rfqEAV_toPersist, ref DM); if (rfqEAV_CRUD.ErrorOccur) { response.ErrorThrown = true; response.ResponseDescription = "ERROR:" + rfqEAV_CRUD.ErrorMessage; return(JsonConvert.SerializeObject(response)); } } TokenCRUD token_CRUD = new TokenCRUD(); Token token = new Token(); token.Subject = "RFQ"; token.SubjectKey = long.Parse(idGenerated); token.TokenNumber = MD5HashGenerator.GenerateKey(DateTime.Now); if (token_CRUD.create(token, ref DM)) { Email NewMail = new Email(); MailMessage Message = new MailMessage(); try { Message.From = new MailAddress("*****@*****.**", "*****@*****.**"); Message.To.Add(new MailAddress(supplier.ContactEmail.ToString())); Message.Subject = "Request For Quote"; Message.IsBodyHtml = true; Message.BodyEncoding = System.Text.Encoding.UTF8; var url = ResolveUrl("~/Vendor/Email_RFQ_Request.htm"); var strEmailContent = HTMLContent(url); strEmailContent = strEmailContent.Replace("{BuyerName}", user.Name); strEmailContent = strEmailContent.Replace("{BuyerPhone}", user.Phone1); strEmailContent = strEmailContent.Replace("{BuyerEmail}", user.Email); strEmailContent = strEmailContent.Replace("{RFQ Number}", rfqNumber.RfqGenerated); strEmailContent = strEmailContent.Replace("{Part Number}", component.PartNumber); strEmailContent = strEmailContent.Replace("{RFQLink}", "http://" + Request.Url.Authority + Request.ApplicationPath + "/Vendor/RFQHandler.ashx?token=" + token.TokenNumber); Message.Body = strEmailContent; NewMail.SendMail(Message); } catch (Exception ex) { DM.RollBack(); response.ErrorThrown = true; response.ResponseDescription = "ERROR: Could not send email to: " + supplier.ContactEmail.ToString() + "; " + ex.Message; return(JsonConvert.SerializeObject(response)); } } else { response.ErrorThrown = true; response.ResponseDescription = "ERROR: " + token_CRUD.ErrorMessage; return(JsonConvert.SerializeObject(response)); } } else { response.ErrorThrown = true; response.ResponseDescription = "ERROR: " + rfqCRUD.ErrorMessage; return(JsonConvert.SerializeObject(response)); } } DM.CommitTransaction(); DM.Close_Open_Connection(); if (DM.ErrorOccur) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: " + DM.Error_Mjs; return(JsonConvert.SerializeObject(response)); } resultRFQs.Add(rfq); } } } response.ErrorThrown = false; response.ResponseDescription = "RFQs created successfully."; response.Result = resultRFQs; return(JsonConvert.SerializeObject(response)); }
public string resendRFQ() { GatewayResponse response = new GatewayResponse(); String s; RFQ rfqToResend; try { s = new StreamReader(Request.InputStream).ReadToEnd(); rfqToResend = JsonConvert.DeserializeObject <RFQ>(s); } catch (Exception ex) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: When trying to parse JSON in server. " + ex.Message; return(JsonConvert.SerializeObject(response)); } UserCRUD user_CRUD = new UserCRUD(); string strAuthUser = HttpContext.Current.User.Identity.Name; User user = user_CRUD.readById(strAuthUser); SupplierCRUD supplier_CRUD = new SupplierCRUD(); Supplier supplier = supplier_CRUD.readById(rfqToResend.SupplierId); if (supplier != null) { if (supplier.ContactEmail.Trim() != rfqToResend.LastEmail.Trim()) { supplier.ContactEmail = rfqToResend.LastEmail.Trim(); if (!supplier_CRUD.update(supplier)) { response.ErrorThrown = true; response.ResponseDescription = "ERROR:" + supplier_CRUD.ErrorMessage; return(JsonConvert.SerializeObject(response)); } } } TokenCRUD token_CRUD = new TokenCRUD(); Token token = token_CRUD.readByRFQ(rfqToResend); ConnectionManager CM = new ConnectionManager(); Data_Base_MNG.SQL DM = CM.getDataManager(); /*Begin Transaction*/ DM.Open_Connection("RFQ Re-send"); rfqToResend.SentToVendor = DateTime.Now; if (!rfq_CRUD.update(rfqToResend, ref DM)) { response.ErrorThrown = true; response.ResponseDescription = "ERROR:" + rfq_CRUD.ErrorMessage; return(JsonConvert.SerializeObject(response)); } if (token == null) { token = new Token(); token.Subject = "RFQ"; token.SubjectKey = rfqToResend.Id; token.TokenNumber = MD5HashGenerator.GenerateKey(DateTime.Now); token_CRUD.create(token, ref DM); if (token_CRUD.ErrorOccur) { response.ErrorThrown = true; response.ResponseDescription = "ERROR:" + token_CRUD.ErrorMessage; return(JsonConvert.SerializeObject(response)); } } Email NewMail = new Email(); MailMessage Message = new MailMessage(); try { Message.From = new MailAddress("*****@*****.**", "*****@*****.**"); Message.To.Add(new MailAddress(supplier.ContactEmail.ToString())); Message.Subject = "Request For Quote"; Message.IsBodyHtml = true; Message.BodyEncoding = System.Text.Encoding.UTF8; var url = ResolveUrl("~/Vendor/Email_RFQ_Request.htm"); var strEmailContent = HTMLContent(url); strEmailContent = strEmailContent.Replace("{BuyerName}", user.Name); strEmailContent = strEmailContent.Replace("{BuyerPhone}", user.Phone1); strEmailContent = strEmailContent.Replace("{BuyerEmail}", user.Email); strEmailContent = strEmailContent.Replace("{RFQ Number}", rfqToResend.RfqGenerated); strEmailContent = strEmailContent.Replace("{Part Number}", rfqToResend.PartNumber); strEmailContent = strEmailContent.Replace("{RFQLink}", "http://" + Request.Url.Authority + Request.ApplicationPath + "/Vendor/RFQHandler.ashx?token=" + token.TokenNumber); Message.Body = strEmailContent; NewMail.SendMail(Message); } catch (Exception ex) { DM.RollBack(); response.ErrorThrown = true; response.ResponseDescription = "ERROR: Could not send email to: " + supplier.ContactEmail.ToString(); return(JsonConvert.SerializeObject(response)); } DM.CommitTransaction(); DM.Close_Open_Connection(); if (DM.ErrorOccur) { response.ErrorThrown = true; response.ResponseDescription = "ERROR:" + DM.Error_Mjs; return(JsonConvert.SerializeObject(response)); } response.ErrorThrown = false; response.ResponseDescription = "RFQ " + rfqToResend.RfqGenerated + " re-sent successfully."; response.Result = rfqToResend; return(JsonConvert.SerializeObject(response)); }
public string GetReferencesHash() { return(MD5HashGenerator.GetMd5Hash(this)); }
public object Post(PostAvatar request) { var response = new CommonResponse(); if (Request.Files.Length == 0) { throw new HttpError(HttpStatusCode.BadRequest, "NoFile"); } var postedFile = Request.Files[0]; string fileName = postedFile.FileName; string baseAttachmentsPath = ConfigurationManager.AppSettings["Avatar"]; bool useAttachmentsRelativePath = false; string sUseAttachmentsRelativePath = ConfigurationManager.AppSettings["UseAttachmentsRelativePath"]; if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath)) { useAttachmentsRelativePath = bUseAttachmentsRelativePath; } string currentPathAttachments; string folderName = request.TargetFolder; if (!string.IsNullOrWhiteSpace(folderName)) { if (useAttachmentsRelativePath) { currentPathAttachments = "~/" + baseAttachmentsPath + folderName + @"/".MapHostAbsolutePath(); } else { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; } if (!Directory.Exists(currentPathAttachments)) { Directory.CreateDirectory(currentPathAttachments); } else { AttachmentsIO.ClearDirectory(currentPathAttachments); } } else { do { DateTime date = DateTime.Now; folderName = date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); if (useAttachmentsRelativePath) { currentPathAttachments = "~/" + baseAttachmentsPath + folderName.MapHostAbsolutePath(); } else { currentPathAttachments = baseAttachmentsPath + folderName; } } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); if (useAttachmentsRelativePath) { currentPathAttachments += @"/"; } else { currentPathAttachments += @"\"; } } if (postedFile.ContentLength > 0) { postedFile.SaveTo(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } var attachmentsResult = AttachmentsIO.getAvatarsFromFolder(folderName, "Avatar"); response.ErrorThrown = false; response.ResponseDescription = folderName; response.Result = attachmentsResult; return(response); }
public object Post(PostAttachment request) { var response = new CommonResponse(); string attachmentKind = request.AttachmentKind; if (attachmentKind == null || attachmentKind == "") { response.ErrorThrown = true; response.ResponseDescription = "Attachment Kind was not specified."; return(response); } if (Request.Files.Length == 0) { throw new HttpError(HttpStatusCode.BadRequest, "NoFile"); } var postedFile = Request.Files[0]; string fileName = postedFile.FileName; string baseAttachmentsPath = AppSettings.Get <string>(attachmentKind); bool useAttachmentsRelativePath = false; string sUseAttachmentsRelativePath = AppSettings.Get <string>("UseAttachmentsRelativePath"); if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath)) { useAttachmentsRelativePath = bUseAttachmentsRelativePath; } string currentPathAttachments; string folderName = request.TargetFolder; if (!string.IsNullOrWhiteSpace(folderName)) { if (useAttachmentsRelativePath) { currentPathAttachments = "~/" + baseAttachmentsPath + folderName + @"/".MapHostAbsolutePath(); } else { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; } if (!Directory.Exists(currentPathAttachments)) { Directory.CreateDirectory(currentPathAttachments); } } else { string folderPrefix = request.FolderPrefix; if (string.IsNullOrWhiteSpace(folderPrefix) || folderPrefix == "undefined" || folderPrefix == "null") { folderPrefix = ""; } do { DateTime date = DateTime.Now; folderName = folderPrefix + date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); if (useAttachmentsRelativePath) { currentPathAttachments = "~/" + baseAttachmentsPath + folderName.MapHostAbsolutePath(); } else { currentPathAttachments = baseAttachmentsPath + folderName; } } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); if (useAttachmentsRelativePath) { currentPathAttachments += @"/"; } else { currentPathAttachments += @"\"; } } if (postedFile.ContentLength > 0) { postedFile.SaveTo(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } var attachmentsResult = AttachmentsIO.getAttachmentsFromFolder(folderName, attachmentKind); response.ErrorThrown = false; response.ResponseDescription = folderName; response.Result = attachmentsResult; return(response); }
public object avatar() { CommonResponse response = new CommonResponse(); try { if (HttpContext.Current.Request.Files.AllKeys.Any()) { var postedFile = HttpContext.Current.Request.Files["file"]; if (postedFile != null) { string fileName = postedFile.FileName; string baseAttachmentsPath = ConfigurationManager.AppSettings["Avatar"]; string currentPathAttachments; string folderName = HttpContext.Current.Request["targetFolder"]; if (folderName != null && folderName.Trim() != "") { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; if (!Directory.Exists(currentPathAttachments)) { Directory.CreateDirectory(currentPathAttachments); } else { AttachmentsIO.ClearDirectory(currentPathAttachments); } } else { do { DateTime date = DateTime.Now; folderName = date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); currentPathAttachments = baseAttachmentsPath + folderName; } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); currentPathAttachments += @"\"; } if (postedFile.ContentLength > 0) { postedFile.SaveAs(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } List <Avatar> attachmentsResult = AttachmentsIO.getAvatarsFromFolder(folderName, "Avatar"); response.ErrorThrown = false; response.ResponseDescription = folderName; response.Result = attachmentsResult; } } } catch (Exception e) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: " + e.Message; response.Result = e; } return(response); }
protected void btnSendSurvey_Click(object sender, EventArgs e) { if (supplier.ContactEmail.Trim() != txtEmail.Text.Trim()) { SupplierCRUD supplierCRUD = new SupplierCRUD(); supplier.ContactEmail = txtEmail.Text.Trim(); if (!supplierCRUD.update(supplier)) { Navigator.goToPage("~/Error.aspx", "ERROR:" + supplierCRUD.ErrorMessage); return; } } SupplierSurveyCRUD surveyCRUD = new SupplierSurveyCRUD(); SupplierSurvey survey = new SupplierSurvey(); survey.SupplierMasterKey = supplier.Id; survey.SentToVendor = DateTime.Now; supplier.SupplierSurvey = survey; ConnectionManager CM = new ConnectionManager(); Data_Base_MNG.SQL DM = CM.getDataManager(); /*Begin Transaction*/ DM.Open_Connection("Survey Save"); string idGenerated = surveyCRUD.createAndReturnIdGenerated(survey, ref DM); if (!surveyCRUD.ErrorOccur) { TokenCRUD token_CRUD = new TokenCRUD(); Token token = new Token(); token.Subject = "SURVEY"; token.SubjectKey = long.Parse(idGenerated); token.TokenNumber = MD5HashGenerator.GenerateKey(DateTime.Now); if (token_CRUD.create(token, ref DM)) { Email NewMail = new Email(); MailMessage Message = new MailMessage(); Message.From = new MailAddress("*****@*****.**", "*****@*****.**"); Message.To.Add(new MailAddress(supplier.ContactEmail.ToString())); Message.Subject = "Survey"; Message.IsBodyHtml = true; Message.BodyEncoding = System.Text.Encoding.UTF8; //Message.Body = "Aqui va el link con el token= " + " <a href:\"http://localhost:29724/APQM/Vendor/RFQ.aspx?token=" + token.TokenNumber + "\">Link</a>"; //Message.Body = "Aqui va el link con el token= " + " <a href:\"http://www.google.com\">Google</a>"; string strEmailContent = "Dear Potential Supplier," + Environment.NewLine + "Please click the following link to fill out our supplier survey form. Please fill out as completely as possible. Once we have received your completed survey, a representative will contact you to discuss the next steps." + Environment.NewLine + Environment.NewLine + "http://" + Request.Url.Authority + Request.ApplicationPath + "/Vendor/Survey.aspx?token=" + token.TokenNumber + Environment.NewLine + Environment.NewLine + "Thank you for your time. We look forward to hearing from you." + Environment.NewLine + Environment.NewLine + "Sincerely," + Environment.NewLine + Environment.NewLine + "The Capsonic Advanced Purchasing Team"; AlternateView htmlView = AlternateView.CreateAlternateViewFromString(strEmailContent); Message.AlternateViews.Add(htmlView); try { NewMail.SendMail(Message); } catch { DM.RollBack(); Navigator.goToPage("~/Error.aspx", "ERROR:Could not send email to: " + supplier.ContactEmail.ToString()); return; } } else { Navigator.goToPage("~/Error.aspx", "ERROR:" + token_CRUD.ErrorMessage); return; } } else { Navigator.goToPage("~/Error.aspx", "ERROR:" + surveyCRUD.ErrorMessage); return; } DM.CommitTransaction(); DM.Close_Open_Connection(); if (DM.ErrorOccur) { Navigator.goToPage("~/Error.aspx", "ERROR:" + DM.Error_Mjs); return; } supplier = null; Ok_Click(this, e); }
public object Post(PostAttachment request) { var AttachmentKind = request.AttachmentKind; if (!IsValidJSValue(AttachmentKind)) { throw new KnownError("Invalid [Attachment Kind]."); } if (Request.Files.Length == 0) { throw new HttpError(HttpStatusCode.BadRequest, "NoFile"); } var postedFile = Request.Files[0]; string FileName = postedFile.FileName; string baseAttachmentsPath = AppSettings.Get <string>(AttachmentKind); if (string.IsNullOrWhiteSpace(baseAttachmentsPath)) { throw new KnownError("Invalid Attachment Kind."); } bool useAttachmentsRelativePath = false; string sUseAttachmentsRelativePath = AppSettings.Get <string>("UseAttachmentsRelativePath"); if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath)) { useAttachmentsRelativePath = bUseAttachmentsRelativePath; } string currentPathAttachments; string folderName = request.TargetFolder; if (IsValidJSValue(folderName)) { if (useAttachmentsRelativePath) { currentPathAttachments = "~/" + baseAttachmentsPath + folderName + @"/".MapHostAbsolutePath(); } else { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; } if (!Directory.Exists(currentPathAttachments)) { Directory.CreateDirectory(currentPathAttachments); } } else { string folderPrefix = request.FolderPrefix; if (!IsValidJSValue(folderPrefix)) { folderPrefix = ""; } do { DateTime date = DateTime.Now; folderName = folderPrefix + date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); if (useAttachmentsRelativePath) { currentPathAttachments = "~/" + baseAttachmentsPath + folderName.MapHostAbsolutePath(); } else { currentPathAttachments = baseAttachmentsPath + folderName; } } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); if (useAttachmentsRelativePath) { currentPathAttachments += @"/"; } else { currentPathAttachments += @"\"; } } if (postedFile.ContentLength > 0) { Log.Info($"Attachment Posted: [{currentPathAttachments + Path.GetFileName(postedFile.FileName)}] by User: [{GetSession().UserName}]"); postedFile.SaveTo(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } return(new // FileId { FileName, AttachmentKind, Directory = folderName }); }