Exemple #1
0
        protected virtual void IndexDynamicProperty(IndexDocument document, DynamicObjectProperty property)
        {
            var propertyName = property.Name?.ToLowerInvariant();

            if (!string.IsNullOrEmpty(propertyName))
            {
                var            isCollection = property.IsDictionary || property.IsArray;
                IList <object> values;

                if (!property.IsDictionary)
                {
                    values = property.Values.Where(x => x.Value != null)
                             .Select(x => x.Value)
                             .ToList();
                }
                else
                {
                    //add all locales in dictionary to searchIndex
                    values = property.Values.Select(x => x.Value)
                             .Cast <DynamicPropertyDictionaryItem>()
                             .Where(x => !string.IsNullOrEmpty(x.Name))
                             .Select(x => x.Name)
                             .ToList <object>();
                }

                if (values.Any())
                {
                    document.Add(new IndexDocumentField(propertyName, values)
                    {
                        IsRetrievable = true, IsFilterable = true, IsCollection = isCollection
                    });
                }
            }
        }
Exemple #2
0
        private static void SetFilteredBrowsingAttributes(Store store, AttributeFilter[] attributes)
        {
            var browsing = GetFilteredBrowsing(store) ?? new FilteredBrowsing();

            browsing.Attributes = attributes;
            var serializer = new XmlSerializer(typeof(FilteredBrowsing));
            var builder    = new StringBuilder();
            var writer     = new StringWriter(builder);

            serializer.Serialize(writer, browsing);
            var value = builder.ToString();

            var property = store.DynamicProperties.FirstOrDefault(p => p.Name == _filteredBrowsingPropertyName);

            if (property == null)
            {
                property = new DynamicObjectProperty {
                    Name = _filteredBrowsingPropertyName
                };
                store.DynamicProperties.Add(property);
            }

            property.Values = new List <DynamicPropertyObjectValue>(new[] { new DynamicPropertyObjectValue {
                                                                                Value = value
                                                                            } });
        }
Exemple #3
0
 protected virtual DynamicObjectProperty ToOrderModel(DynamicObjectProperty item)
 {
     return(new DynamicObjectProperty
     {
         Name = item.Name,
         IsDictionary = item.IsDictionary,
         ValueType = item.ValueType,
         Values = item.Values
     });
 }
        public static DynamicObjectProperty ToDynamicObjectProperty(this DynamicPropertyEntity entity, string objectId)
        {
            var retVal = new DynamicObjectProperty();

            retVal.InjectFrom(entity);
            retVal.ObjectId     = objectId;
            retVal.ValueType    = EnumUtility.SafeParse(entity.ValueType, DynamicPropertyValueType.Undefined);
            retVal.DisplayNames = entity.DisplayNames.Select(x => x.ToModel()).ToArray();
            retVal.Values       = entity.ObjectValues.Select(x => x.ToModel()).ToArray();
            return(retVal);
        }
Exemple #5
0
        public static DynamicPropertyEntity ToEntity(this DynamicObjectProperty model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var result = ((DynamicProperty)model).ToEntity();

            result.ObjectValues = new ObservableCollection <DynamicPropertyObjectValueEntity>(model.Values.Select(x => x.ToEntity(model)));

            return(result);
        }
        public static DynamicPropertyEntity ToEntity(this DynamicObjectProperty model, string objectId)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var result = model.ToEntity();

            result.DisplayNames = new NullCollection <DynamicPropertyNameEntity>();
            result.ObjectValues = new ObservableCollection <DynamicPropertyObjectValueEntity>(model.Values.Select(x => x.ToEntity(model, objectId)));

            return(result);
        }
        public static void AddDynamicProperties(IEnumerable <PropertyGridAttribute> attributes, DynamicObject dynamicObject)
        {
            if (attributes == null || dynamicObject == null)
            {
                return;
            }

            foreach (PropertyGridAttribute pga in attributes)
            {
                if (string.IsNullOrWhiteSpace(pga.Name))
                {
                    continue;
                }

                DynamicObjectProperty prop = dynamicObject.AddProperty(pga.Name, pga.Type, null);
                prop.SetValue(dynamicObject, pga.Value);
            }
        }
        protected virtual async Task SaveSerializedValue(string storeId, string serializedValue)
        {
            var store = await _storeService.GetByIdAsync(storeId);

            if (store != null)
            {
                var property = store.DynamicProperties.FirstOrDefault(p => p.Name == FilteredBrowsingPropertyName);
                if (property == null)
                {
                    property = new DynamicObjectProperty {
                        Name = FilteredBrowsingPropertyName
                    };
                    store.DynamicProperties.Add(property);
                }

                property.Values = new List <DynamicPropertyObjectValue>(new[] { new DynamicPropertyObjectValue {
                                                                                    Value = serializedValue
                                                                                } });

                await _storeService.SaveChangesAsync(new[] { store });
            }
        }
