Example #1
0
 public ResolveComponentLocalizationMapperArgument(ImportEntityArgument importEntityArgument, CommerceEntity commerceEntity, Component component, ILanguageEntity languageEntity, IEntity sourceComponent)
 {
     ImportEntityArgument = importEntityArgument;
     LanguageEntity       = languageEntity;
     CommerceEntity       = commerceEntity;
     Component            = component;
     SourceComponent      = sourceComponent;
 }
Example #2
0
        public virtual IList <LocalizablePropertyValues> Map(ILanguageEntity languageEntity, IList <LocalizablePropertyValues> entityLocalizableProperties)
        {
            Type t = typeof(TCommerceEntity);

            var commerceEntity = Activator.CreateInstance(t) as TCommerceEntity;

            ILanguageEntity <TSourceEntity> l = languageEntity as ILanguageEntity <TSourceEntity>;

            if (l == null)
            {
                Context.Abort(Context.CommerceContext.AddMessage(Context.GetPolicy <KnownResultCodes>().Error, "LanguageEntityMissing", null, "Language entity cannot be null").Result, Context);
            }
            else
            {
                MapLocalizeValues(l.Entity, commerceEntity);

                if (entityLocalizableProperties == null)
                {
                    entityLocalizableProperties = LocalizablePropertyListManager.GetEntityProperties(t, Context);
                    entityLocalizableProperties = entityLocalizableProperties?.Clone();
                }

                if (entityLocalizableProperties == null || !entityLocalizableProperties.Any())
                {
                    return(new List <LocalizablePropertyValues>());
                }

                var properties = TypePropertyListManager.GetProperties(t);
                foreach (var localizablePropertyValues in entityLocalizableProperties)
                {
                    if (!string.IsNullOrEmpty(localizablePropertyValues.PropertyName))
                    {
                        var propertyInfo = properties.FirstOrDefault(x =>
                                                                     x.Name.Equals(localizablePropertyValues.PropertyName, StringComparison.OrdinalIgnoreCase));
                        if (propertyInfo != null)
                        {
                            var propertyValue = propertyInfo.GetValue(commerceEntity);
                            var parameter     = localizablePropertyValues.Parameters.FirstOrDefault(x =>
                                                                                                    x.Key.Equals(languageEntity.Language, StringComparison.OrdinalIgnoreCase));

                            if (parameter == null)
                            {
                                parameter = new Parameter {
                                    Key = languageEntity.Language, Value = null
                                };
                                localizablePropertyValues.Parameters.Add(parameter);
                            }

                            parameter.Value = propertyValue;
                        }
                    }
                }
            }

            return(entityLocalizableProperties);
        }
Example #3
0
        public override IList <IEntity> GetVariants(ILanguageEntity languageEntity)
        {
            var languages = GetLanguages();

            if (languages != null &&
                languages.Any())
            {
                var matchedLanguage = languages.FirstOrDefault(x =>
                                                               x.Language.Equals(languageEntity.Language, StringComparison.OrdinalIgnoreCase));
                if (matchedLanguage != null)
                {
                    return(GetVariants(languageEntity.GetEntity()));
                }
            }

            return(new List <IEntity>());
        }
Example #4
0
        public override bool HasVariants(ILanguageEntity languageEntity)
        {
            var languages = GetLanguages();

            if (languages != null &&
                languages.Any())
            {
                var matchedLanguage = languages.FirstOrDefault(x =>
                                                               x.Language.Equals(languageEntity.Language, StringComparison.OrdinalIgnoreCase));
                if (matchedLanguage != null)
                {
                    var variants = GetVariants(languageEntity.GetEntity());
                    return(variants != null && variants.GetEnumerator().MoveNext());
                }
            }

            return(false);
        }
Example #5
0
 public ResolveComponentLocalizationMapperArgument(ImportEntityArgument importEntityArgument,
                                                   CommerceEntity commerceEntity, Component component, ILanguageEntity languageEntity)
     : this(importEntityArgument, commerceEntity, component, languageEntity, null)
 {
 }
Example #6
0
 public virtual IList <IEntity> GetVariants(ILanguageEntity languageEntity)
 {
     return(new List <IEntity>());
 }
