コード例 #1
0
 public void OnAction(Action <T> act)
 {
     using (var dataContext = _dataSourceFactory.Create())
     {
         act(dataContext);
     }
 }
コード例 #2
0
        public async Task <Property[]> GetPropertiesAsync(BulkActionContext context)
        {
            var result      = new List <Property>();
            var propertyIds = new HashSet <string>();
            var dataSource  = _dataSourceFactory.Create(context);

            result.AddRange(GetStandardProperties());

            while (await dataSource.FetchAsync())
            {
                var productIds = dataSource.Items.Select(item => item.Id).ToArray();
                var products   = await _itemService.GetByIdsAsync(productIds, (ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemProperties).ToString());

                // using only product inherited properties from categories,
                // own product props (only from PropertyValues) are not set via bulk update action
                var newProperties = products.SelectMany(CollectionSelector())
                                    .Distinct(AnonymousComparer.Create <Property, string>(property => property.Id))
                                    .Where(property => !propertyIds.Contains(property.Id)).ToArray();

                propertyIds.AddRange(newProperties.Select(property => property.Id));
                result.AddRange(newProperties);
            }

            foreach (var property in result)
            {
                await FillOwnerName(property);
            }

            return(result.ToArray());
        }
        protected override async Task ProcessAsync(ModelConfiguration model, List <RefreshPlan> refreshPlans,
                                                   CancellationToken cancellationToken)
        {
            using (var server = await GetServerAsync())
            {
                try
                {
                    var database = GetDatabase(server, model.DatabaseName);

                    await _dataSourceFactory.Create(model.DataSource.Type)
                    .ProcessAsync(database, model, cancellationToken);

                    refreshPlans.ForEach(x =>
                    {
                        Logger.Info($"Processing table {x.Table}.");
                        var table = GetTable(database, x.Table);
                        x.Refresh.Refresh(table);
                    });

                    Logger.Info("Saving model changes.");
                    database.Model.SaveChanges(new SaveOptions {
                        MaxParallelism = model.MaxParallelism
                    });
                }
                finally
                {
                    server.Disconnect();
                }
            }
        }
コード例 #4
0
    public override async Task <IViewComponentResult> InvokeAsync(EntityFieldDefinition fieldDefinition, object value)
    {
        if (value is not IEnumerable <string> typedValue)
        {
            throw new ArgumentException($"ViewComponent parameter ${value} must be of type {nameof(IEnumerable<string>)}", nameof(value));
        }

        var metadata = fieldDefinition.Using <CrudAdminEntityFieldFeature>();

        if (!metadata.EditorProperties.TryGetValue("DataSource", out var dataSourceDefinition))
        {
            throw new ArgumentNullException("DataSource");
        }

        var dataSource = dataSourceFactory.Create(dataSourceDefinition);
        var data       = await dataSourceReader.ReadFrom(dataSource);

        return(View(new MultiSelectFieldEditorViewModel
        {
            Id = fieldDefinition.Property.Name,
            FieldName = fieldDefinition.Property.Name,
            Label = fieldDefinition.DisplayName,
            Value = typedValue,
            Options = data.Select(x => new DropDownOptionViewModel
            {
                Value = x.Key,
                Label = x.Value,
            }),
        }));
    }
