Ejemplo n.º 1
0
        private void AllComponentClassess(IEndpointRequest request)
        {
            var components = new List <ComponentVersionRecord>();

            foreach (var componentEntry in _nameManager.AllComponents().OrderBy(c => c.Key))
            {
                var componentRecord = new ComponentVersionRecord
                {
                    Name          = componentEntry.Key,
                    DisplayName   = componentEntry.Key,
                    CreatedWhen   = DateTime.UtcNow,
                    CreatedBy     = request.Identity,
                    ComponentName = componentEntry.Key.ToLower()
                };

                var component     = componentEntry.Value;
                var componentType = component.GetType();

                componentRecord.Name = componentType.FullName;

                var descriptions = componentType.GetCustomAttributes(typeof(DescriptionAttribute), true);
                if (descriptions != null && descriptions.Length > 0)
                {
                    componentRecord.Description = ((DescriptionAttribute)descriptions[0]).Html;
                }

                var excludedProperties = new List <string>
                {
                    "ElementType",
                    "HeadWriters",
                    "ScriptWriters",
                    "StyleWriters",
                    "BodyWriters",
                    "InitializationWriters",
                    "CssRules",
                    "JavascriptFunctions",
                    "AssetDeployment",
                    "Module",
                    "Package",
                    "Name",
                    "ServiceName",
                    "ClientScript"
                };

                var properties = componentType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                if (properties != null && properties.Length > 0)
                {
                    componentRecord.Properties = properties
                                                 .Where(p => !excludedProperties.Contains(p.Name))
                                                 .Select(p => new ElementPropertyRecord
                    {
                        Name        = p.Name,
                        DisplayName = p.Name,
                        CreatedBy   = request.Identity,
                        CreatedWhen = DateTime.UtcNow,
                        Type        = p.PropertyType,
                        TypeName    = p.PropertyType.FullName
                    })
                                                 .ToArray();
                }

                components.Add(componentRecord);
            }
            request.Success(components);
        }