PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 1.00 average.

Faxing with C# using Fax Service Extended COM API - FAXCOMEXLib and C#

 
 
Patrick Kenney via AdminLife
Guest
Posts: n/a
 
      26th Jun 2004
this code works but I am having trouble with making it wait using AutoResetEvent[] or ManualResetEvent any suggestions with a code snippet of what to try?

Microsoft does not appear to have any C# samples of event handling with their fax service api using C# and the c++ and vb6 ones do not translate well to C#.

if I am missing something please advise...

thanks in advance.


namespace FaxDrill
{
public class FaxDrill
{
[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);

public static AutoResetEvent[] autoEvents; //event array
public static int intAryCtr;

protected FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM FaxSvrEnum;
protected FAXCOMEXLib.FaxDocument objFaxDocument = new FAXCOMEXLib.FaxDocumentClass();
protected FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM objFaxSvrEnum;
protected FAXCOMEXLib.FaxServer objFaxServer;
protected static object JobID;

public static void Main()
{
try
{
SendFaxOrEmail();
}

catch (Exception ex)
{
MessageBox(0,ex.Message + "source: " + ex.Source + "stack trace: " + ex.StackTrace ,"error",0);
}

}

//event handlers
public static void objFaxServer_OnOutgoingJobAdded(FaxServer pFaxServer, string bstrJobId)
{
MessageBox(0,"JobID: " + bstrJobId + "Added to queue","csFax",0);
}

public static void objFaxServer_OnServerShutDown(FaxServer pFaxServer)
{
MessageBox(0,"Fax Server Shutting Down","csFax",0);
}

public static void objFaxServer_OnOutgoingJobChanged(FaxServer pFaxServer, string bstrJobId, FaxJobStatus pJobStatus)
{
if (pJobStatus.Status == FAXCOMEXLib.FAX_JOB_STATUS_ENUM.fjsCOMPLETED)
{
try
{
MessageBox(0,"Fax Job Completed","csFax",0);
autoEvents[intAryCtr].Set();
}

catch (Exception Ex)
{
MessageBox(0,Ex.Message,"thread error",0);
}
}

}//end onOutGoingJobChanged

public static void SendFaxOrEmail()
{
try
{
FaxDrill objFaxDrill = new FaxDrill();
string FileName;
string strSubString;

objFaxDrill.objFaxServer = new FAXCOMEXLib.FaxServer();
objFaxDrill.objFaxServer.Connect("");//empty string will default to local host.

objFaxDrill.objFaxSvrEnum = (FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE | FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED);

//Register this method to listen to fax status events.
objFaxDrill.objFaxServer.ListenToServerEvents(objFaxDrill.objFaxSvrEnum);
/*
Delegates.
To wire the events, create a delegate instance and add it to the event you want to raise.
E.G.: OnOutgoingJobAdded event.
*/
objFaxDrill.objFaxServer.OnOutgoingJobAdded +=new IFaxServerNotify_OnOutgoingJobAddedEventHandler(objFaxServer_OnOutgoingJobAdded);
objFaxDrill.objFaxServer.OnServerShutDown +=new IFaxServerNotify_OnServerShutDownEventHandler(objFaxServer_OnServerShutDown);
objFaxDrill.objFaxServer.OnOutgoingJobChanged +=new IFaxServerNotify_OnOutgoingJobChangedEventHandler(objFaxServer_OnOutgoingJobChanged);

ArrayList Values = new ArrayList();
string [] Files = Directory.GetFiles("C:\\FaxDrop\\","*");//give me everything in this directory...
for(intAryCtr=0;intAryCtr<Files.Length;intAryCtr++)
{
autoEvents = new AutoResetEvent[Files.Length];

FileName = Files[intAryCtr];
Values.Add(intAryCtr);


objFaxDrill.objFaxDocument.Body = FileName;

objFaxDrill.objFaxDocument.DocumentName = "C#.NET Fax widget";

objFaxDrill.objFaxDocument.Priority = FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH;

objFaxDrill.objFaxDocument.Recipients.Add("999-999","Test Fax Recipient");

objFaxDrill.objFaxDocument.AttachFaxToReceipt = true;

objFaxDrill.objFaxDocument.CoverPageType = FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptSERVER;
objFaxDrill.objFaxDocument.CoverPage = "generic";

objFaxDrill.objFaxDocument.Note = "Test C# Fax Server";

objFaxDrill.objFaxDocument.ScheduleTime = DateTime.Now;

objFaxDrill.objFaxDocument.Subject = "Today's fax";

objFaxDrill.objFaxDocument.Sender.Name = "Fax Server";
objFaxDrill.objFaxDocument.Sender.City = "Cucamonga";
objFaxDrill.objFaxDocument.Sender.State = "California";
objFaxDrill.objFaxDocument.Sender.Company = "Loony Toons";
objFaxDrill.objFaxDocument.Sender.Country = "USA";
objFaxDrill.objFaxDocument.Sender.Email = "(E-Mail Removed)";
objFaxDrill.objFaxDocument.Sender.FaxNumber = "999-9999";
objFaxDrill.objFaxDocument.Sender.OfficeLocation = "cucamonga";
objFaxDrill.objFaxDocument.Sender.OfficePhone = "999-9999";
objFaxDrill.objFaxDocument.Sender.StreetAddress = "1313 Mocking Bird Lane.";
objFaxDrill.objFaxDocument.Sender.ZipCode = "91786";
objFaxDrill.objFaxDocument.Sender.Department = "BBunny - Fax Server";

objFaxDrill.objFaxDocument.Sender.SaveDefaultSender();

JobID = objFaxDrill.objFaxDocument.ConnectedSubmit(objFaxDrill.objFaxServer);

WaitHandle.WaitAll(autoEvents);
autoEvents[intAryCtr].Set();
}
}

catch (Exception ex)
{
throw (ex);
}
}//end SendFaxOrEmail()
}//end class FaxDrill.
}//end namespace FaxDrill.

