2011-06-23 53 views
1

我可以通過COM庫庫FaxComLib發送傳真(添加引用 - > COM選項卡 - > faxcom 1.0類型庫)並且傳真成功。FaxComLib FaxJob隊列狀態總是「待定」

我的問題是雖然我可以發送傳真,但我似乎無法從傳真隊列中獲得準確的狀態。 FaxJob對象的QueueStatus屬性始終返回「Pending」。

的環境:Windows 2003 R2企業瓦特/ 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

+0

這無疑是您的傳真服務提供商的問題。聯繫製造商尋求支持。 –

+0

我們使用的是本地傳真調制解調器和內置的Windows傳真服務。真的沒有很多可配置的設置,我不知道我應該轉向哪個製造商。這裏沒有第三方參與。 –

+0

你的'for loop'顯示如何枚舉FaxJobs救了我! MSFT文檔sux btw。 – Flea

回答

0

所以,我不能拿出任何實質性的東西,但我已經取得了一些進展。如果您在檢查狀態之前調用FaxJob.Refresh(),您會得到一個更好的結果。看起來大多數時候,你仍然處於無用的狀態(在我的情況下是「未知」),但至少它並不總是「待定」。 如果傳真失敗,這也會返回「Retries Exceeded」狀態,但否則,「未知」是唯一可以獲得的狀態,我想。

下面是一些示例代碼:

 if (j.JobId == queueNum) 
     { 
      MessageBox.Show("Found Job:\r\n" + CreateStatus(j)); 
      j.Refresh(); 
      isInQueue = true; 
     } 
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

+0

優秀的答案。謝謝你的幫助! –