Imports Renci.SshNet
Imports System.IO

Public Class cMDMFunctions


    'Shared Function send_Data_To_Dakosy_FTP(file, dySt_BezugsNr, dy_Id)
    '    Try
    '        If Not VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("ZOLL_DakosyZA_Senden", "AVISO") Then
    '            MsgBox("Sie haben keine Sendeberechtigung.")
    '            Return False
    '        End If

    '        If Not IO.File.Exists(file) Then Return False
    '        Dim F As New System.IO.FileInfo(file)

    '        Dim DY_server = ""
    '        Dim DY_name = ""
    '        Dim DY_pwd = ""
    '        Dim DY_port = ""
    '        Dim DY_PFAD_IN = ""

    '        getSFTPLoginData(DY_server, DY_name, DY_pwd, DY_port, DY_PFAD_IN, "")

    '        Dim ConnectionInfo As New ConnectionInfo(DY_server, DY_port, DY_name, New PasswordAuthenticationMethod(DY_name, DY_pwd))
    '        Using client = New SftpClient(ConnectionInfo)
    '            client.Connect()
    '            'client.Create(file, file)
    '            client.ChangeDirectory(DY_PFAD_IN)
    '            If IO.File.Exists(file) Then
    '                'MsgBox(file)
    '                Using uplfileStream = System.IO.File.OpenRead(file)
    '                    client.UploadFile(uplfileStream, "." & F.Name, True)
    '                    client.RenameFile("." & F.Name, F.Name)
    '                End Using
    '                client.Disconnect()
    '            Else
    '                MsgBox("Sendedatei nicht gefunden!")
    '            End If


    '        End Using

    '        Dim STATUS As New DAKOSY_Worker.cDakosy_Statusmeldungen
    '        STATUS.dySt_BezugsNr = dySt_BezugsNr
    '        STATUS.dySt_artMitteilung = "VERAG_SND"
    '        STATUS.dySt_dyArt = "" '"NCTS" 'T1/T2

    '        STATUS.dySt_status = DAKOSY_Worker.cDY_Statusliste.S_03
    '        'STATUS.dySt_ergCode = "ANR"
    '        STATUS.dySt_ergCode = "SND"
    '        STATUS.dySt_ergMitteilung = "An Dakosy gesendet"
    '        STATUS.dySt_ergZeitpunkt = Now

    '        STATUS.dySt_dyId = dy_Id
    '        STATUS.SAVE()

    '        Return True
    '    Catch ex As Exception
    '        MsgBox(ex.Message & ex.StackTrace)
    '        Return False
    '    End Try
    'End Function

    'Shared Function send_Data_To_Dakosy_FTP(file, Optional misc = False)
    '    Try
    '        If Not IO.File.Exists(file) Then Return False
    '        Dim F As New System.IO.FileInfo(file)

    '        Dim DY_server = ""
    '        Dim DY_name = ""
    '        Dim DY_pwd = ""
    '        Dim DY_port = ""
    '        Dim DY_PFAD_IN = ""

    '        getSFTPLoginData(DY_server, DY_name, DY_pwd, DY_port, DY_PFAD_IN, "")

    '        Dim ConnectionInfo As New ConnectionInfo(DY_server, DY_port, DY_name, New PasswordAuthenticationMethod(DY_name, DY_pwd))
    '        Using client = New SftpClient(ConnectionInfo)
    '            client.Connect()
    '            'client.Create(file, file)
    '            If misc Then
    '                client.ChangeDirectory(DY_PFAD_IN.Replace("gebox", "misc"))
    '            Else
    '                client.ChangeDirectory(DY_PFAD_IN)
    '            End If

    '            If IO.File.Exists(file) Then
    '                'MsgBox(file)
    '                Using uplfileStream = System.IO.File.OpenRead(file)
    '                    client.UploadFile(uplfileStream, "." & F.Name, True)
    '                    client.RenameFile("." & F.Name, F.Name)
    '                End Using
    '                client.Disconnect()
    '            Else
    '                MsgBox("Sendedatei nicht gefunden!")
    '            End If


    '        End Using

    '        Return True
    '    Catch ex As Exception
    '        MsgBox(ex.Message & ex.StackTrace)
    '        Return False
    '    End Try
    'End Function


    Shared Sub getSFTPLoginData(ByRef MDM_server, ByRef MDM_name, ByRef MDM_pwd, ByRef MDM_port, ByRef MDM_PFAD_IN, ByRef MDM_PFAD_OUT)
        MDM_server = cMDM_Paramter.GET_PARAM_ByName("PLOSE_FTP_SERVER", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        MDM_name = cMDM_Paramter.GET_PARAM_ByName("PLOSE_FTP_NAME", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        MDM_pwd = cMDM_Paramter.GET_PARAM_ByName("PLOSE_FTP_PASSWORD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        MDM_port = cMDM_Paramter.GET_PARAM_ByName("PLOSE_FTP_PORT", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        MDM_PFAD_IN = "in/"
        MDM_PFAD_OUT = "out/"
    End Sub




    Shared Function getDefaultFolder_SEND() As String
        Try
            getDefaultFolder_SEND = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "DAKOSY\" & If(VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM, "TESTSYSTEM", "ECHTSYSTEM") & "\Ausgang_Kundendaten\" & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\" ' Path.GetTempPath
            If Not IO.Directory.Exists(getDefaultFolder_SEND) Then
                IO.Directory.CreateDirectory(getDefaultFolder_SEND)
            End If
        Catch ex As Exception
            Try
                getDefaultFolder_SEND = "C:\TEMP\" ' Path.GetTempPath
                If Not IO.Directory.Exists(getDefaultFolder_SEND) Then
                    IO.Directory.CreateDirectory(getDefaultFolder_SEND)
                End If
            Catch ex2 As Exception
                MsgBox(ex2.Message & ex2.StackTrace)
                getDefaultFolder_SEND = ""
            End Try
        End Try

    End Function

End Class