Example #7
0
 public virtual bool HasVariants(ILanguageEntity languageEntity)
 {
     return(false);
 }
        public static IEntityLocalizationMapper GetEntityLocalizationMapper(this Mappings mappings, ILanguageEntity languageEntity, ImportEntityArgument importEntityArgument, CommerceCommander commerceCommander, CommercePipelineExecutionContext context)
        {
            var mapperType = mappings
                             .EntityMappings
                             .FirstOrDefault(x => x.Key.Equals(importEntityArgument.SourceEntityDetail.EntityType, StringComparison.OrdinalIgnoreCase));

            if (mapperType != null)
            {
                var t = Type.GetType(mapperType.ImportHandlerTypeName ?? mapperType.FullTypeName ?? mapperType.LocalizationFullTypeName);

                if (t != null)
                {
                    if (Activator.CreateInstance(t, languageEntity.GetEntity(), commerceCommander, context) is
                        IEntityLocalizationMapper mapper)
                    {
                        return(mapper);
                    }
                }
            }

            return(null);
        }
        public static IComponentLocalizationMapper GetComponentChildComponentLocalizationMapper(this Mappings mappings, CommerceEntity targetEntity, Component component, ILanguageEntity languageEntity, object sourceVariant, CommerceCommander commerceCommander, CommercePipelineExecutionContext context)
        {
            var metadataPolicy = component.GetComponentMetadataPolicy();
            var mapperType     = mappings
                                 .ItemVariationComponentMappings
                                 .FirstOrDefault(
                x => (metadataPolicy != null && !string.IsNullOrEmpty(metadataPolicy.MapperKey) && x.Key.Equals(metadataPolicy.MapperKey, StringComparison.OrdinalIgnoreCase)) ||
                x.Type.Equals(component.GetType().FullName, StringComparison.OrdinalIgnoreCase));

            if (mapperType != null)
            {
                var t = Type.GetType(mapperType.LocalizationFullTypeName ?? mapperType.FullTypeName);

                if (t != null)
                {
                    if (Activator.CreateInstance(t, languageEntity.GetEntity(), sourceVariant, targetEntity, component,
                                                 commerceCommander, context) is IComponentLocalizationMapper mapper)
                    {
                        return(mapper);
                    }
                }
            }

            return(null);
        }
        public static IComponentLocalizationMapper GetItemVariantComponentLocalizationMapper(this Mappings mappings, CommerceEntity targetEntity, Component component, ILanguageEntity languageEntity, object sourceVariant, CommerceCommander commerceCommander, CommercePipelineExecutionContext context)
        {
            var mapperType = mappings
                             .ItemVariationMappings
                             .FirstOrDefault();

            if (mapperType != null)
            {
                var t = Type.GetType(mapperType.LocalizationFullTypeName ?? mapperType.FullTypeName);

                if (t != null)
                {
                    if (Activator.CreateInstance(t, languageEntity.GetEntity(), sourceVariant, targetEntity, component, commerceCommander, context) is IComponentLocalizationMapper mapper)
                    {
                        return(mapper);
                    }
                }
            }

            return(null);
        }
        private async Task PerformEntityVariantLocalization(ImportLocalizeContentArgument arg,
                                                            CommercePipelineExecutionContext context, ILanguageEntity language, IList <LocalizableComponentPropertiesValues> componentsPropertiesList,
                                                            ItemVariationComponent itemVariationComponent, IEntity variant)
        {
            if (itemVariationComponent.ChildComponents != null &&
                itemVariationComponent.ChildComponents.Any())
            {
                foreach (var component in itemVariationComponent.ChildComponents)
                {
                    var mapper = await _commerceCommander.Pipeline <IResolveComponentLocalizationMapperPipeline>()
                                 .Run(new
                                      ResolveComponentLocalizationMapperArgument(arg.ImportEntityArgument, arg.CommerceEntity,
                                                                                 component, language, variant), context).ConfigureAwait(false);

                    if (mapper != null)
                    {
                        mapper.Execute(componentsPropertiesList, component, language);
                    }
                    else
                    {
                        await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().Warning, "ComponentChildComponentLocalizationMapperMissing", null, $"Component's child component localization mapper missing for componentType={component.GetType().FullName} (key={component.GetComponentMetadataPolicy().MapperKey}) not resolved.");
                    }
                }
            }
        }
        private async Task PerformEntityVariantsLocalization(ImportLocalizeContentArgument arg,
                                                             CommercePipelineExecutionContext context, ILanguageEntity language,
                                                             IList <LocalizableComponentPropertiesValues> componentsPropertiesList)
        {
            foreach (var variant in arg.ImportEntityArgument.ImportHandler.GetVariants(language))
            {
                var itemVariationComponent = arg.CommerceEntity.GetVariation(variant.Id);

                if (itemVariationComponent == null)
                {
                    continue;
                }

                var itemVariantComponentLocalizationMapper = await _commerceCommander
                                                             .Pipeline <IResolveComponentLocalizationMapperPipeline>()
                                                             .Run(new ResolveComponentLocalizationMapperArgument(arg.ImportEntityArgument, arg.CommerceEntity,
                                                                                                                 itemVariationComponent, language, variant), context).ConfigureAwait(false);

                if (itemVariantComponentLocalizationMapper != null)
                {
                    itemVariantComponentLocalizationMapper.Execute(componentsPropertiesList, itemVariationComponent,
                                                                   language);

                    await PerformEntityVariantLocalization(arg, context, language, componentsPropertiesList,
                                                           itemVariationComponent, variant).ConfigureAwait(false);
                }
                else
                {
                    await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().Warning, "ItemVariantComponentLocalizationMapperMissing", null, "Item variant component localization mapper instance for not resolved.");
                }
            }
        }
        private async Task <IList <LocalizablePropertyValues> > PerformEntityLocalization(ImportLocalizeContentArgument arg,
                                                                                          CommercePipelineExecutionContext context, ILanguageEntity language, IList <LocalizablePropertyValues> entityLocalizableProperties)
        {
            if (arg.ImportEntityArgument.ImportHandler is IEntityLocalizationMapper mapper)
            {
                entityLocalizableProperties = mapper.Map(language, entityLocalizableProperties);
            }
            else
            {
                var entityLocalizationMapper = await _commerceCommander
                                               .Pipeline <IResolveEntityLocalizationMapperPipeline>()
                                               .Run(new ResolveEntityLocalizationMapperArgument(arg.ImportEntityArgument, language),
                                                    context).ConfigureAwait(false);

                if (entityLocalizationMapper != null)
                {
                    entityLocalizableProperties = entityLocalizationMapper.Map(language, entityLocalizableProperties);
                }
                else
                {
                    await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().Warning, "EntityLocalizationMapperMissing", null, $"Entity Localization Mapper instance for entityType={arg.ImportEntityArgument.SourceEntityDetail.EntityType} not resolved.");
                }
            }

            return(entityLocalizableProperties);
        }
