Exemple #1
0
        /// <summary>
        /// Initializes all fields in the given block.
        /// </summary>
        /// <param name="scope">The current service scope</param>
        /// <param name="block">The block</param>
        /// <param name="managerInit">If this is initialization used by the manager</param>
        private async Task InitBlockAsync(IServiceScope scope, Extend.Block block, bool managerInit)
        {
            if (block != null)
            {
                var properties = block.GetType().GetProperties(App.PropertyBindings);

                // Initialize all of the fields
                foreach (var property in properties)
                {
                    if (typeof(Extend.IField).IsAssignableFrom(property.PropertyType))
                    {
                        var field = property.GetValue(block);

                        if (field != null)
                        {
                            await InitFieldAsync(scope, field, managerInit).ConfigureAwait(false);
                        }
                    }
                }

                // Initialize the block
                var appBlock = App.Blocks.GetByType(block.GetType());
                if (appBlock != null)
                {
                    await appBlock.Init.InvokeAsync(block, scope, managerInit).ConfigureAwait(false);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes all fields in the given block.
        /// </summary>
        /// <param name="scope">The current service scope</param>
        /// <param name="block">The block</param>
        /// <param name="regionType">The region type</param>
        private async Task InitBlockAsync(IServiceScope scope, Extend.Block block)
        {
            if (block != null)
            {
                var type       = block.GetType();
                var properties = block.GetType().GetProperties(App.PropertyBindings);

                foreach (var property in properties)
                {
                    if (typeof(Extend.IField).IsAssignableFrom(property.PropertyType))
                    {
                        var field = property.GetValue(block);

                        if (field != null)
                        {
                            await InitFieldAsync(scope, field).ConfigureAwait(false);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Initializes all fields in the given block.
        /// </summary>
        /// <param name="scope">The current service scope</param>
        /// <param name="block">The block</param>
        /// <param name="regionType">The region type</param>
        private void InitBlock(IServiceScope scope, Extend.Block block)
        {
            if (block != null)
            {
                var type       = block.GetType();
                var properties = block.GetType().GetProperties(App.PropertyBindings);

                foreach (var property in properties)
                {
                    if (typeof(Extend.IField).IsAssignableFrom(property.PropertyType))
                    {
                        var field = property.GetValue(block);

                        if (field != null)
                        {
                            InitField(scope, field);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Gets the fields for the given block.
        /// </summary>
        /// <param name="block">The block</param>
        /// <returns>The available fields</returns>
        public static IList <FieldModel> GetBlockFields(Extend.Block block)
        {
            var fields = new List <FieldModel>();

            foreach (var prop in block.GetType().GetProperties(App.PropertyBindings))
            {
                if (typeof(Extend.IField).IsAssignableFrom(prop.PropertyType))
                {
                    var fieldType = App.Fields.GetByType(prop.PropertyType);
                    var field     = new FieldModel
                    {
                        Model = (Extend.IField)prop.GetValue(block),
                        Meta  = new FieldMeta
                        {
                            Id        = prop.Name,
                            Name      = prop.Name,
                            Component = fieldType.Component,
                        }
                    };

                    // Check if this is a select field
                    if (typeof(Extend.Fields.SelectFieldBase).IsAssignableFrom(fieldType.Type))
                    {
                        foreach (var item in ((Extend.Fields.SelectFieldBase)Activator.CreateInstance(fieldType.Type)).Items)
                        {
                            field.Meta.Options.Add(Convert.ToInt32(item.Value), item.Title);
                        }
                    }

                    // Check if we have field meta-data available
                    var attr = prop.GetCustomAttribute <Extend.FieldAttribute>();
                    if (attr != null)
                    {
                        field.Meta.Name        = !string.IsNullOrWhiteSpace(attr.Title) ? attr.Title : field.Meta.Name;
                        field.Meta.Placeholder = attr.Placeholder;
                        field.Meta.IsHalfWidth = attr.Options.HasFlag(FieldOption.HalfWidth);
                    }

                    // Check if we have field description meta-data available
                    var descAttr = prop.GetCustomAttribute <Extend.FieldDescriptionAttribute>();
                    if (descAttr != null)
                    {
                        field.Meta.Description = descAttr.Text;
                    }
                    fields.Add(field);
                }
            }
            return(fields);
        }