Ejemplo n.º 1
0
        public void TestPackagePathLocation()
        {
            string packageID = "d1f7cade-cb74-4457-a9a0-27d94f5c2d5b";
            string templateFileName = "Demo Employment Agreement.docx";
            HotDocs.Sdk.PackagePathTemplateLocation location = CreatePackagePathLocation(packageID);
            Template template;
            Assert.IsTrue(File.Exists(location.PackagePath));

            // Verify that null switches and key are resolved to empty strings.
            template = new Template(location, null, null);
            Assert.AreEqual("", template.Switches);
            Assert.AreEqual("", template.Key);
            Assert.IsTrue(template.HasInterview);
            template.Switches = "/nw /naw /ni";
            Assert.IsFalse(template.HasInterview);

            string switches = "/ni";
            string key = "Test file key";
            template = new Template(location, switches, key);

            Assert.AreEqual(templateFileName, template.FileName);
            Assert.AreEqual(key, template.Key);
            Assert.AreEqual(switches, template.Switches);

            Assert.AreEqual("Employment Agreement (Word RTF version)", template.Title.Trim());

            string filePath = template.GetFullPath();
            Assert.IsTrue(File.Exists(filePath));
            //Directory.Delete(Path.GetDirectoryName(filePath));

            //Check the second time since the folder has been deleted.
            //filePath = template.GetFullPath();//The folder should come into existence here.
            //Assert.IsTrue(File.Exists(filePath));
            //Directory.Delete(Path.GetDirectoryName(filePath));//Clean up.

            TestTemplate(template, new TemplateInfo()
            {
                Title = "Employment Agreement",
                DocExtension = ".docx",
                TmpType = TemplateType.WordDOCX,
                DocType = DocumentType.WordDOCX
            });
        }
Ejemplo n.º 2
0
    protected string GetSessionID()
    {
        var client = new RestClient(Settings.SubscriberID, Settings.SigningKey, null, SamplePortal.Settings.CloudServicesAddress);

        if (_resume)
        {
            // Resume a previously-saved session.
            _resume = false;
            return client.ResumeSession(SnapshotField.Value);
        }
        else
        {
            // Make sure we have a packageID to use with the new session.
            if (string.IsNullOrEmpty(_packageID))
                return null;

            // Create the new session.
            InterviewFormat format = HotDocs.Sdk.Util.ReadConfigurationEnum<InterviewFormat>("InterviewFormat", InterviewFormat.Unspecified);
            HotDocs.Sdk.Template template = new HotDocs.Sdk.Template(new HotDocs.Sdk.PackagePathTemplateLocation(_packageID, Path.Combine(Settings.TemplatePath, _packageID + ".pkg")));
            return client.CreateSession(template, null, null, null, format);
        }
    }
