Пример #1
0
        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());
        }
Пример #2
0
 public CachedDocument(string path, IDocumentTemplate template, IDictionary<string, object> templateData)
 {
     this.path = path;
     this.CreationDate = new DateTime();
     this.template = template;
     this.templateData = templateData;
 }
Пример #3
0
 public CachedDocument(string path, IDocumentTemplate template, IDictionary <string, object> templateData)
 {
     this.path         = path;
     this.CreationDate = new DateTime();
     this.template     = template;
     this.templateData = templateData;
 }
Пример #4
0
        /// <summary>
        /// Creates a new document in the specified path, with the specified format, and opens it
        /// </summary>
        /// <param name="format"></param>
        /// <param name="path"></param>
        public IDocumentEditor Create(IDocumentTemplate format)
        {
            // Create document
            var document = format.CreateDocument();

            document.IsDirty = true;

            // Find and create editor
            IDocumentEditor editor = CreateEditor(document);

            // Trigger event
            if (DocumentOpened != null)
            {
                DocumentOpened(this, new DocumentOpenedEventArgs(editor));
            }

            return(editor);
        }
Пример #5
0
 /// <summary>
 /// Registers a document template
 /// </summary>
 /// <param name="template">The document template</param>
 public void RegisterTemplate(IDocumentTemplate template)
 {
     _templates.Add(template);
 }
 /// <summary>
 /// Initializes the document template view model
 /// </summary>
 /// <param name="template">The document template</param>
 public DocumentTemplateViewModel(IDocumentTemplate template)
 {
     this.Template = template;
 }