예제 #1
0
        /// <summary>
        /// Register a Lava Tag elemennt.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="factoryMethod"></param>
        public static void RegisterTag(string name, Func <string, ILavaTag> factoryMethod)
        {
            if (_engine == null)
            {
                return;
            }

            _engine.RegisterTag(name, factoryMethod);
        }
예제 #2
0
        private static void InitializeLavaTags(ILavaEngine engine)
        {
            // Get all tags and call OnStartup methods
            try
            {
                var elementTypes = Rock.Reflection.FindTypes(typeof(ILavaTag)).Select(a => a.Value).ToList();

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

                    var name = instance.SourceElementName;

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

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

                        return(shortcode);
                    });

                    try
                    {
                        instance.OnStartup(engine);
                    }
                    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);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }
        }
        private static void RegisterTags(ILavaEngine engine)
        {
            // Get all tags and call OnStartup methods
            if (engine.GetType() == typeof(RockLiquidEngine))
            {
                // Find all tag elements that implement IRockStartup.
                var elementTypes = Rock.Reflection.FindTypes(typeof(DotLiquid.Tag)).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);
                    }
                }
            }

            if (engine.GetType() == typeof(RockLiquidEngine))
            {
                return;
            }

            // Get all Lava tags and call the OnStartup method.
            try
            {
                List <Type> elementTypes;

                elementTypes = Rock.Reflection.FindTypes(typeof(ILavaTag)).Select(a => a.Value).ToList();

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

                    var name = instance.SourceElementName;

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

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

                        return(shortcode);
                    });

                    try
                    {
                        instance.OnStartup(engine);
                    }
                    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);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }
        }