/// <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); }
private static ArrayList <TokenizerRegex> LoadRules(string resName) { Regex splitRegex = new Regex(@"^(?<regex>.*)((--)|(==))\>(?<rhs>.*)$", RegexOptions.Compiled); ArrayList <TokenizerRegex> rules = new ArrayList <TokenizerRegex>(); StreamReader rulesReader = new StreamReader(Utils.GetManifestResourceStream(typeof(Rules), resName)); string line; while ((line = rulesReader.ReadLine()) != null) { if (line.Trim() == "stop") { break; } if (!line.StartsWith("#") && line.Trim() != "") { RegexOptions opt = RegexOptions.Compiled | RegexOptions.Multiline; if (line.Contains("-->")) { opt |= RegexOptions.IgnoreCase; } TokenizerRegex tknRegex = new TokenizerRegex(); tknRegex.mVal = line.Contains("$val"); tknRegex.mTxt = line.Contains("$txt"); Match match = splitRegex.Match(line); if (match.Success) { try { tknRegex.mRegex = new Regex(match.Result("${regex}").Trim(), opt); tknRegex.mRhs = match.Result("${rhs}").Trim(); rules.Add(tknRegex); } catch { Console.WriteLine("*** Warning: Cannot parse line \"{0}\".", line); } } else { Console.WriteLine("*** Warning: Cannot parse line \"{0}\".", line); } } } return(rules); }