Пример #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Gets exporter object by identificator.
        /// </summary>
        /// <param name="identificator">Export type identificator (name or file extension).</param>
        /// <returns>Unifed document exporter.</returns>
        private static IDocumentExport _GetExporter(string identificator)
        {
            Debug.Assert(!string.IsNullOrEmpty(identificator));

            IDocumentExport export = null;

            // select export format type
            switch (identificator)
            {
            case EXPORT_EXTENSION_HTM:
            case EXPORT_TYPE_NAME_HTM:
                export = new HtmlExport();
                break;

            case EXPORT_EXTENSION_PDF:
            case EXPORT_TYPE_NAME_PDF:
                export = new PdfExport();
                break;

            case EXPORT_EXTENSION_RTF:
            case EXPORT_TYPE_NAME_RTF:
                export = new RtfExport();
                break;

            case EXPORT_EXTENSION_TIF:
            case EXPORT_TYPE_NAME_TIF:
                export = new TiffExport();
                break;

            case EXPORT_EXTENSION_TXT:
            case EXPORT_TYPE_NAME_TXT:
                export = new TextExport();
                break;

            case EXPORT_EXTENSION_XLS:
            case EXPORT_TYPE_NAME_XLS:
                export = new XlsExport();
                break;

            default:
                Debug.Assert(false);     // NOTE: not supported
                break;
            }

            return(export);
        }
Пример #2
0
        public static FileStreamResult ToRtfResult(this DataDynamics.ActiveReports.Document.Document reportDocument, string name)
        {
            // Do not close or dispose MemoryStream as the FileStreamResult disposes it after use
            var memoryStream = new MemoryStream();

            using (var exported = new RtfExport())
            {
                exported.Export(reportDocument, memoryStream);

                memoryStream.Flush();
                memoryStream.Seek(0, SeekOrigin.Begin);

                var fileStreamResult = new FileStreamResult(memoryStream, "application/msword");

                fileStreamResult.FileDownloadName = string.Format("{0}.doc", name);

                return(fileStreamResult);
            }
        }
 public override void WriteToStream(Type type, object value, Stream writeStream, HttpContent content)
 {
     using (var writer = new StreamWriter(writeStream)) {
         var report = value as SectionReport;
         if (report != null)
         {
             var memStream = new MemoryStream();
             var rtfExport = new RtfExport();
             rtfExport.Export(report.Document, memStream);
             memStream.Position = 0;
             writeStream.Write(memStream.ToArray(), 0, (int)memStream.Length);
             content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
             {
                 FileName = report.Name + ".rtf"
             };
         }
         else
         {
             throw new InvalidOperationException("Cannot serialize type");
         }
     }
 }
Пример #4
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Gets exporter object by identificator.
        /// </summary>
        /// <param name="identificator">Export type identificator (name or file extension).</param>
        /// <returns>Unifed document exporter.</returns>
        private static IDocumentExport _GetExporter(string identificator)
        {
            Debug.Assert(!string.IsNullOrEmpty(identificator));

            IDocumentExport export = null;
            // select export format type
            switch (identificator)
            {
                case EXPORT_EXTENSION_HTM:
                case EXPORT_TYPE_NAME_HTM:
                    export = new HtmlExport();
                    break;

                case EXPORT_EXTENSION_PDF:
                case EXPORT_TYPE_NAME_PDF:
                    export = new PdfExport();
                    break;

                case EXPORT_EXTENSION_RTF:
                case EXPORT_TYPE_NAME_RTF:
                    export = new RtfExport();
                    break;

                case EXPORT_EXTENSION_TIF:
                case EXPORT_TYPE_NAME_TIF:
                    export = new TiffExport();
                    break;

                case EXPORT_EXTENSION_TXT:
                case EXPORT_TYPE_NAME_TXT:
                    export = new TextExport();
                    break;

                case EXPORT_EXTENSION_XLS:
                case EXPORT_TYPE_NAME_XLS:
                    export = new XlsExport();
                    break;

                default:
                    Debug.Assert(false); // NOTE: not supported
                    break;
            }

            return export;
        }