Exemple #9
0
        protected virtual void SetFilteredBrowsing(Store store, FilteredBrowsing browsing)
        {
            var builder = new StringBuilder();
            var writer  = new StringWriter(builder);

            _serializer.Serialize(writer, browsing);
            var value = builder.ToString();

            var property = store.DynamicProperties.FirstOrDefault(p => p.Name == FilteredBrowsingPropertyName);

            if (property == null)
            {
                property = new DynamicObjectProperty {
                    Name = FilteredBrowsingPropertyName
                };
                store.DynamicProperties.Add(property);
            }

            property.Values = new List <DynamicPropertyObjectValue>(new[] { new DynamicPropertyObjectValue {
                                                                                Value = value
                                                                            } });
        }
Exemple #10
0
        public async Task EvaluateUserGroupsAsync_HasDynamicGroups_GroupsReturned()
        {
            // Arrange
            var birthDate               = DateTime.UtcNow;
            var organizations           = new string[] { "Org1", "Org2" };
            var associatedOrganizations = new string[] { "Org3", "Org4" };
            var firstName               = "Test first name";
            var middleName              = "Test middle name";
            var lastName               = "Test last name";
            var fullName               = "Test full name";
            var salutation             = "Test salutation";
            var defaultLanguage        = "en-US";
            var timeZone               = "UTC";
            var taxPayerId             = "TesTaxPayerId";
            var preferredDelivery      = "PreferredDelivery";
            var preferredCommunication = "PreferredCommunication";

            var dynamicPropertis = new DynamicObjectProperty[]
            {
                new DynamicObjectProperty
                {
                    Values = new DynamicPropertyObjectValue[]
                    {
                        new DynamicPropertyObjectValue
                        {
                            Value     = "DynamicPropertyObjectValueTest",
                            ValueType = DynamicPropertyValueType.ShortText
                        },
                        new DynamicPropertyObjectValue
                        {
                            Value     = "DynamicPropertyObjectValueTest2",
                            ValueType = DynamicPropertyValueType.ShortText
                        }
                    }
                }
            };

            var evaluateContext = new UserGroupEvaluationContext()
            {
                Customer = new Contact
                {
                    Groups                  = new List <string>(),
                    DynamicProperties       = dynamicPropertis,
                    Organizations           = organizations,
                    AssociatedOrganizations = associatedOrganizations,
                    BirthDate               = birthDate,
                    FirstName               = firstName,
                    MiddleName              = middleName,
                    LastName                = lastName,
                    FullName                = fullName,
                    Salutation              = salutation,
                    DefaultLanguage         = defaultLanguage,
                    TimeZone                = timeZone,
                    TaxPayerId              = taxPayerId,
                    PreferredDelivery       = preferredDelivery,
                    PreferredCommunication  = preferredCommunication
                }
            };

            var expressionTree = new CustomerSegmentTree()
            {
                Children = new IConditionTree[]
                {
                    new CustomerSegmentConditionPropertyValues
                    {
                        Properties              = dynamicPropertis,
                        Organizations           = organizations,
                        AssociatedOrganizations = associatedOrganizations,
                        FirstName = firstName,
                        LastName  = lastName,
                        FullName  = fullName,
                        BirthDate = birthDate,
                    }
                }
            };

            var searchResult = new CustomerSegmentSearchResult
            {
                Results = new List <CustomerSegment>()
                {
                    new CustomerSegment
                    {
                        Id             = "CustomerSegmentId",
                        Name           = "Test Customer Segment Name",
                        UserGroup      = "Dynamic User Group",
                        ExpressionTree = expressionTree
                    }
                }
            };

            var searchService = new Mock <ICustomerSegmentSearchService>();

            searchService.Setup(x => x.SearchCustomerSegmentsAsync(It.IsAny <CustomerSegmentSearchCriteria>())).ReturnsAsync(searchResult);
            var evaluator = new UserGroupEvaluator(searchService.Object);

            // Act
            var evaluationResult = await evaluator.EvaluateUserGroupsAsync(evaluateContext);

            // Assert
            var expectedResult = searchResult.Results.Select(s => new UserGroupInfo
            {
                IsDynamic       = true,
                DynamicRuleId   = s.Id,
                DynamicRuleName = s.Name,
                UserGroup       = s.UserGroup
            });

            evaluationResult.Should().BeEquivalentTo(expectedResult);
        }
        public static DynamicPropertyObjectValueEntity ToEntity(this DynamicPropertyObjectValue propertyValue, DynamicObjectProperty property, string objectId)
        {
            var result = new DynamicPropertyObjectValueEntity
            {
                ObjectType = property.ObjectType,
                ObjectId   = property.ObjectId,
                ValueType  = property.ValueType.ToString()
            };

            result.InjectFrom(propertyValue);

            if (!string.IsNullOrEmpty(objectId))
            {
                result.ObjectId = objectId;
            }

            if (property.IsDictionary)
            {
                var item = propertyValue.Value as DynamicPropertyDictionaryItem;

                if (item == null)
                {
                    var jObject = propertyValue.Value as JObject;
                    if (jObject != null)
                    {
                        item = jObject.ToObject <DynamicPropertyDictionaryItem>();
                    }
                }

                if (item != null)
                {
                    result.DictionaryItemId = item.Id;
                }
            }
            else
            {
                switch (property.ValueType)
                {
                case DynamicPropertyValueType.Boolean:
                    result.BooleanValue = propertyValue.Value.ToNullable <Boolean>();
                    break;

                case DynamicPropertyValueType.DateTime:
                    result.DateTimeValue = propertyValue.Value.ToNullable <DateTime>();
                    break;

                case DynamicPropertyValueType.Decimal:
                    result.DecimalValue = propertyValue.Value.ToNullable <Decimal>();
                    break;

                case DynamicPropertyValueType.Integer:
                    result.IntegerValue = propertyValue.Value.ToNullable <Int32>();
                    break;

                case DynamicPropertyValueType.ShortText:
                    result.ShortTextValue = (string)propertyValue.Value;
                    break;

                default:
                    result.LongTextValue = (string)propertyValue.Value;
                    break;
                }
            }

            return(result);
        }
