コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="template">The template for which component information is being requested.</param>
        /// <param name="includeDialogs">Indicates whether or not information about dialogs should be included.</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="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal override ComponentInfo GetComponentInfoImpl(
            Template template,
            bool includeDialogs,
            string billingRef,
            bool uploadPackage)
        {
            var timestamp = DateTime.UtcNow;

            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;

            string hmac = HMAC.CalculateHMAC(
                SigningKey,
                timestamp,
                SubscriberId,
                packageTemplateLocation.PackageID,
                template.FileName,
                uploadPackage,
                billingRef,
                includeDialogs);

            return(_proxy.GetComponentInfo(
                       SubscriberId,
                       packageTemplateLocation.PackageID,
                       template.FileName,
                       includeDialogs,
                       billingRef,
                       timestamp,
                       GetPackageIfNeeded(packageTemplateLocation, uploadPackage),
                       hmac));
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="template"></param>
        /// <param name="includeDialogs">Indicates whether or not information about dialogs should be included.</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="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal override ComponentInfo GetComponentInfoImpl(
            Template template,
            bool includeDialogs,
            string billingRef,
            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,
                template.FileName,
                false,
                billingRef,
                includeDialogs);

            StringBuilder urlBuilder = new StringBuilder(string.Format(
                                                             "{0}/componentinfo/{1}/{2}/{3}?includedialogs={4}&billingref={5}",
                                                             EndpointAddress, SubscriberId, packageTemplateLocation.PackageID, template.FileName, includeDialogs.ToString(), billingRef));

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

            request.Method = "GET";
            request.Headers["x-hd-date"] = timestamp.ToString("r");
            request.Headers[HttpRequestHeader.Authorization] = hmac;

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

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            var          serializer = new XmlSerializer(typeof(ComponentInfo));
            MemoryStream stream     = new MemoryStream();

            return((ComponentInfo)serializer.Deserialize(response.GetResponseStream()));
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="location"></param>
        /// <param name="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal BinaryObject GetPackageIfNeeded(PackageTemplateLocation location, bool uploadPackage)
        {
            if (!uploadPackage)
            {
                return(null);
            }

            using (Stream stream = location.GetPackageStream())
            {
                byte[] data;
                if (stream.CanSeek)
                {
                    data = new byte[stream.Length];
                    using (MemoryStream memStream = new MemoryStream(data))
                    {
                        stream.CopyTo(memStream);
                    }
                }
                else
                {
                    // Since we can't get the stream length for a non-seekable stream,
                    // we have to just let the buffer grow as needed.  After the streaming
                    // is done, we have to copy the data from the buffer to a correctly
                    // sized array.  This is very inefficient, but that's the price of
                    // using a non-seekable stream.
                    using (MemoryStream memStream = new MemoryStream())
                    {
                        stream.CopyTo(memStream);
                        data = memStream.ToArray();
                    }
                }

                return(new BinaryObject()
                {
                    FileName = "",
                    DataEncoding = null,
                    Data = data
                });
            }
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="location"></param>
        /// <param name="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal BinaryObject GetPackageIfNeeded(PackageTemplateLocation location, bool uploadPackage)
        {
            if (!uploadPackage)
            {
                return(null);
            }

            using (Stream stream = location.GetPackageStream())
            {
                byte[] data;
                if (stream.CanSeek)
                {
                    data = new byte[stream.Length];
                    using (MemoryStream memStream = new MemoryStream(data))
                    {
                        stream.CopyTo(memStream);
                    }
                }
                else
                {
                    // This is very inefficient, but what are you gonna do?
                    using (MemoryStream memStream = new MemoryStream())
                    {
                        stream.CopyTo(memStream);
                        data = memStream.ToArray();
                    }
                }

                return(new BinaryObject()
                {
                    FileName = "",
                    DataEncoding = null,
                    Data = data
                });
            }
        }
コード例 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="location"></param>
        /// <param name="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal BinaryObject GetPackageIfNeeded(PackageTemplateLocation location, bool uploadPackage)
        {
            if (!uploadPackage)
                return null;

            using (Stream stream = location.GetPackageStream())
            {
                byte[] data;
                if (stream.CanSeek)
                {
                    data = new byte[stream.Length];
                    using (MemoryStream memStream = new MemoryStream(data))
                    {
                        stream.CopyTo(memStream);
                    }
                }
                else
                {
                    // This is very inefficient, but what are you gonna do?
                    using (MemoryStream memStream = new MemoryStream())
                    {
                        stream.CopyTo(memStream);
                        data = memStream.ToArray();
                    }
                }

                return new BinaryObject()
                {
                    FileName = "",
                    DataEncoding = null,
                    Data = data
                };
            }
        }
コード例 #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}/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());
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="template"></param>
        /// <param name="answers"></param>
        /// <param name="settings"></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="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal override BinaryObject[] GetInterviewImpl(
            Template template,
            string answers,
            InterviewSettings settings,
            string billingRef,
            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 interviewImageUrl = string.Empty;

            if (settings != null)
            {
                settings.Settings.TryGetValue("TempInterviewUrl", out interviewImageUrl);
            }
            else
            {
                settings = new InterviewSettings();
            }

            string hmac = HMAC.CalculateHMAC(
                SigningKey,
                timestamp,
                SubscriberId,
                packageTemplateLocation.PackageID,
                template.FileName,
                false,
                billingRef,
                settings.Format,
                interviewImageUrl,
                settings.Settings);

            StringBuilder urlBuilder = new StringBuilder(string.Format(
                                                             "{0}/interview/{1}/{2}/{3}?format={4}&markedvariables={5}&tempimageurl={6}&billingref={7}",
                                                             EndpointAddress, SubscriberId, packageTemplateLocation.PackageID, template.FileName, settings.Format.ToString(),
                                                             settings.MarkedVariables != null ? string.Join(",", settings.MarkedVariables) : null, interviewImageUrl, billingRef));

            if (settings.Settings != null)
            {
                foreach (KeyValuePair <string, string> kv in settings.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 : 0L;

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

            using (Stream stream = request.GetRequestStream())
            {
                if (answers != null)
                {
                    byte[] data = Encoding.UTF8.GetBytes(answers);
                    stream.Write(data, 0, data.Length);
                }
            }

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Directory.CreateDirectory(OutputDir);
                using (var resultsStream = new MemoryStream())
                {
                    // Each part is written to a file whose name is specified in the content-disposition
                    // header, except for the BinaryObject[] part, which has a file name of "meta0.xml",
                    // and is parsed into an BinaryObject[] object.
                    _parser.WritePartsToStreams(
                        response.GetResponseStream(),
                        h =>
                    {
                        string id = GetFileNameFromHeaders(h);
                        if (id != null)
                        {
                            if (id.Equals("meta0.xml", StringComparison.OrdinalIgnoreCase))
                            {
                                return(resultsStream);
                            }

                            // The following stream will be closed by the parser
                            return(new FileStream(Path.Combine(OutputDir, id), FileMode.Create));
                        }
                        return(Stream.Null);
                    },
                        (new ContentType(response.ContentType)).Boundary);

                    if (resultsStream.Position > 0)
                    {
                        resultsStream.Position = 0;
                        var serializer = new XmlSerializer(typeof(BinaryObject[]));
                        return((BinaryObject[])serializer.Deserialize(resultsStream));
                    }
                    return(null);
                }
            }
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="template"></param>
        /// <param name="answers"></param>
        /// <param name="settings"></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="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal override AssemblyResult AssembleDocumentImpl(
            Template template,
            string answers,
            AssembleDocumentSettings settings,
            string billingRef,
            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,
                template.FileName,
                false,
                billingRef,
                settings.Format,
                settings.Settings);

            StringBuilder urlBuilder = new StringBuilder(string.Format(
                                                             "{0}/assemble/{1}/{2}/{3}?format={4}&billingref={5}",
                                                             EndpointAddress, SubscriberId, packageTemplateLocation.PackageID, template.FileName ?? "",
                                                             settings.Format.ToString(), billingRef));

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

            // Note that the Comments and/or Keywords values, and therefore the resulting URL, could
            // be extremely long.  Consumers should be aware that overly-long URLs could be rejected
            // by Cloud Services.  If the Comments and/or Keywords values cannot be truncated, the
            // consumer should use the SOAP version of the client.
            var outputOptionsPairs = GetOutputOptionsPairs(settings.OutputOptions);

            foreach (KeyValuePair <string, string> kv in outputOptionsPairs)
            {
                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.Timeout       = 10 * 60 * 1000;       // Ten minute timeout
            request.ContentLength = answers != null ? answers.Length : 0L;

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

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

            Directory.CreateDirectory(OutputDir);
            using (var resultsStream = new MemoryStream())
            {
                // Each part is written to a file whose name is specified in the content-disposition
                // header, except for the AssemblyResult part, which has a file name of "meta0.xml",
                // and is parsed into an AssemblyResult object.
                _parser.WritePartsToStreams(
                    response.GetResponseStream(),
                    h =>
                {
                    string fileName = GetFileNameFromHeaders(h);
                    if (fileName != null)
                    {
                        if (fileName.Equals("meta0.xml", StringComparison.OrdinalIgnoreCase))
                        {
                            return(resultsStream);
                        }

                        return(new FileStream(Path.Combine(OutputDir, fileName), FileMode.Create));
                    }
                    return(Stream.Null);
                },
                    (new ContentType(response.ContentType)).Boundary);

                if (resultsStream.Position > 0)
                {
                    resultsStream.Position = 0;
                    var serializer = new XmlSerializer(typeof(AssemblyResult));
                    return((AssemblyResult)serializer.Deserialize(resultsStream));
                }
                return(null);
            }
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="template">The template to assemble.</param>
        /// <param name="answers">The answers to use when assembling the document.</param>
        /// <param name="settings">The settings to use when assembling the document.</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="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal override AssemblyResult AssembleDocumentImpl(
            Template template,
            string answers,
            AssembleDocumentSettings settings,
            string billingRef,
            bool uploadPackage)
        {
            var timestamp = DateTime.UtcNow;

            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;

            // Determine the output format to use (e.g., translate settings.Type to Contracts.InterviewFormat)
            OutputFormat outputFormat;

            switch (settings.Format)
            {
            case DocumentType.HFD:
                outputFormat = OutputFormat.HFD;
                break;

            case DocumentType.HPD:
                outputFormat = OutputFormat.HPD;
                break;

            case DocumentType.HTML:
                outputFormat = OutputFormat.HTML;
                break;

            case DocumentType.HTMLwDataURIs:
                outputFormat = OutputFormat.HTMLwDataURIs;
                break;

            case DocumentType.MHTML:
                outputFormat = OutputFormat.MHTML;
                break;

            case DocumentType.Native:
                outputFormat = OutputFormat.Native;
                break;

            case DocumentType.PDF:
                outputFormat = OutputFormat.PDF;
                break;

            case DocumentType.PlainText:
                outputFormat = OutputFormat.PlainText;
                break;

            case DocumentType.WordDOC:
                outputFormat = OutputFormat.DOCX;
                break;

            case DocumentType.WordDOCX:
                outputFormat = OutputFormat.DOCX;
                break;

            case DocumentType.WordPerfect:
                outputFormat = OutputFormat.WPD;
                break;

            case DocumentType.WordRTF:
                outputFormat = OutputFormat.RTF;
                break;

            default:
                outputFormat = OutputFormat.None;
                break;
            }

            // Always include the Answers output
            outputFormat |= OutputFormat.Answers;

            string hmac = HMAC.CalculateHMAC(
                SigningKey,
                timestamp,
                SubscriberId,
                packageTemplateLocation.PackageID,
                template.FileName,
                uploadPackage,
                billingRef,
                outputFormat,
                settings.Settings);

            return(_proxy.AssembleDocument(
                       SubscriberId,
                       packageTemplateLocation.PackageID,
                       template.FileName,
                       GetBinaryObjectArrayFromString(answers),
                       outputFormat,
                       settings.OutputOptions,
                       settings.Settings,
                       billingRef,
                       timestamp,
                       GetPackageIfNeeded(packageTemplateLocation, uploadPackage),
                       hmac));
        }
コード例 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="template">The template for which the interview is being requested.</param>
        /// <param name="answers">The answers to use with the interview.</param>
        /// <param name="settings">The settings to use when requesting the interview.</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="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal override BinaryObject[] GetInterviewImpl(
            Template template,
            string answers,
            InterviewSettings settings,
            string billingRef,
            bool uploadPackage)
        {
            var timestamp = DateTime.UtcNow;

            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;

            string interviewImageUrl = string.Empty;

            if (settings != null)
            {
                settings.Settings.TryGetValue("TempInterviewUrl", out interviewImageUrl);
            }
            else
            {
                settings = new InterviewSettings();
            }

            Dictionary <string, string> settingsDict = new Dictionary <string, string>(settings.Settings);

            // Workaround for bug in server that does not honor the Disable settings, so we have to just clear the url instead.
            // To do this, we make a copy of the settings that were given to us, modify them, and then use the modified version
            // in the call to Cloud Services.
            // TODO: After TFS #5598 is fixed, we can remove this workaround.
            // Note: TFS #5598 has been fixed, but the cloud implememntation does not pass those values through
            // to the cloud implmementation of HotDocs Server, so for now we leave these next 4 lines here that provide
            // equivalent functionality:
            if (settings.DisableDocumentPreview)
            {
                settingsDict.Remove("DocPreviewUrl");
            }
            if (settings.DisableSaveAnswers)
            {
                settingsDict.Remove("SaveAnswersPageUrl");
            }

            string hmac = HMAC.CalculateHMAC(
                SigningKey,
                timestamp,
                SubscriberId,
                packageTemplateLocation.PackageID,
                template.FileName,
                uploadPackage,
                billingRef,
                settings.Format,
                interviewImageUrl,
                settingsDict);

            return(_proxy.GetInterview(
                       SubscriberId,
                       packageTemplateLocation.PackageID,
                       template.FileName,
                       GetBinaryObjectArrayFromString(answers),
                       settings.Format,
                       settings.MarkedVariables.ToArray <string>(),
                       interviewImageUrl,
                       settingsDict,
                       billingRef,
                       timestamp,
                       GetPackageIfNeeded(packageTemplateLocation, uploadPackage),
                       hmac));
        }
コード例 #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="location"></param>
        /// <param name="uploadPackage">Indicates if the package should be uploaded (forcefully) or not. This should only be true if the package does not already exist in the Cloud Services cache.</param>
        /// <returns></returns>
        protected internal BinaryObject GetPackageIfNeeded(PackageTemplateLocation location, bool uploadPackage)
        {
            if (!uploadPackage)
                return null;

            using (Stream stream = location.GetPackageStream())
            {
                byte[] data;
                if (stream.CanSeek)
                {
                    data = new byte[stream.Length];
                    using (MemoryStream memStream = new MemoryStream(data))
                    {
                        stream.CopyTo(memStream);
                    }
                }
                else
                {
                    // Since we can't get the stream length for a non-seekable stream,
                    // we have to just let the buffer grow as needed.  After the streaming
                    // is done, we have to copy the data from the buffer to a correctly
                    // sized array.  This is very inefficient, but that's the price of
                    // using a non-seekable stream.
                    using (MemoryStream memStream = new MemoryStream())
                    {
                        stream.CopyTo(memStream);
                        data = memStream.ToArray();
                    }
                }

                return new BinaryObject()
                {
                    FileName = "",
                    DataEncoding = null,
                    Data = data
                };
            }
        }