Example #1
0
        void Inner()
        {
            using (var catalog = CatalogBuilder.GetCatalog())
                using (var container = new CompositionContainer(catalog))
                {
                    container.ComposeExportedValue <IConfig>(this);
                    container.ComposeExportedValue(this);
                    container.ComposeExportedValue(BuildEngine);
                    container.ComposeExportedValue(logger);
                    container.GetExportedValue <TargetPathFinder>().Execute("TargetPath");

                    logger.LogMessage(string.Format("\tTargetPath: {0}", TargetPath));


                    container.GetExportedValue <AssemblyResolver>().Execute();
                    container.GetExportedValue <ModuleReader>().Execute();

                    var fileChangedChecker = container.GetExportedValue <FileChangedChecker>();
                    if (!fileChangedChecker.ShouldStart())
                    {
                        return;
                    }

                    container.GetExportedValue <MsCoreReferenceFinder>().Execute();

                    container.GetExportedValue <AssemblyLoaderImporter>().Execute();
                    container.GetExportedValue <ModuleLoaderImporter>().Execute();


                    container.GetExportedValue <ProjectKeyReader>().Execute();
                    container.GetExportedValue <ModuleWriter>().Execute();
                }
        }
Example #2
0
        public void Can_query_item_by_linq_expression_tree()
        {
            var          categoryIds = new List <string>();
            var          repository  = GetRepository();
            const string catalogId   = "testCatalog";

            var catalogBuilder = CatalogBuilder.BuildCatalog(catalogId).WithCategory("category").WithProducts(20);

            for (int i = 0; i < 5; i++)
            {
                catalogBuilder = catalogBuilder.WithCategory("category " + i, "code-" + i);
            }
            var catalog = catalogBuilder.GetCatalog();
            var items   = catalogBuilder.GetItems();

            categoryIds.AddRange(catalog.CategoryBases.Select(x => x.CategoryId));

            repository.Add(catalog);
            foreach (var item in items)
            {
                repository.Add(item);
            }

            repository.UnitOfWork.Commit();
            RefreshRepository(ref repository);

            var query = repository.Items;
            // the expression is: expression = x => x.CatalogId == catalogId || x.CategoryId == categoryIds[0] || x.CategoryId == categoryIds[1] || ..
            // the query is: query = repository.Items.Where(item => item.CategoryItemRelations.Any(expression));
            var parameterCIR       = linq.Expression.Parameter(typeof(CategoryItemRelation), "x");
            var propertyCategoryId = linq.Expression.Property(parameterCIR, "CategoryId");

            linq.Expression condition = linq.Expression.Equal(linq.Expression.Property(parameterCIR, "CatalogId"), linq.Expression.Constant(catalogId));
            condition = categoryIds.Aggregate(condition, (current, id) => linq.Expression.OrElse(current, linq.Expression.Equal(propertyCategoryId, linq.Expression.Constant(id))));
            var expression = linq.Expression.Lambda <Func <CategoryItemRelation, bool> >(condition, parameterCIR);

            var methodAny = typeof(Enumerable).GetMethods(BindingFlags.Public | BindingFlags.Static)
                            .Where(x => x.Name == "Any")
                            .Single(mi => mi.GetParameters().Count() == 2)
                            .MakeGenericMethod(typeof(CategoryItemRelation));

            var parameterItem = linq.Expression.Parameter(typeof(Item), "item");

            query = query.Where(
                linq.Expression.Lambda <Func <Item, bool> >(
                    linq.Expression.Call(null, methodAny, new linq.Expression[]
            {
                linq.Expression.PropertyOrField(parameterItem, "CategoryItemRelations"), expression
            }),
                    new[] { parameterItem }));

            var result = query.ToList();

            Assert.NotNull(result);
            Assert.True(result.Count > 0);
        }
        public static void Initialise()
        {
            var catalog = new CatalogBuilder()
                              .ForAssembly(typeof(IComponentRegistrarMarker).Assembly)
                              .ForMvcAssembly(Assembly.GetExecutingAssembly())
                              .ForMvcAssembliesInDirectory(HttpRuntime.BinDirectory, "Leatn*.dll") // Won't work in Partial trust
                              .Build();

            var compositionContainer = new CompositionContainer(catalog);

            compositionContainer.GetExports<IComponentInitialiser>()
                .ForeEach(e => e.Value.Initialise());
        }
        public void Can_create_catalog_propertysets_and_acceptchanges()
        {
            var catalogBuilder = CatalogBuilder.BuildCatalog("Test catalog").WithCategory("category").WithProducts(2);
            var catalog        = catalogBuilder.GetCatalog() as Catalog;

            var     propertySet = catalog.PropertySets[0];
            dynamic copy        = propertySet.Local();

            copy.Name = "new name";
            copy.AcceptChanges();

            Assert.Equal(propertySet.Name, "new name");
        }
        public static void Register(IWindsorContainer container)
        {
            var catalog = new CatalogBuilder()
                              .ForAssembly(typeof(IComponentRegistrarMarker).Assembly)
                              .ForMvcAssembly(Assembly.GetExecutingAssembly())
                              .ForMvcAssembliesInDirectory(HttpRuntime.BinDirectory, "WhoCanHelpMe*.dll") // Won't work in Partial trust
                              .Build();

            var compositionContainer = new CompositionContainer(catalog);

            compositionContainer
                .GetExports<IComponentRegistrar>()
                .Each(e => e.Value.Register(container));
        }
        protected void CreateFullGraphCatalog(string catalogId, ref Item[] items)
        {
            var catalogBuilder = CatalogBuilder.BuildCatalog(catalogId).WithCategory("category").WithProducts(10);
            var catalog        = catalogBuilder.GetCatalog();

            items = catalogBuilder.GetItems();

            CatalogRepository.Add(catalog);

            foreach (var item in items)
            {
                CatalogRepository.Add(item);
            }

            CatalogRepository.UnitOfWork.Commit();
        }
