using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using FastReport.Export;
namespace FastReport.Messaging
{
///
/// The base class for all messengers.
///
public class MessengerBase
{
#region Fields
private string filename;
private ProxySettings proxySettings;
#endregion // Fields
#region Properties
///
/// Gets the filename.
///
public string Filename
{
get { return filename; }
protected set { filename = value; }
}
///
/// Gets or sets the proxy settings.
///
public ProxySettings ProxySettings
{
get { return proxySettings; }
set { proxySettings = value; }
}
#endregion // Properties
#region Constructors
///
/// Initializes a new instance of the class.
///
public MessengerBase()
{
filename = "";
proxySettings = null;
}
#endregion // Constructors
#region Protected Methods
///
/// Authorizes the user.
///
/// True if user has been successfully authorized.
protected virtual bool Authorize()
{
return true;
}
///
/// Prepares the report before it will be send.
///
/// The report template.
/// The export filter.
/// Memory stream that contains prepared report.
protected MemoryStream PrepareToSave(Report report, ExportBase export)
{
MemoryStream stream = new MemoryStream();
if (export != null)
{
export.OpenAfterExport = false;
if (!export.HasMultipleFiles)
{
export.Export(report, stream);
}
else
{
export.ExportAndZip(report, stream);
}
}
else
{
report.PreparedPages.Save(stream);
}
filename = "Report";
if (!String.IsNullOrEmpty(report.FileName))
{
filename = Path.GetFileNameWithoutExtension(report.FileName);
}
string ext = ".fpx";
if (export != null)
{
if (!export.HasMultipleFiles)
{
ext = export.FileFilter.Substring(export.FileFilter.LastIndexOf('.')).ToLower();
}
else
{
ext = ".zip";
}
}
filename += ext;
stream.Position = 0;
return stream;
}
#endregion // Protected Methods
#region Public Methods
///
/// Sends the report.
///
/// The report template that should be sent.
/// The export filter that should export template before.
/// True if report has been successfully sent.
public virtual bool SendReport(Report report, ExportBase export)
{
return true;
}
#endregion // Public Methods
}
}