Exemple #1
0
        private List <IFieldTypeEditor> GetFieldEditors(string definitionName, string propertyName)
        {
            var fieldTypeEditors = new List <IFieldTypeEditor>();
            // drivers for the ContentField
            var drivers = DriversForField(definitionName);
            // delegate that will help us figure out the tables
            var membersContext = new DescribeMembersContext(
                (storageName, storageType, displayName, description) => {
                // get the correct field type editor
                if ((storageName == null && propertyName == null) ||
                    (storageName ?? string.Empty).Equals(propertyName ?? string.Empty))
                {
                    IFieldTypeEditor fieldTypeEditor = _fieldTypeEditors
                                                       .FirstOrDefault(x => x.CanHandle(storageType));
                    if (fieldTypeEditor != null)
                    {
                        fieldTypeEditors.Add(fieldTypeEditor);
                    }
                }
            });

            foreach (var driver in drivers)
            {
                driver.Describe(membersContext);
            }
            return(fieldTypeEditors);
        }
        public dynamic Render(PropertyContext context, ContentItem contentItem, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            var p = contentItem.Parts.FirstOrDefault( x => x.PartDefinition.Name == part.Name);

            if(p == null) {
                return String.Empty;
            }

            var f = p.Fields.FirstOrDefault(x => x.Name == field.Name);

            if(f == null) {
                return String.Empty;
            }

            object value = null;

            _contentFieldValueProviders.Invoke(provider => {
                var result = provider.GetValue(contentItem, f);
                if (result != null) {
                    value = result;
                }
            }, Logger);

            if (value == null) {
                value = f.Storage.Get<object>(storageName);
            }

            if (value == null) {
                return null;
            }

            // call specific formatter rendering
            return _propertyFormater.Format(storageType, value, context.State);
        }
Exemple #3
0
        public dynamic Render(PropertyContext context, ContentItem contentItem, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field)
        {
            var p = contentItem.Parts.FirstOrDefault(x => x.PartDefinition.Name == part.Name);

            if (p == null)
            {
                return(String.Empty);
            }

            var f = p.Fields.FirstOrDefault(x => x.Name == field.Name);

            if (f == null)
            {
                return(String.Empty);
            }

            var value = f.Storage.Get <object>(storageName);

            if (value == null)
            {
                return(null);
            }

            // call specific formatter rendering
            return(_propertyFormater.Format(storageType, value, context.State));
        }
Exemple #4
0
        public static QueryVersionScopeOptions GetQueryVersionScope(this IFieldTypeEditor editor, string value)
        {
            if (!Enum.TryParse(value, out QueryVersionScopeOptions versionScope))
            {
                versionScope = QueryVersionScopeOptions.Published;
            }

            return(versionScope);
        }
        public void ApplyFilter(FilterContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            var propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action<IHqlExpressionFactory> predicate = fieldTypeEditor.GetFilterPredicate(context.State);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService
            Action<IHqlExpressionFactory> andPredicate = x => x.And(y => y.Eq("PropertyName", propertyName), predicate);

            // apply where clause
            context.Query = context.Query.Where(relationship, andPredicate);
        }
        private void DescribeNumericFieldMemberContext(
            ContentPartFieldDefinition localField,
            ContentPartDefinition localPart,
            DescribeGroupByParameterFor descriptor,
            string storageName,
            LocalizedString description,
            LocalizedString displayName,
            IFieldTypeEditor fieldTypeEditor)
        {
            if (localField.FieldDefinition.Name != "NumericField")
            {
                throw new ArgumentException("localField is not an instance of DateTimeField");
            }

            //field.FieldDefinition.Name
            List <AggregateMethods> methods = new List <AggregateMethods>();

            methods.Add(AggregateMethods.Count);
            methods.Add(AggregateMethods.Sum);
            methods.Add(AggregateMethods.Average);
            methods.Add(AggregateMethods.Minimum);
            methods.Add(AggregateMethods.Maximum);

            Tuple <string, string, int>[] intervals = new Tuple <string, string, int>[] {
                new Tuple <string, string, int>("Without", "Without any interval", 1),
                new Tuple <string, string, int>("By10", "in intervals of 10", 10),
                new Tuple <string, string, int>("By100", "in intervals of 100", 100),
                new Tuple <string, string, int>("By1000", "in intervals of 1000", 1000),
                new Tuple <string, string, int>("By10000", "in intervals of 10000", 10000),
            };

            foreach (var interval in intervals)
            {
                string typeValue = string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}", localPart.Name, localField.Name, storageName, interval.Item1);

                LocalizedString name = interval.Item3 != 1 ?
                                       T("{0} ({1})", localField.DisplayName, interval.Item3.ToString(CultureInfo.InvariantCulture)) :
                                       T(localField.DisplayName);

                descriptor.Element(
                    type: typeValue,
                    name: name,
                    description: T("group the result by {0} values {1}", localField.DisplayName, interval.Item2),
                    run: (query, method) => { return(this.fieldAggregateQueryService.RunNumericAggregation(query, method, localField.Name, localPart.Name, interval.Item3)); },
                    aggregateMethods: methods,
                    display: context => fieldTypeEditor.DisplayFilter(localPart.Name.CamelFriendly() + "." + localField.DisplayName, storageName, context.State));
            }
        }
        public void ApplyFilter(FilterContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field)
        {
            var propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action <IHqlExpressionFactory> predicate = fieldTypeEditor.GetFilterPredicate(context.State);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService
            Action <IHqlExpressionFactory> andPredicate = x => x.And(y => y.Eq("PropertyName", propertyName), predicate);

            // apply where clause
            context.Query = context.Query.Where(relationship, andPredicate);
        }
