コード例 #1
0
        /// <summary>
        /// Creates a new session for assembling documents using the HotDocs Cloud Services Rest API.
        /// </summary>
        /// <param name="template">The template to use with the session.</param>
        /// <param name="billingRef">This parameter lets you specify information that will be included in usage logs for this call. For example, you can use a string to uniquely identify the end user that initiated the request and/or the context in which the call was made. When you review usage logs, you can then see which end users initiated each request. That information could then be used to pass costs on to those end users if desired.</param>
        /// <param name="answers">The answers to use.</param>
        /// <param name="markedVariables">An array of variable names, whose prompts should be "marked" when displayed in an interview.</param>
        /// <param name="interviewFormat">The format to use when displaying an interview.</param>
        /// <param name="outputFormat">The format to use when assembling a document.</param>
        /// <param name="settings">The settings to use with the session.</param>
        /// <param name="theme">The interview theme.</param>
        /// <param name="showDownloadLinks">Indicates whether or not links for downloading the assembled document(s) should appear at the end of the interview.</param>
        /// <returns></returns>
        public string CreateSession(
			Template template,
			string billingRef = null,
			string answers = null,
			string[] markedVariables = null,
			InterviewFormat interviewFormat = InterviewFormat.JavaScript,
			OutputFormat outputFormat = OutputFormat.Native,
			Dictionary<string, string> settings = null,
			string theme = null,
			bool showDownloadLinks = true
		)
        {
            return (string)TryWithoutAndWithPackage(
                (uploadPackage) => CreateSessionImpl(
                    template,
                    billingRef,
                    answers,
                    markedVariables,
                    interviewFormat,
                    outputFormat,
                    settings,
                    theme,
                    showDownloadLinks,
                    uploadPackage)
            );
        }
コード例 #2
0
 /// <summary>
 /// Creates a new session for assembling documents using the HotDocs Cloud Services Rest API.
 /// </summary>
 /// <param name="template">The template to use with the session.</param>
 /// <param name="billingRef">This parameter lets you specify information that will be included in usage logs for this call. For example, you can use a string to uniquely identify the end user that initiated the request and/or the context in which the call was made. When you review usage logs, you can then see which end users initiated each request. That information could then be used to pass costs on to those end users if desired.</param>
 /// <param name="answers">The answers to use.</param>
 /// <param name="markedVariables">An array of variable names, whose prompts should be "marked" when displayed in an interview.</param>
 /// <param name="interviewFormat">The format to use when displaying an interview.</param>
 /// <param name="outputFormat">The format to use when assembling a document.</param>
 /// <param name="settings">The settings to use with the session.</param>
 /// <param name="theme">The interview theme.</param>
 /// <param name="showDownloadLinks">Indicates whether or not links for downloading the assembled document(s) should appear at the end of the interview.</param>
 /// <returns></returns>
 public string CreateSession(
     Template template,
     string billingRef                    = null,
     string answers                       = null,
     string[] markedVariables             = null,
     InterviewFormat interviewFormat      = InterviewFormat.JavaScript,
     OutputFormat outputFormat            = OutputFormat.Native,
     Dictionary <string, string> settings = null,
     string theme           = null,
     bool showDownloadLinks = true
     )
 {
     return((string)TryWithoutAndWithPackage(
                (uploadPackage) => CreateSessionImpl(
                    template,
                    billingRef,
                    answers,
                    markedVariables,
                    interviewFormat,
                    outputFormat,
                    settings,
                    theme,
                    showDownloadLinks,
                    uploadPackage)
                ));
 }
