Example #1
0
        public virtual void Index(SearchConnection searchConnection, string dbConnectionString, string documentType, bool rebuild)
        {
            SafeWriteVerbose("Server: " + searchConnection);
            IServiceLocator serviceLocatorBackup = null;
            try
            {
                // backup existing LocatorProvider
                if (ServiceLocator.IsLocationProviderSet)
                    serviceLocatorBackup = ServiceLocator.Current;

                var controller = GetLocalSearchController(searchConnection, dbConnectionString);

                SafeWriteVerbose("Preparing workload");
                controller.Prepare(scope: searchConnection.Scope, documentType: documentType, rebuild: rebuild);

                SafeWriteVerbose("Processing workload");
                controller.Process(scope: searchConnection.Scope, documentType: documentType);

                // Multi threaded processing
                //IndexProcess(searchConnection, dbConnectionString, documentType);
            }
            finally
            {
                // reseting original LocatorProvider
                if (serviceLocatorBackup != null)
                    ServiceLocator.SetLocatorProvider(() => serviceLocatorBackup);
            }
        }
 private void IndexProcess(SearchConnection searchConnection, string dbConnectionString,
                                 string documentType)
 {
     SafeWriteVerbose("Processing workload - 5 threads in parallel");
     var controller = GetLocalSearchController(searchConnection, dbConnectionString);
     Parallel.For(0, 5, (i, loopState) => controller.Process(scope: searchConnection.Scope, documentType: documentType));
 }
 public void Can_create_lucene_index()
 {
     var scope = "default";
     var queryBuilder = new LuceneSearchQueryBuilder();
     var conn = new SearchConnection(_LuceneStorageDir, scope);
     var provider = new LuceneSearchProvider(queryBuilder, conn);
     SearchHelper.CreateSampleIndex(provider, scope);
     Directory.Delete(_LuceneStorageDir, true);
 }
 public void Can_create_azuresearch_index()
 {
     var scope = "test";
     var queryBuilder = new AzureSearchQueryBuilder();
     var conn = new SearchConnection(Datasource, scope, accessKey: AccessKey);
     var provider = new AzureSearchProvider(queryBuilder, conn);           
     SearchHelper.CreateSampleIndex(provider, scope);
     provider.RemoveAll(scope, String.Empty);
 }
        public void Can_create_connection_azuresearch()
        {
            var connectionString =
                "server=virtocommerce;scope=default;key=accesskey;provider=azuresearch";

            var connection = new SearchConnection(connectionString);

            Assert.True(connection.DataSource == "virtocommerce");
            Assert.True(connection.Provider == "azuresearch");
            Assert.True(connection.Scope == "default");
            Assert.True(connection.AccessKey == "accesskey");
        }
        public virtual void Index(SearchConnection searchConnection, string dbConnectionString, string documentType, bool rebuild)
        {
            SafeWriteVerbose("Server: " + searchConnection);
           
            var controller = GetLocalSearchController(searchConnection, dbConnectionString);

            SafeWriteVerbose("Preparing workload");
            controller.Prepare(scope: searchConnection.Scope, documentType: documentType, rebuild: rebuild);

            SafeWriteVerbose("Processing workload");
            controller.Process(scope: searchConnection.Scope, documentType: documentType);

            // Multi threaded processing
            //IndexProcess(searchConnection, dbConnectionString, documentType);
        }
        public void Can_find_item_lucene()
        {
            var scope = "default";
            var queryBuilder = new LuceneSearchQueryBuilder();
            var conn = new SearchConnection(_LuceneStorageDir, scope);
            var provider = new LuceneSearchProvider(queryBuilder, conn);


            if (Directory.Exists(_LuceneStorageDir))
            {
                Directory.Delete(_LuceneStorageDir, true);
            }

            SearchHelper.CreateSampleIndex(provider, scope);

            var criteria = new CatalogItemSearchCriteria
                               {
                                   SearchPhrase = "product",
                                   IsFuzzySearch = true,
                                   Catalog = "goods",
                                   RecordsToRetrieve = 10,
                                   StartingRecord = 0,
                                   Pricelists = new string[] { }
                               };


            var results = provider.Search(scope, criteria);

            Assert.True(results.DocCount == 1, String.Format("Returns {0} instead of 1", results.DocCount));

            criteria = new CatalogItemSearchCriteria
            {
                SearchPhrase = "sample product ",
                IsFuzzySearch = true,
                Catalog = "goods",
                RecordsToRetrieve = 10,
                StartingRecord = 0,
                Pricelists = new string[] { }
            };


            results = provider.Search(scope, criteria);

            Assert.True(results.DocCount == 1, String.Format("\"Sample Product\" search returns {0} instead of 1", results.DocCount));

            Directory.Delete(_LuceneStorageDir, true);
        }
        public void Can_find_item_azuresearch()
        {
            var scope = "test";
            var queryBuilder = new AzureSearchQueryBuilder();
            var conn = new SearchConnection(Datasource, scope, accessKey: AccessKey);
            var provider = new AzureSearchProvider(queryBuilder, conn);

            provider.RemoveAll(scope, String.Empty);
            SearchHelper.CreateSampleIndex(provider, scope);

            var criteria = new CatalogItemSearchCriteria
            {
                SearchPhrase = "product",
                IsFuzzySearch = true,
                Catalog = "goods",
                RecordsToRetrieve = 10,
                StartingRecord = 0,
                Pricelists = new string[] { }
            };


            // force delay, otherwise records are not available
            Thread.Sleep(1000); 

            var results = provider.Search(scope, criteria);
            
            Assert.True(results.DocCount == 1, String.Format("Returns {0} instead of 1", results.DocCount));

            criteria = new CatalogItemSearchCriteria
            {
                SearchPhrase = "sample product ",
                IsFuzzySearch = true,
                Catalog = "goods",
                RecordsToRetrieve = 10,
                StartingRecord = 0,
                Pricelists = new string[] { }
            };


            results = provider.Search(scope, criteria);

            Assert.True(results.DocCount == 1, String.Format("\"Sample Product\" search returns {0} instead of 1", results.DocCount));

            provider.RemoveAll(scope, String.Empty);
        }
        public void Can_find_items_azuresearch()
        {
            var scope = "default";
            var queryBuilder = new AzureSearchQueryBuilder();
            var conn = new SearchConnection(Datasource, scope, accessKey: AccessKey);
            var provider = new AzureSearchProvider(queryBuilder, conn);

            var criteria = new CatalogItemSearchCriteria
                           {
                               SearchPhrase = "sony",
                               IsFuzzySearch = true,
                               Catalog = "vendorvirtual",
                               RecordsToRetrieve = 10,
                               StartingRecord = 0,
                               Pricelists = new string[] { },
                               StartDate = DateTime.UtcNow,
                               Sort = new SearchSort("price_usd_saleusd")
                           };

            criteria.Outlines.Add("vendorvirtual*");

            //"(startdate lt 2014-09-26T22:05:11Z) and sys__hidden eq 'false' and sys__outline/any(t:t eq 'VendorVirtual/e1b56012-d877-4bdd-92d8-3fc186899d0f*') and catalog/any(t: t eq 'VendorVirtual')"
            var results = provider.Search(scope, criteria);
        }
        public void Can_get_item_multiple_filters_lucene()
        {
            var scope = "default";
            var queryBuilder = new LuceneSearchQueryBuilder();
            var conn = new SearchConnection(_LuceneStorageDir, scope);
            var provider = new LuceneSearchProvider(queryBuilder, conn);
            Debug.WriteLine("Lucene connection: {0}", conn.ToString());

            if (Directory.Exists(_LuceneStorageDir))
            {
                Directory.Delete(_LuceneStorageDir, true);
            }

            SearchHelper.CreateSampleIndex(provider, scope);

            var criteria = new CatalogItemSearchCriteria
            {
                SearchPhrase = "",
                IsFuzzySearch = true,
                Catalog = "goods",
                RecordsToRetrieve = 10,
                StartingRecord = 0,
                Currency = "USD",
                Pricelists = new[] { "default" }
            };

            var colorFilter = new AttributeFilter { Key = "Color" };
            colorFilter.Values = new[]
                                {
                                    new AttributeFilterValue { Id = "red", Value = "red" },
                                    new AttributeFilterValue { Id = "blue", Value = "blue" },
                                    new AttributeFilterValue { Id = "black", Value = "black" }
                                };

            var filter = new AttributeFilter { Key = "Color" };
            filter.Values = new[]
                                {
                                    new AttributeFilterValue { Id = "black", Value = "black" }
                                };

            var rangefilter = new RangeFilter { Key = "size" };
            rangefilter.Values = new[]
                                     {
                                         new RangeFilterValue { Id = "0_to_5", Lower = "0", Upper = "5" },
                                         new RangeFilterValue { Id = "5_to_10", Lower = "5", Upper = "11" }
                                     };

            var priceRangefilter = new PriceRangeFilter { Currency = "usd" };
            priceRangefilter.Values = new[]
                                          {
                                              new RangeFilterValue { Id = "100_to_700", Lower = "100", Upper = "700" }
                                          };

            criteria.Add(colorFilter);
            criteria.Add(priceRangefilter);

            // add applied filters
            criteria.Apply(filter);
            //criteria.Apply(rangefilter);
            //criteria.Apply(priceRangefilter);

            var results = provider.Search(scope, criteria);

            var blackCount = GetFacetCount(results, "Color", "black");
            Assert.True(blackCount == 1, String.Format("Returns {0} facets of black instead of 2", blackCount));

            //Assert.True(results.DocCount == 1, String.Format("Returns {0} instead of 1", results.DocCount));

            Directory.Delete(_LuceneStorageDir, true);
        }
