7 Replies - 3161 Views - Last Post: 08 September 2011 - 11:04 AM Rate Topic: -----

#1 hlx   User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 135
  • Joined: 13-November 10

Microsoft Fax Error Monitoring (SBS2008)

Posted 02 September 2011 - 05:37 AM

Hello there. Having some issues figuring out how to catch faxing errors (outbound) using VB.NET.

I am using this reference: MSDN

Basically, the issue is that SBS2008 Event Log does not give the same amount of information that Windows XP did, so the users are being forced to look in the text activity log. Am I forced to loop through the log for new items, or can I actually catch errors as they come?

My ultimate goal is to send an email report with the erroneous fax information (destination#, error reason, code, body or attachment).

So essentially I need to figure out how to catch fax errors as they arise, by listening (this will be a VB.NET console app), and then I can take it from there.

Private Sub GetOutgoingArchiveMessages()
        Dim objFaxServer As New FAXCOMEXLib.FaxServer
        Dim vMessages As FAXCOMEXLib.FaxOutgoingMessageIterator

        objFaxServer.Connect("") ' Add server name ' 
        vMessages = objFaxServer.Folders.OutgoingArchive.GetMessages
        If Not vMessages.AtEOF Then
            With vMessages
                vMessages.MoveFirst()

                Do While Not vMessages.AtEOF

                    ' Here get all the properties of the message ' 
                    ' vMessages.Message.DocumentName 
                    ' vMessages.Message.Id 
                    ' vMessages.Message.Transmissionend 
                    ' vMessages.Message.Transmissionend 
                    ' vMessages.Message.Delete 

                    vMessages.MoveNext()
                Loop

            End With

        End If

    End Sub


This is what I am using to get the outgoing archive messages, but I either need to reliably get an error when it happens there, or get one on demand. I would much rather just poll the fax service for the information if I can.

Thanks a lot.

Is This A Good Question/Topic? 0
  • +

Replies To: Microsoft Fax Error Monitoring (SBS2008)

#2 hlx   User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 135
  • Joined: 13-November 10

Re: Microsoft Fax Error Monitoring (SBS2008)

Posted 07 September 2011 - 03:44 PM

Does anyone know? Basically on error I want it to report back that a fax failed and why. If anyone knows how to achieve this please let me know. Or if this is even possible on server 2008 r2
Was This Post Helpful? 0
  • +
  • -

#3 hlx   User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 135
  • Joined: 13-November 10

Re: Microsoft Fax Error Monitoring (SBS2008)

Posted 07 September 2011 - 08:29 PM

Updated code. Won't ever raise my events (as per MSDN), Need some help working out the ManualResetEvent.

Imports System.Threading

Module Module1
    Dim addevent As ManualResetEvent
    Dim WithEvents faxsvr As FAXCOMEXLib.FaxServer

    Dim jobstatus As FAXCOMEXLib.FaxJobStatus

    Sub Main()


        Try

            faxsvr = New FAXCOMEXLib.FaxServer


            faxsvr.Connect("sbs2k8")

            faxsvr.ListenToServerEvents(FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED Or FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE)
            addevent = New ManualResetEvent(False)
            addevent.WaitOne()


            'If the fax service is stopped - > faxsvr_OnServerShutdown() will be called.
            'If something is added to the outgoing queue - > faxsvr_OnOutgoingJobAdded() will be called.
            'If the status of the outgoing job changes -> faxsvr_OnOutgoingJobChanged() gets called.

        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try
        Console.WriteLine("Waiting for thread..")
        

    End Sub

    Private Sub faxsvr_OnOutgoingJobAdded(ByVal pFaxServer As FAXCOMEXLib.IFaxServer, ByVal bstrJobId As String)
        Console.WriteLine("++  New outgoing fax added to queue.")
        addevent.Set()
    End Sub

    Private Sub faxsvr_OnOutgoingJobChanged(ByVal pFaxServer As FAXCOMEXLib.IFaxServer, _
            ByVal bstrJobId As String, ByVal pJobStatus As FAXCOMEXLib.IFaxJobStatus)
        'This event receives the FaxJobStatus object

        'Since this event is likely to result in errors, such as trying to 
        'report the transmission end time before the transmission has ended, 
        'this subroutine includes error handling

        'Error handling
        Try




            'Display the FaxJobStatus object's properties when the event is called
            Console.WriteLine(pJobStatus.AvailableOperations,
            "\nCaller ID: " & pJobStatus.CallerId & _
            "\nCSID: " & pJobStatus.CSID & _
            "\nCurrent page: " & pJobStatus.CurrentPage & _
            "\nDevice ID: " & pJobStatus.DeviceId & _
            "\nExtended status: " & pJobStatus.ExtendedStatus & _
            "\nExtended status code: " & pJobStatus.ExtendedStatusCode & _
            "\nJob type: " & pJobStatus.JobType & _
            "\nPages: " & pJobStatus.Pages & _
            "\nRetries: " & pJobStatus.Retries & _
            "\nRouting information: " & pJobStatus.RoutingInformation & _
            "\nScheduled time: " & pJobStatus.ScheduledTime & _
            "\nSize: " & pJobStatus.Size & _
            "\nStatus: " & pJobStatus.Status & _
            "\nTransmission start: " & pJobStatus.Transmissionstart & _
            "\nTSID: " & pJobStatus.TSID)

            'Display the transmission end time separately, as this will cause an error
            'while the transmission is still in progress
            Console.WriteLine("Transmission end: " & pJobStatus.Transmissionend)
        Catch ex As Exception

        End Try
        addevent.Set()
    End Sub

    Private Sub faxsvr_OnServerShutDown(ByVal pFaxServer As FAXCOMEXLib.IFaxServer)

        Console.WriteLine("-- The local fax server has been shut down")

        addevent.Set()
    End Sub


End Module


Was This Post Helpful? 0
  • +
  • -

#4 p00ndawg   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 09-November 09

Re: Microsoft Fax Error Monitoring (SBS2008)

Posted 08 September 2011 - 09:59 AM

I am in a similar situation as you. I cannot offer any advice but will monitor this thread in case of any breakthroughs.
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Microsoft Fax Error Monitoring (SBS2008)

Posted 08 September 2011 - 10:11 AM

So seem to have written the Sub routines that would handle the events but you either need to use AddHandler statements to wire them up or add the Handles clause on the declaration of the sub.

I'm just guessing here, but intellisense will tell that part.
Private Sub faxsvr_OnServerShutDown(ByVal pFaxServer As FAXCOMEXLib.IFaxServer) Handles faxsvr.OnServerShutDown

Was This Post Helpful? 1
  • +
  • -

#6 hlx   User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 135
  • Joined: 13-November 10

Re: Microsoft Fax Error Monitoring (SBS2008)

Posted 08 September 2011 - 10:14 AM

I have a working solution, that is now reporting events (thanks to help resources around the internet)

NOTE: This has to be resident on the server. It will not remotely pull events.

'Visual Basic 2008 - .net 3.5 - Any CPU
Imports FAXCOMEXLib
Public Class Form1
    Private WithEvents pFaxSrv As FaxServer
    Private StatusBox As TextBox
    Private ServerNameBox As TextBox
    Private ServerLabel As Label
    Private ConnectButton As Button
    Dim JOBID As String = Nothing
    Private Sub ConnectButtonclicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If ServerNameBox.Text.Length > 0 Then
            pFaxSrv = New FaxServer
            Try
                pFaxSrv.Connect(ServerNameBox.Text)
                StatusBox.AppendText("Connected to Server: " + ServerNameBox.Text() + vbCrLf)

            Catch ex As Exception
                MsgBox(ex.Message)
                Exit Sub
            End Try
            pFaxSrv.ListenToServerEvents(FAX_SERVER_EVENTS_TYPE_ENUM.fsetDEVICE_STATUS Or FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED Or FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE)
            AddHandler pFaxSrv.OnDeviceStatusChange, AddressOf pFaxSrv_OnDeviceStatusChange
            AddHandler pFaxSrv.OnServerShutDown, AddressOf pFaxSrv_OnServerShutDown
            AddHandler pFaxSrv.OnOutgoingJobAdded, AddressOf pFaxSrv_OnOutgoingJobAdded
            AddHandler pFaxSrv.OnOutgoingJobChanged, AddressOf pFaxSrv_OnOutgoingJobChanged


        Else
            MsgBox("You need to provide the name of the computer which is running the fax service", MsgBoxStyle.Critical)
        End If
    End Sub
    Private Sub pFaxSrv_OnDeviceStatusChange(ByVal pFaxServer As FAXCOMEXLib.FaxServer, ByVal lDeviceId As Integer, ByVal bPoweredOff As Boolean, ByVal bSending As Boolean, ByVal bReceiving As Boolean, ByVal bRinging As Boolean)
        Static MyDeviceID As Integer = -1
        Dim Value As String = String.Empty

        If bReceiving Or bRinging Or bPoweredOff Then
            Value = "Rec:" & bReceiving.ToString & " - " & "Ring:" & bRinging.ToString & " - " & "Pow:" & bPoweredOff.ToString
        End If

        If (MyDeviceID <> lDeviceId) Then
            If (bReceiving Or bRinging Or bPoweredOff) Then
                Value &= " - "
            End If
            Value &= "Dev:" & lDeviceId.ToString
            MyDeviceID = lDeviceId
        End If
        StatusBox.AppendText(Value & vbCrLf)

    End Sub

    Private Sub pFaxSrv_OnServerShutDown(ByVal pFaxServer As FAXCOMEXLib.IFaxServer)

        StatusBox.AppendText("The FAX Service has been stopped." & vbCrLf)

    End Sub

    Private Sub pFaxSrv_OnOutgoingJobAdded(ByVal pFaxServer As FAXCOMEXLib.IFaxServer, _
            ByVal bstrJobId As String)

        StatusBox.AppendText("New job added to queue with ID: " + bstrJobId & vbCrLf)
        JOBID = bstrJobId

    End Sub

    Private Sub pFaxSrv_OnOutgoingJobChanged(ByVal pFaxServer As FAXCOMEXLib.IFaxServer, _
            ByVal bstrJobId As String, ByVal pJobStatus As FAXCOMEXLib.IFaxJobStatus)
        'This event receives the FaxJobStatus object

        'Since this event is likely to result in errors, such as trying to 
        'report the transmission end time before the transmission has ended, 
        'this subroutine includes error handling

        'Error handling
        On Error GoTo Error_Handler


        'Display the FaxJobStatus object's properties when the event is called
        'StatusBox.AppendText(pJobStatus.AvailableOperations & _
        'vbCrLf & "Caller ID: " & pJobStatus.CallerId & _
        'vbCrLf & "CSID: " & pJobStatus.CSID & _
        'vbCrLf & "Current page: " & pJobStatus.CurrentPage & _
        'vbCrLf & "Device ID: " & pJobStatus.DeviceId & _
        'vbCrLf & "Extended status: " & pJobStatus.ExtendedStatus & _
        'vbCrLf & "Extended status code: " & pJobStatus.ExtendedStatusCode & _
        'vbCrLf & "Job type: " & pJobStatus.JobType & _
        'vbCrLf & "Pages: " & pJobStatus.Pages & _
        'vbCrLf & "Retries: " & pJobStatus.Retries & _
        'vbCrLf & "Routing information: " & pJobStatus.RoutingInformation & _
        'vbCrLf & "Scheduled time: " & pJobStatus.ScheduledTime & _
        'vbCrLf & "Size: " & pJobStatus.Size & _
        'vbCrLf & "Status: " & pJobStatus.Status & _
        'vbCrLf & "Transmission start: " & pJobStatus.Transmissionstart & _
        'vbCrLf & "TSID: " & pJobStatus.TSID & vbCrLf)

        MsgBox(pJobStatus.ExtendedStatusCode.ToString())
        If pJobStatus.ExtendedStatusCode.ToString() = "fjesBUSY" Then
            If pJobStatus.Status.ToString() = "fjsRETRIES_EXCEEDED" Then
                StatusBox.AppendText(vbCrLf & "Job ID " + bstrJobId + " has exceeded the max amount of retries.")
                'TODO: Call to fax FAILED email function here.
                Exit Sub
            End If

            StatusBox.AppendText(vbCrLf + "Job ID: " + bstrJobId + " has encountered a BUSY signal. Attempting retry...")
        End If

        

        Exit Sub

Error_Handler:
        'Implement error handling at the end of your subroutine. This 
        'implementation is for demonstration purposes
        StatusBox.AppendText("Error number: " & Hex(Err.Number) & ", " & Err.Description & vbCrLf)
    End Sub

    Public Sub New()
        InitializeComponent()
        AddControls()
    End Sub
    Private Sub AddControls()
        StatusBox = New TextBox
        StatusBox.Multiline = True
        StatusBox.ScrollBars = ScrollBars.Both
        StatusBox.Location = New Point(12, 51)
        StatusBox.Size = New Size(258, 103)
        Me.Controls.Add(StatusBox)

        ServerNameBox = New TextBox
        ServerNameBox.Location = New Point(50, 21)
        ServerNameBox.Size = New Size(152, 20)
        Me.Controls.Add(ServerNameBox)

        ServerLabel = New Label
        ServerLabel.Location = New Point(12, 25)
        ServerLabel.Text = "Server"
        Me.Controls.Add(ServerLabel)

        ConnectButton = New Button
        ConnectButton.Location = New Point(212, 12)
        ConnectButton.Size = New Size(58, 33)
        ConnectButton.Text = "Connect"
        Me.Controls.Add(ConnectButton)
        Me.Height = 200
        Me.Width = 290
        AddHandler ConnectButton.Click, AddressOf ConnectButtonclicked
    End Sub


    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        RemoveHandler ConnectButton.Click, AddressOf ConnectButtonclicked
        If pFaxSrv IsNot Nothing Then
            RemoveHandler pFaxSrv.OnDeviceStatusChange, AddressOf pFaxSrv_OnDeviceStatusChange
            RemoveHandler pFaxSrv.OnServerShutDown, AddressOf pFaxSrv_OnServerShutDown
            RemoveHandler pFaxSrv.OnOutgoingJobAdded, AddressOf pFaxSrv_OnOutgoingJobAdded
            RemoveHandler pFaxSrv.OnOutgoingJobChanged, AddressOf pFaxSrv_OnOutgoingJobChanged
            pFaxSrv.Disconnect()
        End If
    End Sub
End Class


for some reason, fjesBUSY is getting thrown twice each time the event is called. Why is this?
Was This Post Helpful? 0
  • +
  • -

#7 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Microsoft Fax Error Monitoring (SBS2008)

Posted 08 September 2011 - 10:54 AM

Did you try debugging and follow the code?
Was This Post Helpful? 0
  • +
  • -

#8 hlx   User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 135
  • Joined: 13-November 10

Re: Microsoft Fax Error Monitoring (SBS2008)

Posted 08 September 2011 - 11:04 AM

I would hawk, but I'm compiling on a machine that is not the server. I do not have licenses for the server.

This post has been edited by hlx: 08 September 2011 - 12:01 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1