public void Add(string key, ParseList parseList) { if (string.IsNullOrEmpty(key)) throw new ArgumentOutOfRangeException("key", "A valid key must be used."); lock (cacheItems) { while ((cacheItems.Count) >= this.MaxCacheItems) { ParseListCacheItem item = null; string lastKey = null; foreach (string key2 in cacheItems.Keys) { ParseListCacheItem item2 = cacheItems[key2] as ParseListCacheItem; if ((item == null) || (item2 != null && item2.LastAccessed < item.LastAccessed)) { item = item2; lastKey = key2; } } if (lastKey != null) { cacheItems.Remove(lastKey); } } ParseListCacheItem item3 = new ParseListCacheItem {Item = parseList, LastAccessed = DateTime.Now.Ticks}; cacheItems.Add(key.ToLower(), item3); } }
public void Add(string key, ParseList parseList) { if (string.IsNullOrEmpty(key)) { throw new ArgumentOutOfRangeException("key", "A valid key must be used."); } lock (cacheItems) { while ((cacheItems.Count) >= this.MaxCacheItems) { ParseListCacheItem item = null; string lastKey = null; foreach (string key2 in cacheItems.Keys) { ParseListCacheItem item2 = cacheItems[key2] as ParseListCacheItem; if ((item == null) || (item2 != null && item2.LastAccessed < item.LastAccessed)) { item = item2; lastKey = key2; } } if (lastKey != null) { cacheItems.Remove(lastKey); } } ParseListCacheItem item3 = new ParseListCacheItem { Item = parseList, LastAccessed = DateTime.Now.Ticks }; cacheItems.Add(key.ToLower(), item3); } }
private void LoadTemplate(string templatePath, bool parseTemplate) { if (string.IsNullOrEmpty(templatePath) || !File.Exists(templatePath)) { throw new ArgumentException("The template specified is invalid or could not be found", "templatePath"); } // save the template path this._templatePath = templatePath; // check for a cached version of this template if (templateCache != null && (_parseList = templateCache.Get(templatePath)) != null) { return; } string templateContent = File.ReadAllText(_templatePath); string templateFolder = Path.GetDirectoryName(_templatePath); templateContent = templateParser.PreProcessTemplate(templateContent, templateFolder); // parse the template ready for running _parseList = templateParser.ParseTemplate(templateContent); // check if we need to cache this template if (templateCache != null && _parseList != null) { templateCache.Add(templatePath, _parseList); } }
private void ParseLine() { if (!IsParsed) { ParseList.AddRange(Line.Split(Delimiters, StringSplitOptions.None)); IsParsed = true; } }
public ParseList ParseTemplate(string template) { List <int> newLinePositions = new List <int>(); for (int i = 0, len = template.Length; i < len; i++) { if (template[i] == '\n') { newLinePositions.Add(i); } } ParseList parseList = new ParseList(); MatchCollection matches = TagFinderRegex.Matches(template); int peekIndex = 0; foreach (Match match in matches) { Group g = match.Groups[0]; if (g.Index > peekIndex) { parseList.AddRange((ParseExpressions(template.Substring(peekIndex, g.Index - peekIndex)))); } // determine the row number the tag is on and the character position int row = 1, pos = 0; int len = newLinePositions.Count; for (row = 1; row <= len; row++) { if (g.Index < newLinePositions[row - 1]) { pos = g.Index - ((row <= 1) ? 0 : newLinePositions[row - 2]); break; } } parseList.Add(tagFactory.ParseTag(g.Value, row, pos)); // update the peekIndex to be the end of the match peekIndex = g.Index + g.Length; } if (peekIndex < template.Length) { parseList.AddRange(ParseExpressions(template.Substring(peekIndex))); } return(parseList); }
private string Run(ParseList parseList, IPropertyBag bag) { IInterpretContext ctx = new InterpretContext(); ctx.Bag = bag; ctx.ParseList = parseList; int listLength = ctx.ParseList.Count; while (ctx.ListPosition < listLength) { // go through the parseList and act on each item we find MarkupBase markupItem = parseList[ctx.ListPosition]; markupItem.Interpret(ctx); } return(ctx.Builder.ToString()); }
public ParseList Get(string key) { ParseList list = null; lock (cacheItems) { if (string.IsNullOrEmpty(key)) { throw new ArgumentOutOfRangeException("key", "A valid key must be used."); } string lookupKey = key.ToLower(); if (cacheItems.ContainsKey(lookupKey)) { var item = cacheItems[lookupKey] as ParseListCacheItem; item.LastAccessed = DateTime.Now.Ticks; list = item.Item; } } return(list); }
private string Run(ParseList parseList, IPropertyBag bag) { IInterpretContext ctx = new InterpretContext(); ctx.Bag = bag; ctx.ParseList = parseList; int listLength = ctx.ParseList.Count; while (ctx.ListPosition < listLength) { // go through the parseList and act on each item we find MarkupBase markupItem = parseList[ctx.ListPosition]; markupItem.Interpret(ctx); } return ctx.Builder.ToString(); }
private void LoadTemplate(string templatePath, bool parseTemplate) { if (string.IsNullOrEmpty(templatePath) || !File.Exists(templatePath)) throw new ArgumentException("The template specified is invalid or could not be found", "templatePath"); // save the template path this._templatePath = templatePath; // check for a cached version of this template if (templateCache != null && (_parseList = templateCache.Get(templatePath)) != null) return; string templateContent = File.ReadAllText(_templatePath); string templateFolder = Path.GetDirectoryName(_templatePath); templateContent = templateParser.PreProcessTemplate(templateContent, templateFolder); // parse the template ready for running _parseList = templateParser.ParseTemplate(templateContent); // check if we need to cache this template if (templateCache != null && _parseList != null) templateCache.Add(templatePath, _parseList); }
public ParseList ParseTemplate(string template) { List<int> newLinePositions = new List<int>(); for (int i = 0, len = template.Length; i < len; i++) { if (template[i] == '\n') { newLinePositions.Add(i); } } ParseList parseList = new ParseList(); MatchCollection matches = TagFinderRegex.Matches(template); int peekIndex = 0; foreach (Match match in matches) { Group g = match.Groups[0]; if (g.Index > peekIndex) { parseList.AddRange((ParseExpressions(template.Substring(peekIndex, g.Index - peekIndex)))); } // determine the row number the tag is on and the character position int row = 1, pos = 0; int len = newLinePositions.Count; for (row = 1; row <= len; row++) { if (g.Index < newLinePositions[row - 1]) { pos = g.Index - ((row <= 1) ? 0 : newLinePositions[row - 2]); break; } } parseList.Add(tagFactory.ParseTag(g.Value, row, pos)); // update the peekIndex to be the end of the match peekIndex = g.Index + g.Length; } if (peekIndex < template.Length) { parseList.AddRange(ParseExpressions(template.Substring(peekIndex))); } return parseList; }
public string RunString(string template) { ParseList parseList = templateParser.ParseTemplate(template); return(this.Run(parseList, this.Bag)); }