MS-KW39 Änderungen UpdateClass und VersionChecker
This commit is contained in:
@@ -21,6 +21,8 @@ Public Class ClassUpdate
|
||||
Public Shared UPDATE_ERROR As Boolean = False
|
||||
|
||||
Private Shared RecExe_found As Boolean = False
|
||||
Private Shared DT_USER_DATA As DataTable
|
||||
Private Shared USER_INFO1, USER_INFO2, USER_INFO3 As String
|
||||
Public Shared Function Init()
|
||||
Try
|
||||
If InitInstallPath() = False Then
|
||||
@@ -33,7 +35,7 @@ Public Class ClassUpdate
|
||||
MIN_REQUIRED_VERSION = KONFIG_DT.Rows(0).Item("MIN_REQUIRED_VERSION")
|
||||
End If
|
||||
sql = String.Format("Select * FROM TBDD_VERSION_UPDATE WHERE GUID = (Select MAX(GUID) FROM TBDD_VERSION_UPDATE WHERE UPPER(MODULE_NAME) = UPPER('{0}'))", "Record-Organizer")
|
||||
DT_UPDATE = clsDatabase.Return_Datatable(sql, False)
|
||||
DT_UPDATE = clsDatabase.Return_Datatable(sql)
|
||||
If Not IsNothing(DT_UPDATE) Then
|
||||
If DT_UPDATE.Rows.Count = 1 Then
|
||||
UPDATE_ID = DT_UPDATE.Rows(0).Item("GUID")
|
||||
@@ -43,6 +45,7 @@ Public Class ClassUpdate
|
||||
ALL_USERS = DT_UPDATE.Rows(0).Item("ALL_USERS")
|
||||
sql = String.Format("SELECT * FROM TBDD_VERSION_ITEMS WHERE UPDATE_ID = {0} AND [INFO1] IS NOT NULL ORDER BY GUID", UPDATE_ID)
|
||||
DT_UPDATE_ITEMS = clsDatabase.Return_Datatable(sql)
|
||||
ClassLogger.Add(String.Format("{0} items need to be updated!", DT_UPDATE_ITEMS.Rows.Count.ToString), False)
|
||||
Else
|
||||
ClassLogger.Add(">> No Updates Configured!", False)
|
||||
End If
|
||||
@@ -116,17 +119,12 @@ Public Class ClassUpdate
|
||||
Else
|
||||
USER_GUID = USER_DT.Rows(0).Item("GUID")
|
||||
USER_LANGUAGE = USER_DT.Rows(0).Item("LANGUAGE")
|
||||
sql = String.Format("SELECT UPDATE_PATH FROM TBDD_VERSION_USER_UPDATE_PATH WHERE USER_ID = {0} AND UPPER(MODULE_NAME) = UPPER('{1}')", USER_GUID, "Record-Organizer")
|
||||
Dim USER_UPDATE_PATH = clsDatabase.Execute_Scalar(sql)
|
||||
If Not IsNothing(USER_UPDATE_PATH) Then
|
||||
If USER_UPDATE_PATH <> String.Empty Then
|
||||
MyServer_UpdatePath = USER_UPDATE_PATH
|
||||
End If
|
||||
Else
|
||||
MyServer_UpdatePath = String.Empty
|
||||
End If
|
||||
sql = String.Format("SELECT UPDATE_PATH,TEMPPATH,INFO1,INFO2,INFO3 FROM TBDD_VERSION_USER_UPDATE_PATH WHERE USER_ID = {0} AND UPPER(MODULE_NAME) = UPPER('{1}')", USER_GUID, "Record-Organizer")
|
||||
DT_USER_DATA = clsDatabase.Return_Datatable(sql)
|
||||
MyServer_UpdatePath = DT_USER_DATA.Rows(0).Item("UPDATE_PATH")
|
||||
|
||||
sql = String.Format("SELECT CASE VERSION_CLIENT WHEN '' THEN '{3}' ELSE VERSION_CLIENT END AS VERSION_CLIENT FROM VWDD_LOGIN_USER_HISTORY WHERE GUID = (select MAX(GUID) from VWDD_LOGIN_USER_HISTORY where USER_ID = {0} AND VERSION_CLIENT <> '' AND UPPER(MACHINE_NAME) = UPPER('{1}') AND UPPER(MODULE) = UPPER('{2}'))", USER_GUID, Environment.MachineName, "Record-Organizer", VERSION_SERVER)
|
||||
VERSION_USER = clsDatabase.Execute_Scalar(sql)
|
||||
VERSION_USER = clsDatabase.Execute_Scalar(sql)
|
||||
If IsNothing(VERSION_USER) Then
|
||||
sql = String.Format("SELECT CASE VERSION_CLIENT WHEN '' THEN '{2}' ELSE VERSION_CLIENT END AS VERSION_CLIENT FROM VWDD_LOGIN_USER_HISTORY WHERE GUID = (select MAX(GUID) from VWDD_LOGIN_USER_HISTORY where USER_ID = {0} AND VERSION_CLIENT <> '' AND UPPER(MODULE) = UPPER('{1}'))", USER_GUID, "Record-Organizer", VERSION_SERVER)
|
||||
VERSION_USER = clsDatabase.Execute_Scalar(sql)
|
||||
@@ -145,89 +143,188 @@ Public Class ClassUpdate
|
||||
|
||||
End Function
|
||||
Public Shared Sub RUN_UPDATE()
|
||||
Dim UPD_VC As Boolean = False
|
||||
Dim UPD_RM As Boolean = False
|
||||
Dim KEEP_TEMPPATH As Boolean = False
|
||||
If DT_USER_DATA.Rows.Count <> 1 Then
|
||||
Exit Sub
|
||||
Else
|
||||
USER_INFO1 = DT_USER_DATA.Rows(0).Item("INFO1")
|
||||
USER_INFO2 = DT_USER_DATA.Rows(0).Item("INFO2")
|
||||
USER_INFO3 = DT_USER_DATA.Rows(0).Item("INFO3")
|
||||
|
||||
If (VERSION_USER = VERSION_SERVER) Or VERSION_SERVER = 1000 Or VERSION_USER = 1000 Then
|
||||
If DT_USER_DATA.Rows(0).Item("TEMPPATH") <> "" Then
|
||||
FOLDER_TEMP = DT_USER_DATA.Rows(0).Item("TEMPPATH")
|
||||
Else
|
||||
For Each Upd_item As DataRow In DT_UPDATE_ITEMS.Rows
|
||||
If Upd_item.Item("ITEM_INFO") = "VERSION_CHECKER.exe" Then
|
||||
If Not USER_INFO1.Contains(Upd_item.Item("INFO2")) Then
|
||||
UPD_VC = True
|
||||
|
||||
End If
|
||||
ElseIf Upd_item.Item("ITEM_INFO") = "RecordOrganizer_RightManager.exe" Then
|
||||
If Not USER_INFO1.Contains(Upd_item.Item("INFO2")) Then
|
||||
UPD_RM = True
|
||||
End If
|
||||
End If
|
||||
If Not IsDBNull(Upd_item.Item("INFO3")) Then
|
||||
FOLDER_TEMP = Upd_item.Item("INFO3")
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
If UPD_VC = True Or UPD_RM = True Then
|
||||
UPDATE_NECESSARY = True
|
||||
End If
|
||||
|
||||
If UPDATE_NECESSARY = False Then
|
||||
Exit Sub
|
||||
End If
|
||||
UPDATE_NECESSARY = True
|
||||
If FORCE_UPDATE = False Then
|
||||
'If FORCE_UPDATE = False Then
|
||||
|
||||
If VERSIONS_FOR_FORCE_UPDATE.Contains(VERSION_USER) Then
|
||||
ClassLogger.Add(String.Format("VersionChecker: ForceUpdate for User as Version '{0}' is used!", VERSION_USER), False)
|
||||
ClassHelper.InsertEssential_Log(USER_GUID, "USER-ID", String.Format("VersionChecker: ForceUpdate for User as Version '{0}' is used!", VERSION_USER))
|
||||
FORCE_UPDATE = True
|
||||
End If
|
||||
' If VERSIONS_FOR_FORCE_UPDATE.Contains(VERSION_USER) Then
|
||||
' ClassLogger.Add(String.Format("VersionChecker: ForceUpdate for User as Version '{0}' is used!", VERSION_USER), False)
|
||||
' ClassHelper.InsertEssential_Log(USER_GUID, "USER-ID", String.Format("VersionChecker: ForceUpdate for User as Version '{0}' is used!", VERSION_USER))
|
||||
' FORCE_UPDATE = True
|
||||
' End If
|
||||
'End If
|
||||
'If FORCE_UPDATE = False Then
|
||||
|
||||
' If ALL_USERS = False Then
|
||||
' sql = String.Format("SELECT COUNT(GUID) FROM TBDD_VERSION_USER_UPDATE WHERE USER_ID = {0} AND UPDATE_ID = {1}", USER_GUID, UPDATE_ID)
|
||||
' If clsDatabase.Execute_Scalar(sql) = 0 Then
|
||||
' ClassLogger.Add(String.Format("VersionChecker: User is not part of update-group - UPDATE-ID: {0}", UPDATE_ID), False)
|
||||
' ClassHelper.InsertEssential_Log(USER_GUID, "USER-ID", String.Format("VersionChecker: User is not part of update-group - UPDATE-ID: {0}", UPDATE_ID))
|
||||
' Exit Sub
|
||||
' End If
|
||||
' End If
|
||||
|
||||
Dim msg = "Auf dem Server liegt ein Update für ein ADDI-AddOn bereit!" & vbNewLine & "Wollen Sie das Update nun durchführen? Die Dauer ist abhängig von Ihrer Netzwerkverbindung!"
|
||||
If USER_LANGUAGE <> "de-DE" Then
|
||||
msg = "There is a new release available for an ADDI-AddOn!" & vbNewLine & "Would You like to install the update now? This might take some time minute(s)!"
|
||||
End If
|
||||
If FORCE_UPDATE = False Then
|
||||
|
||||
If ALL_USERS = False Then
|
||||
Dim sql = String.Format("SELECT COUNT(GUID) FROM TBDD_VERSION_USER_UPDATE WHERE USER_ID = {0} AND UPDATE_ID = {1}", USER_GUID, UPDATE_ID)
|
||||
If clsDatabase.Execute_Scalar(sql) = 0 Then
|
||||
ClassLogger.Add(String.Format("VersionChecker: User is not part of update-group - UPDATE-ID: {0}", UPDATE_ID), False)
|
||||
ClassHelper.InsertEssential_Log(USER_GUID, "USER-ID", String.Format("VersionChecker: User is not part of update-group - UPDATE-ID: {0}", UPDATE_ID))
|
||||
Exit Sub
|
||||
End If
|
||||
End If
|
||||
|
||||
Dim msg = "Auf dem Server liegt ein Update für ein ADDI-AddOn bereit!" & vbNewLine & "Wollen Sie das Update nun durchführen? Die Dauer ist abhängig von Ihrer Netzwerkverbindung!"
|
||||
If USER_LANGUAGE <> "de-DE" Then
|
||||
msg = "There is a new release available for an ADDI-AddOn!" & vbNewLine & "Would You like to install the update now? This might take some time (minute(s))!"
|
||||
End If
|
||||
Dim result As MsgBoxResult
|
||||
Dim result As MsgBoxResult
|
||||
result = MessageBox.Show(msg, "Confirmation:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
||||
If result = MsgBoxResult.No Then
|
||||
UPDATE_CANCELLED = True
|
||||
Exit Sub
|
||||
End If
|
||||
End If
|
||||
'End If
|
||||
|
||||
If MyServer_UpdatePath <> String.Empty Then
|
||||
If Directory.Exists(MyServer_UpdatePath) Then
|
||||
GetTempFolderGuid()
|
||||
If FOLDER_TEMP <> String.Empty Then
|
||||
If FOLDER_TEMP <> String.Empty Then
|
||||
If Directory.Exists(FOLDER_TEMP) Then
|
||||
' GetTempFolderGuid()
|
||||
' If FOLDER_TEMP <> String.Empty Then
|
||||
|
||||
' Make a reference to a directory.
|
||||
Dim di As New DirectoryInfo(MyServer_UpdatePath)
|
||||
' Get a reference to each file in that directory.
|
||||
Dim fiArr As FileInfo() = di.GetFiles()
|
||||
' Display the names of the files.
|
||||
'Dim fri As FileInfo
|
||||
Dim error_while_copying = False
|
||||
For Each Upd_item As DataRow In DT_UPDATE_ITEMS.Rows
|
||||
If error_while_copying = True Then
|
||||
Exit For
|
||||
End If
|
||||
Dim updatefile2copy = Path.Combine(MyServer_UpdatePath, Upd_item.Item("ITEM_INFO"))
|
||||
|
||||
Dim tempfilename = Path.Combine(FOLDER_TEMP, Upd_item.Item("ITEM_INFO"))
|
||||
|
||||
If File.Exists(updatefile2copy) Then
|
||||
Try
|
||||
System.IO.File.Copy(updatefile2copy, tempfilename)
|
||||
Catch ex As Exception
|
||||
ClassLogger.Add(String.Format("Error while copying file {0} to {1}: " & ex.Message, updatefile2copy, tempfilename))
|
||||
error_while_copying = True
|
||||
UPDATE_ERROR = True
|
||||
End Try
|
||||
Else
|
||||
ClassLogger.Add(String.Format("UpdateFile {0} is not existing or accessible", updatefile2copy))
|
||||
End If
|
||||
Next
|
||||
|
||||
If error_while_copying = False Then
|
||||
Replace_Files()
|
||||
Dim error_while_copying = False
|
||||
For Each Upd_item As DataRow In DT_UPDATE_ITEMS.Rows
|
||||
ClassLogger.Add(String.Format("...working on item {0}: ", Upd_item.Item("ITEM_INFO")), False)
|
||||
|
||||
If Upd_item.Item("ITEM_INFO") = "VERSION_CHECKER.exe" Then
|
||||
KEEP_TEMPPATH = Upd_item.Item("BIT3")
|
||||
End If
|
||||
|
||||
Try
|
||||
If error_while_copying = True Then
|
||||
Exit For
|
||||
End If
|
||||
Dim tempfilename = Path.Combine(FOLDER_TEMP, Upd_item.Item("ITEM_INFO"))
|
||||
If File.Exists(tempfilename) Then
|
||||
Try
|
||||
Dim error_while_replacing = False
|
||||
|
||||
Dim BackUpOfFileToReplace As String = MY_INSTALL_PATH & "\" & Upd_item.Item("INFO1") & Upd_item.Item("ITEM_INFO") & ".bac"
|
||||
BackUpOfFileToReplace = BackUpOfFileToReplace.Replace("//", "/")
|
||||
|
||||
Dim sourcefile = Path.Combine(FOLDER_TEMP, Upd_item.Item("ITEM_INFO"))
|
||||
Dim targetfile
|
||||
If IsDBNull(Upd_item.Item("INFO1")) Then
|
||||
targetfile = Path.Combine(MY_INSTALL_PATH, Upd_item.Item("ITEM_INFO"))
|
||||
Else
|
||||
If Upd_item.Item("INFO1") <> String.Empty Then
|
||||
targetfile = Path.Combine(MY_INSTALL_PATH, Upd_item.Item("INFO1"), Upd_item.Item("ITEM_INFO"))
|
||||
Else
|
||||
targetfile = Path.Combine(MY_INSTALL_PATH, Upd_item.Item("ITEM_INFO"))
|
||||
End If
|
||||
End If
|
||||
targetfile = targetfile.ToString.Replace("//", "/")
|
||||
ClassLogger.Add(String.Format("...replacing targetfile '{0}': ", targetfile), False)
|
||||
Try
|
||||
' Replace the file.
|
||||
If File.Exists(targetfile) Then
|
||||
If File_Rename(targetfile, BackUpOfFileToReplace) = True Then
|
||||
If File.Exists(BackUpOfFileToReplace) Then
|
||||
If KEEP_TEMPPATH Then
|
||||
If CopyFile(sourcefile, targetfile) = True Then
|
||||
File_Delete(BackUpOfFileToReplace)
|
||||
ClassLogger.Add(String.Format("...targetfile '{0}' was copied! ", targetfile), False)
|
||||
Dim updinfo
|
||||
If USER_INFO1 <> "" Then
|
||||
updinfo = USER_INFO1 & ";" & Upd_item.Item("INFO1") & "V" & Upd_item.Item("INFO2")
|
||||
Else
|
||||
updinfo = Upd_item.Item("INFO1") & "V" & Upd_item.Item("INFO2")
|
||||
End If
|
||||
Dim _Sql = String.Format("Update TBDD_VERSION_USER_UPDATE_PATH SET INFO1 = '{2}' WHERE USER_ID = {0} AND UPPER(MODULE_NAME) = UPPER('{1}')", USER_GUID, "Record-Organizer", updinfo)
|
||||
clsDatabase.Execute_non_Query(_Sql)
|
||||
End If
|
||||
Else
|
||||
If MoveFile(sourcefile, targetfile) = True Then
|
||||
File_Delete(BackUpOfFileToReplace)
|
||||
ClassLogger.Add(String.Format("...targetfile '{0}' was replaced! ", targetfile), False)
|
||||
Dim updinfo
|
||||
If USER_INFO1 <> "" Then
|
||||
updinfo = USER_INFO1 & ";" & Upd_item.Item("INFO1") & "V" & Upd_item.Item("INFO2")
|
||||
Else
|
||||
updinfo = Upd_item.Item("INFO1") & "V" & Upd_item.Item("INFO2")
|
||||
End If
|
||||
Dim _Sql = String.Format("Update TBDD_VERSION_USER_UPDATE_PATH SET INFO1 = '{2}' WHERE USER_ID = {0} AND UPPER(MODULE_NAME) = UPPER('{1}')", USER_GUID, "Record-Organizer", updinfo)
|
||||
clsDatabase.Execute_non_Query(_Sql)
|
||||
Else
|
||||
ClassLogger.Add(String.Format("MoveFile was not successfull! BackupFile will be activated!"))
|
||||
'Verschieben hat nicht geklappt also die Backupdatei wieder umbenennen!
|
||||
File_Rename(BackUpOfFileToReplace, targetfile)
|
||||
End If
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
Else
|
||||
|
||||
End If
|
||||
|
||||
|
||||
Catch ex As Exception
|
||||
ClassLogger.Add(String.Format("Error while copying file {0} to {1}: " & ex.Message, sourcefile, targetfile))
|
||||
error_while_replacing = True
|
||||
UPDATE_ERROR = True
|
||||
End Try
|
||||
|
||||
|
||||
|
||||
Catch ex As Exception
|
||||
ClassLogger.Add(String.Format("Unexpected Error in Replace_Files: {0}", ex.Message))
|
||||
UPDATE_ERROR = True
|
||||
End Try
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
Dim upd = String.Format("Update TBDD_VERSION_USER_UPDATE_PATH SET TEMPPATH = '' WHERE USER_ID = {0} AND UPPER(MODULE_NAME) = UPPER('{1}')", USER_GUID, "Record-Organizer")
|
||||
clsDatabase.Execute_non_Query(upd)
|
||||
Try
|
||||
If KEEP_TEMPPATH = False Then
|
||||
'Delete the tempfolder and all data
|
||||
System.IO.Directory.Delete(FOLDER_TEMP, True)
|
||||
Catch ex As Exception
|
||||
Else
|
||||
ClassLogger.Add(String.Format("TEMP FOLDER SHALL BE KEPT..."), False)
|
||||
End If
|
||||
|
||||
End Try
|
||||
Else
|
||||
ClassLogger.Add(String.Format("The temporaryFolder could not be created!"))
|
||||
End If
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
'Else
|
||||
' ClassLogger.Add(String.Format("The temporaryFolder could not be created!"))
|
||||
'End If
|
||||
Else
|
||||
ClassLogger.Add(String.Format("The Updatepath '{0}'is not accessible or does not exist", MyServer_UpdatePath))
|
||||
End If
|
||||
@@ -248,64 +345,6 @@ Public Class ClassUpdate
|
||||
End Try
|
||||
|
||||
End Function
|
||||
Private Shared Sub Replace_Files()
|
||||
Try
|
||||
|
||||
'Jede Datei im tempfolder wird replaced
|
||||
Dim di As New DirectoryInfo(FOLDER_TEMP)
|
||||
' Get a reference to each file in that directory.
|
||||
Dim fiArr As FileInfo() = di.GetFiles()
|
||||
' Display the names of the files.
|
||||
' Dim fri As FileInfo
|
||||
Dim error_while_replacing = False
|
||||
For Each Upd_item As DataRow In DT_UPDATE_ITEMS.Rows
|
||||
Dim BackUpOfFileToReplace As String = MY_INSTALL_PATH & "\" & Upd_item.Item("INFO1") & Upd_item.Item("ITEM_INFO") & ".bac"
|
||||
BackUpOfFileToReplace = BackUpOfFileToReplace.Replace("//", "/")
|
||||
|
||||
Dim sourcefile = Path.Combine(FOLDER_TEMP, Upd_item.Item("ITEM_INFO"))
|
||||
Dim targetfile
|
||||
If IsDBNull(Upd_item.Item("INFO1")) Then
|
||||
targetfile = Path.Combine(MY_INSTALL_PATH, Upd_item.Item("ITEM_INFO"))
|
||||
Else
|
||||
If Upd_item.Item("INFO1") <> String.Empty Then
|
||||
targetfile = Path.Combine(MY_INSTALL_PATH, Upd_item.Item("INFO1"), Upd_item.Item("ITEM_INFO"))
|
||||
Else
|
||||
targetfile = Path.Combine(MY_INSTALL_PATH, Upd_item.Item("ITEM_INFO"))
|
||||
End If
|
||||
End If
|
||||
targetfile = targetfile.ToString.Replace("//", "/")
|
||||
Try
|
||||
' Replace the file.
|
||||
If File.Exists(targetfile) Then
|
||||
If File_Rename(targetfile, BackUpOfFileToReplace) = True Then
|
||||
If File.Exists(BackUpOfFileToReplace) Then
|
||||
If MoveFile(sourcefile, targetfile) = True Then
|
||||
File_Delete(BackUpOfFileToReplace)
|
||||
Else
|
||||
'Verschieben hat nicht geklappt also die Backupdatei wieder umbenennen!
|
||||
File_Rename(BackUpOfFileToReplace, targetfile)
|
||||
End If
|
||||
End If
|
||||
|
||||
End If
|
||||
Else
|
||||
MoveFile(sourcefile, targetfile)
|
||||
End If
|
||||
|
||||
|
||||
Catch ex As Exception
|
||||
ClassLogger.Add(String.Format("Error while copying file {0} to {1}: " & ex.Message, sourcefile, targetfile))
|
||||
error_while_replacing = True
|
||||
UPDATE_ERROR = True
|
||||
End Try
|
||||
|
||||
Next
|
||||
|
||||
Catch ex As Exception
|
||||
ClassLogger.Add(String.Format("Unexpected Error in Replace_Files: {0}", ex.Message))
|
||||
UPDATE_ERROR = True
|
||||
End Try
|
||||
End Sub
|
||||
Private Shared Function File_Rename(targetfile As String, Renamefilestring As String)
|
||||
Try
|
||||
Renamefilestring = Renamefilestring.Replace("\\", "\")
|
||||
@@ -343,4 +382,14 @@ Public Class ClassUpdate
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Shared Function CopyFile(sourcefile As String, destfile As String)
|
||||
Try
|
||||
File.Copy(sourcefile, destfile, True)
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
ClassLogger.Add(String.Format("Unexpected Error in CopyFile: sourcefile '{0}', destfile '{1}' - ERROR: {2}", sourcefile, destfile, ex.Message))
|
||||
UPDATE_ERROR = True
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user