-
-
Save stimms/4320360 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TokenReplacementCheckSheetProcessor : BaseChecksheetDecorator, IChecksheetDecorator | |
{ | |
//A list of all the token resolvers known to the container | |
public IEnumerable<ITokenResolver> Resolvers {get;set;} | |
//A cache of the tokens to replace in a single check sheet | |
//It is time consuming to search a word document for the | |
//tokens so we try to do it only once for each sort of checkseet | |
public ICheckSheetTokenCache CheckSheetTokenCache {get;set;} | |
public void ProcessChecksheet(int tagId, int checksheetId, Doc doc) | |
{ | |
//check the cache to make sure that we don't already have a built cache for this check sheet | |
if(CheckSheetTokenCache.Any(x=>x.CheckSheetId == checkSheetId)) | |
{ | |
CheckSheetTokenCache.Add(BuildCacheEntry(checksheetId)); | |
} | |
//pull the list of tokens in this check sheet from the cache | |
var tokens = CheckSheetTokenCache.Where(x=>x.CheckSheetId == checkSheetId).Single(); | |
//give each resolver the tokens to resolve | |
foreach(var resolver in Resolvers) | |
foreach(var token in tokens) | |
{ | |
var resolvedToken = resolver.TryResolve(token, tagId); | |
//replace the token in the document if we have resolved it | |
if(resolvedToken != null) | |
doc.ReplaceAll(token, resolvedToken); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment