Ms Änderungen FileCopy
This commit is contained in:
@@ -334,7 +334,19 @@ Partial Public Class frmEnvelopeEditor
|
||||
If My.Settings.NetUse_PW <> String.Empty And My.Settings.NetUse_Usr <> String.Empty Then
|
||||
Dim oDecrypted = Decryption.Decrypt(My.Settings.NetUse_PW)
|
||||
For Each odoc In Controller.Envelope.Documents 'envelope ist leer!
|
||||
MoveFileWithNetUse(odoc.Filepath, DOCUMENT_PATH_MOVE_AFTSEND, My.Settings.NetUse_Usr, My.Settings.NetUse_PW)
|
||||
Directory2Delete = ""
|
||||
CopyFileWithNetUse(odoc.Filepath, DOCUMENT_PATH_MOVE_AFTSEND, My.Settings.NetUse_Usr, My.Settings.NetUse_PW)
|
||||
If Directory2Delete <> String.Empty Then
|
||||
Logger.Debug("Now Deleting SourcePath: {0} ...", Directory2Delete)
|
||||
Try
|
||||
System.IO.Directory.Delete(Directory2Delete, True)
|
||||
Logger.Debug("Successfully deleted Sourcepath!")
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Unexpected Error while deleting SourcePath {0}", Directory2Delete)
|
||||
Logger.Warn("ErrorMessage: {0}", ex.Message)
|
||||
End Try
|
||||
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
@@ -345,47 +357,86 @@ Partial Public Class frmEnvelopeEditor
|
||||
End Sub
|
||||
|
||||
|
||||
Sub MoveFileWithNetUse(pSourcePath As String, pDestinationPath As String, pUsername As String, pPassword As String)
|
||||
Dim oDectryptedPW = Decryption.Decrypt(pPassword)
|
||||
Dim oFilename = System.IO.Path.GetFileName(pSourcePath)
|
||||
|
||||
Dim netUseCommand As String = $"net use {pDestinationPath} /user:{pUsername} {oDectryptedPW}"
|
||||
|
||||
Dim processInfo As New ProcessStartInfo("cmd.exe", $"/C {netUseCommand}")
|
||||
processInfo.RedirectStandardOutput = True
|
||||
processInfo.UseShellExecute = False
|
||||
processInfo.CreateNoWindow = True
|
||||
|
||||
Using process As Process = Process.Start(processInfo)
|
||||
process.WaitForExit()
|
||||
|
||||
' Prüfe den Rückgabewert des net use Befehls
|
||||
If process.ExitCode = 0 Then
|
||||
' Verschiebe die Datei
|
||||
Try
|
||||
Dim oFilePath As String = pSourcePath
|
||||
Dim oDirectory As String = Path.GetDirectoryName(oFilePath)
|
||||
Dim split As String() = oFilePath.Split("\")
|
||||
Dim parentFolder As String = split(split.Length - 2)
|
||||
pDestinationPath &= "\" + parentFolder
|
||||
If Not System.IO.Directory.Exists(pDestinationPath) Then
|
||||
System.IO.Directory.CreateDirectory(pDestinationPath)
|
||||
End If
|
||||
pDestinationPath &= "\" + oFilename
|
||||
If File.Exists(pDestinationPath) Then
|
||||
File.Delete(pDestinationPath)
|
||||
End If
|
||||
System.IO.File.Move(pSourcePath, pDestinationPath)
|
||||
System.IO.Directory.Delete(oDirectory)
|
||||
Catch ex As Exception
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error in MoveFileWithNetUse")
|
||||
End Try
|
||||
|
||||
Else
|
||||
MsgBox("Error while connecting to network: " & pDestinationPath, MsgBoxStyle.Critical, "Unexpected error in MoveFileWithNetUse")
|
||||
Function CopyFileWithNetUse(pSourcePath As String, pDestinationPath As String, pUsername As String, pPassword As String) As Boolean
|
||||
Logger.Debug("EXECUTING CopyFileWithNetUse for " & pDestinationPath)
|
||||
Dim oDirectoryExists As Boolean = False
|
||||
Try
|
||||
If Directory.Exists(pDestinationPath) Then
|
||||
oDirectoryExists = True
|
||||
End If
|
||||
End Using
|
||||
End Sub
|
||||
Catch ex As Exception
|
||||
Logger.Warn("CopyFileWithNetUse - path not accessible or existing: {0}", ex.Message)
|
||||
End Try
|
||||
Logger.Debug("CopyFileWithNetUse - Folder accessible [{0}]", oDirectoryExists.ToString)
|
||||
|
||||
If oDirectoryExists = False Then
|
||||
Dim oDectryptedPW = Decryption.Decrypt(pPassword)
|
||||
Dim netUseCommand As String = $"net use {pDestinationPath} /user:{pUsername} {oDectryptedPW}"
|
||||
Logger.Debug("netUseCommand " & netUseCommand)
|
||||
Dim processInfo As New ProcessStartInfo("cmd.exe", $"/C {netUseCommand}")
|
||||
processInfo.RedirectStandardOutput = True
|
||||
processInfo.RedirectStandardInput = True
|
||||
processInfo.UseShellExecute = False
|
||||
processInfo.CreateNoWindow = True
|
||||
Using oProcess As Process = Process.Start(processInfo)
|
||||
oProcess.WaitForExit()
|
||||
' Prüfe den Rückgabewert des net use Befehls
|
||||
If oProcess.ExitCode = 0 Then
|
||||
' Verschiebe die Datei
|
||||
Try
|
||||
Dim oReturn = COPY_TO_DMZ(pSourcePath, pDestinationPath)
|
||||
oProcess.Close()
|
||||
Return oReturn
|
||||
Catch ex As Exception
|
||||
oProcess.Close()
|
||||
Logger.Warn("Unexpected error in CopyFileWithNetUse " & pDestinationPath)
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error in CopyFileWithNetUse")
|
||||
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Else
|
||||
Logger.Warn("Error while connecting to network-path: " & pDestinationPath)
|
||||
MsgBox("Error while connecting to network: " & pDestinationPath, MsgBoxStyle.Critical, "Unexpected error in CopyFileWithNetUse")
|
||||
Return False
|
||||
End If
|
||||
End Using
|
||||
Else
|
||||
Return COPY_TO_DMZ(pSourcePath, pDestinationPath)
|
||||
End If
|
||||
|
||||
|
||||
|
||||
|
||||
End Function
|
||||
Private Function COPY_TO_DMZ(pSourcePath As String, pDestinationPath As String) As Boolean
|
||||
Try
|
||||
Dim oFilename = System.IO.Path.GetFileName(pSourcePath)
|
||||
Dim oFilePath As String = pSourcePath
|
||||
Dim oSourceDirectory As String = Path.GetDirectoryName(oFilePath)
|
||||
Dim split As String() = oFilePath.Split("\")
|
||||
Dim parentFolder As String = split(split.Length - 2)
|
||||
pDestinationPath &= "\" + parentFolder
|
||||
If Not System.IO.Directory.Exists(pDestinationPath) Then
|
||||
System.IO.Directory.CreateDirectory(pDestinationPath)
|
||||
End If
|
||||
pDestinationPath &= "\" + oFilename
|
||||
If File.Exists(pDestinationPath) Then
|
||||
File.Delete(pDestinationPath)
|
||||
End If
|
||||
Logger.Debug("Now copying file ...")
|
||||
Logger.Debug("from [{0}] ", pSourcePath)
|
||||
Logger.Debug("to [{0}]... ", pDestinationPath)
|
||||
System.IO.File.Copy(pSourcePath, pDestinationPath)
|
||||
Logger.Debug("Successfully Copied!")
|
||||
Directory2Delete = oSourceDirectory
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Warn("COPY_TO_DMZ - Unexpected error {0}", ex.Message)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
End Function
|
||||
Private Sub btnCancel_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnCancel.ItemClick
|
||||
' Speichern?
|
||||
Dim oMessage = Resources.Envelope.Should_The_Envelope_Be_Saved
|
||||
@@ -524,4 +575,7 @@ Partial Public Class frmEnvelopeEditor
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub RibbonControl1_Click(sender As Object, e As EventArgs) Handles RibbonControl1.Click
|
||||
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user