Exemple #8
0
        public void Describe(DescribeFilterContext describe)
        {
            foreach (var part in _contentDefinitionManager.ListPartDefinitions())
            {
                if (!part.Fields.Any())
                {
                    continue;
                }

                var descriptor = describe.For(part.Name + "ContentFields", T("{0} Content Fields", part.Name.CamelFriendly()), T("Content Fields for {0}", part.Name.CamelFriendly()));

                foreach (var field in part.Fields)
                {
                    var localField = field;
                    var localPart  = part;
                    var drivers    = _contentFieldDrivers.Where(x => x.GetFieldInfo().Any(fi => fi.FieldTypeName == localField.FieldDefinition.Name)).ToList();

                    var membersContext = new DescribeMembersContext(
                        (storageName, storageType, displayName, description) => {
                        // look for a compatible field type editor
                        IConcreteFieldTypeEditor concreteFieldTypeEditor = _fieldTypeEditors.FirstOrDefault(x => x.CanHandle(localField.FieldDefinition.Name, storageType))
                                                                           ?? _fieldTypeEditors.FirstOrDefault(x => x.CanHandle(storageType));
                        IFieldTypeEditor fieldTypeEditor = concreteFieldTypeEditor;

                        if (fieldTypeEditor == null)
                        {
                            return;
                        }

                        descriptor.Element(
                            type: localPart.Name + "." + localField.Name + "." + storageName,
                            name: new LocalizedString(localField.DisplayName + (displayName != null ? ":" + displayName.Text : "")),
                            description: description ?? T("{0} property for {1}", storageName, localField.DisplayName),
                            filter: context => concreteFieldTypeEditor.ApplyFilter(context, storageName, storageType, localPart, localField),
                            display: context => fieldTypeEditor.DisplayFilter(localPart.Name.CamelFriendly() + "." + localField.DisplayName, storageName, context.State),
                            form: fieldTypeEditor.FormName);
                    });

                    foreach (var driver in drivers)
                    {
                        driver.Describe(membersContext);
                    }
                }
            }
        }
Exemple #9
0
        public void ApplyFilter(FilterContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field)
        {
            // The filter has to be applied only if there's an actual value (not null or empty) to filter with.
            if (context.State.Value != null && context.State.Value != "")
            {
                var propertyName = string.Join(".", part.Name, field.Name, storageName ?? "");

                // Use an alias with the generated property name, so that two filters on the same Field Type won't collide.
                var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

                // Generate the predicate based on the editor, which has been used.
                Action <IHqlExpressionFactory> predicate = fieldTypeEditor.GetFilterPredicate(context.State);
                // Combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService.
                Action <IHqlExpressionFactory> andPredicate = x => x.And(y => y.Eq("PropertyName", propertyName), predicate);

                // Apply where clause.
                context.Query = context.Query.Where(relationship, andPredicate);
            }
        }
