using System;
using FACSys.AFM;
namespace FACSysAFMSampleCodes
{
/// <summary>
The FaxAttachments collection object contains zero or more FaxAttachment
objects and identifies the available attachments. Implements IFaxAttachments
from FACSys.AFM, IDisposable and IEnumerable from .Net Framework SDK. It uses an
ArrayList to host FaxAttachment objects.
/// </summary>
public class AttachmentSampleCode1 : ISampleCode
{
private FaxSession m_Session;
public AttachmentSampleCode1()
{
m_Session = new FaxSession();
m_Session.NetworkProtocol = 2;
m_Session.Logon("10.8.88.144", "Admin","password");
}
#region ISampleCode Members
public void Run()
{
try
{
//Check if the session exist.
if (m_Session == null)
throw new Exception("Session is null.");
int index = 0;
while (index == 0)
{
Console.WriteLine("Enter a message Id:");
string input = Console.ReadLine();
try
{
index = int.Parse(input);
}
catch
{
Console.WriteLine("Invalid number, enter again.");
continue;
}
}
IFaxMessage msg = m_Session.GetMessage(index);
if (msg == null)
throw new Exception("Cannot find the message with message id " + index.ToString());
IFaxAttachments attachments = msg.Attachments;
foreach (IFaxAttachment attachment in attachments)
{
DisplayAttachmentProperties(attachment);
Console.WriteLine("\nEnter the filename to save to your local:");
string filename = Console.ReadLine();
attachment.WriteToFile(filename);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void DisplayAttachmentProperties(IFaxAttachment attachment)
{
Console.WriteLine("=======FaxAttachment=======");
//Display Property FaxAttachment.Class
Console.WriteLine("FaxAttachment.Class: " + ((FaxMsg_Object)attachment.Class).ToString());
//Display Property FaxAttachment.Index
Console.WriteLine("FaxAttachment.Index: " + attachment.Index.ToString());
//Display Property FaxAttachment.Pages
Console.WriteLine("FaxAttachment.Pages: " + attachment.Pages.ToString());
//Display Property FaxAttachment.DefaultFileExtension
Console.WriteLine("FaxAttachment.DefaultFileExtension: " +
attachment.DefaultFileExtension.ToString());
//Display Property FaxAttachment.DeleteMode
Console.WriteLine("FaxAttachment.DeleteMode: " + attachment.DeleteMode.ToString());
//Display Property FaxAttachment.DisplayName
Console.WriteLine("FaxAttachment.DisplayName: " +
attachment.DisplayName.ToString());
//Display Property FaxAttachment.FileName
Console.WriteLine("FaxAttachment.FileName: " + attachment.FileName.ToString());
//Display Property FaxAttachment.FileOnServer
Console.WriteLine("FaxAttachment.FileOnServer: " +
attachment.FileOnServer.ToString());
//Display Property FaxAttachment.Font
Console.WriteLine("FaxAttachment.Font: " + attachment.Font.ToString());
//Display Property FaxAttachment.Resolution
Console.WriteLine("FaxAttachment.Resolution: " + ((FaxMsg_Resolution)attachment.Resolution).ToString());
//Display Property FaxAttachment.ScaleToWidth
Console.WriteLine("FaxAttachment.ScaleToWidth: " +
attachment.ScaleToWidth.ToString());
//Display Property FaxAttachment.SeamWithNext
Console.WriteLine("FaxAttachment.SeamWithNext: " +
attachment.SeamWithNext.ToString());
//Display Property FaxAttachment.Type
Console.WriteLine("FaxAttachment.Type: " + ((FaxMsg_FileType)attachment.Type).ToString());
//Display Property FaxAttachment.Parent
Console.WriteLine("FaxAttachment.Parent: " + attachment.Parent.ToString());
//Display Property FaxAttachment.Session
Console.WriteLine("FaxAttachment.Session: " + attachment.Session.ToString());
}
#endregion
#region IDisposable Members
public void Dispose()
{
if (m_Session != null)
m_Session.Logoff();
}
#endregion
~AttachmentSampleCode1()
{
Dispose();
}
}
}