コード例 #3
0
        /// <summary>
        /// Retrieves a file required by the interview. This could be either an interview definition that contains the
        /// variables and logic required to display an interview (questionaire) for the main template or one of its
        /// inserted templates, or it could be an image file displayed on a dialog within the interview.
        /// </summary>
        /// <param name="template">The template related to the requested file.</param>
        /// <param name="fileName">The file name of the image, or the file name of the template for which the interview
        /// definition is being requested. In either case, this value is passed as "template" on the query string by the browser interview.</param>
        /// <param name="fileType">The type of file being requested: img (image file), js (JavaScript interview definition),
        /// or dll (Silverlight interview definition).</param>
        /// <returns>A stream containing the requested interview file, to be returned to the caller.</returns>
        public Stream GetInterviewFile(Template template, string fileName, string fileType)
        {
            // Validate input parameters, creating defaults as appropriate.
            if (template == null)
            {
                throw new ArgumentNullException("template", @"WebService.Services.GetInterviewFile: the ""template"" parameter passed in was null");
            }

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName", @"WebService.Services.GetInterviewFile: the ""fileName"" parameter passed in was null or empty");
            }

            if (string.IsNullOrEmpty(fileType))
            {
                throw new ArgumentNullException("fileType", @"WebService.Services.GetInterviewFile: the ""fileType"" parameter passed in was null or empty");
            }

            // Return an image or interview definition from the template.
            InterviewFormat format = InterviewFormat.Unspecified;

            switch (fileType.ToUpper())
            {
            case "IMG":
                return(template.Location.GetFile(fileName));

            case "DLL":
                format = InterviewFormat.Silverlight;
                break;

            case "JS":
                format = InterviewFormat.JavaScript;
                break;
            }

            if (format == InterviewFormat.Unspecified)
            {
                throw new ArgumentOutOfRangeException();                 // The format must be either JS or DLL.
            }
            System.IO.Stream result = null;

            using (Proxy client = new Proxy(_endPointName))
            {
                string       templateId    = GetRelativePath(Path.Combine(Path.GetDirectoryName(template.GetFullPath()), fileName)); // The relative path to the template folder.
                string       templateName  = fileName;                                                                               // The name of the template file for which the interview is being requested (e.g., demoempl.rtf).
                string       templateState = string.Empty;                                                                           // We are using the templateId rather than template state since all we have to work with is a template locator.
                BinaryObject binaryObject  = client.GetInterviewDefinition(templateId, templateName, format, templateState);
                SafeCloseClient(client, null);
                result = new MemoryStream(binaryObject.Data);
            }
            return(result);
        }
コード例 #4
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));
        }
    }
