More on Controlling Windows Fax Services Using VB.Net - What is the Code Doing? (Page 2 of 4 )
The first five lines are just our object and variable declarations. The first object (objFaxServer) is our actual connection to the fax server. As discussed in the first article, all the methods we need when controlling the fax services are in FAXCOMEXLib.
Next, we have our activity object called objFaxActivity. This will let us ask the fax service about what active jobs it is currently handling. Our last object is collFaxDevices. This gives us the number of physical fax devices that the fax server is using. These are normally modems but could be ISDNs or others depending on your setup.
The final declaration lines are just a variable we will use to keep track of the number of jobs and our streamwriter object so we can write the values out to a file.
Next, we use our fax server object, and connect it to our fax server. In a production application you should enclose this statement in a Try/Catch in order to gracefully handle any exceptions, the main one here being that you can't see the server or don't have permissions to connect to it.
Next we set the activity object we created to the server object. This will now allow us to query that server for activity, so the first thing we do after that is use the refresh method to get all the latest information.
Using our newly created activity object, we then add together its QueuedMessages and OutgoingMessages and hold them in the count variable. This number will tell us how many jobs are currently being sent out from the server, and how many are waiting to be sent.
We then set our devices object to be the number of devices on the server to which we have attached. Now that we have all the information available to us, we can write it out to our file.
First of all we set our StreamWriter to create a new file (c:num_jobs.txt) and append text to it. Then, line by line we write out the current time, the number of modems, the total number of faxes being and waiting to be sent, the number of current outgoing jobs, the number of queued jobs and the number of incoming jobs.
Run the application in Visual Studio, and hit the new button. If all has gone according to plan you should now have a file similar to this one at c:num_jobs.txt:
Time: 11/07/2007 11:38:22
Modems:4
Total Faxes:1
Outgoing: 1
Queued: 0
Incoming: 0
While information like this might not be of too much use, you now should have all the code you need to get overall job information from the server.
I have used this information in the past when load balancing more than one fax server. Before sending any new jobs I look at a file similar to this on all my fax servers, decide which one is the quietest and send my new job to that one.
Next: Submitting a Job to the Server >>
More Visual Basic.NET Articles
More By Luke Niland