Imports DigitalData.Modules.Windream
Imports DigitalData.Modules.Logging
Imports System.ComponentModel
Imports DigitalData.Controls.LookupGrid
Imports DevExpress.XtraEditors

Public Class frmOld
    Dim MyLogger As LogConfig
    Dim Logger As Logger

    Protected _windream2 As Windream
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim serverName As String = TextBox1.Text

        ' Windream.vb
        '_windream2 = New Windream("W", True, False)

        ' Windream2.vb
        Try
            _windream2 = New ConnectionBuilder(MyLogger).
                WithDriveLetter("W").
                WithSessionReconnect().
                With64BitSupport().
                WithServerName("sdd-vmx02-aps01").
                Connect()
        Catch ex As Exception
            Logger.Error(ex)
            MsgBox("Login failed!")
            Exit Sub
        End Try

        If _windream2.SessionLoggedin = True Then
            MsgBox("Session created")
        Else
            MsgBox("No session created")
        End If
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Process.Start(MyLogger.LogDirectory)
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        MyLogger = New LogConfig(LogConfig.PathType.CurrentDirectory, Nothing, "MAIN")
        MyLogger.Debug = True
        Logger = MyLogger.GetLogger()

        Dim MySecondLogger = New LogConfig(LogConfig.PathType.CurrentDirectory, Nothing, "MAIN2")
        Dim SecondLogger = MySecondLogger.LogFactory.GetCurrentClassLogger()

        Logger.Warn("WANRING!!!")
        Logger.Info("INFO!!!")
        Logger.Debug("DEBUG!!!")

        SecondLogger.Warn("WANRING!!!")
        SecondLogger.Info("INFO!!!")
        SecondLogger.Debug("DEBUG!!!")



        Dim datatable As New DataTable("FOO")
        datatable.Columns.Add(New DataColumn("TEST1", GetType(String)))
        datatable.Columns.Add(New DataColumn("TEST2", GetType(String)))
        datatable.Columns.Add(New DataColumn("TEST3", GetType(String)))

        Dim dr As DataRow = datatable.NewRow()
        dr.Item("TEST1") = "foo"
        dr.Item("TEST2") = "bar"
        dr.Item("TEST3") = "baz"

        Dim dr2 As DataRow = datatable.NewRow()
        dr2.Item("TEST1") = "foo2"
        dr2.Item("TEST2") = "bar2"
        dr2.Item("TEST3") = "baz2"

        Dim dr3 As DataRow = datatable.NewRow()
        dr3.Item("TEST1") = "foo3"
        dr3.Item("TEST2") = "bar3"
        dr3.Item("TEST3") = "baz3"

        datatable.Rows.Add(dr)
        datatable.Rows.Add(dr2)
        datatable.Rows.Add(dr3)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles GetValue.Click
        My.Settings.Save()
        If IsNothing(_windream2) Then
            MsgBox("windream initialisieren")
            Exit Sub
        End If
        Dim result As List(Of String) = _windream2.GetIndexValue(txtWMFile.Text, txtWMIndex.Text)
        If result.Count = 0 Then
            MsgBox("No result")
        Else
            txtWMValue.Text = result.Item(0).ToString
        End If
    End Sub

    Private Sub IndexFile_Click(sender As Object, e As EventArgs) Handles IndexFile.Click
        My.Settings.Save()
        If IsNothing(_windream2) Then
            MsgBox("windream initialisieren")
            Exit Sub
        End If
        Dim arrValue() As String = Nothing
        ReDim Preserve arrValue(0)
        arrValue(0) = txtWMValue.Text
        'If _windream2.NewIndexFile(txtWMFile.Text, txtWMIndex.Text, arrValue) = True Then
        '    MsgBox("Success")
        'Else
        '    MsgBox("no indexing")
        'End If

    End Sub

    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        My.Settings.Save()
        If IsNothing(_windream2) Then
            MsgBox("windream initialisieren")
            Exit Sub
        End If

        Dim DTResults As DataTable = _windream2.GetSearchDocuments(txtwmsearch.Text, "Dokument-ID")
        If DTResults.Rows.Count > 0 Then
            GridControl1.DataSource = DTResults
        Else
            GridControl1.DataSource = Nothing
            GridView1.Columns.Clear()
        End If
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim items As New List(Of String)

        items = _windream2.GetChoiceListItems(ComboBox1.Text)

        MsgBox("choicelist items:" & vbNewLine & (String.Join(vbNewLine, items.ToArray)))
    End Sub

    Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click
        Dim lists = _windream2.GetChoiceLists()

        ComboBox1.Items.Clear()

        For Each list As String In lists
            ComboBox1.Items.Add(list)
        Next

        ComboBox1.DroppedDown = True

    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim bw1 As New BackgroundWorker
        Dim bw2 As New BackgroundWorker

        AddHandler bw1.DoWork, Sub()
                                   Dim config1 As New LogConfig(LogConfig.PathType.CurrentDirectory, Nothing, "TEST1")
                                   Dim logger As NLog.Logger = config1.LogFactory.GetCurrentClassLogger()

                                   logger.Warn("WANRING!!!")
                                   logger.Info("INFO!!!")
                                   logger.Debug("DEBUG!!!")

                                   Console.WriteLine("This is logger 1 calling!")
                                   Console.WriteLine(config1.LogFile)
                               End Sub


        bw1.RunWorkerAsync()
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Logger.Error(New ApplicationException("Some Error occurred!"))

        ListBox1.Items.Clear()
        For Each oLog In MyLogger.Logs
            ListBox1.Items.Add(oLog)
        Next
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        MyLogger.ClearLogs()

        ListBox1.Items.Clear()
        For Each oLog In MyLogger.Logs
            ListBox1.Items.Add(oLog)
        Next
    End Sub
End Class
