ZsgImport/app/ZSG_Import/MyService.vb.orig
Digital Data d2310ea20b Merge branch 'master' of http://172.24.11.74:90/scm/git/ZsgImport
# Conflicts:
#	app/ZSG_Import/MyService.vb
2017-02-15 16:34:31 +01:00

145 lines
7.4 KiB
VB.net
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<<<<<<< HEAD
' TEST - D
=======
' TEST - J
>>>>>>> 045edda55a5f52f4e684acc09e40dfb5be44cce2
Imports System.ComponentModel
Imports System.IO
Public Class MyService
'Variablen
Public Shared threadRunner As BackgroundWorker
Protected Overrides Sub OnStart(ByVal args() As String)
' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte Vorgänge
' ausführen, damit der Dienst gestartet werden kann.
' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte Vorgänge
' ausführen, damit der Dienst gestartet werden kann.
Try
clsLogger.Init(My.Application.Info.DirectoryPath & "\Log", "")
clsLogger.Add("## ZSGImport Service started - " & Now & " ## ", False)
If My.Settings.MyConnectionString = String.Empty Then
clsLogger.Add("NO CONNECTIONSTRING CONFIGURED.", True)
Else
If clsDatabase.Init = False Then
clsLogger.Add("ATTENTION: No Connection was established '" & My.Settings.MyConnectionString & "'!", True)
Else
LOG_ERRORS_ONLY = My.Settings.LOG_ERRORS_ONLY
'### Thread für das nachträgliche Setzen von Rechten generieren
MyService.threadRunner = New BackgroundWorker()
MyService.threadRunner.WorkerReportsProgress = True
MyService.threadRunner.WorkerSupportsCancellation = True
AddHandler threadRunner.DoWork, AddressOf RUN_THREAD
AddHandler threadRunner.RunWorkerCompleted, AddressOf Thread1_Completed
' Und den Durchlauf das erste Mal starten
threadRunner.RunWorkerAsync()
End If
End If
clsLogger.WriteLog()
Catch ex As Exception
clsLogger.AddError(ex.Message, "OnStart")
clsLogger.WriteLog()
End Try
End Sub
Public Shared Sub RUN_THREAD(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Try
'erst einmal die Technischen Plätze bestimmen die noch nciht importiert wurden
Dim DT_TP As DataTable = clsDatabase.Return_Datatable("SELECT DISTINCT [UNIQUE_STR] FROM [EXPORT_COMOS] where dokumentart is not null and imported = 0 and [UNIQUE_STR] LIKE '472%' order by [UNIQUE_STR]")
Try
If Not IsNothing(DT_TP) Then
If DT_TP.Rows.Count > 0 Then
clsLogger.Add(String.Format(">> {0} TPs need to be worked - {1}", DT_TP.Rows.Count.ToString, Now), False)
'Jeden Technischen Platz einzeln durchlaufen weil für diesen ein Record existiert
For Each TP As DataRow In DT_TP.Rows
Dim _TP As String = TP.Item(0)
clsLogger.AddDetailLog(String.Format(">> Working on technical place: '{0}'", _TP))
Dim selrecid = String.Format("SELECT [Record-ID] FROM VWTEMP_PMO_FORM3 where UPPER(TPLNR) = UPPER('{0}')", _TP)
Dim _RECORD_ID = clsDatabase.Execute_Scalar(selrecid)
If Not IsNothing(_RECORD_ID) Then
'Jede Datei einzeln durchlaufen
Dim sel = String.Format("SELECT * FROM [EXPORT_COMOS] WHERE IMPORTED = 0 AND [UNIQUE_STR] = '{0}'", TP.Item("UNIQUE_STR"))
Dim DT_TP_DOCS As DataTable = clsDatabase.Return_Datatable(sel)
If Not IsNothing(DT_TP_DOCS) Then
If DT_TP_DOCS.Rows.Count > 0 Then
For Each _docRow As DataRow In DT_TP_DOCS.Rows
Dim GUID = _docRow.Item("GUID")
Dim filename = _docRow.Item("Link")
If File.Exists(filename) Then
Else
clsLogger.Add(String.Format(">> File not found: {0}", filename), False)
Update_COMMENT_GUID(GUID, "FILE NOT FOUND")
End If
Next
End If
End If
Else
clsLogger.Add(String.Format(">> No Record found for TP: {0}", _TP), False)
Update_COMMENT(_TP, "NO RECORD-ID FOUND")
End If
Next
'DD_Rights.clsLogger.Init(My.Application.Info.DirectoryPath & "\Log", "")
'If DD_Rights.ClassRights.Init_Service(LOG_ERRORS_ONLY, DT_RIGHTS_2b_WORKED.Rows.Count) Then
' If DD_Rights.ClassRights.WORK_RIGHT2B_CHANGED(DT_RIGHTS_2b_WORKED) = True Then
' clsLogger.Add(">> All rights were worked - " & Now, False)
' End If
'End If
End If
End If
Catch ex As Exception
clsLogger.AddError("Uncexpected Error in working rights: " & ex.Message, "DT_RIGHTS_2b_WORKED")
End Try
clsLogger.WriteLog()
Catch ex As Exception
clsLogger.AddError("Uncexpected Error: " & ex.Message, "RUN_THREAD")
End Try
End Sub
Private Shared Sub Update_COMMENT(UNIQUE_STR As String, comment As String)
Try
Dim upd = String.Format("UPDATE EXPORT_COMOS_472 SET COMMENT = '{0}' where UPPER(UNIQUE_STR) = UPPER('{1}') AND IMPORTED = 0")
clsDatabase.Execute_non_Query(upd)
Catch ex As Exception
clsLogger.AddError("Uncexpected Error in Update_COMMENT: " & ex.Message)
End Try
End Sub
Private Shared Sub Update_COMMENT_GUID(GUID As Integer, comment As String)
Try
Dim upd = String.Format("UPDATE EXPORT_COMOS_472 SET COMMENT = '{0}' where GUID = {1}")
clsDatabase.Execute_non_Query(upd)
Catch ex As Exception
clsLogger.AddError("Uncexpected Error in Update_COMMENT_GUID: " & ex.Message)
End Try
End Sub
Protected Overrides Sub OnStop()
' Hier Code zum Ausführen erforderlicher Löschvorgänge zum Beenden des Dienstes einfügen.
clsLogger.Add("## ZSGImport Service was stopped manually - " & Now & " ## ", False)
clsLogger.WriteLog()
End Sub
Private Shared Sub Thread1_Completed(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) 'Handles threadDateiimport.RunWorkerCompleted
' This event fires when the DoWork event completes
Try
Dim result As String = ""
If e.Cancelled Then
clsLogger.Add("## The thread was cancelled", False)
clsLogger.WriteLog()
ElseIf e.Error IsNot Nothing Then
clsLogger.Add("Fehler bei Durchlauf. Der Vorgang wird abgebrochen.", True, "Thread_Completed")
clsLogger.Add(e.Error.Message, True, "Thread_Completed")
clsLogger.WriteLog()
End If
Catch ex As Exception
clsLogger.AddError(ex.Message, "Thread_Completed")
End Try
End Sub
End Class