예제 #1
0
        /// <summary>
        /// Creates a display field metadata for the specified reference field.
        /// </summary>
        /// <param name="parentField">
        /// The parent reference field.
        /// </param>
        /// <param name="itemType">
        /// The cross-reference item type.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property that represents the display field.
        /// </param>
        /// <param name="displayFieldMetadata">
        /// The created display field metadata.
        /// </param>
        /// <returns>
        /// <c>true</c> if the display field metadata is created successfully; otherwise, <c>false</c>.
        /// </returns>
        public static bool TryCreateDisplayField(IReferenceFieldMetadata parentField, Type itemType, string propertyName, out DisplayFieldMetadata displayFieldMetadata)
        {
            if (parentField == null)
                throw new ArgumentNullException("parentField");

            if (itemType == null)
                throw new ArgumentNullException("itemType");

            if (string.IsNullOrEmpty(propertyName))
                throw new ArgumentException(@"Property name is null or empty.", propertyName);

            displayFieldMetadata = null;

            var property = itemType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
            if (property == null)
            {
                return false;
            }

            var displayFieldAttribute = property.GetCustomAttribute<ReferenceDisplayFieldAttribute>(false);
            if (displayFieldAttribute == null)
            {
                return false;
            }

            if (string.IsNullOrEmpty(displayFieldAttribute.FullPath))
            {
                return false;
            }

            var joinFields = new List<IReferenceFieldMetadata>();
            var referencedProcess = parentField.ReferencedProcess;
            var fieldNames = displayFieldAttribute.FullPath.Split(new[] { "." }, StringSplitOptions.None);
            for (var i = 0; i < fieldNames.Length - 1; ++i)
            {
                IFieldMetadata field;
                if (!referencedProcess.TryGetField(fieldNames[i], out field))
                {
                    return false;
                }

                var joinField = field as IReferenceFieldMetadata;
                if (joinField == null)
                {
                    return false;
                }

                joinFields.Add(joinField);
                referencedProcess = joinField.ReferencedProcess;
            }

            IFieldMetadata displayField;
            if (!referencedProcess.TryGetField(fieldNames.Last(), out displayField))
            {
                return false;
            }

            displayFieldMetadata = new DisplayFieldMetadata(property.Name, displayField, joinFields);

            return true;
        }
예제 #2
0
        private static string FormatValue(DisplayFieldMetadata displayField, object value)
        {
            if (displayField.IsAggregated)
            {
                // Aggregated fields are formatted on SQL Server.
                return (string)value;
            }

            if (displayField.Field.ColumnType == ColumnTypes.Approval)
            {
                return FormatApprovalValue(value);
            }

            var dateTimeFieldMetadata = displayField.Field as DateTimeFieldMetadata;
            if (dateTimeFieldMetadata != null)
            {
                return FormatDateTimeValue(dateTimeFieldMetadata, value);
            }

            var booleanFieldMetadata = displayField.Field as BooleanFieldMetadata;
            if (booleanFieldMetadata != null)
            {
                return FormatBooleanValue(booleanFieldMetadata, value);
            }

            var numericFieldMetadata = displayField.Field as NumericFieldMetadata;
            if (numericFieldMetadata != null)
            {
                return FormatNumericValue(numericFieldMetadata, value);
            }

            return value != null ? value.ToString() : null;
        }
예제 #3
0
        private static FilterMemberValue CreateMemberValue(IReferenceItem item, DisplayFieldMetadata displayField, IList<DisplayFieldMetadata> displayFields)
        {
            IDictionary<string, object> details = null;

            if (displayFields.Count > 1)
            {
                details = new Dictionary<string, object>();

                foreach (var field in displayFields)
                {
                    var formattedValue = FormatValue(field, item.GetValueByPropertyName(field.Name));
                    if (formattedValue != null)
                    {
                        details[field.Name] = formattedValue;
                    }
                }
            }

            return new FilterMemberValue(FormatValue(displayField, item.GetValueByPropertyName(displayField.Name)), item.Id, details);
        }
예제 #4
0
        private IEnumerable<FilterMemberValue> GetReferenceFieldValues(
            IFieldMetadata referenceField,
            DisplayFieldMetadata displayField,
            IList<DisplayFieldMetadata> detailsFields)
        {
            using (new BypassPropertyCheckContext())
            {
                var items = DynamicTypeManager.GetReferenceList<IReferenceItem>(
                    referenceField.DeclaringProcess.Name,
                    referenceField.Name,
                    null,
                    null,
                    int.MaxValue,
                    0,
                    null);

                detailsFields = detailsFields.Where(CanIncludeInMemberDetails).ToArray();

                return items.OrderBy(x => x.GetValueByPropertyName(displayField.Name)).Select(x => CreateMemberValue(x, displayField, detailsFields)).ToList();
            }
        }
예제 #5
0
 private static FilterMemberDetailsFieldDefinition CreateDetailsFieldDefinition(DisplayFieldMetadata displayField)
 {
     return new FilterMemberDetailsFieldDefinition { DisplayName = displayField.DisplayName, ColumnName = displayField.Name };
 }
예제 #6
0
 private static bool CanIncludeInMemberDetails(DisplayFieldMetadata displayField)
 {
     return displayField.Field.ColumnType != ColumnTypes.Image;
 }