public override void PostInitialize() { base.PostInitialize(); var registrar = _container.Resolve <IKnownExportTypesRegistrar>(); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportableCustomerReview, CustomerReviewExportDataQuery>() .WithDataSourceFactory(_container.Resolve <ICustomerReviewsExportPagedDataSourceFactory>()) .WithPermissionAuthorization(Core.ModuleConstants.Security.Permissions.Export, CustomerReviews.Core.ModuleConstants.Security.Permissions.CustomerReviewRead) .WithMetadata(typeof(ExportableCustomerReview).GetPropertyNames()) .WithTabularMetadata(typeof(TabularCustomerReview).GetPropertyNames())); }
public static ExportedTypeDefinitionBuilder WithGroup(this ExportedTypeDefinitionBuilder builder, string group) { builder.ExportedTypeDefinition.Group = group; return(builder); }
public static ExportedTypeDefinitionBuilder WithTypeName(this ExportedTypeDefinitionBuilder builder, string typeName) { builder.ExportedTypeDefinition.TypeName = typeName; return(builder); }
public static ExportedTypeDefinitionBuilder WithTabularMetadata(this ExportedTypeDefinitionBuilder builder, ExportedTypeMetadata tabularMetadata) { builder.ExportedTypeDefinition.TabularMetaData = tabularMetadata; return(builder); }
public static ExportedTypeDefinitionBuilder WithMetadata(this ExportedTypeDefinitionBuilder builder, ExportedTypeMetadata metadata) { builder.ExportedTypeDefinition.MetaData = metadata; return(builder); }
public void PostInitialize(IApplicationBuilder appBuilder) { _appBuilder = appBuilder; var settingsRegistrar = appBuilder.ApplicationServices.GetRequiredService <ISettingsRegistrar>(); settingsRegistrar.RegisterSettings(ModuleConstants.Settings.AllSettings, ModuleInfo.Id); //Register module permissions var permissionsProvider = appBuilder.ApplicationServices.GetRequiredService <IPermissionsRegistrar>(); permissionsProvider.RegisterPermissions(ModuleConstants.Security.Permissions.AllPermissions.Select(x => new Permission() { GroupName = "Catalog", Name = x }).ToArray()); //Register Permission scopes AbstractTypeFactory <PermissionScope> .RegisterType <SelectedCatalogScope>(); permissionsProvider.WithAvailabeScopesForPermissions(new[] { ModuleConstants.Security.Permissions.Read, ModuleConstants.Security.Permissions.Update, ModuleConstants.Security.Permissions.Delete, }, new SelectedCatalogScope()); var mvcJsonOptions = appBuilder.ApplicationServices.GetService <IOptions <MvcNewtonsoftJsonOptions> >(); mvcJsonOptions.Value.SerializerSettings.Converters.Add(new SearchCriteriaJsonConverter()); var inProcessBus = appBuilder.ApplicationServices.GetService <IHandlerRegistrar>(); inProcessBus.RegisterHandler <ProductChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <LogChangesChangedEventHandler>().Handle(message)); inProcessBus.RegisterHandler <CategoryChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <LogChangesChangedEventHandler>().Handle(message)); inProcessBus.RegisterHandler <CategoryChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <IndexCategoryChangedEventHandler>().Handle(message)); inProcessBus.RegisterHandler <ProductChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <IndexProductChangedEventHandler>().Handle(message)); //Force migrations using (var serviceScope = appBuilder.ApplicationServices.CreateScope()) { var catalogDbContext = serviceScope.ServiceProvider.GetRequiredService <CatalogDbContext>(); catalogDbContext.Database.MigrateIfNotApplied(MigrationName.GetUpdateV2MigrationName(ModuleInfo.Id)); catalogDbContext.Database.EnsureCreated(); catalogDbContext.Database.Migrate(); } var searchRequestBuilderRegistrar = appBuilder.ApplicationServices.GetService <ISearchRequestBuilderRegistrar>(); searchRequestBuilderRegistrar.Register(KnownDocumentTypes.Product, appBuilder.ApplicationServices.GetService <ProductSearchRequestBuilder>); searchRequestBuilderRegistrar.Register(KnownDocumentTypes.Category, appBuilder.ApplicationServices.GetService <CategorySearchRequestBuilder>); // Ensure that required dynamic properties are always registered in the system var dynamicPropertyService = appBuilder.ApplicationServices.GetRequiredService <IDynamicPropertyService>(); dynamicPropertyService.SaveDynamicPropertiesAsync(new[] { new DynamicProperty { Id = BrowseFilterService.FilteredBrowsingPropertyId, Name = BrowseFilterService.FilteredBrowsingPropertyName, ObjectType = typeof(Store).FullName, ValueType = DynamicPropertyValueType.LongText, CreatedBy = "Auto" } }).GetAwaiter().GetResult(); #region Register types for generic Export var registrar = appBuilder.ApplicationServices.GetService <IKnownExportTypesRegistrar>(); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportableProduct, ProductExportDataQuery>() .WithDataSourceFactory(appBuilder.ApplicationServices.GetService <ICatalogExportPagedDataSourceFactory>()) .WithMetadata(typeof(ExportableProduct).GetPropertyNames( nameof(ExportableProduct.Properties), $"{nameof(ExportableProduct.Properties)}.{nameof(Property.Values)}", $"{nameof(ExportableProduct.Properties)}.{nameof(Property.Attributes)}", $"{nameof(ExportableProduct.Properties)}.{nameof(Property.DisplayNames)}", $"{nameof(ExportableProduct.Properties)}.{nameof(Property.ValidationRules)}", nameof(ExportableProduct.Assets), nameof(ExportableProduct.Links), nameof(ExportableProduct.SeoInfos), nameof(ExportableProduct.Reviews), nameof(ExportableProduct.Associations), nameof(ExportableProduct.ReferencedAssociations), nameof(ExportableProduct.Outlines), nameof(ExportableProduct.Images))) .WithTabularMetadata(typeof(ExportableProduct).GetPropertyNames())); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportableCatalogFull, CatalogFullExportDataQuery>() .WithDataSourceFactory(appBuilder.ApplicationServices.GetService <ICatalogExportPagedDataSourceFactory>()) .WithMetadata(new ExportedTypeMetadata { PropertyInfos = Array.Empty <ExportedTypePropertyInfo>() }) .WithRestrictDataSelectivity()); #endregion #region BulkActions AbstractTypeFactory <BulkActionContext> .RegisterType <CategoryChangeBulkActionContext>(); AbstractTypeFactory <BulkActionContext> .RegisterType <PropertiesUpdateBulkActionContext>(); RegisterBulkAction(nameof(CategoryChangeBulkAction), nameof(CategoryChangeBulkActionContext)); RegisterBulkAction(nameof(PropertiesUpdateBulkAction), nameof(PropertiesUpdateBulkActionContext)); #endregion }
public override void PostInitialize() { base.PostInitialize(); var securityScopeService = _container.Resolve <IPermissionScopeService>(); securityScopeService.RegisterSope(() => new CatalogSelectedScope()); securityScopeService.RegisterSope(() => new CatalogSelectedCategoryScope(_container.Resolve <ICategoryService>())); var httpConfiguration = _container.Resolve <HttpConfiguration>(); httpConfiguration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new SearchCriteriaJsonConverter()); // Register dynamic property for storing browsing filters var filteredBrowsingProperty = new DynamicProperty { Id = "2b15f370ab524186bec1ace82509a60a", Name = BrowseFilterService.FilteredBrowsingPropertyName, ObjectType = typeof(Store).FullName, ValueType = DynamicPropertyValueType.LongText, CreatedBy = "Auto" }; var dynamicPropertyService = _container.Resolve <IDynamicPropertyService>(); dynamicPropertyService.SaveProperties(new[] { filteredBrowsingProperty }); // Product indexing configuration var productIndexingConfiguration = new IndexDocumentConfiguration { DocumentType = KnownDocumentTypes.Product, DocumentSource = new IndexDocumentSource { ChangesProvider = _container.Resolve <ProductDocumentChangesProvider>(), DocumentBuilder = _container.Resolve <ProductDocumentBuilder>(), }, }; _container.RegisterInstance(productIndexingConfiguration.DocumentType, productIndexingConfiguration); // Category indexing configuration var categoryIndexingConfiguration = new IndexDocumentConfiguration { DocumentType = KnownDocumentTypes.Category, DocumentSource = new IndexDocumentSource { ChangesProvider = _container.Resolve <CategoryDocumentChangesProvider>(), DocumentBuilder = _container.Resolve <CategoryDocumentBuilder>(), }, }; _container.RegisterInstance(categoryIndexingConfiguration.DocumentType, categoryIndexingConfiguration); #region Register types for generic Export var registrar = _container.Resolve <IKnownExportTypesRegistrar>(); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportableCatalogFull, CatalogFullExportDataQuery>() .WithDataSourceFactory(_container.Resolve <ICatalogExportPagedDataSourceFactory>()) .WithPermissionAuthorization(CatalogPredefinedPermissions.Export, CatalogPredefinedPermissions.Read) .WithMetadata(new ExportedTypeMetadata { PropertyInfos = Array.Empty <ExportedTypePropertyInfo>() }) .WithAuthorizationHandler(_container.Resolve <CatalogExportSecurityHandler>()) ); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportableProduct, ProductExportDataQuery>() .WithDataSourceFactory(_container.Resolve <ICatalogExportPagedDataSourceFactory>()) .WithMetadata(typeof(ExportableProduct).GetPropertyNames( nameof(ExportableProduct.Properties), $"{nameof(ExportableProduct.Properties)}.{nameof(Property.Attributes)}", $"{nameof(ExportableProduct.Properties)}.{nameof(Property.DisplayNames)}", $"{nameof(ExportableProduct.Properties)}.{nameof(Property.ValidationRules)}", nameof(ExportableProduct.PropertyValues), nameof(ExportableProduct.Assets), nameof(ExportableProduct.Links), nameof(ExportableProduct.SeoInfos), nameof(ExportableProduct.Reviews), nameof(ExportableProduct.Associations), nameof(ExportableProduct.ReferencedAssociations), nameof(ExportableProduct.Outlines), nameof(ExportableProduct.Images))) .WithTabularMetadata(typeof(ExportableProduct).GetPropertyNames()) .WithPermissionAuthorization(CatalogPredefinedPermissions.Export, CatalogPredefinedPermissions.Read) .WithAuthorizationHandler(_container.Resolve <CatalogExportSecurityHandler>())); #endregion }
public override void PostInitialize() { base.PostInitialize(); // Next lines allow to use polymorph types in API controller methods var httpConfiguration = _container.Resolve <HttpConfiguration>(); var storeJsonConverter = _container.Resolve <PolymorphicPricingJsonConverter>(); httpConfiguration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(storeJsonConverter); #region Search var settingsManager = _container.Resolve <ISettingsManager>(); var priceIndexingEnabled = settingsManager.GetValue("Pricing.Indexing.Enable", true); if (priceIndexingEnabled) { // Add price document source to the product indexing configuration var productIndexingConfigurations = _container.Resolve <IndexDocumentConfiguration[]>(); if (productIndexingConfigurations != null) { var productPriceDocumentSource = new IndexDocumentSource { ChangesProvider = _container.Resolve <IPricingDocumentChangesProvider>(), DocumentBuilder = _container.Resolve <ProductPriceDocumentBuilder>(), }; foreach (var configuration in productIndexingConfigurations.Where(c => c.DocumentType == KnownDocumentTypes.Product)) { if (configuration.RelatedSources == null) { configuration.RelatedSources = new List <IndexDocumentSource>(); } configuration.RelatedSources.Add(productPriceDocumentSource); } } } #endregion var eventHandlerRegistrar = _container.Resolve <IHandlerRegistrar>(); var settingManager = _container.Resolve <ISettingsManager>(); if (settingManager.GetValue("Pricing.Search.EventBasedIndexation.Enable", false)) { eventHandlerRegistrar.RegisterHandler <PriceChangedEvent>(async(message, token) => await _container.Resolve <IndexPricesProductChangedEventHandler>().Handle(message)); } eventHandlerRegistrar.RegisterHandler <ProductChangedEvent>(async(message, token) => await _container.Resolve <DeletePricesProductChangedEvent>().Handle(message)); #region GenericExport var registrar = _container.Resolve <IKnownExportTypesRegistrar>(); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePrice, PriceExportDataQuery>() .WithDataSourceFactory(_container.Resolve <IPricingExportPagedDataSourceFactory>()) .WithPermissionAuthorization(PricingPredefinedPermissions.Export, PricingPredefinedPermissions.Read) .WithMetadata(typeof(ExportablePrice).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPrice).GetPropertyNames())); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePricelist, PricelistExportDataQuery>() .WithDataSourceFactory(_container.Resolve <IPricingExportPagedDataSourceFactory>()) .WithPermissionAuthorization(PricingPredefinedPermissions.Export, PricingPredefinedPermissions.Read) .WithMetadata(typeof(ExportablePricelist).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPricelist).GetPropertyNames())); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePricelistAssignment, PricelistAssignmentExportDataQuery>() .WithDataSourceFactory(_container.Resolve <IPricingExportPagedDataSourceFactory>()) .WithPermissionAuthorization(PricingPredefinedPermissions.Export, PricingPredefinedPermissions.Read) .WithMetadata(typeof(ExportablePricelistAssignment).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPricelistAssignment).GetPropertyNames())); #endregion }
public Task PriceCsvExport() { IKnownExportTypesRegistrar registrar = new KnownExportTypesService(); var resolver = (IKnownExportTypesResolver)registrar; var searchServiceMock = new Mock <IPricingSearchService>(); searchServiceMock.Setup(x => x.SearchPrices(It.Is <PricesSearchCriteria>(y => y.Skip == 0))).Returns(GetTestPriceResult <Price>()); searchServiceMock.Setup(x => x.SearchPrices(It.Is <PricesSearchCriteria>(y => y.Skip > 0))).Returns(new PricingSearchResult <Price>()); var priceServiceMock = new Mock <IPricingService>(); var itemServiceMock = new Mock <IItemService>(); var metadata = typeof(ExportablePrice).GetPropertyNames(); registrar.RegisterType(ExportedTypeDefinitionBuilder.Build <ExportablePrice, PriceExportDataQuery>() .WithDataSourceFactory(new PriceExportPagedDataSourceFactory(searchServiceMock.Object, priceServiceMock.Object, itemServiceMock.Object, null)) .WithMetadata(metadata) .WithTabularMetadata(typeof(TabularPrice).GetPropertyNames())); var exportProviderFactories = new[] { new Func <ExportDataRequest, IExportProvider>((request) => new JsonExportProvider(request)), new Func <ExportDataRequest, IExportProvider>((request) => new CsvExportProvider(request)), }; var includedPropertyNames = new string[] { "Currency", "ProductId" }; var IncludedProperties = metadata.PropertyInfos.Where(x => includedPropertyNames.Contains(x.FullName, StringComparer.OrdinalIgnoreCase)).ToArray(); var dataExporter = new DataExporter(resolver, new ExportProviderFactory(exportProviderFactories)); var result = string.Empty; using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, Encoding.UTF8) { AutoFlush = true }) { dataExporter.Export( stream, new ExportDataRequest() { DataQuery = new PriceExportDataQuery() { IncludedProperties = IncludedProperties, }, ExportTypeName = typeof(ExportablePrice).FullName, ProviderName = nameof(CsvExportProvider) }, new Action <ExportProgressInfo>(x => Console.WriteLine(x.Description)), new CancellationTokenWrapper(CancellationToken.None)); stream.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(stream); result = reader.ReadToEnd(); } Assert.Equal("Currency,ProductId\r\nUSD,d029526eab5948b189694f1bddba8e68\r\nEUR,85e7aa089a4e4a97a4394d668e37e3f8\r\nEUR,f427108e75ed4676923ddc47632111e3\r\n", result); return(Task.CompletedTask); }
public Task PricelistAssignmentJsonExport() { IKnownExportTypesRegistrar registrar = new KnownExportTypesService(); var searchServiceMock = new Mock <IPricingSearchService>(); searchServiceMock.Setup(x => x.SearchPricelistAssignments(It.Is <PricelistAssignmentsSearchCriteria>(y => y.Skip == 0))).Returns(GetPricelistAssignmentSearchResult <PricelistAssignment>()); searchServiceMock.Setup(x => x.SearchPricelistAssignments(It.Is <PricelistAssignmentsSearchCriteria>(y => y.Skip > 0))).Returns(new PricingSearchResult <PricelistAssignment>()); var priceServiceMock = new Mock <IPricingService>(); var catalogServiceMock = new Mock <ICatalogService>(); var metadata = typeof(ExportablePricelistAssignment).GetPropertyNames(); var resolver = (IKnownExportTypesResolver)registrar; registrar.RegisterType(ExportedTypeDefinitionBuilder.Build <ExportablePricelistAssignment, PricelistAssignmentExportDataQuery>() .WithDataSourceFactory(new PricelistAssignmentExportPagedDataSourceFactory(searchServiceMock.Object, priceServiceMock.Object, catalogServiceMock.Object)) .WithMetadata(metadata)); var exportProviderFactories = new[] { new Func <ExportDataRequest, IExportProvider>((request) => new JsonExportProvider(request)), }; var dataExporter = new DataExporter(resolver, new ExportProviderFactory(exportProviderFactories)); var includedPropertyNames = new string[] { "CatalogId", "PricelistId", "Priority", "Id" }; var IncludedProperties = metadata.PropertyInfos.Where(x => includedPropertyNames.Contains(x.FullName, StringComparer.OrdinalIgnoreCase)).ToArray(); //Act var result = string.Empty; using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, Encoding.UTF8) { AutoFlush = true }) { dataExporter.Export( stream, new ExportDataRequest() { DataQuery = new PricelistAssignmentExportDataQuery() { IncludedProperties = IncludedProperties }, ExportTypeName = typeof(ExportablePricelistAssignment).FullName, ProviderName = nameof(JsonExportProvider) }, new Action <ExportProgressInfo>(x => Console.WriteLine(x.Description)), new CancellationTokenWrapper(CancellationToken.None)); stream.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(stream); result = reader.ReadToEnd(); } //Assert var pricelistsAssigments = JsonConvert.DeserializeObject <ExportablePricelistAssignment[]>(result); Assert.NotNull(pricelistsAssigments); Assert.NotEmpty(pricelistsAssigments); var assigment = pricelistsAssigments.FirstOrDefault(x => x.Id == "d4a4e5271046497eaef61ee47efe6215"); Assert.NotNull(assigment); Assert.Null(assigment.Name); Assert.Equal("80873a35a34a4cf8997ac87e69cac6d6", assigment.PricelistId); Assert.Equal("4974648a41df4e6ea67ef2ad76d7bbd4", assigment.CatalogId); Assert.Equal(10, assigment.Priority); return(Task.CompletedTask); }
public Task PricelistJsonExport() { //Arrange IKnownExportTypesRegistrar registrar = new KnownExportTypesService(); var searchServiceMock = new Mock <IPricingSearchService>(); searchServiceMock.Setup(x => x.SearchPricelists(It.Is <PricelistSearchCriteria>(y => y.Skip == 0))).Returns(GetTestPricelistResult <Pricelist>()); searchServiceMock.Setup(x => x.SearchPricelists(It.Is <PricelistSearchCriteria>(y => y.Skip > 0))).Returns(new PricingSearchResult <Pricelist>()); searchServiceMock.Setup(x => x.SearchPrices(It.IsAny <PricesSearchCriteria>())).Returns(new PricingSearchResult <Price>() { TotalCount = 0, Results = new List <Price>(), }); var priceServiceMock = new Mock <IPricingService>(); var metadata = typeof(ExportablePricelist).GetPropertyNames(); var resolver = (IKnownExportTypesResolver)registrar; registrar.RegisterType(ExportedTypeDefinitionBuilder.Build <ExportablePricelist, PricelistExportDataQuery>() .WithDataSourceFactory(new PricelistExportPagedDataSourceFactory(searchServiceMock.Object, priceServiceMock.Object)) .WithMetadata(metadata)); var exportProviderFactories = new[] { new Func <ExportDataRequest, IExportProvider>((request) => new JsonExportProvider(request)), }; var dataExporter = new DataExporter(resolver, new ExportProviderFactory(exportProviderFactories)); var includedPropertyNames = new string[] { "Currency", "Id", "Name" }; var IncludedProperties = metadata.PropertyInfos.Where(x => includedPropertyNames.Contains(x.FullName, StringComparer.OrdinalIgnoreCase)).ToArray(); //Act var result = string.Empty; using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, Encoding.UTF8) { AutoFlush = true }) { dataExporter.Export( stream, new ExportDataRequest() { DataQuery = new PricelistExportDataQuery() { IncludedProperties = IncludedProperties }, ExportTypeName = typeof(ExportablePricelist).FullName, ProviderName = nameof(JsonExportProvider) }, new Action <ExportProgressInfo>(x => Console.WriteLine(x.Description)), new CancellationTokenWrapper(CancellationToken.None)); stream.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(stream); result = reader.ReadToEnd(); } //Assert var pricelists = JsonConvert.DeserializeObject <ExportablePricelist[]>(result); Assert.NotNull(pricelists); Assert.NotEmpty(pricelists); var pricelist = pricelists.FirstOrDefault(x => x.Name.Equals("BoltsUSD", StringComparison.InvariantCultureIgnoreCase)); Assert.NotNull(pricelist); Assert.Equal("0456b3ebc0a24c0ab7054ec9a5cea78e", pricelist.Id); Assert.Equal("USD", pricelist.Currency); return(Task.CompletedTask); }
public void PostInitialize(IApplicationBuilder appBuilder) { _applicationBuilder = appBuilder; var settingsManager = _applicationBuilder.ApplicationServices.GetService <ISettingsManager>(); var settingsRegistrar = appBuilder.ApplicationServices.GetRequiredService <ISettingsRegistrar>(); settingsRegistrar.RegisterSettings(ModuleConstants.Settings.AllSettings, ModuleInfo.Id); var modulePermissions = ModuleConstants.Security.Permissions.AllPermissions.Select(p => new Permission { Name = p, GroupName = "Pricing", ModuleId = ModuleInfo.Id }).ToArray(); var permissionsRegistrar = appBuilder.ApplicationServices.GetRequiredService <IPermissionsRegistrar>(); permissionsRegistrar.RegisterPermissions(modulePermissions); using (var serviceScope = appBuilder.ApplicationServices.CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetRequiredService <PricingDbContext>(); dbContext.Database.MigrateIfNotApplied(MigrationName.GetUpdateV2MigrationName(ModuleInfo.Id)); dbContext.Database.EnsureCreated(); dbContext.Database.Migrate(); } // Next lines allow to use polymorph types in API controller methods var mvcJsonOptions = appBuilder.ApplicationServices.GetService <IOptions <MvcNewtonsoftJsonOptions> >(); mvcJsonOptions.Value.SerializerSettings.Converters.Add(appBuilder.ApplicationServices.GetService <PolymorphicPricingJsonConverter>()); var priceIndexingEnabled = settingsManager.GetValue(ModuleConstants.Settings.General.PricingIndexing.Name, true); if (priceIndexingEnabled) { // Add price document source to the product indexing configuration var productIndexingConfigurations = _applicationBuilder.ApplicationServices.GetServices <IndexDocumentConfiguration>(); if (productIndexingConfigurations != null) { var productPriceDocumentSource = new IndexDocumentSource { ChangesProvider = _applicationBuilder.ApplicationServices.GetService <IPricingDocumentChangesProvider>(), DocumentBuilder = _applicationBuilder.ApplicationServices.GetService <ProductPriceDocumentBuilder>(), }; foreach (var configuration in productIndexingConfigurations.Where(c => c.DocumentType == KnownDocumentTypes.Product)) { if (configuration.RelatedSources == null) { configuration.RelatedSources = new List <IndexDocumentSource>(); } configuration.RelatedSources.Add(productPriceDocumentSource); } } } var inProcessBus = appBuilder.ApplicationServices.GetService <IHandlerRegistrar>(); inProcessBus.RegisterHandler <PriceChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <LogChangesChangedEventHandler>().Handle(message)); inProcessBus.RegisterHandler <ProductChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <DeletePricesProductChangedEventHandler>().Handle(message)); if (settingsManager.GetValue(ModuleConstants.Settings.General.EventBasedIndexation.Name, false)) { inProcessBus.RegisterHandler <PriceChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <IndexPricesProductChangedEventHandler>().Handle(message)); } foreach (var conditionTree in AbstractTypeFactory <PriceConditionTreePrototype> .TryCreateInstance().Traverse <IConditionTree>(x => x.AvailableChildren)) { AbstractTypeFactory <IConditionTree> .RegisterType(conditionTree.GetType()); } var registrar = appBuilder.ApplicationServices.GetService <IKnownExportTypesRegistrar>(); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePrice, PriceExportDataQuery>() .WithDataSourceFactory(appBuilder.ApplicationServices.GetService <IPricingExportPagedDataSourceFactory>()) .WithMetadata(typeof(ExportablePrice).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPrice).GetPropertyNames())); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePricelist, PricelistExportDataQuery>() .WithDataSourceFactory(appBuilder.ApplicationServices.GetService <IPricingExportPagedDataSourceFactory>()) .WithMetadata(typeof(ExportablePricelist).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPricelist).GetPropertyNames())); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePricelistAssignment, PricelistAssignmentExportDataQuery>() .WithDataSourceFactory(appBuilder.ApplicationServices.GetService <IPricingExportPagedDataSourceFactory>()) .WithMetadata(typeof(ExportablePricelistAssignment).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPricelistAssignment).GetPropertyNames())); }
public void PostInitialize(IApplicationBuilder appBuilder) { _applicationBuilder = appBuilder; var settingsManager = _applicationBuilder.ApplicationServices.GetService <ISettingsManager>(); var settingsRegistrar = appBuilder.ApplicationServices.GetRequiredService <ISettingsRegistrar>(); settingsRegistrar.RegisterSettings(ModuleConstants.Settings.AllSettings, ModuleInfo.Id); var modulePermissions = ModuleConstants.Security.Permissions.AllPermissions.Select(p => new Permission { Name = p, GroupName = "Pricing", ModuleId = ModuleInfo.Id }).ToArray(); var permissionsRegistrar = appBuilder.ApplicationServices.GetRequiredService <IPermissionsRegistrar>(); permissionsRegistrar.RegisterPermissions(modulePermissions); using (var serviceScope = appBuilder.ApplicationServices.CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetRequiredService <PricingDbContext>(); dbContext.Database.MigrateIfNotApplied(MigrationName.GetUpdateV2MigrationName(ModuleInfo.Id)); dbContext.Database.EnsureCreated(); dbContext.Database.Migrate(); } // Next lines allow to use polymorph types in API controller methods var mvcJsonOptions = appBuilder.ApplicationServices.GetService <IOptions <MvcNewtonsoftJsonOptions> >(); mvcJsonOptions.Value.SerializerSettings.Converters.Add(appBuilder.ApplicationServices.GetService <PolymorphicPricingJsonConverter>()); //Subscribe for Search configuration changes var inProcessBus = appBuilder.ApplicationServices.GetService <IHandlerRegistrar>(); inProcessBus.RegisterHandler <ObjectSettingChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <ObjectSettingEntryChangedEventHandler>().Handle(message)); //Configure Search var moduleConfigurator = appBuilder.ApplicationServices.GetService <ModuleConfigurator>(); moduleConfigurator.ConfigureSearchAsync(); inProcessBus.RegisterHandler <PriceChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <LogChangesChangedEventHandler>().Handle(message)); inProcessBus.RegisterHandler <ProductChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <DeletePricesProductChangedEventHandler>().Handle(message)); inProcessBus.RegisterHandler <PriceChangedEvent>(async(message, token) => await appBuilder.ApplicationServices.GetService <IndexPricesProductChangedEventHandler>().Handle(message)); foreach (var conditionTree in AbstractTypeFactory <PriceConditionTreePrototype> .TryCreateInstance().Traverse <IConditionTree>(x => x.AvailableChildren)) { AbstractTypeFactory <IConditionTree> .RegisterType(conditionTree.GetType()); } var registrar = appBuilder.ApplicationServices.GetService <IKnownExportTypesRegistrar>(); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePrice, PriceExportDataQuery>() .WithDataSourceFactory(appBuilder.ApplicationServices.GetService <IPricingExportPagedDataSourceFactory>()) .WithMetadata(typeof(ExportablePrice).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPrice).GetPropertyNames())); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePricelist, PricelistExportDataQuery>() .WithDataSourceFactory(appBuilder.ApplicationServices.GetService <IPricingExportPagedDataSourceFactory>()) .WithMetadata(typeof(ExportablePricelist).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPricelist).GetPropertyNames())); registrar.RegisterType( ExportedTypeDefinitionBuilder.Build <ExportablePricelistAssignment, PricelistAssignmentExportDataQuery>() .WithDataSourceFactory(appBuilder.ApplicationServices.GetService <IPricingExportPagedDataSourceFactory>()) .WithMetadata(typeof(ExportablePricelistAssignment).GetPropertyNames()) .WithTabularMetadata(typeof(TabularPricelistAssignment).GetPropertyNames())); }
public static ExportedTypeDefinitionBuilder WithExportDataQueryType(this ExportedTypeDefinitionBuilder builder, string exportDataQueryType) { builder.ExportedTypeDefinition.ExportDataQueryType = exportDataQueryType; return(builder); }
public Task PriceJsonExport() { //Arrange IKnownExportTypesRegistrar registrar = new KnownExportTypesService(); var searchServiceMock = new Mock <IPricingSearchService>(); searchServiceMock.Setup(x => x.SearchPrices(It.Is <PricesSearchCriteria>(y => y.Skip == 0))).Returns(GetTestPriceResult <Price>()); searchServiceMock.Setup(x => x.SearchPrices(It.Is <PricesSearchCriteria>(y => y.Skip > 0))).Returns(new PricingSearchResult <Price>()); var priceServiceMock = new Mock <IPricingService>(); var itemServiceMock = new Mock <IItemService>(); var metadata = typeof(ExportablePrice).GetPropertyNames(); var resolver = (IKnownExportTypesResolver)registrar; registrar.RegisterType(ExportedTypeDefinitionBuilder.Build <ExportablePrice, PriceExportDataQuery>() .WithDataSourceFactory(new PriceExportPagedDataSourceFactory(searchServiceMock.Object, priceServiceMock.Object, itemServiceMock.Object, null)) .WithMetadata(metadata)); var includedPropertyNames = new string[] { "Currency", "ProductId", "Sale", "List", "MinQuantity", "StartDate", "EndDate", "EffectiveValue" }; var IncludedProperties = metadata.PropertyInfos.Where(x => includedPropertyNames.Contains(x.FullName, StringComparer.OrdinalIgnoreCase)).ToArray(); var exportProviderFactories = new[] { new Func <ExportDataRequest, IExportProvider>((request) => new JsonExportProvider(request)), }; var dataExporter = new DataExporter(resolver, new ExportProviderFactory(exportProviderFactories)); //Act var result = string.Empty; using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, Encoding.UTF8) { AutoFlush = true }) { dataExporter.Export( stream, new ExportDataRequest() { DataQuery = new PriceExportDataQuery() { IncludedProperties = IncludedProperties }, ExportTypeName = typeof(ExportablePrice).FullName, ProviderName = nameof(JsonExportProvider) }, new Action <ExportProgressInfo>(x => Console.WriteLine(x.Description)), new CancellationTokenWrapper(CancellationToken.None)); stream.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(stream); result = reader.ReadToEnd(); } //Assert var prices = JsonConvert.DeserializeObject <ExportablePrice[]>(result); Assert.NotNull(prices); Assert.Equal(3, prices.Length); Assert.Equal(2, prices.Count(x => x.List == 3.99m)); Assert.Equal(1, prices.Count(x => x.ProductId == "d029526eab5948b189694f1bddba8e68")); return(Task.CompletedTask); }
public static ExportedTypeDefinitionBuilder WithDataSourceFactory(this ExportedTypeDefinitionBuilder builder, Func <ExportDataQuery, IPagedDataSource> factory) { builder.ExportedTypeDefinition.ExportedDataSourceFactory = factory; return(builder); }
/// <summary> /// Restrict access to select data for export /// </summary> public static ExportedTypeDefinitionBuilder WithRestrictDataSelectivity(this ExportedTypeDefinitionBuilder builder) { builder.ExportedTypeDefinition.RestrictDataSelectivity = true; return(builder); }