开发者

FaxComLib FaxJob Queue Status is Always "Pending"

I'm able to send a fax through the COM library FaxComLib (Add Reference -> COM tab -> faxcom 1.0 Type Library) and the fax goes through successfully.

My problem is that while I can send a fax, I can't seem to get an accurate status back from the fax queue. The QueueStatus property of the FaxJob object always returns "Pending."

The environment: Windows 2003 R2 Enterprise w/SP2 -- have also tried on Windows 2008 R2 with same results

Here's my prototype code:

    public void GetFaxStatus(int queueNum)
    {
        FaxServer faxServer = new FaxServer();
        faxServer.Connect("myfaxservername");
        bool isInQueue = false;

        FaxJobs faxJobs = (FaxJobs)faxServer.GetJobs();

        for (int i = 1; i <= faxJobs.Count; i++)
        {
            FaxJob j = (FaxJob)faxJobs.Item[i];
            MessageBox.Show(faxJobs.Item[i].GetType().ToString() + "\r\n" + CreateStatus(j));

            if (j.JobId == queueNum)
            {
                MessageBox.Show("Found Job:\r\n" + CreateStatus(j));
                isInQueue = true;
            }

        }

        if (isInQueue == false)
        {
            MessageBox.Show("Fax is no longer in queue.(...or does not exist)");
        }

        faxServer.Disconnect();
    }

    static string CreateStatus(FaxJob job)
    {
        StringBuilder sb = new StringBuilder();

        sb.AppendLine(string.Format("Billing Code: {0}", job.BillingCode));
        sb.AppendLine(string.Format("Device Status: {0}\r\n", job.DeviceStatus));
       开发者_如何学C sb.AppendLine(string.Format("Queue Status: {0}", job.QueueStatus));
        sb.AppendLine(string.Format("Display Name: {0}", job.DisplayName));
        sb.AppendLine(string.Format("Fax Number: {0}", job.FaxNumber));
        sb.AppendLine(string.Format("Job Id: {0}", job.JobId));
        sb.AppendLine(string.Format("Tsid: {0}", job.Tsid));
        sb.AppendLine(string.Format("Type: {0}", job.Type));
        sb.AppendLine(string.Format("Page Count: {0}", job.PageCount));

        return sb.ToString();
    }

When I run it for a job that has failed (retry limit was exceeded), I get this:

FaxComLib FaxJob Queue Status is Always "Pending"

That is the only status I ever get for any fax job; in any status. Am I doing something wrong? Have I configured the fax server wrong? Can you shed any light on my problem for me?

Thanks. -Jason


What I found to be the most robust for fax status is to use the "Microsoft Fax Service Extended COM Type" library instead. After adding a reference to the COM library, you can listen for status events that detail what is happening with the fax server.

I wrote a FaxServerListener class that registers events that are important to listen to and one of the events includes a FaxJobStatus object which contains pertinent status properties.

Here's what you do to register for the OnOutgoingJobChanged event and then listen to it.

// ...
using FAXCOMEXLib;

public class FaxServerListener
{
    private FaxServer faxServer;

    public FaxServerListener(string faxServerMachineName)
    {
        faxServer = new FaxServer();
        faxServer.Connect(faxServerMachineName);
        RegisterFaxServerEvents();
    }

    private void RegisterFaxServerEvents()
    {
        // subscribe to multiple FaxServer events here ...
        faxServer.OnOutgoingJobChanged += faxServer_OnOutgoingJobChanged;

        /* very important, you MUST tell the FaxServer object which events you're
         * listening for, otherwise the events will never raise!
         * This is what I have set and you should only need one of the event types
         * to listen for but I didn't research this for your problem
         */
        var events = FAX_SERVER_EVENTS_TYPE_ENUM.fsetACTIVITY |
                     FAX_SERVER_EVENTS_TYPE_ENUM.fsetDEVICE_STATUS |
                     FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_ARCHIVE |
                     FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE;

        faxServer.ListenToServerEvents(events);
    }

    private void faxServer_OnOutgoingJobChanged(FaxServer faxServer, string jobId,
        FaxJobStatus jobStatus)
    {
        // Of course you can do whatever you wish here. This is the method that
        // subscribes to the event with a JobStatus object
        string output = string.Format("Outgoing Job Changed -> {0}{1}{2}",
            jobId, Environment.NewLine, GetJobStatusOutput(jobStatus));

        // you could process the FaxJobStatus object how ever you wish here
        // I raised another event from this listener class with the output data
        // for other client code to listen to.
    }

    private string GetJobStatusOutput(FaxJobStatus jobStatus)
    {
        StringBuilder sb = new StringBuilder();

        sb.AppendLine("\tDeviceID: " + jobStatus.DeviceId.ToString());
        sb.AppendLine("\tCurrent Page: " + jobStatus.CurrentPage.ToString());
        sb.AppendLine("\tExt. Status Code: " + jobStatus.ExtendedStatusCode.ToString());
        sb.AppendLine("\tExt. Status: " + jobStatus.ExtendedStatus);
        sb.AppendLine("\tJob Type: " + jobStatus.JobType.ToString());
        sb.AppendLine("\tRetries: " + jobStatus.Retries.ToString());
        sb.AppendLine("\tSize: " + jobStatus.Size.ToString());
        sb.AppendLine("\tStatus: " + jobStatus.Status.ToString());
        sb.AppendLine("\tStart: " + jobStatus.TransmissionStart.ToShortTimeString());

        if (jobStatus.ExtendedStatusCode != FAX_JOB_EXTENDED_STATUS_ENUM.fjesTRANSMITTING)
        {
            sb.AppendLine("\tStop: " + jobStatus.TransmissionEnd.ToShortTimeString());
        }

        sb.AppendLine("\tTSID: " + jobStatus.TSID);

        return sb.ToString();
    }

}

This is some example output for this code

Outgoing Job Changed -> 201cce11ee0903f
    DeviceID: 65538
    Current Page: 1
    Ext. Status Code: fjesCALL_COMPLETED
    Ext. Status: 
    Job Type: fjtSEND
    Retries: 0
    Size: 10841
    Status: fjsINPROGRESS
    Start: 3:20 PM
    Stop: 3:21 PM
    TSID: Fax

As you can see it still show's the pending fax status that you mentioned but better status is provided with the ExtendedStatusCode enum value.

Detailed status information regarding each extended status code is referenced here.


So, I couldn't come up with anything substantial, but I have made a little progress. If you call FaxJob.Refresh() prior to checking the status, you get a little better result. It appears that a majority of the time, you still get an unhelpful status ("Unknown" in my case), but at least it's not always "Pending." This also returns a "Retries Exceeded" status if the fax fails, but otherwise, "Unknown" is the only status you can get, I guess.

Here's some sample code:

        if (j.JobId == queueNum)
        {
            MessageBox.Show("Found Job:\r\n" + CreateStatus(j));
            j.Refresh();
            isInQueue = true;
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