Beispiel #1
0
        public void RegisterAssembly(Assembly assembly)
        {
            foreach (var type in assembly.DefinedTypes)
            {
                var attr = type.GetCustomAttributes <DomainDescriptorAttribute>().FirstOrDefault();

                foreach (var property in type.DeclaredProperties)
                {
                    if (property.PropertyType == typeof(DomainDescription))
                    {
                        var attrDomainDescription = property.GetCustomAttribute <DomainDescriptionAttribute>();

                        var domainDescription = property.GetValue(null, null) as DomainDescription;
                        domainDescription.Key = attrDomainDescription.Key;
                        _domains.Add(attrDomainDescription.Key, domainDescription);
                    }
                }
            }

            foreach (var type in assembly.DefinedTypes)
            {
                var attr = type.GetCustomAttributes <EntityDescriptionAttribute>().FirstOrDefault();
                if (attr != null)
                {
                    var entityDescription = EntityDescription.Create(type.AsType(), attr);
                    entityDescription.Domain = _domains[entityDescription.DomainName];
                    _entities.Add(entityDescription);
                    _entitySummaries.Add(EntitySummary.Create(entityDescription));
                }
            }
            _assemblies.Add(assembly);
        }
Beispiel #2
0
        public static EntityDescription Create(Type entityType, EntityDescriptionAttribute attr)
        {
            var entityDescription = new EntityDescription();

            entityDescription.Elements    = new List <FormField>();
            entityDescription.ListColumns = new List <ListColumn>();

            var properties = entityType.GetRuntimeProperties();

            foreach (var property in properties)
            {
                var fieldAttributes = property.GetCustomAttributes <FormFieldAttribute>();
                if (fieldAttributes.Any())
                {
                    entityDescription.Elements.Add(FormField.Create(property.Name, fieldAttributes.First(), property));
                }

                var listAttributes = property.GetCustomAttributes <ListColumnAttribute>();
                if (listAttributes.Any())
                {
                    entityDescription.ListColumns.Add(ListColumn.Create(property.Name, listAttributes.First()));
                }
            }

            entityDescription.Name = entityType.Name;

            var titleProperty = attr.ResourceType.GetTypeInfo().GetDeclaredProperty(attr.TitleResource);

            if (titleProperty != null)
            {
                entityDescription.Title = titleProperty.GetValue(titleProperty.DeclaringType, null) as String;
            }
            else
            {
                entityDescription.Title = entityType.Name;
            }

            var descriptionProperty = attr.ResourceType.GetTypeInfo().GetDeclaredProperty(attr.DescriptionResource);

            if (descriptionProperty != null)
            {
                entityDescription.Description = descriptionProperty.GetValue(descriptionProperty.DeclaringType, null) as String;
            }

            var userHelpProperty = attr.ResourceType.GetTypeInfo().GetDeclaredProperty(attr.UserHelpResource);

            if (userHelpProperty != null)
            {
                entityDescription.UserHelp = userHelpProperty.GetValue(userHelpProperty.DeclaringType, null) as String;
            }

            entityDescription.DomainName = attr.Domain;


            entityDescription.EntityType = attr.EntityType;

            return(entityDescription);
        }
Beispiel #3
0
 public static EntitySummary Create(EntityDescription desc)
 {
     return(new EntitySummary()
     {
         ClassName = desc.Name,
         Name = desc.Title,
         DomainKey = desc.DomainName
     });
 }
Beispiel #4
0
        public static DetailResponse <TModel> Create(TModel model)
        {
            var response = new DetailResponse <TModel>();

            response.Model      = model;
            response.FormFields = new List <string>();
            var viewItems = new Dictionary <string, FormField>();
            var attr      = typeof(TModel).GetTypeInfo().GetCustomAttributes <EntityDescriptionAttribute>().FirstOrDefault();
            var entity    = EntityDescription.Create(typeof(TModel), attr);

            if (model is IFormDescriptor)
            {
                response.FormFields = (model as IFormDescriptor).GetFormFields();
            }

            response.Title = entity.Title;
            response.Help  = entity.UserHelp;

            var properties = typeof(TModel).GetRuntimeProperties();

            foreach (var property in properties)
            {
                var fieldAttributes = property.GetCustomAttributes <FormFieldAttribute>();
                if (fieldAttributes.Any())
                {
                    var camelCaseName = property.Name.Substring(0, 1).ToLower() + property.Name.Substring(1);
                    var field         = FormField.Create(camelCaseName, fieldAttributes.First());
                    var defaultValue  = property.GetValue(model);
                    if (defaultValue != null)
                    {
                        field.DefaultValue = defaultValue.ToString();
                    }

                    viewItems.Add(camelCaseName, field);
                }
            }
            response.View = viewItems;
            return(response);
        }