/// <summary>
        /// Export the report to memory stream
        /// </summary>
        /// <param name="source">Xml source of report</param>
        /// <param name="parameters">Example: parameter1=someValue&parameter2=anotherValue</param>
        public static MemoryStream ExportToMemoryStream(string source, string parameters, OutputPresentationType exportType)
        {
            // Compile the report
            report = GetReport(source);
            if (report == null)
            {
                throw new ArgumentException("Can not compile report");
            }

            report.RunGetData(GetParmeters(parameters));

            MemoryStreamGen ms = null;

            try {
                ms = new MemoryStreamGen();
                report.RunRender(ms, exportType);
            } catch (Exception ex) {
                ms.CloseMainStream();
                throw ex;
            }
            return(ms.GetStream() as MemoryStream);
        }
Beispiel #2
0
        private void Generate(Report report)
        {
            MemoryStreamGen sg = null;

            try
            {
                sg = new MemoryStreamGen("ShowFile.aspx?type=", null, this.RenderType);

                report.RunRender(sg, _RenderType, this.UniqueID);
                _CSS        = "";
                _JavaScript = "";
                switch (_RenderType)
                {
                case OutputPresentationType.ASPHTML:
                case OutputPresentationType.HTML:
                    _CSS        = report.CSS;//.Replace("position: relative;", "position: absolute;");
                    _JavaScript = report.JavaScript;
                    _Html       = sg.GetText();
                    break;

                case OutputPresentationType.XML:
                    _Xml = sg.GetText();
                    break;

                case OutputPresentationType.CSV:
                    _Csv = sg.GetText();
                    break;

                case OutputPresentationType.PDF:
                {
                    MemoryStream ms = sg.MemoryList[0] as MemoryStream;
                    _Object = ms.ToArray();
                    break;
                }
                }

                // Now save off the other streams in the session context for later use
                IList strms = sg.MemoryList;
                IList names = sg.MemoryNames;
                for (int i = 1; i < sg.MemoryList.Count; i++)                   // we skip the first one
                {
                    string       n  = names[i] as string;
                    MemoryStream ms = strms[i] as MemoryStream;
                    Context.Session[n] = ms.ToArray();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (sg != null)
                {
                    sg.CloseMainStream();
                }
            }

            if (report.ErrorMaxSeverity > 0)
            {
                AddError(report.ErrorMaxSeverity, report.ErrorItems);
                report.ErrorReset();
            }

            return;
        }