/// <summary> /// Gets the current person. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> private static Person GetCurrentPerson(ILavaRenderContext context) { // First check for a person override value included in lava context var currentPerson = context.GetMergeField("CurrentPerson", null) as Person; if (currentPerson == null) { var httpContext = System.Web.HttpContext.Current; if (httpContext != null && httpContext.Items.Contains("CurrentPerson")) { currentPerson = httpContext.Items["CurrentPerson"] as Person; } } return(currentPerson); }
/// <summary> /// Parses the element attributes markup to collate parameter settings for the shortcode. /// </summary> /// <param name="elementAttributesMarkup">The markup.</param> /// <param name="context">The context.</param> /// <returns></returns> private void SetParametersFromElementAttributes(Dictionary <string, object> parameters, string elementAttributesMarkup, ILavaRenderContext context) { // Resolve any Lava merge fields in the element attributes markup. var resolvedMarkup = _engine.RenderTemplate(elementAttributesMarkup, LavaRenderParameters.WithContext(context)); var markupItems = Regex.Matches(resolvedMarkup.Text, @"(\S*?:'[^']+')") .Cast <Match>() .Select(m => m.Value) .ToList(); foreach (var item in markupItems) { var itemParts = item.ToString().Split(new char[] { ':' }, 2); if (itemParts.Length > 1) { parameters.AddOrReplace(itemParts[0].Trim().ToLower(), itemParts[1].Trim().Substring(1, itemParts[1].Length - 2)); } } // OK, now let's look for any passed variables ala: name:variable var variableTokens = Regex.Matches(resolvedMarkup.Text, @"\w*:\w+") .Cast <Match>() .Select(m => m.Value) .ToList(); foreach (var item in variableTokens) { var itemParts = item.Trim().Split(new char[] { ':' }, 2); if (itemParts.Length > 1) { var scopeKey = itemParts[1].Trim(); var scopeObject = context.GetMergeField(scopeKey, null); if (scopeObject != null) { parameters.AddOrReplace(itemParts[0].Trim().ToLower(), scopeObject); break; } } } }
/// <summary> /// Gets the current person. /// </summary> /// <param name="context">The context.</param> /// <returns>The current person or null if not found.</returns> /// <exception cref="ArgumentNullException">context</exception> public static Person GetCurrentPerson(ILavaRenderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } string currentPersonKey = "CurrentPerson"; Person currentPerson = null; // First, check for a person override value included in the lava context. currentPerson = context.GetMergeField(currentPersonKey, null) as Person; if (currentPerson == null) { var httpContext = HttpContext.Current; if (httpContext != null && httpContext.Items.Contains(currentPersonKey)) { currentPerson = httpContext.Items[currentPersonKey] as Person; } } return(currentPerson); }