public virtual ExportProfile InsertExportProfile( string providerSystemName, string name, string fileExtension, ExportFeatures features, bool isSystemProfile = false, string profileSystemName = null, int cloneFromProfileId = 0) { Guard.ArgumentNotEmpty(() => providerSystemName); var profileCount = _exportProfileRepository.Table.Count(x => x.ProviderSystemName == providerSystemName); if (name.IsEmpty()) { name = providerSystemName; } if (!isSystemProfile) { name = string.Concat(_localizationService.GetResource("Common.My"), " ", name); } name = string.Concat(name, " ", profileCount + 1); var cloneProfile = GetExportProfileById(cloneFromProfileId); ScheduleTask task = null; ExportProfile profile = null; if (cloneProfile == null) { task = new ScheduleTask { CronExpression = "0 */6 * * *", // every six hours Type = typeof(DataExportTask).AssemblyQualifiedNameWithoutVersion(), Enabled = false, StopOnError = false, IsHidden = true }; } else { task = cloneProfile.ScheduleTask.Clone(); task.LastEndUtc = task.LastStartUtc = task.LastSuccessUtc = null; } task.Name = string.Concat(name, " Task"); _scheduleTaskService.InsertTask(task); if (cloneProfile == null) { profile = new ExportProfile { FileNamePattern = _defaultFileNamePattern }; if (isSystemProfile) { profile.Enabled = true; profile.PerStore = false; profile.CreateZipArchive = false; profile.Cleanup = false; } else { // what we do here is to preset typical settings for feed creation // but on the other hand they may be untypical for generic data export\exchange var projection = new ExportProjection { RemoveCriticalCharacters = true, CriticalCharacters = "¼,½,¾", PriceType = PriceDisplayType.PreSelectedPrice, NoGroupedProducts = (features.HasFlag(ExportFeatures.CanOmitGroupedProducts) ? true : false), DescriptionMerging = ExportDescriptionMerging.Description }; var filter = new ExportFilter { IsPublished = true }; profile.Projection = XmlHelper.Serialize <ExportProjection>(projection); profile.Filtering = XmlHelper.Serialize <ExportFilter>(filter); } } else { profile = cloneProfile.Clone(); } profile.IsSystemProfile = isSystemProfile; profile.Name = name; profile.ProviderSystemName = providerSystemName; profile.SchedulingTaskId = task.Id; var cleanedSystemName = providerSystemName .Replace("Exports.", "") .Replace("Feeds.", "") .Replace("/", "") .Replace("-", ""); var folderName = SeoHelper.GetSeName(cleanedSystemName, true, false) .ToValidPath() .Truncate(_dataExchangeSettings.MaxFileNameLength); profile.FolderName = "~/App_Data/ExportProfiles/" + FileSystemHelper.CreateNonExistingDirectoryName(CommonHelper.MapPath("~/App_Data/ExportProfiles"), folderName); if (profileSystemName.IsEmpty() && isSystemProfile) { profile.SystemName = cleanedSystemName; } else { profile.SystemName = profileSystemName; } _exportProfileRepository.Insert(profile); task.Alias = profile.Id.ToString(); _scheduleTaskService.UpdateTask(task); if (fileExtension.HasValue() && !isSystemProfile) { if (cloneProfile == null) { if (features.HasFlag(ExportFeatures.CreatesInitialPublicDeployment)) { var subFolder = FileSystemHelper.CreateNonExistingDirectoryName(CommonHelper.MapPath("~/" + DataExporter.PublicFolder), folderName); profile.Deployments.Add(new ExportDeployment { ProfileId = profile.Id, Enabled = true, DeploymentType = ExportDeploymentType.PublicFolder, Name = profile.Name, SubFolder = subFolder }); UpdateExportProfile(profile); } } else { foreach (var deployment in cloneProfile.Deployments) { profile.Deployments.Add(deployment.Clone()); } UpdateExportProfile(profile); } } _eventPublisher.EntityInserted(profile); return(profile); }
public virtual ImportProfile InsertImportProfile(string fileName, string name, ImportEntityType entityType) { Guard.ArgumentNotEmpty(() => fileName); if (name.IsEmpty()) { name = GetNewProfileName(entityType); } var task = new ScheduleTask { CronExpression = "0 */24 * * *", Type = typeof(DataImportTask).AssemblyQualifiedNameWithoutVersion(), Enabled = false, StopOnError = false, IsHidden = true }; task.Name = string.Concat(name, " Task"); _scheduleTaskService.InsertTask(task); var profile = new ImportProfile { Name = name, EntityType = entityType, Enabled = true, SchedulingTaskId = task.Id }; if (Path.GetExtension(fileName).IsCaseInsensitiveEqual(".xlsx")) { profile.FileType = ImportFileType.XLSX; } else { profile.FileType = ImportFileType.CSV; } string[] keyFieldNames = null; switch (entityType) { case ImportEntityType.Product: keyFieldNames = ProductImporter.DefaultKeyFields; break; case ImportEntityType.Category: keyFieldNames = CategoryImporter.DefaultKeyFields; break; case ImportEntityType.Customer: keyFieldNames = CustomerImporter.DefaultKeyFields; break; case ImportEntityType.NewsLetterSubscription: keyFieldNames = NewsLetterSubscriptionImporter.DefaultKeyFields; break; } profile.KeyFieldNames = string.Join(",", keyFieldNames); profile.FolderName = SeoHelper.GetSeName(name, true, false) .ToValidPath() .Truncate(_dataExchangeSettings.MaxFileNameLength); profile.FolderName = FileSystemHelper.CreateNonExistingDirectoryName(CommonHelper.MapPath("~/App_Data/ImportProfiles"), profile.FolderName); _importProfileRepository.Insert(profile); task.Alias = profile.Id.ToString(); _scheduleTaskService.UpdateTask(task); _eventPublisher.EntityInserted(profile); return(profile); }