Member 11025896 Ответов: 0

Как вызвать событие факса во время отправки факса с факс-модем-в-используется CSharp используя faxcomexlib


Привет,
Я могу успешно отправить факс и получить JobID.
Но событие faxServer_OnOutgoingJobChanged () не сработало, поэтому я не могу получить факс Satatus.Срабатывает только событие faxServer_OnOutgoingJobAdded ().

Пожалуйста, помогите мне.
мой код..

Что я уже пробовал:

public class FaxSender
{
#region Global Variable
private static string eFaxServerName = ConfigurationManager.AppSettings["eFaxServerName"].ToString();
#endregion
 
Hide   Expand    Copy Code
    private static FaxServer faxServer;
    private FaxDocument faxDoc;
    private static string faxNumber = string.Empty;
 
    public FaxSender()
    {
        StringBuilder objSBTrace = new StringBuilder();
 
        try
        {               
 
            faxServer = new FaxServer();
            faxServer.Connect(eFaxServerName);
            RegisterFaxServerEvents();
        }
        catch (Exception ex)
        {
 
        }
    }
 
    private void RegisterFaxServerEvents()
    {
 
        try
        {
 
            faxServer.OnOutgoingJobAdded +=
            new IFaxServerNotify2_OnOutgoingJobAddedEventHandler(faxServer_OnOutgoingJobAdded);
            faxServer.OnOutgoingJobChanged +=
                new IFaxServerNotify2_OnOutgoingJobChangedEventHandler(faxServer_OnOutgoingJobChanged);
            faxServer.OnOutgoingJobRemoved +=
                new IFaxServerNotify2_OnOutgoingJobRemovedEventHandler(faxServer_OnOutgoingJobRemoved);
 
            var eventsToListen =
                FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED | FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE |
                FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_ARCHIVE | FAX_SERVER_EVENTS_TYPE_ENUM.fsetQUEUE_STATE |
                FAX_SERVER_EVENTS_TYPE_ENUM.fsetACTIVITY | FAX_SERVER_EVENTS_TYPE_ENUM.fsetDEVICE_STATUS;
 
            faxServer.ListenToServerEvents(eventsToListen);
        }
        catch (Exception ex)
        {
 
        }
    }
 
    #region Event Listeners
    private static void faxServer_OnOutgoingJobAdded(FaxServer pFaxServer, string bstrJobId)
    {           
 
        Console.WriteLine("OnOutgoingJobAdded event fired. A fax is added to the outgoing queue.");
    }
 
    private static void faxServer_OnOutgoingJobChanged(FaxServer pFaxServer, string bstrJobId, FaxJobStatus pJobStatus)
    {           
 
        Console.WriteLine("OnOutgoingJobChanged event fired. A fax is changed to the outgoing queue.");
 
        pFaxServer.Folders.OutgoingQueue.Refresh();
        PrintFaxStatus(pJobStatus, bstrJobId);
    }
 
    private static void faxServer_OnOutgoingJobRemoved(FaxServer pFaxServer, string bstrJobId)
    {
 
        Console.WriteLine("OnOutgoingJobRemoved event fired. Fax job is removed to outbound queue.");
    }
    #endregion

    private static void PrintFaxStatus(FaxJobStatus faxJobStatus, string bstrJobId)
    {
        try
        {
            if (faxJobStatus.ExtendedStatusCode == FAX_JOB_EXTENDED_STATUS_ENUM.fjesDIALING)
            {
                Console.WriteLine("Dialing...");
            }
 
            if (faxJobStatus.ExtendedStatusCode == FAX_JOB_EXTENDED_STATUS_ENUM.fjesTRANSMITTING)
            {
                Console.WriteLine("Sending Fax...");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsCOMPLETED
                && faxJobStatus.ExtendedStatusCode == FAX_JOB_EXTENDED_STATUS_ENUM.fjesCALL_COMPLETED)
            {
                Console.WriteLine("Fax is sent successfully.");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsFAILED)
            {
                Console.WriteLine("Fax sending Failed.");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsINPROGRESS)
            {
                Console.WriteLine("Fax is in-progress.");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsNOLINE)
            {
                Console.WriteLine("Fax is no line.");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsPAUSED)
            {
                Console.WriteLine("Fax is paused.");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsPENDING)
            {
                Console.WriteLine("Fax is pending.");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsRETRIES_EXCEEDED)
            {
                Console.WriteLine("Fax retry exceeded.");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsRETRYING)
            {
                objSTrace.Append("Fax is retrying");
                SaveLogger.SaveLoggerTrace(objSTrace);
                objSTrace.Clear();
                Console.WriteLine("Fax is retrying.");
            }
 
            if (faxJobStatus.Status == FAX_JOB_STATUS_ENUM.fjsROUTING)
            {
                objSTrace.Append("Fax is routing.");
                SaveLogger.SaveLoggerTrace(objSTrace);
                objSTrace.Clear();
                Console.WriteLine("Fax is routing.");
            }  
 
        }
        catch (Exception ex)
        {
        }
 
    }
 
    public string SendFax(string subject, string FaxDocument, string FaxNumber)
    {
 
        faxNumber = FaxNumber;<br />
        try
        {
            FaxDocumentSetup(subject, FaxDocument, FaxNumber);
            var JobId = faxDoc.Submit(faxServer.ServerName);
            faxDoc = null;              
 
            result = Convert.ToString(JobId[0]);
            Console.WriteLine("Job Id: " + Convert.ToString(JobId[0]));
        }
        catch (System.Runtime.InteropServices.COMException comException)
        {
 
            Console.WriteLine("Error connecting to fax server. Error Message: " + comException.Message);
            Console.WriteLine("StackTrace: " + comException.StackTrace);
        }
        catch (Exception ex)
        {
        }
        return result;
    }
 
    private void FaxDocumentSetup(string subject, string FaxDocument, string FaxNumber)
    {
 
        try
        {                
 
            faxDoc = new FaxDocument();
            faxDoc.Priority = FAX_PRIORITY_TYPE_ENUM.fptHIGH;
            faxDoc.ReceiptType = FAX_RECEIPT_TYPE_ENUM.frtNONE;
            faxDoc.AttachFaxToReceipt = true;
            faxDoc.Body = FaxDocument;
            faxDoc.Subject = subject;
            faxDoc.Recipients.Add(FaxNumber);
        }
        catch (Exception ex)
        {<br />
        }
    }
 
}

0 Ответов