コード例 #5
0
        private string CreateSessionImpl(
            Template template,
            string billingRef,
            string answers,
            string[] markedVariables,
            InterviewFormat interviewFormat,
            OutputFormat outputFormat,
            Dictionary <string, string> settings,
            string theme,
            bool showDownloadLinks,
            bool uploadPackage)
        {
            if (!(template.Location is PackageTemplateLocation))
            {
                throw new Exception("HotDocs Cloud Services requires the use of template packages. Please use a PackageTemplateLocation derivative.");
            }
            PackageTemplateLocation packageTemplateLocation = (PackageTemplateLocation)template.Location;

            if (uploadPackage)
            {
                UploadPackage(packageTemplateLocation.PackageID, billingRef, packageTemplateLocation.GetPackageStream());
            }

            var timestamp = DateTime.UtcNow;

            string hmac = HMAC.CalculateHMAC(
                SigningKey,
                timestamp,
                SubscriberId,
                packageTemplateLocation.PackageID,
                billingRef,
                interviewFormat,
                outputFormat,
                settings);                 // Additional settings = null for this app

            StringBuilder urlBuilder = new StringBuilder(string.Format(
                                                             "{0}/embed/newsession/{1}/{2}?interviewformat={3}&outputformat={4}",
                                                             EndpointAddress, SubscriberId, packageTemplateLocation.PackageID,
                                                             interviewFormat.ToString(), outputFormat.ToString()));

            if (markedVariables != null && markedVariables.Length > 0)
            {
                urlBuilder.AppendFormat("&markedvariables={0}", string.Join(",", markedVariables));
            }

            if (!string.IsNullOrEmpty(theme))
            {
                urlBuilder.AppendFormat("&theme={0}", theme);
            }

            if (!string.IsNullOrEmpty(billingRef))
            {
                urlBuilder.AppendFormat("&billingref={0}", billingRef);
            }

            if (showDownloadLinks)
            {
                urlBuilder.Append("&showdownloadlinks=true");
            }

            if (settings != null)
            {
                foreach (KeyValuePair <string, string> kv in settings)
                {
                    urlBuilder.AppendFormat("&{0}={1}", kv.Key, kv.Value ?? "");
                }
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlBuilder.ToString());

            request.Method               = "POST";
            request.ContentType          = "text/xml";
            request.Headers["x-hd-date"] = timestamp.ToString("r");
            request.Headers[HttpRequestHeader.Authorization] = hmac;
            request.ContentLength = answers != null ? answers.Length : 0;

            if (!string.IsNullOrEmpty(ProxyServerAddress))
            {
                request.Proxy = new WebProxy(ProxyServerAddress);
            }
            else
            {
                request.Proxy = null;
            }

            Stream stream = request.GetRequestStream();

            if (answers != null)
            {
                byte[] data = Encoding.UTF8.GetBytes(answers);
                stream.Write(data, 0, data.Length);
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    reader   = new StreamReader(response.GetResponseStream());

            return(reader.ReadLine());
        }
コード例 #6
0
        private string CreateSessionImpl(
			Template template,
			string billingRef,
			string answers,
			string[] markedVariables,
			InterviewFormat interviewFormat,
			OutputFormat outputFormat,
			Dictionary<string, string> settings,
			string theme,
			bool showDownloadLinks,
			bool uploadPackage)
        {
            if (!(template.Location is PackageTemplateLocation))
                throw new Exception("HotDocs Cloud Services requires the use of template packages. Please use a PackageTemplateLocation derivative.");
            PackageTemplateLocation packageTemplateLocation = (PackageTemplateLocation)template.Location;

            if (uploadPackage)
            {
                UploadPackage(packageTemplateLocation.PackageID, billingRef, packageTemplateLocation.GetPackageStream());
            }

            var timestamp = DateTime.UtcNow;

            string hmac = HMAC.CalculateHMAC(
                SigningKey,
                timestamp,
                SubscriberId,
                packageTemplateLocation.PackageID,
                billingRef,
                interviewFormat,
                outputFormat,
                settings); // Additional settings = null for this app

            StringBuilder urlBuilder = new StringBuilder(string.Format(
                "{0}/newsession/{1}/{2}?interviewformat={3}&outputformat={4}",
                EmbeddedEndpointAddress, SubscriberId, packageTemplateLocation.PackageID,
                interviewFormat.ToString(), outputFormat.ToString()));

            if (markedVariables != null && markedVariables.Length > 0)
            {
                urlBuilder.AppendFormat("&markedvariables={0}", string.Join(",", markedVariables));
            }

            if (!string.IsNullOrEmpty(theme))
            {
                urlBuilder.AppendFormat("&theme={0}", theme);
            }

            if (!string.IsNullOrEmpty(billingRef))
            {
                urlBuilder.AppendFormat("&billingref={0}", billingRef);
            }

            if (showDownloadLinks)
            {
                urlBuilder.Append("&showdownloadlinks=true");
            }

            if (settings != null)
            {
                foreach (KeyValuePair<string, string> kv in settings)
                {
                    urlBuilder.AppendFormat("&{0}={1}", kv.Key, kv.Value ?? "");
                }
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlBuilder.ToString());
            request.Method = "POST";
            request.ContentType = "text/xml; charset=utf-8";
            request.Headers["x-hd-date"] = timestamp.ToString("r");
            request.Headers[HttpRequestHeader.Authorization] = hmac;
            byte[] data = null;
            if (answers != null)
            {
                data = Encoding.UTF8.GetBytes(answers);
            }
            request.ContentLength = data != null ? data.Length : 0;

            if (!string.IsNullOrEmpty(ProxyServerAddress))
            {
                request.Proxy = new WebProxy(ProxyServerAddress);
            }
            else
            {
                request.Proxy = null;
            }

            Stream stream = request.GetRequestStream();
            if (data != null)
            {
                stream.Write(data, 0, data.Length);
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            return reader.ReadLine();
        }
コード例 #7
0
 public BinaryObject[] GetInterview(string subscriberID, string packageID, string templateName, BinaryObject[] answers, InterviewFormat format, string[] markedVariables, string tempImageUrl, System.Collections.Generic.Dictionary <string, string> settings, string billingRef, System.DateTime timestamp, BinaryObject templatePackage, string hmac)
 {
     return(base.Channel.GetInterview(subscriberID, packageID, templateName, answers, format, markedVariables, tempImageUrl, settings, billingRef, timestamp, templatePackage, hmac));
 }
コード例 #8
0
 /// <summary>
 /// Call GetInterviewDefinition on HotDocs Server via web services.
 /// </summary>
 /// <param name="templateID"></param>
 /// <param name="templateName"></param>
 /// <param name="format"></param>
 /// <param name="templateState"></param>
 /// <returns></returns>
 public BinaryObject GetInterviewDefinition(string templateID, string templateName, InterviewFormat format, string templateState)
 {
     return(base.Channel.GetInterviewDefinition(templateID, templateName, format, templateState));
 }
コード例 #9
0
 /// <summary>
 /// Call GetInterview on HotDocs Server via web services.
 /// </summary>
 /// <param name="templateID"></param>
 /// <param name="answers"></param>
 /// <param name="format"></param>
 /// <param name="options"></param>
 /// <param name="markedVariables"></param>
 /// <param name="formActionUrl"></param>
 /// <param name="serverFilesUrl"></param>
 /// <param name="styleUrl"></param>
 /// <param name="tempInterviewUrl"></param>
 /// <param name="saveAnswersUrl"></param>
 /// <param name="previewUrl"></param>
 /// <param name="interviewDefinitionUrl"></param>
 /// <returns></returns>
 public BinaryObject[] GetInterview(string templateID, BinaryObject[] answers, InterviewFormat format, InterviewOptions options, string[] markedVariables, string formActionUrl, string serverFilesUrl, string styleUrl, string tempInterviewUrl, string saveAnswersUrl, string previewUrl, string interviewDefinitionUrl)
 {
     return(base.Channel.GetInterview(templateID, answers, format, options, markedVariables, formActionUrl, serverFilesUrl, styleUrl, tempInterviewUrl, saveAnswersUrl, previewUrl, interviewDefinitionUrl));
 }