Example #11
0
        protected ISearchIndexController GetLocalSearchController(SearchConnection searchConnection, string connectionString)
        {
            var container = GetLocalContainer(searchConnection, connectionString);
            var locator = new UnityServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => locator);
            var controller = container.Resolve<ISearchIndexController>();

            return controller;
        }
Example #12
0
        private UnityContainer GetLocalContainer(SearchConnection searchConnection, string connectionString)
        {
            var container = new UnityContainer();
            container.RegisterType<IKnownSerializationTypes, CatalogEntityFactory>("catalog", new ContainerControlledLifetimeManager());
            container.RegisterInstance<IConsumerFactory>(new DomainAssemblyScannerConsumerFactory(container));
            container.RegisterType<IKnownSerializationTypes, DomainAssemblyScannerConsumerFactory>("scaned", new ContainerControlledLifetimeManager(), new InjectionConstructor(container));
            container.RegisterType<IConsumerFactory, DomainAssemblyScannerConsumerFactory>();
            container.RegisterType<IEngineProcess, SingleThreadConsumingProcess>();
            container.RegisterType<IMessageSerializer, DataContractMessageSerializer>();
            container.RegisterType<IQueueWriter, InMemoryQueueWriter>();
            container.RegisterType<IQueueReader, InMemoryQueueReader>();
            container.RegisterType<IMessageSender, DefaultMessageSender>(new ContainerControlledLifetimeManager());
            container.RegisterType<ICatalogEntityFactory, CatalogEntityFactory>(new ContainerControlledLifetimeManager());
            container.RegisterType<IReviewEntityFactory, ReviewEntityFactory>(new ContainerControlledLifetimeManager());

            container.RegisterType<ICatalogService, CatalogService>();
            container.RegisterType<ISearchIndexBuilder, CatalogItemIndexBuilder>("catalogitem");
            container.RegisterType<ILogOperationFactory, LogOperationFactory>();
            container.RegisterType<ISearchEntityFactory, SearchEntityFactory>(new ContainerControlledLifetimeManager());
            container.RegisterType<ISearchIndexController, SearchIndexController>();
            container.RegisterType<ICacheRepository, HttpCacheRepository>();

            if (string.Equals(searchConnection.Provider, SearchProviders.Lucene.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                // Lucene Search implementation
                container.RegisterType<ISearchProvider, LuceneSearchProvider>();
                container.RegisterType<ISearchQueryBuilder, LuceneSearchQueryBuilder>();
            }
            else
            {
                container.RegisterType<ISearchProvider, ElasticSearchProvider>();
                container.RegisterType<ISearchQueryBuilder, ElasticSearchQueryBuilder>();
            }


            // register instances here
            container.RegisterInstance<ISearchConnection>(searchConnection);

            var catalogRepository = new EFCatalogRepository(connectionString);
            container.RegisterInstance<ICatalogRepository>(catalogRepository);
            container.RegisterType<ICatalogOutlineBuilder, CatalogOutlineBuilder>();
            container.RegisterInstance<IPricelistRepository>(catalogRepository);
            container.RegisterInstance<IOperationLogRepository>(new OperationLogContext(connectionString));
            container.RegisterInstance<IBuildSettingsRepository>(new EFSearchRepository(connectionString));

            var reviewRepository = new EFReviewRepository(connectionString);
            container.RegisterInstance<IReviewRepository>(reviewRepository);


            var indexingProgress = new ProgressRecord(1, "Indexing Progress", "Progress:");
            var observer = new ProgressObserver(this, indexingProgress);
            container.RegisterInstance<ISystemObserver>(observer);

            return container;
        }
        /// <summary>Registers the type mappings with the Unity container.</summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to 
        /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            #region Common Settings for Web and Services

            // this section is common for both web application and services application and should be kept identical
            var isAzure = AzureCommonHelper.IsAzureEnvironment();

            container.RegisterType<IKnownSerializationTypes, CatalogEntityFactory>("catalog",
                                                                                   new ContainerControlledLifetimeManager
                                                                                       ());

            //container.RegisterType<IKnowSerializationTypes, OrderEntityFactory>("order", new ContainerControlledLifetimeManager(), null);
            container.RegisterInstance<IConsumerFactory>(new DomainAssemblyScannerConsumerFactory(container));
            container.RegisterType<IKnownSerializationTypes, DomainAssemblyScannerConsumerFactory>("scaned",
                                                                                                   new ContainerControlledLifetimeManager
                                                                                                       (),
                                                                                                   new InjectionConstructor
                                                                                                       (container));



            container.RegisterType<IConsumerFactory, DomainAssemblyScannerConsumerFactory>();
            container.RegisterType<ISystemObserver, NullSystemObserver>();
            container.RegisterType<IEngineProcess, SingleThreadConsumingProcess>();
            container.RegisterType<IMessageSerializer, DataContractMessageSerializer>();
            if (isAzure)
            {
                container.RegisterType<IQueueWriter, AzureQueueWriter>();
                container.RegisterType<IQueueReader, AzureQueueReader>();
            }
            else
            {
                container.RegisterType<IQueueWriter, InMemoryQueueWriter>();
                container.RegisterType<IQueueReader, InMemoryQueueReader>();
            }
            container.RegisterType<IMessageSender, DefaultMessageSender>(new ContainerControlledLifetimeManager());
            container.RegisterType<ICurrencyService, CurrencyService>(new ContainerControlledLifetimeManager());

            //container.RegisterType<ICacheProvider, InMemCachingProvider>();
            container.RegisterType<ICacheRepository, HttpCacheRepository>();
            container.RegisterType<IOperationLogRepository, OperationLogContext>(new PerRequestLifetimeManager());
            container.RegisterType<ILogOperationFactory, LogOperationFactory>();

            //Register Sequences
            container.RegisterType<ISequenceService, SequenceService>();

            //Register Template and Email service
            container.RegisterType<ITemplateService, TemplateService>();

            if (isAzure)
            {
                container.RegisterType<IEmailService, AzureEmailService>();
            }
            else
            {
                container.RegisterType<IEmailService, NetEmailService>();
            }

            container.RegisterType<ICatalogOutlineBuilder, CatalogOutlineBuilder>();

            #region Interceptors

            // register interceptors
            container.RegisterType<IInterceptor, AuditChangeInterceptor>("audit");
            container.RegisterType<IInterceptor, LogInterceptor>("log");
            container.RegisterType<IInterceptor, EntityEventInterceptor>("events");

            #endregion

            #region Marketing

            container.RegisterType<IMarketingRepository, EFMarketingRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IMarketingEntityFactory, MarketingEntityFactory>();
            container.RegisterType<IPromotionUsageProvider, PromotionUsageProvider>();
            container.RegisterType<IPromotionEntryPopulate, PromotionEntryPopulate>();

            //Register prmotion evaluation policies
            container.RegisterType<IEvaluationPolicy, GlobalExclusivityPolicy>("global");
            container.RegisterType<IEvaluationPolicy, GroupExclusivityPolicy>("group");
            container.RegisterType<IEvaluationPolicy, CartSubtotalRewardCombinePolicy>("cart");
            container.RegisterType<IEvaluationPolicy, ShipmentRewardCombinePolicy>("shipment");


            container.RegisterType<IPromotionEvaluator, DefaultPromotionEvaluator>();

            #endregion

            #region Search

            var searchConnection = new SearchConnection(ConnectionHelper.GetConnectionString("SearchConnectionString"));
            container.RegisterInstance<ISearchConnection>(searchConnection);
            container.RegisterType<ISearchService, SearchService>(new HierarchicalLifetimeManager());
            container.RegisterType<ISearchIndexController, SearchIndexController>();
            container.RegisterType<IBuildSettingsRepository, EFSearchRepository>(new PerRequestLifetimeManager());
            container.RegisterType<ISearchEntityFactory, SearchEntityFactory>(new ContainerControlledLifetimeManager());
            container.RegisterType<ISearchIndexBuilder, CatalogItemIndexBuilder>("catalogitem");

            // If provider specified as lucene, use lucene libraries, otherwise use default, which is elastic search
            if (string.Equals(searchConnection.Provider, SearchProviders.Lucene.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                // Lucene Search implementation
                container.RegisterType<ISearchProvider, LuceneSearchProvider>();
                container.RegisterType<ISearchQueryBuilder, LuceneSearchQueryBuilder>();
            }
            else
            {
                container.RegisterType<ISearchProvider, ElasticSearchProvider>();
                container.RegisterType<ISearchQueryBuilder, ElasticSearchQueryBuilder>();
            }
            #endregion

            #region Assets

            container.RegisterType<IAssetEntityFactory, AssetEntityFactory>();

            // using azure assets
            if (isAzure)
            {
                container.RegisterType<IAssetRepository, AzureBlobAssetRepository>();
                container.RegisterType<IBlobStorageProvider, AzureBlobAssetRepository>();
                container.RegisterType<IAssetUrl, AzureBlobAssetRepository>();
            }
            else
            {
                // using local storage assets
                container.RegisterType<IAssetRepository, FileSystemBlobAssetRepository>();
                container.RegisterType<IBlobStorageProvider, FileSystemBlobAssetRepository>();
                container.RegisterType<IAssetUrl, FileSystemAssetUrl>();
            }

            container.RegisterType<IAssetService, AssetService>();
            #endregion

            #region Catalog
            container.RegisterType<ICatalogEntityFactory, CatalogEntityFactory>(new ContainerControlledLifetimeManager());

            container.RegisterType<ICatalogRepository, EFCatalogRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IPricelistRepository, EFCatalogRepository>(new PerRequestLifetimeManager());
            container.RegisterType<ICatalogService, CatalogService>();
            container.RegisterType<IPriceListAssignmentEvaluator, PriceListAssignmentEvaluator>();
            container.RegisterType<IPriceListAssignmentEvaluationContext, PriceListAssignmentEvaluationContext>();

            container.RegisterType<IImportJobEntityFactory, ImportJobEntityFactory>(
                new ContainerControlledLifetimeManager());
            container.RegisterType<IImportRepository, EFImportingRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IImportService, ImportService>();
            #endregion

            #region Customer

            container.RegisterType<ICustomerEntityFactory, CustomerEntityFactory>(
                new ContainerControlledLifetimeManager());

            container.RegisterType<ICustomerRepository, EFCustomerRepository>(new PerRequestLifetimeManager());
            container.RegisterType<ICustomerSessionService, CustomerSessionService>();

            #endregion

            #region Inventory

            container.RegisterType<IInventoryEntityFactory, InventoryEntityFactory>(
                new ContainerControlledLifetimeManager());
            container.RegisterType<IInventoryRepository, EFInventoryRepository>(new PerRequestLifetimeManager());

            #endregion

            #region Order

            container.RegisterType<IOrderEntityFactory, OrderEntityFactory>(new ContainerControlledLifetimeManager());

            var activityProvider = WorkflowConfiguration.Instance.DefaultActivityProvider;
            var workflowService = new WFWorkflowService(activityProvider);
            container.RegisterInstance<IWorkflowService>(workflowService);
            container.RegisterType<IOrderStateController, OrderStateController>();

            container.RegisterType<IOrderRepository, EFOrderRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IShippingRepository, EFOrderRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IPaymentMethodRepository, EFOrderRepository>(new PerRequestLifetimeManager());
            container.RegisterType<ITaxRepository, EFOrderRepository>(new PerRequestLifetimeManager());

            container.RegisterType<ICountryRepository, EFOrderRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IOrderService, OrderService>();

            #endregion

            #region Review

            container.RegisterType<IReviewEntityFactory, ReviewEntityFactory>(new ContainerControlledLifetimeManager());

            container.RegisterType<IReviewRepository, EFReviewRepository>(new PerRequestLifetimeManager());

            #endregion

            #region Security

            container.RegisterType<ISecurityEntityFactory, SecurityEntityFactory>(
                new ContainerControlledLifetimeManager());
            container.RegisterType<ISecurityRepository, EFSecurityRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IUserSecurity, WebUserSecurity>();
            container.RegisterType<IAuthenticationService, AuthenticationService>();
            container.RegisterType<ISecurityService, SecurityService>();
            container.RegisterType<IOAuthWebSecurity, OAuthWebSecurityWrapper>();

            #endregion

            #region Store

            container.RegisterType<IStoreEntityFactory, StoreEntityFactory>(new ContainerControlledLifetimeManager());

            container.RegisterType<IStoreService, StoreService>();
            container.RegisterType<IStoreRepository, EFStoreRepository>(new PerRequestLifetimeManager());

            #endregion

            #region Reporting

            container.RegisterType<IReportingService, ReportingService>();
            #endregion

            #endregion

            #region MVC Helpers

            //container.RegisterType<MarketingHelper>();
            container.RegisterType<PriceListClient>();
            container.RegisterType<StoreClient>();
            container.RegisterType<CatalogClient>();
            container.RegisterType<UserClient>();
            container.RegisterType<ShippingClient>();
            container.RegisterType<PromotionClient>();
            container.RegisterType<DynamicContentClient>();
            container.RegisterType<CountryClient>();
            container.RegisterType<OrderClient>();
            container.RegisterType<DisplayTemplateClient>();
            container.RegisterType<SettingsClient>();
            container.RegisterType<SequencesClient>();
            container.RegisterType<SeoKeywordClient>(new PerRequestLifetimeManager());
            container.RegisterType<ReviewClient>();
            //container.RegisterType<IPaymentOption, CreditCardOption>("creditcard");

            #endregion

            #region DynamicContent

            container.RegisterType<IDynamicContentService, DynamicContentService>();
            container.RegisterType<IDynamicContentRepository, EFDynamicContentRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IDynamicContentEvaluator, DynamicContentEvaluator>();

            #endregion

            #region AppConfig

            container.RegisterType<IAppConfigRepository, EFAppConfigRepository>(new PerRequestLifetimeManager());
            container.RegisterType<IAppConfigEntityFactory, AppConfigEntityFactory>(new ContainerControlledLifetimeManager());

            #endregion

            #region DisplayTemplates

            container.RegisterType<IDisplayTemplatesService, DisplayTemplatesService>();
            container.RegisterType<IDisplayTemplateEvaluator, DisplayTemplateEvaluator>();

            #endregion

            #region Events

            // Register event listeners
            container.RegisterType<IEntityEventListener, OrderChangeEventListener>("order");
            container.RegisterType<IEntityEventListener, PublicReplyEventListener>("customer");
            container.RegisterType<IEntityEventListener, CaseChangeEventListener>("customer");
            container.RegisterType<IEntityEventContext, EntityEventContext>(new PerRequestLifetimeManager());

            #endregion

            #region Jobs

            container.RegisterType<GenerateSearchIndexWork>();
            container.RegisterType<ProcessOrderStatusWork>();
            container.RegisterType<ProcessSearchIndexWork>();

            #endregion

            #region OutputCache

            container.RegisterType<IKeyBuilder, KeyBuilder>(new PerRequestLifetimeManager());
            container.RegisterType<IKeyGenerator, KeyGenerator>(new PerRequestLifetimeManager());
            container.RegisterType<IDonutHoleFiller, DonutHoleFiller>(new PerRequestLifetimeManager());
            container.RegisterType<ICacheHeadersHelper, CacheHeadersHelper>(new PerRequestLifetimeManager());
            container.RegisterType<ICacheSettingsManager, CacheSettingsManager>(new PerRequestLifetimeManager());
            container.RegisterType<IReadWriteOutputCacheManager, OutputCacheManager>(new PerRequestLifetimeManager());
            container.RegisterInstance<IActionSettingsSerialiser>(new EncryptingActionSettingsSerialiser(new ActionSettingsSerialiser(), new Encryptor()));
            container.RegisterType<ICacheService, CacheService>();

            #endregion

            #region Globalization

            //For using database resources
            container.RegisterType<IElementRepository, DatabaseElementRepository>(new PerRequestLifetimeManager());
            //For using Local Resources
            //container.RegisterInstance<IElementRepository>(new CacheElementRepository(new XmlElementRepository()));

            #endregion

            container.RegisterInstance(container);
        }
        public void Configure(CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();

            Result = null; // sets result to InProgress
            try
            {
                var searchConnection = _confirmationViewModel.SearchConnection;
                // Update Search index

                // handle special case for lucene, resolve relative path to the actual folder
                if (searchConnection.Provider.Equals(
                    "lucene", StringComparison.OrdinalIgnoreCase) && searchConnection.DataSource.StartsWith("~/"))
                {
                    var dataSource = searchConnection.DataSource.Replace(
                        "~/", _confirmationViewModel.ProjectLocation + "\\");

                    searchConnection = new SearchConnection(dataSource, searchConnection.Scope, searchConnection.Provider);
                }

                new UpdateSearchIndex().Index(searchConnection, _confirmationViewModel.DatabaseConnectionString, null, true);
                ct.ThrowIfCancellationRequested();

                Result = OperationResult.Successful;
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
#if (DEBUG)
                MessageBox.Show(e.StackTrace);
#endif

                Message = string.Format("{0} {1}: {2}", Resources.SearchSettingsAction, Resources.Failed, e.ExpandExceptionMessage());
                Result = OperationResult.Failed;
                throw;
            }
        }
        private void OnConnectionStringChanges()
        {
            SearchConnection searchConnection;
            if (IsSearchProviderLucene)
            {
                searchConnection = new SearchConnection(LuceneFolderLocation, IndexScope, "lucene");
            }
            else
            {
                searchConnection = new SearchConnection(IndexesLocation, IndexScope);
            }

            _confirmationViewModel.SearchConnection = searchConnection;
        }
Example #16
0
        private void UpdateIndex(InstallModel model)
        {
            var searchConnection = new SearchConnection(ConnectionHelper.GetConnectionString("SearchConnectionString"));
            if (searchConnection.Provider.Equals(
                    SearchProviders.Lucene.ToString(), StringComparison.OrdinalIgnoreCase) && searchConnection.DataSource.StartsWith("~/"))
            {
                var dataSource = searchConnection.DataSource.Replace(
                    "~/", HttpRuntime.AppDomainAppPath + "\\");

                searchConnection = new SearchConnection(dataSource, searchConnection.Scope, searchConnection.Provider);
            }

            SendFriendlyMessage("Updating search index...");
            new UpdateSearchIndex().Index(searchConnection, model.ConnectionStringBuilder.ConnectionString, null, true);
        }
        public void Can_get_item_facets_lucene()
        {
            var scope = "default";
            var queryBuilder = new LuceneSearchQueryBuilder();
            var conn = new SearchConnection(_LuceneStorageDir, scope);
            var provider = new LuceneSearchProvider(queryBuilder, conn);
            Debug.WriteLine("Lucene connection: {0}", conn.ToString());

            if (Directory.Exists(_LuceneStorageDir))
            {
                Directory.Delete(_LuceneStorageDir, true);
            }

            SearchHelper.CreateSampleIndex(provider, scope);

            var criteria = new CatalogItemSearchCriteria
                               {
                                   SearchPhrase = "",
                                   IsFuzzySearch = true,
                                   Catalog = "goods",
                                   RecordsToRetrieve = 10,
                                   StartingRecord = 0,
                                   Currency = "USD",
                                   Pricelists = new[] { "default" }
                               };

            var filter = new AttributeFilter { Key = "Color" };
            filter.Values = new[]
                                {
                                    new AttributeFilterValue { Id = "red", Value = "red" },
                                    new AttributeFilterValue { Id = "blue", Value = "blue" },
                                    new AttributeFilterValue { Id = "black", Value = "black" }
                                };

            var rangefilter = new RangeFilter { Key = "size" };
            rangefilter.Values = new[]
                                     {
                                         new RangeFilterValue { Id = "0_to_5", Lower = "0", Upper = "5" },
                                         new RangeFilterValue { Id = "5_to_10", Lower = "5", Upper = "10" }
                                     };

            var priceRangefilter = new PriceRangeFilter { Currency = "usd" };
            priceRangefilter.Values = new[]
                                          {
                                              new RangeFilterValue { Id = "0_to_100", Lower = "0", Upper = "100" },
                                              new RangeFilterValue { Id = "100_to_700", Lower = "100", Upper = "700" }
                                          };

            criteria.Add(filter);
            criteria.Add(rangefilter);
            criteria.Add(priceRangefilter);

            var results = provider.Search(scope, criteria);

            Assert.True(results.DocCount == 4, String.Format("Returns {0} instead of 4", results.DocCount));

            var redCount = GetFacetCount(results, "Color", "red");
            Assert.True(redCount == 2, String.Format("Returns {0} facets of red instead of 2", redCount));

            var priceCount = GetFacetCount(results, "Price", "0_to_100");
            Assert.True(priceCount == 2, String.Format("Returns {0} facets of 0_to_100 prices instead of 2", priceCount));

            var priceCount2 = GetFacetCount(results, "Price", "100_to_700");
            Assert.True(priceCount2 == 2, String.Format("Returns {0} facets of 100_to_700 prices instead of 2", priceCount2));

            var sizeCount = GetFacetCount(results, "size", "0_to_5");
            Assert.True(sizeCount == 2, String.Format("Returns {0} facets of 0_to_5 size instead of 2", sizeCount));

            var sizeCount2 = GetFacetCount(results, "size", "5_to_10");
            Assert.True(sizeCount2 == 1, String.Format("Returns {0} facets of 5_to_10 size instead of 1", sizeCount2)); // only 1 result because upper bound is not included

            var outlineCount = results.Documents[0].Documents[0]["__outline"].Values.Count();
            Assert.True(outlineCount == 2, String.Format("Returns {0} outlines instead of 2", outlineCount));

            Directory.Delete(_LuceneStorageDir, true);
        }
        private static IUnityContainer BuildUnityContainer()
        {
            #region Common Settings for Web and Services
            // this section is common for both web application and services application and should be kept identical
            var container = new UnityContainer();

            container.RegisterType<IKnownSerializationTypes, CatalogEntityFactory>("catalog", new ContainerControlledLifetimeManager());
            //container.RegisterType<IKnowSerializationTypes, OrderEntityFactory>("order", new ContainerControlledLifetimeManager(), null);
            container.RegisterInstance<IConsumerFactory>(new DomainAssemblyScannerConsumerFactory(container));
            container.RegisterType<IKnownSerializationTypes, DomainAssemblyScannerConsumerFactory>("scaned", new ContainerControlledLifetimeManager(), new InjectionConstructor(container));
            container.RegisterType<IConsumerFactory, DomainAssemblyScannerConsumerFactory>();
            container.RegisterType<ISystemObserver, NullSystemObserver>();
            container.RegisterType<IEngineProcess, SingleThreadConsumingProcess>();
            container.RegisterType<IMessageSerializer, DataContractMessageSerializer>();
            container.RegisterType<IQueueWriter, AzureQueueWriter>();
            container.RegisterType<IQueueReader, AzureQueueReader>();
            container.RegisterType<IMessageSender, DefaultMessageSender>(new ContainerControlledLifetimeManager());
            container.RegisterType<ICurrencyService, CurrencyService>(new ContainerControlledLifetimeManager());

            //container.RegisterType<ICacheProvider, InMemCachingProvider>();
            container.RegisterType<ICacheRepository, HttpCacheRepository>();

            container.RegisterType<ILogOperationFactory, LogOperationFactory>();
            container.RegisterType<IOperationLogRepository, OperationLogContext>();

            #region Interceptors

            // register interceptors
            container.RegisterType<IInterceptor, AuditChangeInterceptor>("audit");
            //container.RegisterType<IInterceptor, LogInterceptor>("log");
            //container.RegisterType<IInterceptor, EntityEventInterceptor>("events");

            #endregion

            #region Marketing
            //Needed for RemoveExpiredPromotionReservations SystemJob
            container.RegisterType<IMarketingRepository, EFMarketingRepository>();
            container.RegisterType<IMarketingEntityFactory, MarketingEntityFactory>();
            //container.RegisterType<IPromotionUsageProvider, PromotionUsageProvider>();
            //container.RegisterType<IPromotionEntryPopulate, PromotionEntryPopulate>();
            //container.RegisterType<IDynamicContentRepository, EFDynamicContentRepository>();
            #endregion

            #region Search
            var connectionString = ConnectionHelper.GetConnectionString("SearchConnectionString");
            if (connectionString == null)
            {
                Logger.Error("connectionString is null");
            }

            var searchConnection = new SearchConnection(connectionString);
            container.RegisterInstance<ISearchConnection>(searchConnection);

            container.RegisterType<ISearchService, SearchService>(new HierarchicalLifetimeManager());
            container.RegisterType<ISearchIndexController, SearchIndexController>();
            container.RegisterType<IBuildSettingsRepository, EFSearchRepository>();
            container.RegisterType<ISearchEntityFactory, SearchEntityFactory>(new ContainerControlledLifetimeManager());
            container.RegisterType<ISearchIndexBuilder, CatalogItemIndexBuilder>("catalogitem");

            // If provider specified as lucene, use lucene libraries, otherwise use default, which is elastic search
            if (string.Equals(searchConnection.Provider, SearchProviders.Lucene.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                // Lucene Search implementation
                container.RegisterType<ISearchProvider, LuceneSearchProvider>();
                container.RegisterType<ISearchQueryBuilder, LuceneSearchQueryBuilder>();
            }
            else
            {
                container.RegisterType<ISearchProvider, ElasticSearchProvider>();
                container.RegisterType<ISearchQueryBuilder, ElasticSearchQueryBuilder>();
            }

            #endregion

            #region AppConfig
            container.RegisterType<IAppConfigEntityFactory, AppConfigEntityFactory>();
            container.RegisterType<IAppConfigRepository, EFAppConfigRepository>();
            #endregion

            #region Assets
            container.RegisterType<IAssetEntityFactory, AssetEntityFactory>();
            container.RegisterType<IAssetRepository, AzureBlobAssetRepository>();
            container.RegisterType<IBlobStorageProvider, AzureBlobAssetRepository>();
            container.RegisterType<IAssetService, AssetService>();
            #endregion

            #region Catalog
            container.RegisterType<ICatalogEntityFactory, CatalogEntityFactory>(new ContainerControlledLifetimeManager());

            container.RegisterType<ICatalogRepository, EFCatalogRepository>();
            container.RegisterType<ICatalogOutlineBuilder, CatalogOutlineBuilder>();
            container.RegisterType<IPricelistRepository, EFCatalogRepository>();
            container.RegisterType<ICatalogService, CatalogService>();
            container.RegisterType<IPriceListAssignmentEvaluator, PriceListAssignmentEvaluator>();
            container.RegisterType<IPriceListAssignmentEvaluationContext, PriceListAssignmentEvaluationContext>();

            container.RegisterType<IImportJobEntityFactory, ImportJobEntityFactory>(
                new ContainerControlledLifetimeManager());
            container.RegisterType<IImportRepository, EFImportingRepository>();
            container.RegisterType<IImportService, ImportService>();
            #endregion

            //#region Customer
            //container.RegisterType<ICustomerEntityFactory, CustomerEntityFactory>(new ContainerControlledLifetimeManager());

            //container.RegisterType<ICustomerRepository, EFCustomerRepository>();
            //#endregion

            //#region Inventory
            //container.RegisterType<IInventoryEntityFactory, InventoryEntityFactory>(new ContainerControlledLifetimeManager());
            //#endregion

            #region Order
            container.RegisterType<IOrderEntityFactory, OrderEntityFactory>(new ContainerControlledLifetimeManager());

            var activityProvider = WorkflowConfiguration.Instance.DefaultActivityProvider;
            var workflowService = new WFWorkflowService(activityProvider);
            container.RegisterInstance<IWorkflowService>(workflowService);
            container.RegisterType<IOrderStateController, OrderStateController>();

            container.RegisterType<IOrderRepository, EFOrderRepository>();
            container.RegisterType<IShippingRepository, EFOrderRepository>();
            container.RegisterType<IPaymentMethodRepository, EFOrderRepository>();
            container.RegisterType<ITaxRepository, EFOrderRepository>();

            container.RegisterType<ICountryRepository, EFOrderRepository>();
            container.RegisterType<IOrderService, OrderService>();
            #endregion

            #region Customer
            container.RegisterType<ICustomerEntityFactory, CustomerEntityFactory>(
     new ContainerControlledLifetimeManager());

            container.RegisterType<ICustomerRepository, EFCustomerRepository>();
            container.RegisterType<ICustomerSessionService, CustomerSessionService>();
            #endregion

            #region Review
            container.RegisterType<IReviewEntityFactory, ReviewEntityFactory>(new ContainerControlledLifetimeManager());
            container.RegisterType<IReviewRepository, EFReviewRepository>();
            #endregion

            #region Security
            container.RegisterType<ISecurityEntityFactory, SecurityEntityFactory>(new ContainerControlledLifetimeManager());

            //container.RegisterType<ISecurityService, SecurityService>();
            container.RegisterType<ISecurityRepository, EFSecurityRepository>();
            #endregion


            #region Store
            container.RegisterType<IStoreEntityFactory, StoreEntityFactory>(new ContainerControlledLifetimeManager());

            container.RegisterType<IStoreService, StoreService>();
            container.RegisterType<IStoreRepository, EFStoreRepository>();
            #endregion
            #endregion

            container.RegisterType<GenerateSearchIndexWork>();
            container.RegisterType<ProcessOrderStatusWork>();
            container.RegisterType<ProcessSearchIndexWork>();

            return container;
        }