コード例 #5
0
    public override async Task <IViewComponentResult> InvokeAsync(EntityFieldDefinition fieldDefinition, object value)
    {
        var metadata = fieldDefinition.Using <CrudAdminEntityFieldFeature>();

        if (!metadata.EditorProperties.TryGetValue("DataSource", out var dataSourceDefinition))
        {
            throw new ArgumentNullException("DataSource");
        }

        var dataSource = dataSourceFactory.Create(dataSourceDefinition);
        var data       = await dataSourceReader.ReadFrom(dataSource);

        return(View(new DropDownFieldEditorViewModel
        {
            Id = fieldDefinition.Property.Name,
            FieldName = fieldDefinition.Property.Name,
            Label = fieldDefinition.DisplayName,
            Value = value?.ToString() ?? string.Empty,
            Options = data.Select(x => new DropDownOptionViewModel
            {
                Value = x.Key,
                Label = x.Value,
            }),
        }));
    }
        public void WhenThePropertyIsConfigurationIndependent_ThenNoDimensionsAreProduced()
        {
            var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true);

            var parentEntity  = IEntityWithIdFactory.Create("ParentKey", "ParentKeyValue");
            var configuration = ProjectConfigurationFactory.Create("Alpha|Beta|Gamma", "A|B|C");
            var property      = IPropertyFactory.Create(
                dataSource: IDataSourceFactory.Create(hasConfigurationCondition: false));

            var results = ConfigurationDimensionDataProducer.CreateProjectConfigurationDimensions(parentEntity, configuration, property, properties);

            Assert.Empty(results);
        }
        public void WhenThePropertyIsConfigurationDependent_OneEntityIsCreatedPerDimension()
        {
            var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true);

            var parentEntity  = IEntityWithIdFactory.Create("ParentKey", "ParentKeyValue");
            var configuration = ProjectConfigurationFactory.Create("Alpha|Beta|Gamma", "A|B|C");
            var property      = IPropertyFactory.Create(
                dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true));

            var results = ConfigurationDimensionDataProducer.CreateProjectConfigurationDimensions(parentEntity, configuration, property, properties);

            // We can't guarantee an order for the dimensions, so just check that all the expected values are present.
            Assert.Contains(results, entity => entity is ConfigurationDimensionValue {
                Name: "Alpha", Value: "A"
            });
