protected void DoExport(object objConfiguration) { try { var conf = objConfiguration as ExportConfiguration; HccRequestContext.Current = conf.HccRequestContext; DnnGlobal.SetPortalSettings(conf.DnnPortalSettings); Factory.HttpContext = conf.HttpContext; CultureSwitch.SetCulture(HccApp.CurrentStore, conf.DnnPortalSettings); var products = HccApp.CatalogServices.Products.FindByCriteria(conf.Criteria, 1, int.MaxValue, ref RowCount, false); var export = new CatalogExport(HccApp); var fileName = string.Format("Hotcakes_Products_{0}_{1:yyyyMMddhhMMss}.xlsx", HccApp.CurrentCustomerId, DateTime.UtcNow); var filePath = DiskStorage.GetStoreDataPhysicalPath(HccApp.CurrentStore.Id, "Exports/" + fileName); export.ExportToExcel(products, filePath); var pageLink = DiskStorage.GetHccAdminUrl(HccApp, "catalog/default.aspx", false); var mailMessage = new MailMessage(conf.DnnPortalSettings.Email, HccApp.CurrentCustomer.Email); mailMessage.IsBodyHtml = true; mailMessage.Body = Localization.GetFormattedString("ExportProductsMailBody", pageLink); mailMessage.Subject = Localization.GetString("ExportProductsMailSubject"); MailServices.SendMail(mailMessage, HccApp.CurrentStore); } catch (Exception ex) { EventLog.LogEvent(ex); } }
// // GET: /AdminContent/FileManager/ public ActionResult Index() { var path = Request.QueryString["path"] ?? string.Empty; var cleanPath = DiskStorage.FileManagerCleanPath(path); var model = new FileManagerViewModel(cleanPath) { Directories = DiskStorage.FileManagerListDirectories(HccApp.CurrentStore.Id, cleanPath), Files = DiskStorage.FileManagerListFiles(HccApp.CurrentStore.Id, cleanPath), BreadCrumbs = BuildBreadCrumbs(cleanPath), BasePreviewUrl = DiskStorage.GetStoreDataPhysicalPath(HccApp.CurrentStore.Id) }; return(View(model)); }
private void LoadExistingExports() { var folderPath = DiskStorage.GetStoreDataPhysicalPath(HccApp.CurrentStore.Id, "Exports"); var fileNamePattern = string.Format("Hotcakes_Products_{0}_*.xlsx", HccApp.CurrentCustomerId); var files = PathHelper.ListFiles(folderPath, new[] { fileNamePattern }, new string[] {}); var exportsExists = files.Count > 0; pnlExports.Visible = exportsExists; var fileInfos = files.Select(f => new FileInfo(f)).ToList(); rptExportedFiles.DataSource = fileInfos; rptExportedFiles.DataBind(); }
protected override object HandleAction(HttpContext context, HotcakesApplication hccApp) { var optUniqueId = context.Request.Params["optUniqueId"]; var productChoice = hccApp.CatalogServices.ProductOptions.Find(optUniqueId); if (productChoice == null || productChoice.OptionType != OptionTypes.FileUpload) { // not found context.Response.StatusCode = 404; context.Response.End(); return(null); } if (context.Request.Files.Count <= 0) { return(null); } try { var file = context.Request.Files[0]; var fileName = context.Request.Params["filename"]; var prePath = GetInitialPathOfUploadFolder(hccApp); var orderProductPath = string.Concat(prePath, "\\", optUniqueId); var subPath = string.Format(UPLOAD_PATH_FORMAT, orderProductPath, Path.GetFileName(Text.CleanFileName(fileName))); var fullFilePath = DiskStorage.GetStoreDataPhysicalPath(hccApp.CurrentStore.Id, subPath); //check if path directory exists var dirPath = Path.GetDirectoryName(fullFilePath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } var downloadPath = VirtualPathUtility.ToAbsolute(DiskStorage.GetStoreDataVirtualPath(hccApp.CurrentStore.Id, subPath)); var extension = Path.GetExtension(fullFilePath); // // TODO: Update this DNN API call to check the User File list instead, after upgrading the minimum version to DNN 9.5/9.6 // if (Host.AllowedExtensionWhitelist.IsAllowedExtension(extension) == false) { return(new UploadResponse { StatusCode = 413, Message = "Invalid File Extension" }); } //Check if file is sent in chunks and chunk is present in request var totalChunks = context.Request["chunks"] ?? string.Empty; var chunks = -1; if (!int.TryParse(totalChunks, out chunks)) { chunks = -1; } var chunkNo = context.Request["chunk"] ?? string.Empty; var chunk = -1; if (!int.TryParse(chunkNo, out chunk)) { chunk = -1; } //If there are no chunks sent then the file is sent as one //Indicates Plain HTML4 Upload & 1 single file if (chunks == -1) { if (MaxUploadSize == 0 || context.Request.ContentLength <= MaxUploadSize) { if (OnUploadChunk(file.InputStream, 0, 1, fullFilePath) == false) { return(new UploadResponse { StatusCode = 500, Message = "Unable to write file" }); } } else { return(new UploadResponse { StatusCode = 413, Message = "Uploaded file is too large" }); } //Return the final virtual path of uploaded file return(new UploadResponse { StatusCode = 200, Message = downloadPath }); } //File is sent in chunk, so full size of file & chunk is unknown if (chunk == 0 && MaxUploadSize > 0 && context.Request.ContentLength * (chunks - 1) > MaxUploadSize) { return(new UploadResponse { StatusCode = 413, Message = "Uploaded file is too large" }); } //First Chunk if (chunk == 0) { // TODO: Delete old file on re-uploading of same file again with 0th chunk if (File.Exists(fullFilePath)) { File.SetAttributes(fullFilePath, FileAttributes.Normal); File.Delete(fullFilePath); } } //n'th chunk if (OnUploadChunk(file.InputStream, chunk, chunks, fullFilePath) == false) { return(new UploadResponse { StatusCode = 500, Message = "Unable to write file" }); } //last chunk if (chunk == chunks - 1) { //return the file's virtual download path return(new UploadResponse { StatusCode = 200, Message = downloadPath }); } //If no response is sent yet send the success response return(new UploadResponse { StatusCode = 200, Message = downloadPath }); } catch (Exception ex) { EventLog.LogEvent(ex); return(new UploadResponse { StatusCode = 500, Message = "Unable to write file" }); } }
/// <summary> /// This method will iterate through the specified swatches and emit the requisite HTML for each /// </summary> /// <param name="p">Product - an instance of the product to find swatches for</param> /// <param name="app">HotcakesApplicateion - an instance of the current store application object</param> /// <returns>String - the HTML to be used for rendering the swatches</returns> /// <remarks> /// If the swatch doesn't match an available swatch file, it will not be included in the HTML. Also, all swatch /// images must be PNG or GIF. /// </remarks> public static string GenerateSwatchHtmlForProduct(Product p, HotcakesApplication app) { var result = string.Empty; if (app.CurrentStore.Settings.ProductEnableSwatches == false) { return(result); } if (p.Options.Count > 0) { var found = false; var swatchBase = DiskStorage.GetStoreDataUrl(app, app.IsCurrentRequestSecure()); swatchBase += "swatches"; if (p.SwatchPath.Length > 0) { swatchBase += "/" + p.SwatchPath; } var swatchPhysicalBase = DiskStorage.GetStoreDataPhysicalPath(app.CurrentStore.Id); swatchPhysicalBase += "swatches\\"; if (p.SwatchPath.Length > 0) { swatchPhysicalBase += p.SwatchPath + "\\"; } var sb = new StringBuilder(); sb.Append("<div class=\"productswatches\">"); foreach (var opt in p.Options) { if (opt.IsColorSwatch) { found = true; foreach (var oi in opt.Items) { if (oi.IsLabel) { continue; } var prefix = CleanSwatchName(oi.Name); if (File.Exists(swatchPhysicalBase + prefix + ".png")) { sb.Append("<img width=\"18\" height=\"18\" src=\"" + swatchBase + "/" + prefix + ".png\" border=\"0\" alt=\"" + prefix + "\" />"); } else { sb.Append("<img width=\"18\" height=\"18\" src=\"" + swatchBase + "/" + prefix + ".gif\" border=\"0\" alt=\"" + prefix + "\" />"); } } } } sb.Append("</div>"); if (found) { result = sb.ToString(); } } return(result); }