Example #14
0
        public static IList <LocalizableComponentPropertiesValues> Execute(this IComponentLocalizationMapper mapper, IList <LocalizableComponentPropertiesValues> componentPropertiesList, Component component, ILanguageEntity languageEntity)
        {
            if (mapper == null)
            {
                return(componentPropertiesList);
            }

            var componentProperties = componentPropertiesList.FirstOrDefault(x =>
                                                                             component.Id.Equals(x.Id, StringComparison.OrdinalIgnoreCase));

            componentProperties = mapper.Map(languageEntity, componentProperties);
            if (componentProperties != null)
            {
                componentProperties.Id = component.Id;
                if (!componentPropertiesList.Any(x =>
                                                 component.Id.Equals(x.Id, StringComparison.OrdinalIgnoreCase)))
                {
                    componentPropertiesList.Add(componentProperties);
                }
            }

            return(componentPropertiesList);
        }
        public virtual LocalizableComponentPropertiesValues Map(ILanguageEntity languageEntity, LocalizableComponentPropertiesValues localizableComponentPropertiesValues)
        {
            Type t = typeof(T);

            var component = Activator.CreateInstance(t) as T;

            MapLocalizeValues(component);

            if (localizableComponentPropertiesValues == null)
            {
                var entityComponentsLocalizableProperties =
                    LocalizablePropertyListManager.GetEntityComponentProperties(ComponentHandler.GetEntityType(),
                                                                                Context);

                if (entityComponentsLocalizableProperties == null || !entityComponentsLocalizableProperties.Any())
                {
                    return(null);
                }

                var path = GetLocalizableComponentPath(component);

                var componentProperties =
                    entityComponentsLocalizableProperties.FirstOrDefault(x =>
                                                                         x.Path.Equals(path, StringComparison.OrdinalIgnoreCase));

                if (componentProperties == null || !componentProperties.PropertyValues.Any())
                {
                    return(null);
                }

                localizableComponentPropertiesValues = componentProperties.Clone();
            }


            var properties = TypePropertyListManager.GetProperties(t);

            foreach (var localizablePropertyValues in localizableComponentPropertiesValues.PropertyValues)
            {
                if (!string.IsNullOrEmpty(localizablePropertyValues.PropertyName))
                {
                    var propertyInfo = properties.FirstOrDefault(x =>
                                                                 x.Name.Equals(localizablePropertyValues.PropertyName, StringComparison.OrdinalIgnoreCase));
                    if (propertyInfo != null)
                    {
                        var propertyValue = propertyInfo.GetValue(component);
                        var parameter     = localizablePropertyValues.Parameters.FirstOrDefault(x =>
                                                                                                x.Key.Equals(languageEntity.Language, StringComparison.OrdinalIgnoreCase));

                        if (parameter == null)
                        {
                            parameter = new Parameter {
                                Key = languageEntity.Language, Value = null
                            };
                            localizablePropertyValues.Parameters.Add(parameter);
                        }

                        parameter.Value = propertyValue;
                    }
                }
            }

            return(localizableComponentPropertiesValues);
        }
Example #16
0
 public ResolveEntityLocalizationMapperArgument(ImportEntityArgument importEntityArgument, ILanguageEntity languageEntity)
 {
     ImportEntityArgument = importEntityArgument;
     LanguageEntity       = languageEntity;
 }