Ejemplo n.º 3
0
    protected string GetSessionID()
    {
        var client = new RestClient(Settings.SubscriberID, Settings.SigningKey, null, SamplePortal.Settings.CloudServicesAddress);

        if (_resume)
        {
            // Resume a previously-saved session.
            _resume = false;
            return(client.ResumeSession(SnapshotField.Value));
        }
        else
        {
            // Make sure we have a packageID to use with the new session.
            if (string.IsNullOrEmpty(_packageID))
            {
                return(null);
            }

            // Create the new session.
            InterviewFormat      format   = HotDocs.Sdk.Util.ReadConfigurationEnum <InterviewFormat>("InterviewFormat", InterviewFormat.Unspecified);
            HotDocs.Sdk.Template template = new HotDocs.Sdk.Template(new HotDocs.Sdk.PackagePathTemplateLocation(_packageID, Path.Combine(Settings.TemplatePath, _packageID + ".pkg")));
            return(client.CreateSession(template, null, null, null, format));
        }
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a Template created from a locator string generated by CreateLocator.
        /// </summary>
        /// <param name="locator">A locator string provided by CreateLocator.</param>
        /// <returns></returns>
        public static Template Locate(string locator)
        {
            if (string.IsNullOrEmpty(locator))
                throw new ArgumentNullException("locator");

            string decryptedLocator = Util.DecryptString(locator);
            string[] tokens = decryptedLocator.Split('|');
            if (tokens.Length != 4)
                throw new Exception("Invalid template locator.");

            string fileName = tokens[0];
            string switches = tokens[1];
            string key = tokens[2];
            string locationLocator = tokens[3];

            Template template = new Template(fileName, TemplateLocation.Locate(locationLocator), switches);
            template.Key = key;
            template.UpdateFileName();
            return template;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the assembled document extension for a specific document type.
        /// </summary>
        /// <param name="docType">The document type to find an extension for.</param>
        /// <param name="template">The template to to derive an extension from if docType is DocumentType.Native.</param>
        /// <returns></returns>
        public static string GetDocExtension(DocumentType docType, Template template)
        {
            string ext = "";
            switch (docType)
            {
                case DocumentType.HFD:
                    ext = ".hfd";
                    break;
                case DocumentType.HPD:
                    ext = ".hpd";
                    break;
                case DocumentType.HTML:
                    ext = ".htm";
                    break;
                case DocumentType.HTMLwDataURIs:
                    ext = ".htm";
                    break;
                case DocumentType.MHTML:
                    ext = ".htm";
                    break;
                case DocumentType.Native:
                    {
                        if (template == null)
                            throw new ArgumentNullException("template", "The template cannot be null if the DocumentType is Native.");

                        string templateExt = Path.GetExtension(template.FileName);
                        if (templateExt == ".hpt")
                            ext = ".pdf";
                        else if (templateExt == ".hft")
                            ext = ".hfd";
                        else if (templateExt == ".ttx")
                            ext = ".txt";
                        else if (templateExt == ".wpt")
                            ext = ".wpd";
                        else
                            ext = templateExt;
                        break;
                    }
                case DocumentType.PDF:
                    ext = ".pdf";
                    break;
                case DocumentType.PlainText:
                    ext = ".txt";
                    break;
                case DocumentType.WordDOC://Note that DOC files are not supported on a server.
                    ext = ".doc";
                    break;
                case DocumentType.WordDOCX:
                    ext = ".docx";
                    break;
                case DocumentType.WordPerfect:
                    ext = ".wpd";
                    break;
                case DocumentType.WordRTF:
                    ext = ".rtf";
                    break;
                //For XML, use plain text.
                default:
                    throw new Exception("Unsupported document type.");
            }
            return ext;
        }
Ejemplo n.º 6
0
        private void TestTemplate(Template template, TemplateInfo tInfo)
        {
            Assert.IsFalse(template.HasInterview);
            Assert.IsTrue(template.GeneratesDocument == (tInfo.TmpType != TemplateType.InterviewOnly));
            Assert.AreEqual(template.NativeDocumentType, tInfo.DocType);
            Assert.AreEqual(template.TemplateType, tInfo.TmpType);

            string locator = template.CreateLocator();
            Template template2 = Template.Locate(locator);

            Assert.AreEqual(template.FileName, template2.FileName);
            Assert.AreEqual(template.Key, template2.Key);
            Assert.AreEqual(template.Switches, template2.Switches);
            Assert.AreEqual(template.Title, template2.Title);
            Assert.AreEqual(template.GeneratesDocument, template2.GeneratesDocument);
            Assert.AreEqual(template.HasInterview, template2.HasInterview);
            Assert.AreEqual(template.NativeDocumentType, template2.NativeDocumentType);
            Assert.AreEqual(template.TemplateType, template2.TemplateType);

            template.UpdateFileName();
            Assert.AreEqual(template.FileName, template2.FileName);

            Assert.AreEqual(".hfd", HotDocs.Sdk.Template.GetDocExtension(DocumentType.HFD, null));
            Assert.AreEqual(".hpd", HotDocs.Sdk.Template.GetDocExtension(DocumentType.HPD, null));
            Assert.AreEqual(".htm", HotDocs.Sdk.Template.GetDocExtension(DocumentType.HTML, null));
            Assert.AreEqual(".htm", HotDocs.Sdk.Template.GetDocExtension(DocumentType.HTMLwDataURIs, null));
            Assert.AreEqual(".htm", HotDocs.Sdk.Template.GetDocExtension(DocumentType.MHTML, null));
            Assert.AreEqual(".pdf", HotDocs.Sdk.Template.GetDocExtension(DocumentType.PDF, null));
            Assert.AreEqual(".txt", HotDocs.Sdk.Template.GetDocExtension(DocumentType.PlainText, null));
            Assert.AreEqual(".doc", HotDocs.Sdk.Template.GetDocExtension(DocumentType.WordDOC, null));
            Assert.AreEqual(".docx", HotDocs.Sdk.Template.GetDocExtension(DocumentType.WordDOCX, null));
            Assert.AreEqual(".wpd", HotDocs.Sdk.Template.GetDocExtension(DocumentType.WordPerfect, null));
            Assert.AreEqual(".rtf", HotDocs.Sdk.Template.GetDocExtension(DocumentType.WordRTF, null));
            //Assert.AreEqual(".xml", HotDocs.Sdk.Template.GetDocExtension(DocumentType.XML, null)); // TODO: Should we be testing XML?

            // Unknown doc type.
            try
            {
                Assert.AreEqual(".unk", HotDocs.Sdk.Template.GetDocExtension(DocumentType.Unknown, null));
                Assert.Fail(); // Should have thrown exception.
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Unsupported document type."));
            }

            // Native doc type.
            try
            {
                string extension = HotDocs.Sdk.Template.GetDocExtension(DocumentType.Native, null);
                Assert.Fail(); // We should have had an exception.
            }
            catch (ArgumentNullException ex)
            {
                Assert.IsTrue(ex.Message.Contains("template")); // templae cannot be null if the type is Native.
            }

            // Native doc type.
            if (tInfo.DocType != DocumentType.Unknown)
            {
                Assert.AreEqual(tInfo.DocExtension, template.GetDocExtension());
                Assert.AreEqual(tInfo.DocExtension, HotDocs.Sdk.Template.GetDocExtension(DocumentType.Native, template));
            }

            // Set the template title.
            template.Title = "This has been done.";
            Assert.AreEqual("This has been done.", template.Title);
        }
Ejemplo n.º 7
0
        public void TestPathTemplateLocation()
        {
            string templateDir = Path.Combine(GetSamplePortalTemplateDir(), "TestTemplates");
            Assert.IsTrue(Directory.Exists(templateDir));
            PathTemplateLocation location = new PathTemplateLocation(templateDir);
            Template template;

            // Make sure that null fileName causes exception.
            try
            {
                template = new Template(null, location, null, null);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("fileName"));
            }

            // Make sure that null location causes exception.
            try
            {
                template = new Template("filename.docx", null, null, null);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("location"));
            }

            // Make sure that a null location causes exception.
            try
            {
                template = new Template(null, null, null);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("location"));
            }

            // Try to locate a template with a null locator.
            try
            {
                template = Template.Locate(null);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.IsTrue(ex.Message.Contains("locator"));
            }

            // Try to locate a template with an empty string locator.
            try
            {
                template = Template.Locate("");
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.IsTrue(ex.Message.Contains("locator"));
            }

            // Try to locate a template with an invalid template locator.
            try
            {
                template = Template.Locate(Util.EncryptString("abcdefg"));
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Invalid template locator."));
            }

            try
            {
                HotDocs.Sdk.TemplateLocation.RegisterLocation(typeof(string));
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("The registered location must be of type TemplateLocation."));
            }

            // Try to get the TemplateType for an unknown template type.
            template = new Template("filename.tfx", location, null, null);
            Assert.AreEqual(TemplateType.Unknown, template.TemplateType);
            Assert.AreEqual("", template.Title);

            // Verify that null switches and key resolve to empty string.
            template = new Template("Demo Employment Agreement.docx", location, null, null);
            Assert.AreEqual("", template.Switches);
            Assert.AreEqual("", template.Key);

            string switches = "/ni";
            string key = "Test file key";

            Dictionary<string, TemplateInfo> testTemplates = new Dictionary<string, TemplateInfo>();
            testTemplates.Add("Demo Employment Agreement.docx", new TemplateInfo()
            {
                Title = "Employment Agreement",
                DocExtension = ".docx",
                TmpType = TemplateType.WordDOCX,
                DocType = DocumentType.WordDOCX
            });
            testTemplates.Add("Sample rtf template.rtf", new TemplateInfo()
            {
                Title = "Sample rtf template",
                DocExtension = ".rtf",
                TmpType = TemplateType.WordRTF,
                DocType = DocumentType.WordRTF
            });
            testTemplates.Add("Sample wpt template.wpt", new TemplateInfo()
            {
                Title = "Sample wpt template",
                DocExtension = ".wpd",
                TmpType = TemplateType.WordPerfect,
                DocType = DocumentType.WordPerfect
            });
            testTemplates.Add("sample interview template.cmp", new TemplateInfo()
            {
                Title = "sample interview template",
                DocExtension = ".wpd",
                TmpType = TemplateType.InterviewOnly,
                DocType = DocumentType.Unknown
            });
            testTemplates.Add("sample hft template.hft", new TemplateInfo()
            {
                Title = "sample hft template",
                DocExtension = ".hfd",
                TmpType = TemplateType.HotDocsHFT,
                DocType = DocumentType.HFD
            });
            testTemplates.Add("sample pdf template.hpt", new TemplateInfo()
            {
                Title = "sample pdf template",
                DocExtension = ".pdf",
                TmpType = TemplateType.HotDocsPDF,
                DocType = DocumentType.PDF
            });
            testTemplates.Add("sample ttx template.ttx", new TemplateInfo()
            {
                Title = "sample ttx template",
                DocExtension = ".txt",
                TmpType = TemplateType.PlainText,
                DocType = DocumentType.PlainText
            });

            foreach (var t in testTemplates)
            {
                template = new Template(t.Key, location, switches, key);
                Assert.AreEqual(template.Title, t.Value.Title);
                string filePath = template.GetFullPath();
                Assert.IsTrue(File.Exists(filePath));
                TestTemplate(template, t.Value);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a WorkSession object that a host application can use to step through the process of presenting
 /// all the interviews and assembling all the documents that may result from the given template.
 /// </summary>
 /// <param name="service">An object implementing the IServices interface, encapsulating the instance of
 /// HotDocs Server with which the host app is communicating.</param>
 /// <param name="template">The template upon which this WorkSession is based. The initial interview and/or
 /// document work items in the WorkSession will be based on this template (including its Switches property).</param>
 /// <param name="answers">A collection of XML answers to use as a starting point for the work session.
 /// The initial interview (if any) will be pre-populated with these answers, and the subsequent generation
 /// of documents will have access to these answers as well.</param>
 public WorkSession(IServices service, Template template, TextReader answers)
     : this(service, template, answers, null)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// <c>WorkSession</c> constructor
 /// </summary>
 /// <param name="service">An object implementing the IServices interface, encapsulating the instance of
 /// HotDocs Server with which the host app is communicating.</param>
 /// <param name="template">The template upon which this WorkSession is based. The initial interview and/or
 /// document work items in the WorkSession will be based on this template (including its Switches property).</param>
 public WorkSession(IServices service, Template template)
     : this(service, template, null, null)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates a WorkSession object that a host application can use to step through the process of presenting
 /// all the interviews and assembling all the documents that may result from the given template.
 /// 
 /// Allows the default interview settings to be specified instead of being read from config file
 /// </summary>
 /// <param name="service">An object implementing the IServices interface, encapsulating the instance of
 /// HotDocs Server with which the host app is communicating.</param>
 /// <param name="template">The template upon which this WorkSession is based. The initial interview and/or
 /// document work items in the WorkSession will be based on this template (including its Switches property).</param>
 /// <param name="answers">A collection of XML answers to use as a starting point for the work session.
 /// The initial interview (if any) will be pre-populated with these answers, and the subsequent generation
 /// of documents will have access to these answers as well.</param>
 /// <param name="defaultInterviewSettings">The default interview settings to be used throughout the session</param>
 public WorkSession(IServices service, Template template, TextReader answers, InterviewSettings defaultInterviewSettings)
 {
     _service = service;
     AnswerCollection = new AnswerCollection();
     if (answers != null)
         AnswerCollection.ReadXml(answers);
     DefaultAssemblySettings = new AssembleDocumentSettings();
         if (defaultInterviewSettings != null)
             DefaultInterviewSettings = defaultInterviewSettings;
         else
             DefaultInterviewSettings = new InterviewSettings();
         // add the work items
     _workItems = new List<WorkItem>();
     if (template.HasInterview)
         _workItems.Add(new InterviewWorkItem(template));
     if (template.GeneratesDocument)
         _workItems.Add(new DocumentWorkItem(template));
 }