Beispiel #1
0
        public void Render(AbortState abortState, string reportPath, string executionId, string historyId, string format, XmlNodeList deviceInfo, NameValueCollection urlAccessParameters, Stream reportStream, out string mimeType, out string fileNameExtension)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}?{1}&rs:SessionID={2}&rs:command=Render&rs:Format={3}", Service.UrlForRender, UrlUtil.UrlEncode(reportPath), UrlUtil.UrlEncode(executionId), UrlUtil.UrlEncode(format));
            if (!string.IsNullOrEmpty(historyId))
            {
                stringBuilder.Append("&rs:snapshot=");
                stringBuilder.Append(UrlUtil.UrlEncode(historyId));
            }
            if (deviceInfo != null)
            {
                foreach (XmlNode item in deviceInfo)
                {
                    stringBuilder.Append("&rc:");
                    stringBuilder.Append(UrlUtil.UrlEncode(item.Name));
                    stringBuilder.Append("=");
                    stringBuilder.Append(UrlUtil.UrlEncode(item.InnerText));
                }
            }
            stringBuilder.Append("&rc:Toolbar=false&rs:ErrorResponseAsXml=true&rs:AllowNewSessions=false");
            if (urlAccessParameters != null)
            {
                foreach (string key in urlAccessParameters.Keys)
                {
                    stringBuilder.Append("&");
                    stringBuilder.Append(UrlUtil.UrlEncode(key));
                    stringBuilder.Append("=");
                    stringBuilder.Append(UrlUtil.UrlEncode(urlAccessParameters[key]));
                }
            }
            ServerUrlRequest(abortState, stringBuilder.ToString(), reportStream, out mimeType, out fileNameExtension);
        }
Beispiel #2
0
        private void ServerUrlRequest(AbortState abortState, string url, Stream outputStream, out string mimeType, out string fileNameExtension)
        {
            byte[] userToken = null;
            string userName  = string.Empty;

            if (m_trustedUserHeader != null)
            {
                userName  = m_trustedUserHeader.UserName;
                userToken = m_trustedUserHeader.UserToken;
            }
            HttpWebRequest serverUrlAccessObject = WebRequestHelper.GetServerUrlAccessObject(url, m_timeout, ServerNetworkCredentials, Service.FormsAuthCookie, m_headers, m_cookies, userName, BearerToken, userToken);

            if (abortState != null && !abortState.RegisterAbortableRequest(serverUrlAccessObject))
            {
                throw new OperationCanceledException();
            }
            try
            {
                using (new ServerImpersonationContext(m_impersonationUser))
                {
                    WebResponse response = serverUrlAccessObject.GetResponse();
                    mimeType          = response.Headers["Content-Type"];
                    fileNameExtension = response.Headers["FileExtension"];
                    Stream responseStream = response.GetResponseStream();
                    if (responseStream == null)
                    {
                        return;
                    }
                    using (responseStream)
                    {
                        byte[] array = new byte[81920];
                        int    count;
                        while ((count = responseStream.Read(array, 0, array.Length)) > 0)
                        {
                            outputStream.Write(array, 0, count);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw WebRequestHelper.ExceptionFromWebResponse(e);
            }
        }