Example #7
0
        public async Task <int> ScanAsync(CancellationToken token)
        {
            _folderSpecRepo.Flush();
            var settings = new DLabSettings();

            settings.Folders.AddRange(_folderSpecRepo.Folders);
            int result;

            var cb = new CatalogBuilder(settings);

            try
            {
                result = await Task.Run(() => cb.Build(_scanCancelToken.Token), token);
            }
            finally
            {
                CatalogFiles = cb.Contents;
            }
            return(result);
        }
Example #8
0
    private static Task GenerateCatalogDatabaseAsync(string platformsPath, string packagesPath, string usagesPath, string outputPath)
    {
        if (File.Exists(outputPath))
        {
            return(Task.CompletedTask);
        }

        File.Delete(outputPath);

        using var builder = CatalogBuilder.Create(outputPath);
        builder.Index(platformsPath);
        builder.Index(packagesPath);

        var usageFiles = GetUsageFiles(usagesPath);

        foreach (var(path, name, date) in usageFiles)
        {
            builder.IndexUsages(path, name, date);
        }

        return(Task.CompletedTask);
    }
        public void Can_add_update_delete_item_property_values()
        {
            var catalogName    = "Test catalog";
            var catalogBuilder = CatalogBuilder.BuildCatalog(catalogName).WithCategory("category").WithProducts(1);
            var catalog        = catalogBuilder.GetCatalog() as Catalog;
            var item           = catalogBuilder.GetItems()[0];

            var property1 = new Property {
                Name = "bool", PropertyValueType = PropertyValueType.Boolean.GetHashCode()
            };
            var property2 = new Property {
                Name = "datetime", PropertyValueType = PropertyValueType.DateTime.GetHashCode()
            };
            var property3 = new Property {
                Name = "Decimal", PropertyValueType = PropertyValueType.Decimal.GetHashCode()
            };
            var property4 = new Property {
                Name = "int", PropertyValueType = PropertyValueType.Integer.GetHashCode()
            };
            var property5 = new Property {
                Name = "longstr", PropertyValueType = PropertyValueType.LongString.GetHashCode()
            };
            var property6 = new Property {
                Name = "shorttext", PropertyValueType = PropertyValueType.ShortString.GetHashCode()
            };

            var propertySet = catalog.PropertySets[0];

            propertySet.PropertySetProperties.Add(new PropertySetProperty {
                Property = property1
            });
            propertySet.PropertySetProperties.Add(new PropertySetProperty {
                Property = property2
            });
            propertySet.PropertySetProperties.Add(new PropertySetProperty {
                Property = property3
            });
            propertySet.PropertySetProperties.Add(new PropertySetProperty {
                Property = property4
            });
            propertySet.PropertySetProperties.Add(new PropertySetProperty {
                Property = property5
            });
            propertySet.PropertySetProperties.Add(new PropertySetProperty {
                Property = property6
            });
            propertySet.PropertySetProperties.ToList().ForEach(x =>
            {
                x.Property.IsRequired = true;
                x.Property.CatalogId  = catalogName;
            });

            var repositoryFactory = new DSRepositoryFactory <ICatalogRepository, DSCatalogClient, CatalogEntityFactory>(ServManager.GetUri(ServiceNameEnum.Catalog));

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                repository.Add(catalog);
                repository.Add(item);
                repository.UnitOfWork.Commit();
            }

            IRepositoryFactory <IPricelistRepository>           pricelistRepositoryFactory    = new DSRepositoryFactory <IPricelistRepository, DSCatalogClient, CatalogEntityFactory>(ServManager.GetUri(ServiceNameEnum.Catalog));
            IViewModelsFactory <IPropertyValueBaseViewModel>    propertyValueVmFactory        = new TestCatalogViewModelFactory <IPropertyValueBaseViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            IViewModelsFactory <IPriceViewModel>                priceVmFactory                = new TestCatalogViewModelFactory <IPriceViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            IViewModelsFactory <IItemAssetViewModel>            assetVmFactory                = new TestCatalogViewModelFactory <IItemAssetViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            IViewModelsFactory <IAssociationGroupEditViewModel> associationGroupEditVmFactory = new TestCatalogViewModelFactory <IAssociationGroupEditViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            IViewModelsFactory <IAssociationGroupViewModel>     associationGroupVmFactory     = new TestCatalogViewModelFactory <IAssociationGroupViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            IViewModelsFactory <IItemRelationViewModel>         itemRelationVmFactory         = new TestCatalogViewModelFactory <IItemRelationViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            IViewModelsFactory <IEditorialReviewViewModel>      reviewVmFactory               = new TestCatalogViewModelFactory <IEditorialReviewViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            IViewModelsFactory <ICategoryItemRelationViewModel> categoryVmFactory             = new TestCatalogViewModelFactory <ICategoryItemRelationViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            ICatalogEntityFactory  entityFactory = new CatalogEntityFactory();
            IAuthenticationContext authContext   = new TestAuthenticationContext();
            INavigationManager     navManager    = new TestNavigationManager();

            var itemViewModel = new ItemViewModel(null, null, repositoryFactory, pricelistRepositoryFactory, propertyValueVmFactory, priceVmFactory, assetVmFactory, associationGroupEditVmFactory, associationGroupVmFactory, itemRelationVmFactory, reviewVmFactory, categoryVmFactory, entityFactory, item, authContext, navManager);

            itemViewModel.InitializeForOpen();

            // property change should set IsModified to true
            itemViewModel.InnerItem.EndDate = DateTime.UtcNow;
            Assert.True(itemViewModel.IsModified);

            Assert.False(itemViewModel.PropertyValueEditCommand.CanExecute(null));
            Assert.True(itemViewModel.PropertyValueEditCommand.CanExecute(itemViewModel.PropertiesAndValues[0]));

            itemViewModel.CommonConfirmRequest.Raised += EditValueSetConfirmation;

            foreach (var propItem in itemViewModel.PropertiesAndValues)
            {
                itemViewModel.PropertyValueEditCommand.Execute(propItem);
            }

            itemViewModel.SaveChangesCommand.Execute(null);
            Thread.Sleep(1000);            // waiting for SaveChangesCommand to finish in background thread

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                var itemFromDb = repository.Items.Expand(x => x.ItemPropertyValues).Single();

                Assert.True(itemFromDb.ItemPropertyValues.Count > 0);
                Assert.Equal(itemViewModel.PropertiesAndValues.Count, itemFromDb.ItemPropertyValues.Count);
            }

            // test if values are saved when updated in UI
            DecimalValue = 123123m;
            var valueToEdit =
                itemViewModel.PropertiesAndValues.First(x => x.Property.PropertyValueType == PropertyValueType.Decimal.GetHashCode());

            itemViewModel.PropertyValueEditCommand.Execute(valueToEdit);

            LongTextValue = "other long text";
            valueToEdit   = itemViewModel.PropertiesAndValues.First(x => x.Property.PropertyValueType == PropertyValueType.LongString.GetHashCode());
            itemViewModel.PropertyValueEditCommand.Execute(valueToEdit);

            itemViewModel.SaveChangesCommand.Execute(null);
            Thread.Sleep(1000);            // waiting for SaveChangesCommand to finish in background thread

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                var itemFromDb = repository.Items.Expand(x => x.ItemPropertyValues).Single();

                Assert.Equal(DecimalValue, itemFromDb.ItemPropertyValues.First(x => x.ValueType == PropertyValueType.Decimal.GetHashCode()).DecimalValue);
                Assert.Equal(LongTextValue, itemFromDb.ItemPropertyValues.First(x => x.ValueType == PropertyValueType.LongString.GetHashCode()).LongTextValue);
            }

            // check if item can be saved without required property value
            var valueToDelete =
                itemViewModel.PropertiesAndValues.First(x => x.Property.PropertyValueType == PropertyValueType.Decimal.GetHashCode());

            itemViewModel.PropertyValueDeleteCommand.Execute(valueToDelete);

            itemViewModel.SaveChangesCommand.CanExecute(null);
            Thread.Sleep(1000);            // waiting for SaveChangesCommand to finish in background thread

            //Assert True as the last Save command execution failed as the validation failed
            Assert.True(itemViewModel.IsModified);
        }
        public void Can_create_categoryviewmodel_in_wizardmode()
        {
            var repositoryFactory =
                new DSRepositoryFactory <ICatalogRepository, DSCatalogClient, CatalogEntityFactory>(ServManager.GetUri(ServiceNameEnum.Catalog));

            const string catalogId      = "testcatalog";
            var          catalogBuilder = CatalogBuilder.BuildCatalog(catalogId);
            var          catalog        = catalogBuilder.GetCatalog() as Catalog;

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                repository.Add(catalog);
                repository.UnitOfWork.Commit();
            }

            var propertiesVmFactory = new TestCatalogViewModelFactory <ICategoryPropertiesStepViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            var overviewVmFactory   = new TestCatalogViewModelFactory <ICategoryOverviewStepViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));

            //create item using entity factory
            var entityFactory = new CatalogEntityFactory();
            var item          = entityFactory.CreateEntity <Category>();

            item.CatalogId = catalogId;
            item.Catalog   = catalog;

            var createViewModel   = new CreateCategoryViewModel(propertiesVmFactory, overviewVmFactory, item);
            var overviewViewModel = createViewModel.AllRegisteredSteps[0] as CategoryViewModel;

            overviewViewModel.InitializeForOpen();
            var propertyValuesViewModel = createViewModel.AllRegisteredSteps[1] as CategoryViewModel;

            propertyValuesViewModel.InitializeForOpen();

            //check the default values in stepViewModel
            Assert.False(createViewModel.AllRegisteredSteps[0].IsValid);
            Assert.True(createViewModel.AllRegisteredSteps[1].IsValid);

            // step 1
            //fill the properties for the first step
            overviewViewModel.InnerItem.Name = "TestName";
            overviewViewModel.InnerItem.Code = "TestCode";
            var propertySet = overviewViewModel.AvailableCategoryTypes.First();

            overviewViewModel.InnerItem.PropertySet   = propertySet;
            overviewViewModel.InnerItem.PropertySetId = propertySet.PropertySetId;

            Assert.True(createViewModel.AllRegisteredSteps[0].IsValid);

            // step 2
            //fill the values for the property values step
            propertyValuesViewModel.PropertiesAndValues[0].Value = new CategoryPropertyValue()
            {
                ShortTextValue = "short text",
                Name           = propertyValuesViewModel.PropertiesAndValues[0].Property.Name,
                ValueType      = propertyValuesViewModel.PropertiesAndValues[0].Property.PropertyValueType
            };
            propertyValuesViewModel.InnerItem.CategoryPropertyValues.Add((CategoryPropertyValue)propertyValuesViewModel.PropertiesAndValues[0].Value);

            Assert.True(createViewModel.AllRegisteredSteps[1].IsValid);

            // final actions: save
            propertyValuesViewModel.InnerItem.Catalog = null;
            createViewModel.PrepareAndSave();

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                var itemFromDb = repository.Categories.Where(s => s.CategoryId == item.CategoryId).OfType <Category>().ExpandAll().SingleOrDefault();

                Assert.NotNull(itemFromDb);
                Assert.True(itemFromDb.Name == "TestName");
                Assert.True(itemFromDb.CategoryPropertyValues.Any(x => x.ShortTextValue == "short text"));
            }
        }