Exemple #10
0
        public void Describe(DescribeFilterContext describe)
        {
            foreach (var part in _contentDefinitionManager.ListPartDefinitions())
            {
                if (!part.Fields.Any())
                {
                    continue;
                }

                var descriptor = describe.For(part.Name + "ContentFieldsNullSafe", T("{0} Content Fields (null-safe)", part.Name.CamelFriendly()), T("Content Fields for {0} (null-safe).", part.Name.CamelFriendly()));

                foreach (var field in part.Fields)
                {
                    var localField = field;
                    var localPart  = part;
                    var drivers    = _contentFieldDrivers.Where(x => x.GetFieldInfo().Any(fi => fi.FieldTypeName == localField.FieldDefinition.Name)).ToList();

                    var membersContext = new DescribeMembersContext((storageName, storageType, displayName, description) =>
                    {
                        // Look for a compatible field type editor.
                        IFieldTypeEditor fieldTypeEditor = _fieldTypeEditors.FirstOrDefault(x => x.CanHandle(storageType));

                        if (fieldTypeEditor == null)
                        {
                            return;
                        }

                        descriptor.Element(
                            type: localPart.Name + "." + localField.Name + "." + storageName,
                            name: new LocalizedString(localField.DisplayName + (displayName != null ? ":" + displayName.Text : "") + " (null-safe)"),
                            description: new LocalizedString(description != null ? description + " (null-safe)" : "No filter will be applied if the filter value is empty, so items indexed as null in the database won't be excluded from the result."),
                            filter: context => ApplyFilter(context, fieldTypeEditor, storageName, storageType, localPart, localField),
                            display: context => fieldTypeEditor.DisplayFilter(localPart.Name + "." + localField.DisplayName, storageName, context.State),
                            form: fieldTypeEditor.FormName);
                    });

                    foreach (var driver in drivers)
                    {
                        driver.Describe(membersContext);
                    }
                }
            }
        }
        public void ApplySortCriterion(SortCriterionContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            bool ascending = Convert.ToBoolean(context.State.Sort);
            var propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action<IHqlExpressionFactory> predicate = y => y.Eq("PropertyName", propertyName);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService

            // apply where clause
            context.Query = context.Query.Where(relationship, predicate);
            
            // apply sort
            context.Query = ascending 
                ? context.Query.OrderBy(relationship, x => x.Asc("Value")) 
                : context.Query.OrderBy(relationship, x => x.Desc("Value"));
        }
        public void ApplySortCriterion(SortCriterionContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field)
        {
            bool ascending    = (bool)context.State.Sort;
            var  propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action <IHqlExpressionFactory> predicate = y => y.Eq("PropertyName", propertyName);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService

            // apply where clause
            context.Query = context.Query.Where(relationship, predicate);

            // apply sort
            context.Query = ascending
                ? context.Query.OrderBy(relationship, x => x.Asc(context.GetSortColumnName()))
                : context.Query.OrderBy(relationship, x => x.Desc(context.GetSortColumnName()));
        }
        public void Describe(DescribeGroupByContext describe)
        {
            foreach (var part in _contentDefinitionManager.ListPartDefinitions())
            {
                if (!part.Fields.Any())
                {
                    continue;
                }

                var descriptor = describe.For(part.Name + "ContentFields", T("{0} Content Fields", part.Name.CamelFriendly()), T("Content Fields for {0}", part.Name.CamelFriendly()));

                foreach (var field in part.Fields)
                {
                    var localField = field;
                    var localPart  = part;
                    var drivers    = _contentFieldDrivers.Where(x => x.GetFieldInfo().Any(fi => fi.FieldTypeName == localField.FieldDefinition.Name)).ToList();

                    var membersContext = new DescribeMembersContext(
                        (storageName, storageType, displayName, description) =>
                    {
                        // look for a compatible field type editor
                        IFieldTypeEditor fieldTypeEditor = _fieldTypeEditors.FirstOrDefault(x => x.CanHandle(storageType));

                        if (fieldTypeEditor == null)
                        {
                            return;
                        }

                        if (localField.FieldDefinition.Name == "NumericField")
                        {
                            this.DescribeNumericFieldMemberContext(
                                localField: localField,
                                description: description,
                                storageName: storageName,
                                descriptor: descriptor,
                                displayName: displayName,
                                fieldTypeEditor: fieldTypeEditor,
                                localPart: localPart);
                        }
                        else if (localField.FieldDefinition.Name == "EnumerationField")
                        {
                            //field.FieldDefinition.Name
                            List <AggregateMethods> methods = new List <AggregateMethods>();
                            methods.Add(AggregateMethods.Count);

                            descriptor.Element(
                                type: localPart.Name + "." + localField.Name + "." + storageName,
                                name: T(localField.DisplayName),
                                description: T("group the result by {0} values", localField.DisplayName),
                                run: (query, method) => this.fieldAggregateQueryService.RunEnumerationAggregation(query, method, localField.Name, localPart.Name),
                                aggregateMethods: methods,
                                display: context => fieldTypeEditor.DisplayFilter(localPart.Name.CamelFriendly() + "." + localField.DisplayName, storageName, context.State));
                        }
                    });

                    foreach (var driver in drivers)
                    {
                        driver.Describe(membersContext);
                    }
                }
            }
        }
Exemple #14
0
 public FieldTypeEditorAdaptor(IFieldTypeEditor editor)
 {
     _editor = editor;
 }
 public FieldTypeEditorAdaptor(IFieldTypeEditor editor) {
     _editor = editor;
 }