コード例 #8
0
 // Creates a ConfiguredProject with a given ProjectConfiguration, and a method to
 // call when a property is set in that configuration.
 private static ConfiguredProject CreateConfiguredProject(ProjectConfiguration configuration, Action <string, object?> setValueCallback)
 {
     return(ConfiguredProjectFactory.Create(
                projectConfiguration: configuration,
                services: ConfiguredProjectServicesFactory.Create(
                    IPropertyPagesCatalogProviderFactory.Create(new()
     {
         {
             "Project",
             IPropertyPagesCatalogFactory.Create(new Dictionary <string, ProjectSystem.Properties.IRule>()
             {
                 { "MyPage", IRuleFactory.CreateFromRule(new Rule
                     {
                         Name = "MyPage",
                         Properties = new()
                         {
                             new TestProperty
                             {
                                 Name = "MyProperty",
                                 DataSource = new() { HasConfigurationCondition = true }
                             },
                             new TestProperty
                             {
                                 Name = "MyOtherProperty",
                                 DataSource = new() { HasConfigurationCondition = true }
                             }
                         }
                     },
                                                         properties: new[]
                     {
                         IPropertyFactory.Create(
                             "MyProperty",
                             dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true),
                             setValue: v => setValueCallback("MyProperty", v)),
                         IPropertyFactory.Create(
                             "MyOtherProperty",
                             dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true),
                             setValue: v => setValueCallback("MyOtherProperty", v))
                     }) }
コード例 #9
0
        private async Task ProcessRefreshPlanAsync(ModelConfiguration model, RefreshPlan refreshPlan,
                                                   CancellationToken cancellationToken)
        {
            try
            {
                using (var server = await GetServerAsync())
                {
                    try
                    {
                        var database = GetDatabase(server, model.DatabaseName);

                        await _dataSourceFactory.Create(model.DataSource.Type)
                        .ProcessAsync(database, model, cancellationToken);

                        Logger.Info($"Processing table {refreshPlan.Table}.");

                        var table = GetTable(database, refreshPlan.Table);
                        refreshPlan.Refresh.Refresh(table);

                        Logger.Info($"Saving {refreshPlan.Table}.");
                        database.Model.SaveChanges(new SaveOptions {
                            MaxParallelism = model.MaxParallelism
                        });
                    }
                    finally
                    {
                        server.Disconnect();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                throw;
            }
        }
コード例 #10
0
        public async Task WhenDimensionsAreGiven_ThenThePropertyIsOnlySetInTheMatchingConfigurations()
        {
            var project = UnconfiguredProjectFactory.Create(
                fullPath: @"C:\alpha\beta\MyProject.csproj",
                configuredProject: ConfiguredProjectFactory.Create(
                    services: ConfiguredProjectServicesFactory.Create(
                        IPropertyPagesCatalogProviderFactory.Create(new()
            {
                {
                    "Project",
                    IPropertyPagesCatalogFactory.Create(new Dictionary <string, ProjectSystem.Properties.IRule>()
                    {
                        { "MyPage", IRuleFactory.Create(new Rule
                            {
                                Name       = "MyPage",
                                Properties = new()
                                {
                                    new TestProperty
                                    {
                                        Name       = "MyProperty",
                                        DataSource = new() { HasConfigurationCondition = true }
                                    }
                                }
                            }) }
                    })
                }
            }))));
            var projectConfigurations = GetConfigurations();

            var affectedConfigs = new List <string>();

            var queryCacheProvider = IProjectStateProviderFactory.Create(
                IProjectStateFactory.Create(
                    projectConfigurations,
                    bindToRule: (config, schemaName, context) => IRuleFactory.Create(
                        name: "MyPage",
                        properties: new[]
            {
                IPropertyFactory.Create(
                    "MyProperty",
                    dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true),
                    setValue: o => affectedConfigs.Add(config.Name))
            })));
            var targetDimensions = new List <(string dimension, string value)>
            {
                ("Configuration", "Release"),
                ("Platform", "x86")
            };

            var coreActionExecutor = new ProjectSetUIPropertyValueActionCore(
                queryCacheProvider,
                pageName: "MyPage",
                propertyName: "MyProperty",
                targetDimensions,
                prop => prop.SetValueAsync("new value"));

            await coreActionExecutor.OnBeforeExecutingBatchAsync(new[] { project });

            bool propertyUpdated = await coreActionExecutor.ExecuteAsync(project);

            coreActionExecutor.OnAfterExecutingBatch();

            Assert.True(propertyUpdated);
            Assert.Single(affectedConfigs);
            Assert.Contains("Release|x86", affectedConfigs);
        }
コード例 #11
0
        public async Task WhenNoDimensionsAreGiven_ThenThePropertyIsSetInAllConfigurations()
        {
            var project = UnconfiguredProjectFactory.Create(
                fullPath: @"C:\alpha\beta\MyProject.csproj",
                configuredProject: ConfiguredProjectFactory.Create(
                    services: ConfiguredProjectServicesFactory.Create(
                        IPropertyPagesCatalogProviderFactory.Create(new()
            {
                {
                    "Project",
                    IPropertyPagesCatalogFactory.Create(new Dictionary <string, ProjectSystem.Properties.IRule>()
                    {
                        { "MyPage", IRuleFactory.Create(new Rule
                            {
                                Name       = "MyPage",
                                Properties = new()
                                {
                                    new TestProperty
                                    {
                                        Name       = "MyProperty",
                                        DataSource = new() { HasConfigurationCondition = true }
                                    }
                                }
                            }) }
                    })
                }
            }))));

            var projectConfigurations = GetConfigurations();

            var affectedConfigs = new List <string>();

            var queryCacheProvider = IProjectStateProviderFactory.Create(
                IProjectStateFactory.Create(
                    projectConfigurations,
                    bindToRule: (config, schemaName, context) => IRuleFactory.Create(
                        name: "MyPage",
                        properties: new[]
            {
                IPropertyFactory.Create(
                    "MyProperty",
                    dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true),
                    setValue: o => affectedConfigs.Add(config.Name))
            })));
            var emptyTargetDimensions = Enumerable.Empty <(string dimension, string value)>();

            var coreActionExecutor = new ProjectSetUIPropertyValueActionCore(
                queryCacheProvider,
                pageName: "MyPage",
                propertyName: "MyProperty",
                emptyTargetDimensions,
                prop => prop.SetValueAsync("new value"));

            await coreActionExecutor.OnBeforeExecutingBatchAsync(new[] { project });

            bool propertyUpdated = await coreActionExecutor.ExecuteAsync(project);

            coreActionExecutor.OnAfterExecutingBatch();

            Assert.True(propertyUpdated);
            Assert.Equal(expected: 4, actual: affectedConfigs.Count);
            foreach (var configuration in projectConfigurations)
            {
                Assert.Contains(configuration.Name, affectedConfigs);
            }
        }
コード例 #12
0
ファイル: AbstractDevice.cs プロジェクト: teaserrr/HomeCore
        protected void AddDataSource(string dataId, IDataProvider dataProvider)
        {
            var dataSource = _dataSourceFactory.Create(GetDataSourceId(Id, dataId), dataProvider, _logger);

            _dataSources.Add(dataSource);
        }