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); } }
/// <summary> /// Creates and configures hotcakes store from config file. /// </summary> /// <exception cref="CreateStoreException">Could not create store</exception> private void InstallApplication() { var intallFolderPath = "~/DesktopModules/Hotcakes/Core/Install/"; var configPath = HttpContext.Current.Server.MapPath(intallFolderPath + "Hotcakes.install.config"); if (File.Exists(configPath)) { // hardcoded for now since we create only one store now var portalId = 0; var portalSettings = new PortalSettings(portalId); DnnGlobal.SetPortalSettings(portalSettings); var productsFile = HttpContext.Current.Server.MapPath(intallFolderPath + "Products.xlsx"); var hccApp = HotcakesApplication.Current; var store = hccApp.AccountServices.CreateAndSetupStore(); if (store == null) { throw new CreateStoreException("Could not create store"); } var config = GetStoreConfig(configPath); store.StoreName = config.StoreName; foreach (var settingConfig in config.Settings) { store.Settings.AddOrUpdateLocalSetting(new StoreSetting { SettingName = settingConfig.Name, SettingValue = settingConfig.Value }); } hccApp.CurrentStore = store; hccApp.UpdateCurrentStore(); hccApp.AccountServices.Stores.SetLastOrderNumber(store.Id, config.LastOrderNumber); var systemColumnsFilePath = "~/DesktopModules/Hotcakes/Core/Admin/Parts/ContentBlocks/SystemColumnsData.xml"; hccApp.ContentServices.Columns.CreateFromTemplateFile(systemColumnsFilePath); hccApp.OrderServices.EnsureDefaultZones(store.Id); var urlSettings = hccApp.CurrentStore.Settings.Urls; PageUtils.EnsureTabsExist(urlSettings); hccApp.UpdateCurrentStore(); var catImport = new CatalogImport(hccApp) { ImagesImportPath = intallFolderPath + "Images/" }; catImport.ImportFromExcel(productsFile, (p, l) => { }); Directory.Delete(HttpContext.Current.Server.MapPath(intallFolderPath), true); DnnGlobal.SetPortalSettings(null); } }
protected void DoImport(object objConfiguration) { var conf = objConfiguration as ImportConfiguration; HccRequestContext.Current = conf.HccRequestContext; DnnGlobal.SetPortalSettings(conf.DnnPortalSettings); Factory.HttpContext = conf.HttpContext; CultureSwitch.SetCulture(HccApp.CurrentStore, conf.DnnPortalSettings); var manager = new SessionManager(conf.Session); manager.AdminProductImportLog = null; manager.AdminProductImportProgress = 0; var catImport = new CatalogImport(HccApp); catImport.UpdateExistingProducts = chkImportOverride.Checked; // added import path so version 2.xx knows where import images are stored catImport.ImagesImportPath = string.Format("~/Portals/{0}/Hotcakes/Data/import/", conf.DnnPortalSettings.PortalId); catImport.ImportFromExcel(TempFilePath, (p, l) => { lock (manager.AdminProductImportLog) { manager.AdminProductImportProgress = Math.Round(p * 100); if (!string.IsNullOrEmpty(l)) { var log = manager.AdminProductImportLog; log.Add(l); manager.AdminProductImportLog = log; } } }); }