FaxComLib FaxJob队列状态始终“待定”

时间:2011-06-23 15:00:39

标签: c# com status fax

我可以通过COM库FaxComLib发送传真(添加参考 - > COM选项卡 - > faxcom 1.0类型库),传真顺利通过。

我的问题是,虽然我可以发送传真,但我似乎无法从传真队列中获得准确的状态。 FaxJob对象的QueueStatus属性始终返回“Pending。”

环境:Windows 2003 R2 Enterprise w / SP2 - 也尝试在Windows 2008 R2上使用相同的结果

这是我的原型代码:

    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));
        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();
    }

当我为失败的作业(超出重试限制)运行它时,我得到了这个:

This result is always returned, no matter what the true status of the job is.

这是我获得任何传真工作的唯一状态;处于任何状态。难道我做错了什么?我是否将传真服务器配置错误?你能否为我解决我的问题?

感谢。 -Jason

2 个答案:

答案 0 :(得分:2)

我发现传真状态最强大的是使用“Microsoft传真服务扩展COM类型”库。添加对COM库的引用后,您可以侦听详细说明传真服务器发生情况的状态事件。

我写了一个FaxServerListener类来记录对于监听很重要的事件,其中一个事件包含一个包含相关状态属性的FaxJobStatus对象。

以下是您为注册OnOutgoingJobChanged事件然后收听它而采取的措施。

// ...
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();
    }

}

这是此代码的一些示例输出

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

正如您所看到的,它仍然显示您提到的待处理传真状态,但更好的状态是通过ExtendedStatusCode枚举值提供的。

有关每个扩展状态代码的详细状态信息,请参考here

答案 1 :(得分:0)

所以,我无法想出任何实质性的东西,但我已经取得了一些进展。如果在检查状态之前调用FaxJob.Refresh(),则会得到更好的结果。似乎在大多数情况下,你仍然得到一个无益的状态(在我的情况下是“未知”),但至少它并不总是“等待”。 如果传真失败,这也会返回“Retries Exceeded”状态,否则,“Unknown”是唯一可以获得的状态,我猜。

以下是一些示例代码:

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