''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright (c) Datacard Corporation.  All Rights Reserved.
'
' populate a CommandLineOptions data structure from parsed command line args.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports System.IO
Imports dxp01sdk


Namespace kiosk

    Class CommandLineOptions
        Public jobCompletion As Boolean
        Public emboss As Boolean
        Public printerName As String
        Public hopperID As String = "1"
        Public cardEjectSide As String = "Default"
        Public outputHopperLocation As String = ""
        Private Shared Sub Usage()
            Dim thisExeName As String = Path.GetFileName(Environment.GetCommandLineArgs()(0))
            Console.WriteLine(thisExeName & " demonstrates print functionality of the printer and driver.")
            Console.WriteLine()
            Console.WriteLine(thisExeName & " -n <printername> [-i <input hopper>] [-f <side>]")
            Console.WriteLine()
            Console.WriteLine("options:")
            Console.WriteLine("  -n <printername>. Required. Try -n ""XPS Card Printer"".")
            Console.WriteLine("  -i <input hopper> Defaults to input hopper #1.")
            Console.WriteLine("  -c Poll for job completion.")
            Console.WriteLine("  -e Emboss and Indent.")
            Console.WriteLine("  -f <Front | Back>. Specify the front or back side the card will eject from.")
            Console.WriteLine("  -k Card will be ejected to the front output tray.")
            Console.WriteLine("         If - k is not specified, the card will be dispensed to the rear of the printer")
            Console.WriteLine()
            Console.WriteLine(thisExeName & " -n ""XPS Card Printer""")
            Console.WriteLine("  Pick card from input hopper 1, print a one-sided landscape card and eject card to rear of the printer")
            Console.WriteLine()
            Console.WriteLine(thisExeName + " -n ""XPS Card Printer"" -i r1 -c")
            Console.WriteLine("  Pick card from rear input, print a one-sided landscape card, eject card to rear of the printer and poll for job status.")
            Console.WriteLine()
            Console.WriteLine(thisExeName + " -n ""XPS Card Printer"" -i 2-k -e ")
            Console.WriteLine("  Pick card from from input hopper 2, print and emboss a one-sided landscape card , eject to the front output tray.")

            Environment.Exit(-1)
        End Sub

        Public Sub Validate()

            If String.IsNullOrEmpty(printerName) Then
                Console.WriteLine("printer name is required")
                Environment.Exit(-1)
            End If

            'if hopperID Is an empty string, that Is OK
            If hopperID <> "" Then
                If hopperID <> "1" AndAlso hopperID <> "2" AndAlso hopperID <> "3" AndAlso hopperID <> "4" AndAlso hopperID <> "5" AndAlso hopperID <> "6" AndAlso hopperID <> "r1" AndAlso hopperID <> "exception" Then
                    Console.WriteLine("invalid hopperID: {0}", hopperID)
                    Environment.[Exit](-1)
                End If
            End If

            'if cardEjectSide Is an empty string, that Is OK
            If cardEjectSide <> "" Then
                If cardEjectSide <> "front" AndAlso cardEjectSide <> "back" AndAlso cardEjectSide <> "Default" Then
                    Console.WriteLine("invalid cardEjectSide: {0}", cardEjectSide)
                    Environment.[Exit](-1)
                End If
            End If
        End Sub

        Public Shared Function CreateFromArguments(args As String()) As CommandLineOptions

            If args.Length = 0 Then
                Usage()
            End If

            Dim commandLineOptions As New CommandLineOptions()
            Dim arguments As New CommandLine.Utility.Arguments(args)

            If Not String.IsNullOrEmpty(arguments("h")) Then
                Usage()
            End If

            commandLineOptions.printerName = arguments("n")
            commandLineOptions.jobCompletion = Not String.IsNullOrEmpty(arguments("c"))
            commandLineOptions.emboss = Not String.IsNullOrEmpty(arguments("e"))
            commandLineOptions.hopperID = If(String.IsNullOrEmpty(arguments("i")), String.Empty, arguments("i").ToLower())
            commandLineOptions.cardEjectSide = If(String.IsNullOrEmpty(arguments("f")), String.Empty, arguments("f").ToLower())
            commandLineOptions.outputHopperLocation = If(String.IsNullOrEmpty(arguments("k")), String.Empty, "FrontOutputTray")

            Return commandLineOptions
        End Function
    End Class
End Namespace
