예제 #1
0
        }                                                // null by default
        #endregion

        #region Public IServices Members

        /// <summary>
        /// Returns an HTML fragment suitable for inclusion in any standards-mode web page, which embeds a HotDocs interview
        /// directly in that web page.
        /// </summary>
        /// <param name="template">The template for which the interview will be requested.</param>
        /// <param name="answers">The initial set of answers to include in the interview.</param>
        /// <param name="settings">Settings that define various interview behavior.</param>
        /// <param name="markedVariables">A collection of variables that should be marked with special formatting in the interview.</param>
        /// <param name="logRef">A string to display in logs related to this request.</param>
        /// <returns>An object which contains an HTML fragment to be inserted in a web page to display the interview.</returns>
        public InterviewResult GetInterview(Template template, TextReader answers, InterviewSettings settings, IEnumerable <string> markedVariables, string logRef)
        {
            // Validate input parameters, creating defaults as appropriate.
            string logStr = logRef == null ? string.Empty : logRef;

            if (template == null)
            {
                throw new ArgumentNullException("template", string.Format(@"Cloud.Services.GetInterview: the ""template"" parameter passed in was null, logRef: {0}", logStr));
            }

            if (settings == null)
            {
                settings = new InterviewSettings();
            }

            // Configure interview settings
            settings.Settings["OmitImages"]       = "true";       // Instructs HDS not to return images used by the interview; we'll get them ourselves from the template location. (See GetInterviewFile below.)
            settings.Settings["OmitDefinitions"]  = "true";       // Instructs HDS not to return interview definitions; we'll get them ourselves from the template location. (See GetInterviewFile below.)
            settings.Settings["TempInterviewUrl"] = Util.GetInterviewImageUrl(settings, template);
            settings.Settings["InterviewDefUrl"]  = Util.GetInterviewDefinitionUrl(settings, template);
            settings.MarkedVariables = (string[])(markedVariables ?? new string[0]);

            // Get the interview.
            InterviewResult result = new InterviewResult();

            BinaryObject[] interviewFiles = null;
            using (var client = new SoapClient(_subscriberID, _signingKey, HostAddress, ProxyAddress))
            {
                interviewFiles = client.GetInterview(
                    template,
                    answers == null ? "" : answers.ReadToEnd(),
                    settings,
                    logRef
                    );

                // Throw an exception if we do not have exactly one interview file.
                // Although interviewFiles could potentially contain more than one item, the only one we care about is the
                // first one, which is the HTML fragment. All other items, such as interview definitions (.JS and .DLL files)
                // or dialog element images are not needed, because we can get them out of the package file instead.
                // We enforce this by setting the OmitImages and OmitDefinitions values above, so we will always have exactly one item here.
                if (interviewFiles.Length != 1)
                {
                    throw new Exception();
                }

                StringBuilder htmlFragment = new StringBuilder(Util.ExtractString(interviewFiles[0]));

                Util.AppendSdkScriptBlock(htmlFragment, template, settings);
                result.HtmlFragment = htmlFragment.ToString();
            }

            return(result);
        }