Ejemplo n.º 1
0
		/// <summary>
		/// Gets the process fields.
		/// </summary>
		/// <param name="process">The process.</param>
		/// <returns></returns>
		public static IEnumerable<IFieldInfo> GetProcessFields(string process, IDynamicTypeManager dynamicTypeManager)
		{
			var itemType = dynamicTypeManager.GetEditableRootType(process);
			if (itemType == null)
				return null;

			var fields = AddFieldsForType(itemType);

			var baseEditProperty = itemType.GetProperty(Constants.BaseEditPropertyName);
			while (baseEditProperty != null)
			{
				fields.AddRange(AddFieldsForType(baseEditProperty.PropertyType));
				baseEditProperty = baseEditProperty.PropertyType.GetProperty(Constants.BaseEditPropertyName);
			}

			return fields;
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessMetadata"/> class.
        /// </summary>
        /// <param name="processName">
        /// The process name.
        /// </param>
        /// <param name="processMetadataRepository">
        /// The process metadata repository.
        /// </param>
        /// <param name="dynamicTypeManager">
        /// The dynamic type manager.
        /// </param>
        /// <exception cref="ArgumentException">
        /// The editable root type doesn't have a <see cref="ProcessInfoAttribute"/> attribute.
        /// </exception>
        public ProcessMetadata(string processName, IProcessMetadataRepository processMetadataRepository, IDynamicTypeManager dynamicTypeManager)
        {
            if (processMetadataRepository == null)
                throw new ArgumentNullException("processMetadataRepository");

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

            var editType = dynamicTypeManager.GetEditableRootType(processName);
            var infoType = dynamicTypeManager.GetInfoType(processName);

            _processInfo = editType.GetCustomAttribute<ProcessInfoAttribute>(false);
            if (_processInfo == null)
                throw new ArgumentException(@"ProcessInfo attribute not found.", "processName");

            _repository = processMetadataRepository;

            if (typeof(IHasParent).IsAssignableFrom(editType))
            {
                var baseEditProperty = editType.GetProperty(Constants.BaseEditPropertyName);

                if (baseEditProperty != null)
                {
                    _baseProcess = new Lazy<IProcessMetadata>(
                        () => Repository.GetProcessMetadata(baseEditProperty.PropertyType),
                        LazyThreadSafetyMode.PublicationOnly);
                }
            }

            var properties = editType.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            var fields = new List<IFieldMetadata>();

            foreach (var editProperty in properties)
            {
                if (!Attribute.IsDefined(editProperty, typeof(FieldTypeAttribute), false))
                {
                    continue;
                }

                if (Attribute.IsDefined(editProperty, typeof(LocalizedFieldAttribute), false))
                {
                    continue;
                }

                var infoProperty = infoType.GetProperty(editProperty.Name, BindingFlags.Public | BindingFlags.Instance);

                fields.Add(FieldMetadataFactory.CreateFieldMetadata(this, editProperty, infoProperty));
            }

            _fields = new ReadOnlyCollection<IFieldMetadata>(fields);

            foreach (var field in Fields)
            {
                _fieldMap[field.Name] = field;
            }

            var supportedLocalizations = new List<ILocalizationInfo>(editType.GetCustomAttributes<LocalizationInfoAttribute>(false));
            _supportedLocalizations = new ReadOnlyCollection<ILocalizationInfo>(supportedLocalizations);

            var states = new List<IStateMetadata>();

            if (Attribute.IsDefined(editType, typeof(SupportsStatesAttribute), false))
            {
                _supportsStates = true;
                states.AddRange(editType.GetCustomAttributes<StateInfoAttribute>(false).Select(x => new StateMetadata(x)).OrderBy(s => s.Id));
            }

            _states = new ReadOnlyCollection<IStateMetadata>(states);

            _hiddenFields = new HashSet<string>(dynamicTypeManager.GetHiddenFields(processName));
        }
 public void TestInit()
 {
     _dtm = Mock.Create<IDynamicTypeManager>(Behavior.Loose);
     Mock.Arrange(() => _dtm.GetEditableRootType(ReverseCrossReferenceProcessName)).Returns(typeof(RCRProcess));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the filter additional parameters.
        /// </summary>
        /// <param name="filters">The filters.</param>
        /// <param name="processSystemName">Name of the process system.</param>
        /// <param name="dynamicTypeManager">The dynamic type manager.</param>
        public static void LoadFilterAdditionalParameters(
            IEnumerable<FilterDescriptorDecorator> filters,
            string processSystemName,
            IDynamicTypeManager dynamicTypeManager)
        {
            var filterDescriptorDecorators = filters as IList<FilterDescriptorDecorator> ?? filters.ToList();
            if (dynamicTypeManager == null || filterDescriptorDecorators == null || !filterDescriptorDecorators.Any())
                return;

            var editType = dynamicTypeManager.GetEditableRootType(processSystemName);

            foreach (var filterDescriptor in filterDescriptorDecorators)
            {
                var filteringProcessEditType = GetFilteringProcessEditType(editType, filterDescriptor.ColumnName);
                if (filteringProcessEditType == null)
                {
                    continue;
                }

                var properties = filteringProcessEditType.GetAllPropertiesWithPaths();

                var propertyName = GetFilteredField(filterDescriptor.ColumnName);

                if (filterDescriptor.ColumnName == Constants.CurrentStateGuidColumnName)
                {
                    propertyName = Constants.CurrentStateColumnName;
                    filterDescriptor.ColumnName = ReplaceFilteredField(filterDescriptor.ColumnName, Constants.CurrentStateIdColumnName);
                }

                if (propertyName.EndsWith("Id", StringComparison.Ordinal))
                {
                    propertyName = propertyName.Substring(0, propertyName.Length - 2);
                }

                var property = properties.Where(x => x.Key.Name == propertyName).Select(x => x.Key).FirstOrDefault();
                if (property != null)
                {
                    var crAttribute = property.GetCustomAttribute<CrossRefFieldAttribute>(false);
                    if (crAttribute != null)
                    {
                        filterDescriptor.CrossRefProcessName = crAttribute.ReferenceTableName;
                        filterDescriptor.CrossRefDisplayFieldsList = crAttribute.RefFieldName;
                        filterDescriptor.CrossRefFieldName = propertyName;
                    }

                    var rcrAttribute = property.GetCustomAttribute<ReverseCrossRefFieldAttribute>(false);

                    if (rcrAttribute != null)
                    {
                        filterDescriptor.CrossRefProcessName = rcrAttribute.ReferenceTableName;
                        filterDescriptor.CrossRefDisplayFieldsList = rcrAttribute.RefFieldName;
                        filterDescriptor.CrossRefFieldName = propertyName;
                        filterDescriptor.IsReverseCrossRef = true;
                    }

                    var tvAttribute = property.GetCustomAttribute<TreeViewFieldAttribute>(false);
                    if (tvAttribute != null)
                    {
                        filterDescriptor.CrossRefProcessName = tvAttribute.ReferenceTableName;
                        filterDescriptor.CrossRefDisplayFieldsList = tvAttribute.RefFieldName;
                        filterDescriptor.CrossRefFieldName = propertyName;
                        filterDescriptor.IsReverseCrossRef = true;
                    }

                    var dateTimeFormatAttribute = property.GetCustomAttribute<DateTimeFormatAttribute>(false);
                    filterDescriptor.FilterFormatMemberType = dateTimeFormatAttribute != null
                                                                  ? new FilterFormatType
                                                                        {
                                                                            MemberType = filterDescriptor.MemberType,
                                                                            FormatType = dateTimeFormatAttribute.Value
                                                                        }
                                                                  : new FilterFormatType { MemberType = filterDescriptor.MemberType };
                }

                filterDescriptor.FilteringProcessSystemName = DynamicObjectHelper.GetProcessSystemName(filteringProcessEditType);
            }
        }