Exemple #12
0
 public CustomerSegmentExpressionTest()
 {
     UsualDynamicProperty = new DynamicObjectProperty
     {
         Name      = "Usual Property",
         ValueType = DynamicPropertyValueType.ShortText,
         Values    = new[]
         {
             new DynamicPropertyObjectValue
             {
                 Value = "Usual", ValueType = DynamicPropertyValueType.ShortText
             }
         }
     };
     MultiValueDynamicPropertyWithSingleValue = new DynamicObjectProperty
     {
         Name      = "Multivalue property",
         IsArray   = true,
         ValueType = DynamicPropertyValueType.ShortText,
         Values    = new []
         {
             new DynamicPropertyObjectValue
             {
                 Value = "Value1", ValueType = DynamicPropertyValueType.ShortText
             }
         }
     };
     MultiValueDynamicPropertyWithMultipleValues =
         (DynamicObjectProperty)MultiValueDynamicPropertyWithSingleValue.Clone();
     MultiValueDynamicPropertyWithMultipleValues.Values = MultiValueDynamicPropertyWithSingleValue.Values.Concat(new[]
     {
         new DynamicPropertyObjectValue {
             Value = "Value2", ValueType = DynamicPropertyValueType.ShortText
         }
     }).ToArray();
     MultiLanguageDynamicProperty = new DynamicObjectProperty
     {
         Name           = "Multilingual property",
         IsMultilingual = true,
         ValueType      = DynamicPropertyValueType.ShortText,
         Values         = new[]
         {
             new DynamicPropertyObjectValue
             {
                 Locale = "en-US", Value = "Value1", ValueType = DynamicPropertyValueType.ShortText
             },
             new DynamicPropertyObjectValue
             {
                 Locale = "fr-FR", Value = "Value1", ValueType = DynamicPropertyValueType.ShortText
             },
             new DynamicPropertyObjectValue
             {
                 Locale = "de-DE", Value = "Value2", ValueType = DynamicPropertyValueType.ShortText
             }
         }
     };
     MultiLanguageDynamicPropertyWithMultipleValues =
         (DynamicObjectProperty)MultiLanguageDynamicProperty.Clone();
     MultiLanguageDynamicPropertyWithMultipleValues.Values = MultiLanguageDynamicProperty.Values.Concat(new[]
     {
         new DynamicPropertyObjectValue
         {
             Locale = "en-US", Value = "Value3", ValueType = DynamicPropertyValueType.ShortText
         },
         new DynamicPropertyObjectValue
         {
             Locale = "fr-FR", Value = "Value4", ValueType = DynamicPropertyValueType.ShortText
         },
         new DynamicPropertyObjectValue
         {
             Locale = "de-DE", Value = "Value5", ValueType = DynamicPropertyValueType.ShortText
         }
     }).ToArray();
 }
        protected virtual void IndexDynamicProperty(IndexDocument document, DynamicProperty property, DynamicObjectProperty objectProperty)
        {
            var propertyName = property.Name?.ToLowerInvariant();

            if (!string.IsNullOrEmpty(propertyName))
            {
                IList <object> values       = null;
                var            isCollection = property.IsDictionary || property.IsArray;

                if (objectProperty != null)
                {
                    if (!objectProperty.IsDictionary)
                    {
                        values = objectProperty.Values.Where(x => x.Value != null)
                                 .Select(x => x.Value)
                                 .ToList();
                    }
                    else
                    {
                        //add all locales in dictionary to searchIndex
                        values = objectProperty.Values.Select(x => x.Value)
                                 .Cast <DynamicPropertyDictionaryItem>()
                                 .Where(x => !string.IsNullOrEmpty(x.Name))
                                 .Select(x => x.Name)
                                 .ToList <object>();
                    }
                }

                // Use default or empty value for the property in index to be able to filter by it
                if (values.IsNullOrEmpty())
                {
                    values = new[] { property.IsRequired
                        ? GetDynamicPropertyDefaultValue(property) ?? NoValueString
                        : NoValueString };
                }

                document.Add(new IndexDocumentField(propertyName, values)
                {
                    IsRetrievable = true, IsFilterable = true, IsCollection = isCollection
                });
            }
        }