-----------------------
Posted by a user from AdminLife (http://www.adminlife.com/)

<Id>NiHaFahjQEeqt87yOgI8TA==</Id>
 
Reply With Quote
 
 
 
 
Loganatr [MSFT]
Guest
Posts: n/a
 
      29th Jun 2004
Sample ManualResetEvent,
http://msdn.microsoft.com/library/de...sctorTopic.asp

Using ManualResetEvent in fax

public class SendFax
{
FaxServerClass faxServer;
ManualResetEvent addEvent = null;

void Register()
{
...........register for fax events..............
addEvent = new ManualResetEvent(false);
}

void SendFax()
{
.........Prepare Fax document and Send Fax .........
addEvent.WaitOne(MaxTimeToWait,false); //This will wait till
all faxes are submitted
..............
}

//Delegate, will be called when job is added
void OutJobAdded(FaxServer faxServer, string jobID)
{
numJobAdded++;
if (numJobAdded < numFaxes)
return;
addEvent.Set();
}

}

--
Loganatr [MSFT]
Microsoft Printing, Imaging and Fax Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.'



"Patrick Kenney via AdminLife" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> this code works but I am having trouble with making it wait using
> AutoResetEvent[] or ManualResetEvent any suggestions with a code snippet
> of what to try?
>
> Microsoft does not appear to have any C# samples of event handling with
> their fax service api using C# and the c++ and vb6 ones do not translate
> well to C#.
>
> if I am missing something please advise...
>
> thanks in advance.
>
>
> namespace FaxDrill
> {
> public class FaxDrill
> {
> [DllImport("User32.dll")]
> public static extern int MessageBox(int h, string m, string c, int type);
>
> public static AutoResetEvent[] autoEvents; //event array
> public static int intAryCtr;
>
> protected FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM FaxSvrEnum;
> protected FAXCOMEXLib.FaxDocument objFaxDocument = new
> FAXCOMEXLib.FaxDocumentClass();
> protected FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM objFaxSvrEnum;
> protected FAXCOMEXLib.FaxServer objFaxServer;
> protected static object JobID;
>
> public static void Main()
> {
> try
> {
> SendFaxOrEmail();
> }
>
> catch (Exception ex)
> {
> MessageBox(0,ex.Message + "source: " + ex.Source + "stack trace: " +
> ex.StackTrace ,"error",0);
> }
>
> }
>
> //event handlers
> public static void objFaxServer_OnOutgoingJobAdded(FaxServer pFaxServer,
> string bstrJobId)
> {
> MessageBox(0,"JobID: " + bstrJobId + "Added to queue","csFax",0);
> }
>
> public static void objFaxServer_OnServerShutDown(FaxServer pFaxServer)
> {
> MessageBox(0,"Fax Server Shutting Down","csFax",0);
> }
>
> public static void objFaxServer_OnOutgoingJobChanged(FaxServer pFaxServer,
> string bstrJobId, FaxJobStatus pJobStatus)
> {
> if (pJobStatus.Status == FAXCOMEXLib.FAX_JOB_STATUS_ENUM.fjsCOMPLETED)
> {
> try
> {
> MessageBox(0,"Fax Job Completed","csFax",0);
> autoEvents[intAryCtr].Set();
> }
>
> catch (Exception Ex)
> {
> MessageBox(0,Ex.Message,"thread error",0);
> }
> }
>
> }//end onOutGoingJobChanged
>
> public static void SendFaxOrEmail()
> {
> try
> {
> FaxDrill objFaxDrill = new FaxDrill();
> string FileName;
> string strSubString;
>
> objFaxDrill.objFaxServer = new FAXCOMEXLib.FaxServer();
> objFaxDrill.objFaxServer.Connect("");//empty string will default to local
> host.
>
> objFaxDrill.objFaxSvrEnum =
> (FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE |
> FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED);
>
> //Register this method to listen to fax status events.
> objFaxDrill.objFaxServer.ListenToServerEvents(objFaxDrill.objFaxSvrEnum);
> /*
> Delegates.
> To wire the events, create a delegate instance and add it to the event you
> want to raise.
> E.G.: OnOutgoingJobAdded event.
> */
> objFaxDrill.objFaxServer.OnOutgoingJobAdded +=new
> IFaxServerNotify_OnOutgoingJobAddedEventHandler(objFaxServer_OnOutgoingJobAdded);
> objFaxDrill.objFaxServer.OnServerShutDown +=new
> IFaxServerNotify_OnServerShutDownEventHandler(objFaxServer_OnServerShutDown);
> objFaxDrill.objFaxServer.OnOutgoingJobChanged +=new
> IFaxServerNotify_OnOutgoingJobChangedEventHandler(objFaxServer_OnOutgoingJobChanged);
>
> ArrayList Values = new ArrayList();
> string [] Files = Directory.GetFiles("C:\\FaxDrop\\","*");//give me
> everything in this directory...
> for(intAryCtr=0;intAryCtr<Files.Length;intAryCtr++)
> {
> autoEvents = new AutoResetEvent[Files.Length];
>
> FileName = Files[intAryCtr];
> Values.Add(intAryCtr);
>
>
> objFaxDrill.objFaxDocument.Body = FileName;
>
> objFaxDrill.objFaxDocument.DocumentName = "C#.NET Fax widget";
>
> objFaxDrill.objFaxDocument.Priority =
> FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH;
>
> objFaxDrill.objFaxDocument.Recipients.Add("999-999","Test Fax Recipient");
>
> objFaxDrill.objFaxDocument.AttachFaxToReceipt = true;
>
> objFaxDrill.objFaxDocument.CoverPageType =
> FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptSERVER;
> objFaxDrill.objFaxDocument.CoverPage = "generic";
>
> objFaxDrill.objFaxDocument.Note = "Test C# Fax Server";
>
> objFaxDrill.objFaxDocument.ScheduleTime = DateTime.Now;
>
> objFaxDrill.objFaxDocument.Subject = "Today's fax";
>
> objFaxDrill.objFaxDocument.Sender.Name = "Fax Server";
> objFaxDrill.objFaxDocument.Sender.City = "Cucamonga";
> objFaxDrill.objFaxDocument.Sender.State = "California";
> objFaxDrill.objFaxDocument.Sender.Company = "Loony Toons";
> objFaxDrill.objFaxDocument.Sender.Country = "USA";
> objFaxDrill.objFaxDocument.Sender.Email = "(E-Mail Removed)";
> objFaxDrill.objFaxDocument.Sender.FaxNumber = "999-9999";
> objFaxDrill.objFaxDocument.Sender.OfficeLocation = "cucamonga";
> objFaxDrill.objFaxDocument.Sender.OfficePhone = "999-9999";
> objFaxDrill.objFaxDocument.Sender.StreetAddress = "1313 Mocking Bird
> Lane.";
> objFaxDrill.objFaxDocument.Sender.ZipCode = "91786";
> objFaxDrill.objFaxDocument.Sender.Department = "BBunny - Fax Server";
>
> objFaxDrill.objFaxDocument.Sender.SaveDefaultSender();
>
> JobID =
> objFaxDrill.objFaxDocument.ConnectedSubmit(objFaxDrill.objFaxServer);
>
> WaitHandle.WaitAll(autoEvents);
> autoEvents[intAryCtr].Set();
> }
> }
>
> catch (Exception ex)
> {
> throw (ex);
> }
> }//end SendFaxOrEmail()
> }//end class FaxDrill.
> }//end namespace FaxDrill.
>
> -----------------------
> Posted by a user from AdminLife (http://www.adminlife.com/)
>
> <Id>NiHaFahjQEeqt87yOgI8TA==</Id>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with C# and FAXCOMEXLib: Fax Service Extended COM API (faxcomex.dll) PKenney Microsoft Windows 2000 Fax 2 11th Feb 2010 10:18 AM
Trouble with C# and FAXCOMEXLib: Fax Service Extended COM API Patrick Kenney via AdminLife Microsoft Windows 2000 Fax 3 17th Feb 2006 11:46 PM
Trouble with C# and FAXCOMEXLib: Fax Service Extended COM API (faxcomex.dll) Patrick Kenney via AdminLife Microsoft Windows 2000 Fax 0 5th Jun 2004 07:18 PM
Trouble with C# and FAXCOMEXLib: Fax Service Extended COM API (faxcomex.dll) Patrick Kenney via AdminLife Windows XP Print / Fax 0 5th Jun 2004 07:18 PM
Trouble with C# and FAXCOMEXLib: Fax Service Extended COM API Parick Kenney Windows XP Print / Fax 1 3rd Jun 2004 10:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:28 PM.