Пример #1
0
        /// <summary>
        /// Helper method to register the entity commands.
        /// </summary>
        public static void RegisterEntityCommands(ILavaEngine engine)
        {
            var entityTypes = EntityTypeCache.All();

            // register a business entity
            engine.RegisterBlock("business", (name) => { return(new RockEntityBlock()); });

            // Register the core models, replacing existing blocks of the same name if necessary.
            foreach (var entityType in entityTypes
                     .Where(e =>
                            e.IsEntity &&
                            e.Name.StartsWith("Rock.Model") &&
                            e.FriendlyName != null &&
                            e.FriendlyName != ""))
            {
                RegisterEntityCommand(engine, entityType, useQualifiedNameIfExists: true);
            }

            // Register plugin models, using fully-qualified namespace if necessary.
            foreach (var entityType in entityTypes
                     .Where(e =>
                            e.IsEntity &&
                            !e.Name.StartsWith("Rock.Model") &&
                            e.FriendlyName != null &&
                            e.FriendlyName != "")
                     .OrderBy(e => e.Id))
            {
                RegisterEntityCommand(engine, entityType, useQualifiedNameIfExists: true);
            }
        }
Пример #2
0
        private static void InitializeLavaBlocks(ILavaEngine engine)
        {
            // Get all blocks and call OnStartup methods
            try
            {
                var blockTypes = Rock.Reflection.FindTypes(typeof(ILavaBlock)).Select(a => a.Value).ToList();

                foreach (var blockType in blockTypes)
                {
                    var blockInstance = Activator.CreateInstance(blockType) as ILavaBlock;

                    engine.RegisterBlock(blockInstance.SourceElementName, (blockName) =>
                    {
                        return(Activator.CreateInstance(blockType) as ILavaBlock);
                    });

                    try
                    {
                        blockInstance.OnStartup(engine);
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogService.LogException(ex, null);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }
        }
Пример #3
0
        /// <summary>
        /// Register a Lava Block element.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="factoryMethod"></param>
        public static void RegisterBlock(string name, Func <string, ILavaBlock> factoryMethod)
        {
            if (_engine == null)
            {
                return;
            }

            _engine.RegisterBlock(name, factoryMethod);
        }
Пример #4
0
        private static void RegisterEntityCommand(ILavaEngine engine, EntityTypeCache entityType, bool useQualifiedNameIfExists = false)
        {
            if (entityType != null)
            {
                string entityName = entityType.FriendlyName.RemoveSpaces().ToLower();

                // if entity name is already registered, use the full class name with namespace
                if (useQualifiedNameIfExists &&
                    engine.GetRegisteredElements().ContainsKey(entityName))
                {
                    entityName = entityType.Name.Replace('.', '_');
                }

                engine.RegisterBlock(entityName,
                                     (name) =>
                {
                    // Return a block having a tag name corresponding to the entity name.
                    return(new RockEntityBlock()
                    {
                        SourceElementName = entityName, EntityName = entityName
                    });
                });
            }
        }
        private static void RegisterBlocks(ILavaEngine engine)
        {
            // Get all blocks and call OnStartup methods
            if (engine.GetType() == typeof(RockLiquidEngine))
            {
                // Find all tag elements that implement IRockStartup.
                var elementTypes = Rock.Reflection.FindTypes(typeof(DotLiquid.Block)).Select(a => a.Value).ToList();

                foreach (var elementType in elementTypes)
                {
                    var instance = Activator.CreateInstance(elementType) as IRockStartup;

                    if (instance == null)
                    {
                        continue;
                    }

                    try
                    {
                        // RockLiquid blocks register themselves with the DotLiquid framework during their startup process.
                        instance.OnStartup();
                    }
                    catch (Exception ex)
                    {
                        var lavaException = new Exception(string.Format("Lava component initialization failure. Startup failed for Lava Tag \"{0}\".", elementType.FullName), ex);

                        ExceptionLogService.LogException(lavaException, null);
                    }
                }
            }
            else
            {
                try
                {
                    // Get Lava block components, except shortcodes which are registered separately.
                    var elementTypes = Rock.Reflection.FindTypes(typeof(ILavaBlock)).Select(a => a.Value).ToList();

                    elementTypes = elementTypes.Where(x => !(typeof(ILavaShortcode).IsAssignableFrom(x))).ToList();

                    foreach (var elementType in elementTypes)
                    {
                        var instance = Activator.CreateInstance(elementType) as ILavaBlock;

                        var name = instance.SourceElementName;

                        if (string.IsNullOrWhiteSpace(name))
                        {
                            name = elementType.Name;
                        }

                        engine.RegisterBlock(name, (shortcodeName) =>
                        {
                            var shortcode = Activator.CreateInstance(elementType) as ILavaBlock;

                            return(shortcode);
                        });

                        try
                        {
                            instance.OnStartup(engine);
                        }
                        catch (Exception ex)
                        {
                            var lavaException = new Exception(string.Format("Lava component initialization failure. Startup failed for Lava Block \"{0}\".", elementType.FullName), ex);

                            ExceptionLogService.LogException(lavaException, null);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionLogService.LogException(ex, null);
                }
            }
        }