''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright (c) Datacard Corporation.  All Rights Reserved.
'
' XPS Driver SDK vb.net kiosk sample.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports System.Drawing.Printing
Imports System.Windows.Forms
Imports dxp01sdk

Namespace kiosk

    Class kiosk

        Public Shared Sub Main(args As String())

            Dim commandLineOptions As CommandLineOptions = CommandLineOptions.CreateFromArguments(args)
            commandLineOptions.Validate()

            Dim bidiSpl As BidiSplWrap = Nothing
            Dim printerJobID As Integer = 0

            Try
                bidiSpl = New BidiSplWrap()
                bidiSpl.BindDevice(commandLineOptions.printerName)

                Dim driverVersionXml As String = bidiSpl.GetPrinterData(strings.SDK_VERSION)
                Console.WriteLine(Environment.NewLine & "driver version: " & Util.ParseDriverVersionXML(driverVersionXml) & Environment.NewLine)

                Dim printerOptionsXML As String = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2)
                Dim printerOptionsValues As PrinterOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML)

                If "Ready" <> printerOptionsValues._printerStatus AndAlso "Busy" <> printerOptionsValues._printerStatus Then
                    Throw New Exception(commandLineOptions.printerName + " is not ready. status: " + printerOptionsValues._printerStatus)
                End If

                If "Installed" <> printerOptionsValues._printHead AndAlso "Version1" <> printerOptionsValues._connectionProtocol Then
					Throw New Exception(commandLineOptions.printerName & " does not have a print head installed.")
				End If

                If "Installed" <> printerOptionsValues._kioskOption Then
                    Throw New Exception(commandLineOptions.printerName + " does not have kiosk option installed.")
                End If

                If commandLineOptions.emboss AndAlso "Installed" <> printerOptionsValues._moduleEmbosser Then
                    Throw New Exception(commandLineOptions.printerName + " does not have emboss module installed.")
                End If


                If ((commandLineOptions.hopperID = "r1") AndAlso ("Installed" <> printerOptionsValues._rearPickOption)) Then
                    Throw New Exception(("printer" + (commandLineOptions.printerName + " does not have a rear pick option installed.")))
                End If


                printerJobID = Util.StartJob(bidiSpl,
                        commandLineOptions.hopperID,
                        commandLineOptions.cardEjectSide,
                        commandLineOptions.outputHopperLocation)


                Util.PrintTextAndGraphics(bidiSpl, commandLineOptions.printerName, commandLineOptions.emboss)
                Util.WaitForWindowsJobID(bidiSpl, commandLineOptions.printerName)

                bidiSpl.SetPrinterData(strings.ENDJOB)

                If commandLineOptions.jobCompletion Then
                    Util.PollForJobCompletion(bidiSpl, printerJobID)
                End If
            Catch e As BidiException
                Console.WriteLine(e.Message)
                Util.CancelJob(bidiSpl, e.PrinterJobID, e.ErrorCode)
            Catch e As Exception
                Console.WriteLine(e.Message)
                If 0 <> printerJobID Then
                    Util.CancelJob(bidiSpl, printerJobID, 0)
                End If
            Finally
                bidiSpl.UnbindDevice()
            End Try
        End Sub
    End Class

End Namespace
