public ActionResult DeleteFromList(string list, string email) { try { switch (list) { case "test": string filePath = Path.Combine(UploadPath, (string)Session["TestSeedList"]); new CreativeHelper().Remove(filePath, email); S3FileManager.Upload((string)Session["TestSeedURL"], filePath, true); break; case "live": string filePathLive = Path.Combine(UploadPath, (string)Session["FinalSeedList"]); new CreativeHelper().Remove(filePathLive, email); S3FileManager.Upload((string)Session["LiveSeedURL"], filePathLive, true); break; } return(Json(new JsonResponse() { IsSucess = true })); } catch (Exception ex) { return(Json(new JsonResponse() { IsSucess = false, ErrorMessage = ex.Message })); } }
public static HtmlProcessResult ProcessHtmlZip(string uploadPath, string zipFilePath, string orderNumber, bool isAddOptout, bool isAddViewinBrowser) { _orderNumber = orderNumber; _isAddOptout = isAddOptout; _isAddViewinBrowser = isAddViewinBrowser; // Unzip var directory = $"{uploadPath}\\{orderNumber}"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } ZipFile.ExtractToDirectory(zipFilePath, directory); // Change html var imagesLive = string.Format("{0}/{0}img", orderNumber); string htmlFileName = $"{orderNumber}.htm"; string htmlFileKey = string.Format("{0}/{0}.htm", orderNumber); string htmlFilePath = $"{directory}\\{htmlFileName}"; string htmlFile = Directory.EnumerateFiles(directory).FirstOrDefault(x => x.EndsWith("htm") || x.EndsWith("html")); if (string.IsNullOrEmpty(htmlFile)) { throw new AdsException("Html not found"); } UploadFileStatus status = ProcessHtml(htmlFile, htmlFilePath); // Create 2501 directory S3FileManager.CreateDirectory(orderNumber); // Upload html S3FileManager.Upload(htmlFileKey, htmlFilePath, true); string filePathLive = $"{S3FileManager.ServerPrefix}{htmlFileKey}"; // Create images directory S3FileManager.CreateDirectory(imagesLive); // Upload Images var images = Directory.EnumerateDirectories(directory).FirstOrDefault(); if (images != null) { foreach (var imgFile in Directory.EnumerateFiles(images)) { var imageLive = $"{imagesLive}/{new FileInfo(imgFile).Name}"; S3FileManager.Upload(imageLive, imgFile, true); } } // Delete tmp new DirectoryInfo(directory).Delete(true); return(new HtmlProcessResult() { Status = status, FilePathLive = filePathLive }); }
private static void WriteAndUploadSegmentDataFile(List <SegmentResponse> data, WfpictContext db, CampaignSegment segment, string uploadPath, string orderNumber, Guid campaignId) { string fileName1 = $"{orderNumber}\\{segment.SegmentNumber}data.csv"; var filePath1 = $"{uploadPath}\\{fileName1}"; var data1 = data.Where(x => x.Index >= segment.FirstRangeStart && x.Index <= segment.FirstRangeEnd).ToList(); var data2 = data.Where(x => x.Index >= segment.SecondRangeStart && x.Index <= segment.SecondRangeEnd) .ToList(); var data3 = data.Where(x => x.Index >= segment.ThirdRangeStart && x.Index <= segment.ThirdRangeEnd).ToList(); data2.AddRange(data3); data1.AddRange(data2); data1 = data1.OrderBy(x => x.Index).ToList(); data1.ToCsv(filePath1, new CsvDefinition() { EndOfLine = "\r\n", FieldSeparator = ',', TextQualifier = '"', Columns = new List <string> { "SalesMasterId", "FirstName", "LastName", "Address", "City", "State", "Zip", "Zip4", "Apt", "Dealership_ID", "Index", } }); string amazonFileKey1 = $"{orderNumber}/{segment.SegmentNumber}data.csv"; S3FileManager.Upload(amazonFileKey1, filePath1, true); segment.SegmentDataFileUrl = FileManager.GetFilePathLive(UploadFileType.DataFile, orderNumber, string.Empty, segment.SegmentNumber); segment.DateFetched = DateTime.Now; segment.UploadStatus = (int)UploadFileStatus.Completed; segment.SegmentStatus = (int)SegmentStatus.Generated; LogHelper.AddLog(db, LogType.DataProcessing, orderNumber, fileName1 + " data file generated and uploaded to Amazon sucessfully."); }
private static void WriteAndUploadDataFile(List <SegmentResponse> data, WfpictContext db, string uploadPath, string orderNumber, Guid campaignId) { string fileName = $"{orderNumber}\\{orderNumber}data.csv"; var filePath = $"{uploadPath}\\{fileName}"; data.Sort((x, y) => x.Index.CompareTo(y.Index)); data.ToCsv(filePath, new CsvDefinition() { EndOfLine = "\r\n", FieldSeparator = ',', TextQualifier = '"', Columns = new List <string> { "SalesMasterId", "FirstName", "LastName", "Address", "City", "State", "Zip", "Zip4", "Apt", "Dealership_ID", "Index", } }); string amazonFileKey = $"{orderNumber}/{orderNumber}data.csv"; S3FileManager.Upload(amazonFileKey, filePath, true); LogHelper.AddLog(db, LogType.DataProcessing, orderNumber, $"{fileName} data file generated and uploaded to Amazon sucessfully."); var campaignTesting = db.CampaignsTesting.FirstOrDefault(x => x.CampaignId == campaignId); if (campaignTesting != null) { campaignTesting.DataFileUrl = amazonFileKey; campaignTesting.DateFetched = DateTime.Now; } db.SaveChanges(); }
private static void WriteAndUploadDataFileOpener(List <SegmentResponse> data, WfpictContext db, string uploadPath, string orderNumber, Guid campaignId) { string fileName = $"{orderNumber}\\{orderNumber}opener.csv"; var filePath = $"{uploadPath}\\{fileName}"; data.ToCsv(filePath, new CsvDefinition() { EndOfLine = "\r\n", FieldSeparator = ',', TextQualifier = '"', Columns = new List <string> { "SalesMasterId", "FirstName", "LastName", "Address", "City", "State", "Zip", "Zip4", "Apt" } }); string amazonFileKey = $"{orderNumber}/{orderNumber}opener.csv"; S3FileManager.Upload(amazonFileKey, filePath, true); var campaignTesting = db.CampaignsTesting.FirstOrDefault(x => x.CampaignId == campaignId); if (campaignTesting != null) { campaignTesting.DataFileUrlOpener = FileManager.GetFilePathLive(UploadFileType.DataFileOpener, orderNumber, string.Empty, string.Empty); } db.SaveChanges(); LogHelper.AddLog(db, LogType.DataProcessing, orderNumber, fileName + " data file opener generated and uploaded to Amazon sucessfully."); }
public JsonResult UploadFile(UploadFileVm fileVm) { string amazonFileKey = "", filePath = ""; try { if (Request.Files.Count == 0) { throw new AdsException("File is not uploaded."); } var fileContent = Request.Files[0]; if (fileContent != null && fileContent.ContentLength > 0) { var stream = fileContent.InputStream; filePath = Path.Combine(UploadPath, fileContent.FileName); if (!string.IsNullOrEmpty(fileVm.OrderNumber)) { filePath = Path.Combine(UploadPath, fileVm.OrderNumber, fileContent.FileName); } if (!System.IO.Directory.Exists(Path.Combine(UploadPath, fileVm.OrderNumber))) { Directory.CreateDirectory(Path.Combine(UploadPath, fileVm.OrderNumber)); } using (var fileStream = System.IO.File.Create(filePath)) { stream.CopyTo(fileStream); } // File Validations if (!fileVm.IsValid(filePath)) { throw new AdsException(fileVm.FileType + " is not valid. Please upload valid file."); } if (fileVm.FileType == "CompanyLogo") { string logoFileName = FileHelper.GetValidFileName(LoggedInUser?.Id + Path.GetExtension(fileContent.FileName)); string logoFilePath = Path.Combine(ImagesPath, logoFileName); System.IO.File.Copy(filePath, logoFilePath, true); amazonFileKey = logoFileName; } else if (string.IsNullOrEmpty(fileVm.OrderNumber) && IsUseS3) { amazonFileKey = $"{DateTime.Now:yyyyMMddHHmmss}_{fileContent.FileName}"; S3FileManager.Upload(amazonFileKey, filePath); } else if (!string.IsNullOrEmpty(fileVm.SegmentNumber) && IsUseS3) // Data files Upload only // HtmlImageFiles2500A, HtmlImageFiles2500B { amazonFileKey = $"{fileVm.OrderNumber}/{fileVm.SegmentNumber}_html.zip"; S3FileManager.Upload(amazonFileKey, filePath, true, true); } else { switch (fileVm.FileType) { case "EzLinksFile": amazonFileKey = string.Format("{0}/ez_links.csv", fileVm.OrderNumber); break; case "OpenModelLinksFile": amazonFileKey = string.Format("{0}/openmodel_links.csv", fileVm.OrderNumber); break; case "OpenModelImageFile": amazonFileKey = string.Format("{0}/openmodel_image{1}", fileVm.OrderNumber, Path.GetExtension(filePath)); break; case "DynamicCodingFile": amazonFileKey = string.Format("{0}/dynamic_coding.csv", fileVm.OrderNumber); break; case "Assets_CreativeFiles": amazonFileKey = string.Format("{0}/{0}_html.zip", fileVm.OrderNumber); break; case "Assets_ZipCodeFile": amazonFileKey = string.Format("{0}/{0}zip.csv", fileVm.OrderNumber); break; case "Assets_TestSeedFile": amazonFileKey = string.Format("{0}/{0}test.csv", fileVm.OrderNumber); break; case "Assets_LiveSeedFile": amazonFileKey = string.Format("{0}/{0}live.csv", fileVm.OrderNumber); break; case "Assets_BannersFile": amazonFileKey = string.Format("{0}/{0}_banner{1}", fileVm.OrderNumber, Path.GetExtension(filePath)); break; case "Assets_BannerLinksFile": amazonFileKey = string.Format("{0}/{0}_bannerlinks{1}", fileVm.OrderNumber, Path.GetExtension(filePath)); break; case "Assets_MiscFile": amazonFileKey = string.Format("{0}/{0}_misc{1}", fileVm.OrderNumber, Path.GetExtension(filePath)); break; } if (IsUseS3) { S3FileManager.Upload(amazonFileKey, filePath, true, true); } else { amazonFileKey = string.Format("{0}\\{1}", fileVm.OrderNumber, fileContent.FileName); } } } return(Json(new JsonResponse() { IsSucess = true, Result = amazonFileKey })); } catch (Exception ex) { return(Json(new JsonResponse() { IsSucess = false, ErrorMessage = "Upload failed " + ex.Message })); } finally { // Delete local if (IsUseS3 && System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } }