MessengerBase.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using FastReport.Export;
  6. namespace FastReport.Messaging
  7. {
  8. /// <summary>
  9. /// The base class for all messengers.
  10. /// </summary>
  11. public class MessengerBase
  12. {
  13. #region Fields
  14. private string filename;
  15. private ProxySettings proxySettings;
  16. #endregion // Fields
  17. #region Properties
  18. /// <summary>
  19. /// Gets the filename.
  20. /// </summary>
  21. public string Filename
  22. {
  23. get { return filename; }
  24. protected set { filename = value; }
  25. }
  26. /// <summary>
  27. /// Gets or sets the proxy settings.
  28. /// </summary>
  29. public ProxySettings ProxySettings
  30. {
  31. get { return proxySettings; }
  32. set { proxySettings = value; }
  33. }
  34. #endregion // Properties
  35. #region Constructors
  36. /// <summary>
  37. /// Initializes a new instance of the <see cref="MessengerBase"/> class.
  38. /// </summary>
  39. public MessengerBase()
  40. {
  41. filename = "";
  42. proxySettings = null;
  43. }
  44. #endregion // Constructors
  45. #region Protected Methods
  46. /// <summary>
  47. /// Authorizes the user.
  48. /// </summary>
  49. /// <returns>True if user has been successfully authorized.</returns>
  50. protected virtual bool Authorize()
  51. {
  52. return true;
  53. }
  54. /// <summary>
  55. /// Prepares the report before it will be send.
  56. /// </summary>
  57. /// <param name="report">The report template.</param>
  58. /// <param name="export">The export filter.</param>
  59. /// <returns>Memory stream that contains prepared report.</returns>
  60. protected MemoryStream PrepareToSave(Report report, ExportBase export)
  61. {
  62. MemoryStream stream = new MemoryStream();
  63. if (export != null)
  64. {
  65. export.OpenAfterExport = false;
  66. if (!export.HasMultipleFiles)
  67. {
  68. export.Export(report, stream);
  69. }
  70. else
  71. {
  72. export.ExportAndZip(report, stream);
  73. }
  74. }
  75. else
  76. {
  77. report.PreparedPages.Save(stream);
  78. }
  79. filename = "Report";
  80. if (!String.IsNullOrEmpty(report.FileName))
  81. {
  82. filename = Path.GetFileNameWithoutExtension(report.FileName);
  83. }
  84. string ext = ".fpx";
  85. if (export != null)
  86. {
  87. if (!export.HasMultipleFiles)
  88. {
  89. ext = export.FileFilter.Substring(export.FileFilter.LastIndexOf('.')).ToLower();
  90. }
  91. else
  92. {
  93. ext = ".zip";
  94. }
  95. }
  96. filename += ext;
  97. stream.Position = 0;
  98. return stream;
  99. }
  100. #endregion // Protected Methods
  101. #region Public Methods
  102. /// <summary>
  103. /// Sends the report.
  104. /// </summary>
  105. /// <param name="report">The report template that should be sent.</param>
  106. /// <param name="export">The export filter that should export template before.</param>
  107. /// <returns>True if report has been successfully sent.</returns>
  108. public virtual bool SendReport(Report report, ExportBase export)
  109. {
  110. return true;
  111. }
  112. #endregion // Public Methods
  113. }
  114. }