Exemple #14
0
        public static DynamicPropertyObjectValueEntity ToEntity(this DynamicPropertyObjectValue propertyValue, DynamicObjectProperty property)
        {
            var result = new DynamicPropertyObjectValueEntity
            {
                ObjectType = property.ObjectType,
                ObjectId   = property.ObjectId,
                ValueType  = property.ValueType.ToString()
            };

            result.InjectFrom(propertyValue);

            if (property.IsDictionary)
            {
                var item = propertyValue.Value as DynamicPropertyDictionaryItem;

                if (item == null)
                {
                    var jObject = propertyValue.Value as JObject;
                    if (jObject != null)
                    {
                        item = jObject.ToObject <DynamicPropertyDictionaryItem>();
                    }
                }

                if (item != null)
                {
                    result.DictionaryItemId = item.Id;
                }
            }
            else
            {
                switch (property.ValueType)
                {
                case DynamicPropertyValueType.Boolean:
                    result.BooleanValue = Convert.ToBoolean(propertyValue.Value);
                    break;

                case DynamicPropertyValueType.DateTime:
                    result.DateTimeValue = Convert.ToDateTime(propertyValue.Value, CultureInfo.InvariantCulture);
                    break;

                case DynamicPropertyValueType.Decimal:
                    result.DecimalValue = Convert.ToDecimal(propertyValue.Value, CultureInfo.InvariantCulture);
                    break;

                case DynamicPropertyValueType.Integer:
                    result.IntegerValue = Convert.ToInt32(propertyValue.Value, CultureInfo.InvariantCulture);
                    break;

                case DynamicPropertyValueType.LongText:
                case DynamicPropertyValueType.Html:
                    result.LongTextValue = (string)propertyValue.Value;
                    break;

                default:
                    result.ShortTextValue = (string)propertyValue.Value;
                    break;
                }
            }

            return(result);
        }