예제 #1
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Condition.Requires(entityView).IsNotNull($"{this.Name}: The argument cannot be null");;

            if (string.IsNullOrEmpty(entityView.EntityId))
            {
                return(await Task.FromResult(entityView));
            }

            var entity = await _viewCommander.Command <GetSettingCommand>().Process(context.CommerceContext, entityView.EntityId);

            if (entity == null)
            {
                return(entityView);
            }

            if (!string.IsNullOrEmpty(entityView.Action))
            {
                return(entityView);
            }

            var entityViewArgument = _viewCommander.CurrentEntityViewArgument(context.CommerceContext);

            var pluginPolicy = context.GetPolicy <PluginPolicy>();

            entityView.UiHint = "Flat";
            entityView.Icon   = pluginPolicy.Icon;

            var name = entityView.EntityId;

            try
            {
                entityViewArgument.Entity = entity;
                this.AddBasicData(entityView, context.CommerceContext, entity);
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }
예제 #2
0
        public async override Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Condition.Requires(entityView).IsNotNull($"{this.Name}: The argument cannot be null");;

            if (string.IsNullOrEmpty(entityView.EntityId))
            {
                return(await Task.FromResult(entityView));
            }

            var entity = await _viewCommander.Command <GetSettingCommand>().Process(context.CommerceContext, entityView.EntityId);

            if (entity == null)
            {
                return(entityView);
            }


            if (!string.IsNullOrEmpty(entityView.Action))
            {
                return(entityView);
            }

            var policies = _viewCommander.Command <PolicyCollectionCommand>().Process(context.CommerceContext);

            foreach (var policy in policies)
            {
                string viewName = policy.GetViewName();

                try
                {
                    var policyFromSetting = entity.EntityPolicies.FirstOrDefault(element => element.GetType().FullName.Equals(policy.FullName));
                    if (policyFromSetting == null)
                    {
                        policyFromSetting = Activator.CreateInstance(policy) as Policy;
                    }

                    var importerSettingView = new EntityView
                    {
                        EntityId    = string.Empty,
                        ItemId      = entity.Id,
                        DisplayName = viewName,
                        Name        = viewName
                    };

                    foreach (var property in policyFromSetting.GetType().GetProperties())
                    {
                        var editorSetting = property.GetCustomAttribute <EditorSettingAttribute>();
                        if (editorSetting == null)
                        {
                            continue;
                        }

                        object value      = property.GetValue(policyFromSetting);
                        string valueToUse = string.Empty;
                        if (value is IList <string> )
                        {
                            valueToUse = string.Join("|", value as IList <string>);
                        }
                        else
                        {
                            valueToUse = value?.ToString() ?? string.Empty;
                        }

                        importerSettingView.Properties
                        .Add(new ViewProperty {
                            Name = editorSetting.DisplayName, RawValue = valueToUse
                        });
                    }

                    entityView.ChildViews.Add(importerSettingView);
                }
                catch (Exception ex)
                {
                    context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
                }
            }

            return(entityView);
        }
예제 #3
0
        public async Task <EntityView> ExecuteRun <T>(EntityView entityView, CommercePipelineExecutionContext context, string viewName) where T : Policy
        {
            Condition.Requires(entityView).IsNotNull($"{this.Name}: The argument cannot be null");;

            if (string.IsNullOrEmpty(entityView.EntityId))
            {
                return(await Task.FromResult(entityView));
            }

            var entity = await _viewCommander.Command <GetSettingCommand>().Process(context.CommerceContext, entityView.EntityId);

            if (entity == null)
            {
                return(entityView);
            }


            if (!string.IsNullOrEmpty(entityView.Action))
            {
                return(entityView);
            }

            try
            {
                var importerSetting = entity.GetPolicy <T>();

                var importerSettingView = new EntityView
                {
                    EntityId    = string.Empty,
                    ItemId      = entity.Id,
                    DisplayName = viewName,
                    Name        = viewName
                };

                foreach (var property in importerSetting.GetType().GetProperties())
                {
                    var editorSetting = property.GetCustomAttribute <EditorSettingAttribute>();
                    if (editorSetting == null)
                    {
                        continue;
                    }

                    object value      = property.GetValue(importerSetting);
                    string valueToUse = string.Empty;
                    if (value is IList <string> )
                    {
                        valueToUse = string.Join("|", value as IList <string>);
                    }
                    else
                    {
                        valueToUse = value?.ToString() ?? string.Empty;
                    }

                    importerSettingView.Properties
                    .Add(new ViewProperty {
                        Name = editorSetting.DisplayName, RawValue = valueToUse
                    });
                }

                entityView.ChildViews.Add(importerSettingView);
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }