/// <summary> /// returns cacheability of the passed text regarding all contained tokens /// </summary> /// <param name="strSourcetext">the text to parse for tokens to replace</param> /// <returns>cacheability level (not - safe - fully)</returns> /// <remarks>always check cacheability before caching a module!</remarks> /// <history> /// 10/19/2007 [sleupold] corrected to handle non-empty strings /// </history> public CacheLevel Cacheability(string strSourcetext) { CacheLevel IsSafe = CacheLevel.fullyCacheable; if (strSourcetext != null && !string.IsNullOrEmpty(strSourcetext)) { //initialize PropertyAccess classes string DummyResult = ReplaceTokens(strSourcetext); var Result = new StringBuilder(); foreach (Match currentMatch in TokenizerRegex.Matches(strSourcetext)) { string strObjectName = currentMatch.Result("${object}"); if (!String.IsNullOrEmpty(strObjectName)) { if (strObjectName == "[") { //nothing } else if (!PropertySource.ContainsKey(strObjectName.ToLower())) { } else { CacheLevel c = PropertySource[strObjectName.ToLower()].Cacheability; if (c < IsSafe) { IsSafe = c; } } } } } return(IsSafe); }
protected virtual string ReplaceTokens(string strSourceText) { if (strSourceText == null) { return(string.Empty); } var Result = new StringBuilder(); foreach (Match currentMatch in TokenizerRegex.Matches(strSourceText)) { string strObjectName = currentMatch.Result("${object}"); if (!String.IsNullOrEmpty(strObjectName)) { if (strObjectName == "[") { strObjectName = ObjectLessToken; } string strPropertyName = currentMatch.Result("${property}"); string strFormat = currentMatch.Result("${format}"); string strIfEmptyReplacment = currentMatch.Result("${ifEmpty}"); string strConversion = replacedTokenValue(strObjectName, strPropertyName, strFormat); if (!String.IsNullOrEmpty(strIfEmptyReplacment) && String.IsNullOrEmpty(strConversion)) { strConversion = strIfEmptyReplacment; } Result.Append(strConversion); } else { Result.Append(currentMatch.Result("${text}")); } } return(Result.ToString()); }
/// <summary> /// Checks for present [Object:Property] tokens /// </summary> /// <param name="strSourceText">String with [Object:Property] tokens</param> /// <returns></returns> public bool ContainsTokens(string strSourceText) { if (!string.IsNullOrEmpty(strSourceText)) { return(TokenizerRegex.Matches(strSourceText).Cast <Match>().Any(currentMatch => currentMatch.Result("${object}").Length > 0)); } return(false); }
/// <summary> /// Checks for present [Object:Property] tokens /// </summary> /// <param name="strSourceText">String with [Object:Property] tokens</param> /// <returns></returns> /// <history> /// 08/10/2007 [sleupold] created /// 10/19/2007 [sleupold] corrected to ignore unchanged text returned (issue DNN-6526) /// </history> public bool ContainsTokens(string strSourceText) { if (!string.IsNullOrEmpty(strSourceText)) { foreach (Match currentMatch in TokenizerRegex.Matches(strSourceText)) { if (currentMatch.Result("${object}").Length > 0) { return(true); } } } return(false); }