Exemple #1
0
        public ActionResult OpenDocument(string rdm)
        {
            string output = "Could not find the report requested";
            try
            {
                _logMessage.Append("Opening the report.");
                if (string.IsNullOrEmpty(rdm))
                {
                    _logMessage.Append("Passed the report id "+ rdm + ".");
                    return Content(output);
                }
                                
                string opendocUrl = _restClient.GetReport(Identity.SapToken, Identity.BOSerializedSessionId, rdm);

                _logMessage.Append("Opendocument url obtain from rest client "+ opendocUrl + ".");

                Uri openDocumentUriObject;

                if (Uri.TryCreate(opendocUrl,UriKind.RelativeOrAbsolute,out openDocumentUriObject))
                {
                    HttpWebRequest opendocRequest = (HttpWebRequest)WebRequest.Create(opendocUrl);
                    opendocRequest.Method = "GET";
                    opendocRequest.Accept = "text/html";
                    using (HttpWebResponse openDocResponse = (HttpWebResponse)opendocRequest.GetResponse())
                    {
                        using (Stream getRequestResponseStream = openDocResponse.GetResponseStream())
                        {
                            using (StreamReader sr = new StreamReader(getRequestResponseStream))
                            {
                                output = sr.ReadToEnd();
                                sr.Close();
                            }
                        }
                    }
                    _logMessage.Append("Sending the opendocument request content.");
                    return Content(output);
                }
                else
                {
                    output = "Reporting system did not respond with proper report.";
                }                
            }
            catch (Exception ex)
            {
                _logMessage.Append("An Error occurred Exception Message "+ ex.Message);
                Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
            }
            _logger.Info(_logMessage.ToString());
            return Content(output);
        }