public Stream GetOrCreateDocument(string templateName, IDictionary<string, object> templateData)
{
byte[] hash = ComputeHash(templateName, templateData);
var base64Hash = GetHashString(hash);
var path = Path.Combine(this.documentDirectoryPath, base64Hash + ".pdf");
IDocumentTemplate documentTemplate = null;
foreach (var template in this.DocumentTemplates)
{
if (template.Metadata.Name.Equals(templateName, StringComparison.OrdinalIgnoreCase))
{
documentTemplate = template.Value;
break;
}
}
if (documentTemplate == null)
{
throw new ArgumentException(string.Format("Could not find a template by the name of \"{0\".", templateName), "templateName");
}
var cachedDocument = this.cachedDocuments.GetOrAdd(hash, new CachedDocument(path, documentTemplate, templateData));
return cachedDocument.GetContentStream();
}