diff --git a/WebDoorCreator.CamSrv/ProcMan.vb b/WebDoorCreator.CamSrv/ProcMan.vb index 9321e0e..2cbbdcc 100644 --- a/WebDoorCreator.CamSrv/ProcMan.vb +++ b/WebDoorCreator.CamSrv/ProcMan.vb @@ -8,230 +8,244 @@ Public Class ProcMan #Region "Public Constructors" - Public Sub New() + Public Sub New() - ' This call is required by the designer. - InitializeComponent() + ' This call is required by the designer. + InitializeComponent() - ' Add any initialization after the InitializeComponent() call. - synchronizationContext = SynchronizationContext.Current - ' preparo lista thread... - 'Begin the update - LISTThreadStatus.BeginUpdate() - 'clear the List - LISTThreadStatus.Items.Clear() - 'Add init - LISTThreadStatus.Items.Add(New ListViewItem(New String() {"init", "waiting", "-"})) - 'End the update - LISTThreadStatus.EndUpdate() - StartUiThread() - startAllThreads() - CheckStartAutoRestart() + ' Add any initialization after the InitializeComponent() call. + synchronizationContext = SynchronizationContext.Current + m_bStopProcess = True + SetMaxCamInstances(1) + StartUiThread() + ' preparo lista thread... + LISTThreadStatus.BeginUpdate() + LISTThreadStatus.Items.Clear() + LISTThreadStatus.Items.Add(New ListViewItem(New String() {"init", "waiting", "-"})) + LISTThreadStatus.EndUpdate() - End Sub + ' verifico SE avviare + If chkAutoRestart.Checked Then + startAllThreads() + End If + CheckStartAutoRestart() + + End Sub #End Region #Region "Private Fields" - Private ReadOnly synchronizationContext As SynchronizationContext + Private ReadOnly synchronizationContext As SynchronizationContext - ' caricamento del NEXT STACK da redis (come oggetto) PROD http : https://iis01.egalware.com/WDC/SRV/ - ' DEV: https : https://localhost:7043/ - Dim baseIp As String = "iis01.egalware.com" + ' caricamento del NEXT STACK da redis (come oggetto) PROD http : https://iis01.egalware.com/WDC/SRV/ + ' DEV: https : https://localhost:7043/ + Dim baseIp As String = "iis01.egalware.com" - Dim baseUrl As String = "https://iis01.egalware.com/WDC/SRV/" + Dim baseUrl As String = "https://iis01.egalware.com/WDC/SRV/" - Dim codPost As String = "WRK001" + Dim codPost As String = "WRK001" - ' nome macchina calcolo - Dim currWDC As WDC = New WDC(baseIp, baseUrl, codPost) + ' nome macchina calcolo + Dim currWDC As WDC = New WDC(baseIp, baseUrl, codPost) - Dim idxSim As Integer = 0 + Dim idxSim As Integer = 0 - Dim m_bExecutionThreadStoped As Boolean = False + Dim m_bExecutionThreadStoped As Boolean = False - Dim m_bStopProcess As Boolean = False + Dim m_bStopProcess As Boolean = False - Dim m_ExecutionThread As Thread + Dim m_ExecutionThread As Thread - 'Private m_MaxCamInstances As Integer = 8 - Private m_MaxCamInstances As Integer = 1 + 'Private m_MaxCamInstances As Integer = 8 + Private m_MaxCamInstances As Integer = 1 - Dim risultatoPing As PingReply = Nothing + Dim risultatoPing As PingReply = Nothing - Dim ThreadList As Thread() + Dim ThreadList As Thread() - Dim ThreadDataList As ThreadData() + Dim ThreadDataList As ThreadData() #End Region - Enum ThreadOperations As Integer - WaitingData = 1 - FoundRequest = 2 - WritingDdf = 3 - ProcessingDdf = 4 - ReadingSvg = 5 - SendResult = 6 - Closed = 10 - End Enum + Enum ThreadOperations As Integer + WaitingData = 1 + FoundRequest = 2 + WritingDdf = 3 + ProcessingDdf = 4 + ReadingSvg = 5 + SendResult = 6 + Closed = 10 + End Enum - Private Class ThreadData + Private Class ThreadData - Private m_ThreadOperation As ThreadOperations - Public ReadOnly Property ThreadOperation As ThreadOperations - Get - Return m_ThreadOperation - End Get - End Property - Friend Sub SetThreadOperation(value As ThreadOperations) - m_ThreadOperation = value - End Sub + Private m_ThreadOperation As ThreadOperations + Public ReadOnly Property ThreadOperation As ThreadOperations + Get + Return m_ThreadOperation + End Get + End Property + Friend Sub SetThreadOperation(value As ThreadOperations) + m_ThreadOperation = value + End Sub - Private m_Process As Process - Public ReadOnly Property Process As Process - Get - Return m_Process - End Get - End Property - Friend Sub SetProcess(value As Process) - m_Process = value - End Sub + Private m_Process As Process + Public ReadOnly Property Process As Process + Get + Return m_Process + End Get + End Property + Friend Sub SetProcess(value As Process) + m_Process = value + End Sub - End Class + End Class #Region "Private Methods" - Private Sub UpdateThreadCurrentStatus() - synchronizationContext.Post(New SendOrPostCallback( + Private Sub UpdateThreadCurrentStatus() + synchronizationContext.Post(New SendOrPostCallback( Sub(o) - ThreadCurrentStatusList.BeginUpdate() - ThreadCurrentStatusList.Items.Clear() + ThreadCurrentStatusList.BeginUpdate() + ThreadCurrentStatusList.Items.Clear() - If Not IsNothing(ThreadList) Then - For ThreadIndex = 0 To ThreadList.Count - 1 - If Not IsNothing(ThreadList(ThreadIndex)) Then - Dim ThreadProcessState As String = "Nothing" - 'If Not IsNothing(ThreadDataList(ThreadIndex)) AndAlso Not IsNothing(ThreadDataList(ThreadIndex).Process) AndAlso - 'Not IsNothing(ThreadDataList(ThreadIndex).Process.HasExited) Then - ' ThreadProcessState = ThreadDataList(ThreadIndex).Process.HasExited - 'End If - ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, + If Not IsNothing(ThreadList) Then + For ThreadIndex = 0 To ThreadList.Count - 1 + If Not IsNothing(ThreadList(ThreadIndex)) Then + Dim ThreadProcessState As String = "Nothing" + 'If Not IsNothing(ThreadDataList(ThreadIndex)) AndAlso Not IsNothing(ThreadDataList(ThreadIndex).Process) AndAlso + 'Not IsNothing(ThreadDataList(ThreadIndex).Process.HasExited) Then + ' ThreadProcessState = ThreadDataList(ThreadIndex).Process.HasExited + 'End If + ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, ThreadList(ThreadIndex).ThreadState.ToString(), ThreadProcessState, ThreadDataList(ThreadIndex).ThreadOperation.ToString()})) - Else - ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, + Else + ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, "nothing"})) - End If - Next - End If - ThreadCurrentStatusList.EndUpdate() + End If + Next + End If + ThreadCurrentStatusList.EndUpdate() End Sub), "") - End Sub + End Sub - Private Sub btnQueueStatus_Click(sender As Object, e As EventArgs) Handles btnQueueStatus.Click - DisplayQueueStatus() - End Sub + Private Sub btnQueueStatus_Click(sender As Object, e As EventArgs) Handles btnQueueStatus.Click + DisplayQueueStatus() + End Sub - Private Sub btnResetQueue_Click(sender As Object, e As EventArgs) Handles btnResetQueue.Click - currWDC.ResetQueue() - txtOut.Text = "Queue Resetted!" - End Sub + Private Sub btnResetQueue_Click(sender As Object, e As EventArgs) Handles btnResetQueue.Click + currWDC.ResetQueue() + txtOut.Text = "Queue Resetted!" + End Sub - Private Sub btnTestAlive_Click(sender As Object, e As EventArgs) Handles btnTestAlive.Click - Dim answ As String = "" - If (currWDC.testAlive) Then - lblTestAlive.Text = "Server Alive!!!" - Else - lblTestAlive.Text = "Alive test failed!" - End If - End Sub + Private Sub btnTestAlive_Click(sender As Object, e As EventArgs) Handles btnTestAlive.Click + Dim answ As String = "" + If (currWDC.testAlive) Then + lblTestAlive.Text = "Server Alive!!!" + Else + lblTestAlive.Text = "Alive test failed!" + End If + End Sub - Private Sub btnTestPing_Click(sender As Object, e As EventArgs) Handles btnTestPing.Click - ' chiamo test ping... - risultatoPing = currWDC.testPing - lblpingTest.Text = risultatoPing.Status.ToString() - End Sub + Private Sub btnTestPing_Click(sender As Object, e As EventArgs) Handles btnTestPing.Click + ' chiamo test ping... + risultatoPing = currWDC.testPing + lblpingTest.Text = risultatoPing.Status.ToString() + End Sub - Private Sub DisplayQueueStatus() - Dim queueStatus As New Dictionary(Of String, Long) - queueStatus = currWDC.queueStatus - Dim sb As StringBuilder - sb = New StringBuilder - For Each item As KeyValuePair(Of String, Long) In queueStatus - sb.AppendLine($"{item.Key}: {item.Value}") - Next - sb.AppendLine() - txtQueue.Text = sb.ToString() - txtQueue.Invalidate() - End Sub + Private Sub DisplayQueueStatus() + Dim queueStatus As New Dictionary(Of String, Long) + queueStatus = currWDC.queueStatus + Dim sb As StringBuilder + sb = New StringBuilder + For Each item As KeyValuePair(Of String, Long) In queueStatus + sb.AppendLine($"{item.Key}: {item.Value}") + Next + sb.AppendLine() + txtQueue.Text = sb.ToString() + txtQueue.Invalidate() + End Sub - Private Sub ExecutionProcess() - ' recupero Id dei DDF - Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf" - Dim sCurrDdfDir As String = "" - Dim nDdfId As Integer = 1 + Private Sub ExecutionProcess() + ' recupero Id dei DDF + Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf" + Dim sCurrDdfDir As String = "" + Dim nDdfId As Integer = 1 - Dim bStopMainProcess As Boolean = False - Dim n30SecCounter As Integer = 0 - While Not bStopMainProcess - bStopMainProcess = m_bStopProcess - Dim bOk As Boolean = False - While Not bOk - ' ogni 30 secondi - If n30SecCounter = 30 OrElse n30SecCounter = 0 Then - ' verifica connessione - Dim risultatoPing As PingReply = currWDC.testPing - bOk = risultatoPing.Status = IPStatus.Success - If bOk Then - bOk = currWDC.testAlive - End If - Else - bOk = True + Dim bStopMainProcess As Boolean = False + Dim n30SecCounter As Integer = 0 + While Not bStopMainProcess + bStopMainProcess = m_bStopProcess + Dim bOk As Boolean = False + While Not bOk + ' ogni 30 secondi + If n30SecCounter = 30 OrElse n30SecCounter = 0 Then + ' verifica connessione + Dim risultatoPing As PingReply = currWDC.testPing + bOk = risultatoPing.Status = IPStatus.Success + If bOk Then + bOk = currWDC.testAlive + End If + Else + bOk = True + End If + ' se connessione non ok o processo fermato, fermo i thread + If Not bOk OrElse bStopMainProcess Then + If Not IsNothing(ThreadList) AndAlso ThreadList.Count > 0 AndAlso Not IsNothing(ThreadList(0)) Then + ' li fermo + m_bStopProcess = True + ' verifico siano terminati + Dim bOneNotEnded As Boolean = True + While bOneNotEnded + bOneNotEnded = False + For Each Thread In ThreadList + If Not IsNothing(Thread) Then + If Thread.IsAlive Then + bOneNotEnded = True + End If + End If + Next + End While + ' pulisco la lista + For ThreadIndex = 0 To ThreadList.Count - 1 + ThreadList(ThreadIndex) = Nothing + Next + End If + If bStopMainProcess Then + m_bExecutionThreadStoped = True + Return + End If + End If + If Not bOk Then Thread.Sleep(10) + End While + + If bOk AndAlso (IsNothing(ThreadList) OrElse ThreadList.Count = 0 OrElse IsNothing(ThreadList(0))) Then + ThreadList = New Thread(m_MaxCamInstances - 1) {} + ThreadDataList = New ThreadData(m_MaxCamInstances - 1) {} + For nThreadIndex = 0 To m_MaxCamInstances - 1 + Dim ThreadId As Integer = nThreadIndex + ThreadList(nThreadIndex) = New Thread(Sub() + ThreadFunction(ThreadId) + End Sub) + ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA) + ' avvio thread di gestione della macchina che avvia la connessione + ThreadList(nThreadIndex).Start() + Thread.Sleep(10) + Next End If - ' se connessione non ok o processo fermato, fermo i thread - If Not bOk OrElse bStopMainProcess Then - If Not IsNothing(ThreadList) AndAlso ThreadList.Count > 0 AndAlso Not IsNothing(ThreadList(0)) Then - ' li fermo - m_bStopProcess = True - ' verifico siano terminati - Dim bOneNotEnded As Boolean = True - While bOneNotEnded - bOneNotEnded = False - For Each Thread In ThreadList - If Not IsNothing(Thread) Then - If Thread.IsAlive Then - bOneNotEnded = True - End If - End If - Next - End While - ' pulisco la lista - For ThreadIndex = 0 To ThreadList.Count - 1 - ThreadList(ThreadIndex) = Nothing - Next - End If - If bStopMainProcess Then - m_bExecutionThreadStoped = True - Return - End If - End If - If Not bOk Then Thread.Sleep(10) - End While - - If bOk AndAlso (IsNothing(ThreadList) OrElse ThreadList.Count = 0 OrElse IsNothing(ThreadList(0))) Then - ThreadList = New Thread(m_MaxCamInstances - 1) {} - ThreadDataList = New ThreadData(m_MaxCamInstances - 1) {} - For nThreadIndex = 0 To m_MaxCamInstances - 1 - Dim ThreadId As Integer = nThreadIndex - ThreadList(nThreadIndex) = New Thread(Sub() - ThreadFunction(ThreadId) - End Sub) - ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA) - ' avvio thread di gestione della macchina che avvia la connessione - ThreadList(nThreadIndex).Start() - Thread.Sleep(10) + ' se qualche processo in stop, lo faccio ripartire + For ThreadIndex = 0 To ThreadList.Count - 1 + Dim Thread = ThreadList(ThreadIndex) + If Thread.ThreadState = ThreadState.Stopped Then + Thread.Abort() + Dim ThreadId As Integer = ThreadIndex + Thread = New Thread(Sub() + ThreadFunction(ThreadId) + End Sub) + End If Next End If ' se qualche processo in stop, lo faccio ripartire @@ -245,98 +259,84 @@ Public Class ProcMan ThreadFunction(ThreadId) End Sub) End If - Next - If n30SecCounter <= 30 Then - n30SecCounter += 1 - Else - n30SecCounter = 1 - End If - Thread.Sleep(1000) + Thread.Sleep(1000) - End While + End While - End Sub + End Sub - Private Function GetFileContent(ByVal filePath As String, ByRef fileContent As String) As Boolean + Private Function GetFileContent(ByVal filePath As String, ByRef fileContent As String) As Boolean - Dim bOk As Boolean = File.Exists(filePath) - If bOk Then - Try - fileContent = File.ReadAllText(filePath) - Catch ex As Exception - bOk = False - fileContent = "" - End Try - End If - Return bOk - End Function + Dim bOk As Boolean = File.Exists(filePath) + If bOk Then + Try + fileContent = File.ReadAllText(filePath) + Catch ex As Exception + bOk = False + fileContent = "" + End Try + End If + Return bOk + End Function - Private Sub performBarAdvance() - synchronizationContext.Post(New SendOrPostCallback( + Private Sub performBarAdvance() + synchronizationContext.Post(New SendOrPostCallback( Sub(o) - tsProgBar.PerformStep() - If tsProgBar.Value >= tsProgBar.Maximum Then - tsProgBar.Value = 0 - End If + tsProgBar.PerformStep() + If tsProgBar.Value >= tsProgBar.Maximum Then + tsProgBar.Value = 0 + End If - tsProgBar.Invalidate() + tsProgBar.Invalidate() End Sub ), "") - End Sub + End Sub - Private Sub performUpdateUI() - synchronizationContext.Post(New SendOrPostCallback( + Private Sub performUpdateUI() + synchronizationContext.Post(New SendOrPostCallback( Sub(o) - 'verifico thread attivi e se calano --> riavvia.. - If ThreadCount() <> m_MaxCamInstances And Not m_bStopProcess Then - stopAllThreads() - Thread.Sleep(100) - startAllThreads() - End If + 'verifico thread attivi e se calano --> riavvia.. + If ThreadCount() <> m_MaxCamInstances And Not m_bStopProcess Then + stopAllThreads() + Thread.Sleep(100) + startAllThreads() + End If - lblRunning.Text = $"threads: {ThreadCount()}/{m_MaxCamInstances}" - lblRunning.Invalidate() - DisplayQueueStatus() - ' colore btn start / stop... - If m_bStopProcess Then + lblRunning.Text = $"threads: {ThreadCount()}/{m_MaxCamInstances}" + lblRunning.Invalidate() + DisplayQueueStatus() + ' colore btn start / stop... + If m_bStopProcess Then - StartProcess.BackColor = ButtonBase.DefaultBackColor - StartProcess.ForeColor = ButtonBase.DefaultForeColor - StopProcess.BackColor = Color.Green - StopProcess.ForeColor = Color.White - Else - StartProcess.BackColor = Color.Green - StartProcess.ForeColor = Color.White - StopProcess.BackColor = ButtonBase.DefaultBackColor - StopProcess.ForeColor = ButtonBase.DefaultForeColor - End If + StartProcess.BackColor = ButtonBase.DefaultBackColor + StartProcess.ForeColor = ButtonBase.DefaultForeColor + StopProcess.BackColor = Color.Green + StopProcess.ForeColor = Color.White + Else + StartProcess.BackColor = Color.Green + StartProcess.ForeColor = Color.White + StopProcess.BackColor = ButtonBase.DefaultBackColor + StopProcess.ForeColor = ButtonBase.DefaultForeColor + End If End Sub ), "") - End Sub + End Sub - Private Sub SetMaxCamInstances(value As Integer) - ' Numero di core logici da utilizzare (minimo tra presenti sul PC e imposti da INI) - Dim nMaxThread As Integer = Math.Min(Environment.ProcessorCount, value) - m_MaxCamInstances = nMaxThread - End Sub + Private Sub SetMaxCamInstances(value As Integer) + ' Numero di core logici da utilizzare (minimo tra presenti sul PC e imposti da INI) + Dim nMaxThread As Integer = Math.Min(Environment.ProcessorCount, value) + m_MaxCamInstances = nMaxThread + End Sub - Private Sub startAllThreads() - m_bStopProcess = False - '' fix colori - 'StartProcess.BackColor = Color.Green - 'StartProcess.ForeColor = Color.White + Private Sub startAllThreads() + m_bStopProcess = False + m_ExecutionThread = New Thread(Sub() + ExecutionProcess() + End Sub) - m_ExecutionThread = New Thread(Sub() - ExecutionProcess() - End Sub) - - m_ExecutionThread.SetApartmentState(ApartmentState.STA) - ' avvio thread di gestione della macchina che avvia la connessione - m_ExecutionThread.Start() - - ' avvio il timer di refresh - TimerProgBar.Enabled = True - TimerProgBar.Start() + m_ExecutionThread.SetApartmentState(ApartmentState.STA) + ' avvio thread di gestione della macchina che avvia la connessione + m_ExecutionThread.Start() #If False Then '' recupero Id dei DDF 'Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf" @@ -564,182 +564,187 @@ Public Class ProcMan ' End If #End If - End Sub + End Sub - Private Sub StartProcess_Click(sender As Object, e As EventArgs) Handles StartProcess.Click - startAllThreads() - End Sub + Private Sub StartProcess_Click(sender As Object, e As EventArgs) Handles StartProcess.Click + startAllThreads() + End Sub - Private Sub StartUiThread() - ' avvio timer progBar - TimerUI.Enabled = True - TimerUI.Start() - End Sub + Private Sub StartUiThread() + ' avvio timer progBar + TimerUI.Enabled = True + TimerUI.Start() - Private Sub stopAllThreads() - m_bStopProcess = True + ' avvio il timer di refresh + TimerProgBar.Enabled = True + TimerProgBar.Start() + End Sub - While Not m_bExecutionThreadStoped - Thread.Sleep(20) - End While - m_ExecutionThread = Nothing - ' fix timer - TimerProgBar.Enabled = False - TimerProgBar.Stop() - End Sub + Private Sub stopAllThreads() + m_bStopProcess = True - Private Sub StopProcess_Click(sender As Object, e As EventArgs) Handles StopProcess.Click - stopAllThreads() - End Sub + While Not m_bExecutionThreadStoped + Thread.Sleep(20) + End While + m_ExecutionThread = Nothing + ' fix timer + TimerProgBar.Enabled = False + TimerProgBar.Stop() + End Sub - Private Function ThreadCount() As Integer - Dim numCount = 0 - If Not IsNothing(ThreadList) Then - ' conto i NON nulli - For Each Thread In ThreadList - If Not IsNothing(Thread) Then - numCount += 1 - End If - Next - End If - ' rendo - Return numCount - End Function + Private Sub StopProcess_Click(sender As Object, e As EventArgs) Handles StopProcess.Click + stopAllThreads() + End Sub - Private Sub ThreadFunction(ThreadIndex As Integer) - Dim MyThreadData As New ThreadData - ThreadDataList(ThreadIndex) = MyThreadData - Dim sExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe" - Dim sCurrDdfDir As String = "c:\EgtData\WebDoor\Ddf" - Dim stopWatch As New Stopwatch() - Dim lExeTime As Long = 0 - Dim lOtherTime As Long = 0 + Private Function ThreadCount() As Integer + Dim numCount = 0 + If Not IsNothing(ThreadList) Then + ' conto i NON nulli + For Each Thread In ThreadList + If Not IsNothing(Thread) Then + numCount += 1 + End If + Next + End If + ' rendo + Return numCount + End Function - While Not m_bStopProcess - MyThreadData.SetThreadOperation(ThreadOperations.WaitingData) - ' se c'e' qualcosa da processare - If currWDC.numTask2proc > 0 Then - Dim LastRequest As Dictionary(Of String, String) = currWDC.queueList(1) - If LastRequest.Count > 0 Then - MyThreadData.SetThreadOperation(ThreadOperations.FoundRequest) - Dim Item As KeyValuePair(Of String, String) = LastRequest.First() - Dim bOk As Boolean = Not IsNothing(Item) - If bOk Then + Private Sub ThreadFunction(ThreadIndex As Integer) + Dim MyThreadData As New ThreadData + ThreadDataList(ThreadIndex) = MyThreadData + Dim sExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe" + Dim sCurrDdfDir As String = "c:\EgtData\WebDoor\Ddf" + Dim stopWatch As New Stopwatch() + Dim lExeTime As Long = 0 + Dim lOtherTime As Long = 0 - ' avvio cronometro - 'stopWatch.Reset() - stopWatch.Restart() - ' svuoto vecchio set file della porta richiesta - Dim fileList As String() = Directory.GetFiles(sCurrDdfDir, Item.Key + ".*") - ' elimino vecchi - If Not IsNothing(fileList) Then - For Each sFile In fileList - File.Delete(sFile) - Next - End If + While Not m_bStopProcess + MyThreadData.SetThreadOperation(ThreadOperations.WaitingData) + ' se c'e' qualcosa da processare + If currWDC.numTask2proc > 0 Then + Dim LastRequest As Dictionary(Of String, String) = currWDC.queueList(1) + If LastRequest.Count > 0 Then + MyThreadData.SetThreadOperation(ThreadOperations.FoundRequest) + Dim Item As KeyValuePair(Of String, String) = LastRequest.First() + Dim bOk As Boolean = Not IsNothing(Item) + If bOk Then - ' scrivo ddf - MyThreadData.SetThreadOperation(ThreadOperations.WritingDdf) - Dim sDdfPath As String = sCurrDdfDir & "\" & Item.Key & ".ddf" - Try - File.WriteAllText(sDdfPath, Item.Value) - Catch ex As Exception - bOk = False - End Try - - If bOk Then - MyThreadData.SetThreadOperation(ThreadOperations.ProcessingDdf) - - ' eseguo calcolo - Dim Proc As Process = New Process() - MyThreadData.SetProcess(Proc) - Proc.StartInfo.FileName = sExePath - Proc.StartInfo.Arguments = """C:\EgtData\WebDoor\Main.lua""" & " """ & sDdfPath & """" - Proc.StartInfo.UseShellExecute = False - - If Proc.Start() Then - - While Not Proc.HasExited - Thread.Sleep(1) - End While - MyThreadData.SetProcess(Nothing) - ' salvo exe time... - stopWatch.Stop() - lExeTime = stopWatch.ElapsedMilliseconds + ' avvio cronometro + 'stopWatch.Reset() stopWatch.Restart() - Dim procResults As New List(Of CalcResultDTO) - Dim currRes As New CalcResultDTO - Dim fContent As String = "" - MyThreadData.SetThreadOperation(ThreadOperations.ReadingSvg) - ' verifico esistenza file svg e lo carico - bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "svg"), fContent) - ' invio risposta - currRes.Validated = Proc.ExitCode = 0 AndAlso bOk - currRes.DoorIdVers = Item.Key - ' se NON fosse validato --> messo il messaggio... - If (currRes.Validated) Then - currRes.SvgGen = fContent - Else - bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "txt"), fContent) - currRes.ErrorMsg = fContent + ' svuoto vecchio set file della porta richiesta + Dim fileList As String() = Directory.GetFiles(sCurrDdfDir, Item.Key + ".*") + ' elimino vecchi + If Not IsNothing(fileList) Then + For Each sFile In fileList + File.Delete(sFile) + Next End If - MyThreadData.SetThreadOperation(ThreadOperations.SendResult) - procResults.Add(currRes) - Dim respPut As String = currWDC.SendProcResults(procResults) + ' scrivo ddf + MyThreadData.SetThreadOperation(ThreadOperations.WritingDdf) + Dim sDdfPath As String = sCurrDdfDir & "\" & Item.Key & ".ddf" + Try + File.WriteAllText(sDdfPath, Item.Value) + Catch ex As Exception + bOk = False + End Try - stopWatch.Stop() - lOtherTime = stopWatch.ElapsedMilliseconds - ' aggiorno thread display... - UpdateThreadList(Item.Key, lExeTime, lOtherTime) - ' cambio nomi file generati in old - Dim OldSvg As String = Path.ChangeExtension(sDdfPath, "svg") - Dim NewSvg As String = Path.GetDirectoryName(sDdfPath) & "\" & Path.GetFileNameWithoutExtension(sDdfPath) & "_old.svg" - Try - File.Delete(NewSvg) - Catch ex As Exception - End Try - Try - File.Delete(Path.ChangeExtension(NewSvg, "txt")) - Catch ex As Exception - End Try - Try - File.Delete(Path.ChangeExtension(NewSvg, "log")) - Catch ex As Exception - End Try - Try - File.Delete(Path.ChangeExtension(NewSvg, "nge")) - Catch ex As Exception - End Try - Try - File.Delete(Path.ChangeExtension(NewSvg, "ddf")) - Catch ex As Exception - End Try - Try - File.Move(OldSvg, NewSvg) - Catch ex As Exception - End Try - Try - File.Move(Path.ChangeExtension(OldSvg, "txt"), Path.ChangeExtension(NewSvg, "txt")) - Catch ex As Exception - End Try - Try - File.Move(Path.ChangeExtension(OldSvg, "log"), Path.ChangeExtension(NewSvg, "log")) - Catch ex As Exception - End Try - Try - File.Move(Path.ChangeExtension(OldSvg, "nge"), Path.ChangeExtension(NewSvg, "nge")) - Catch ex As Exception - End Try - Try - File.Move(Path.ChangeExtension(OldSvg, "ddf"), Path.ChangeExtension(NewSvg, "ddf")) - Catch ex As Exception - End Try - End If - stopWatch.Stop() - End If - End If + If bOk Then + MyThreadData.SetThreadOperation(ThreadOperations.ProcessingDdf) + + ' eseguo calcolo + Dim Proc As Process = New Process() + MyThreadData.SetProcess(Proc) + Proc.StartInfo.FileName = sExePath + Proc.StartInfo.Arguments = """C:\EgtData\WebDoor\Main.lua""" & " """ & sDdfPath & """" + Proc.StartInfo.UseShellExecute = False + + If Proc.Start() Then + + While Not Proc.HasExited + Thread.Sleep(1) + End While + MyThreadData.SetProcess(Nothing) + ' salvo exe time... + stopWatch.Stop() + lExeTime = stopWatch.ElapsedMilliseconds + stopWatch.Restart() + Dim procResults As New List(Of CalcResultDTO) + Dim currRes As New CalcResultDTO + Dim fContent As String = "" + MyThreadData.SetThreadOperation(ThreadOperations.ReadingSvg) + ' verifico esistenza file svg e lo carico + bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "svg"), fContent) + ' invio risposta + currRes.Validated = Proc.ExitCode = 0 AndAlso bOk + currRes.DoorIdVers = Item.Key + ' se NON fosse validato --> messo il messaggio... + If (currRes.Validated) Then + currRes.SvgGen = fContent + Else + bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "txt"), fContent) + currRes.ErrorMsg = fContent + End If + MyThreadData.SetThreadOperation(ThreadOperations.SendResult) + + procResults.Add(currRes) + Dim respPut As String = currWDC.SendProcResults(procResults) + + stopWatch.Stop() + lOtherTime = stopWatch.ElapsedMilliseconds + ' aggiorno thread display... + UpdateThreadList(Item.Key, lExeTime, lOtherTime) + ' cambio nomi file generati in old + Dim OldSvg As String = Path.ChangeExtension(sDdfPath, "svg") + Dim NewSvg As String = Path.GetDirectoryName(sDdfPath) & "\" & Path.GetFileNameWithoutExtension(sDdfPath) & "_old.svg" + Try + File.Delete(NewSvg) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "txt")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "log")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "nge")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "ddf")) + Catch ex As Exception + End Try + Try + File.Move(OldSvg, NewSvg) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "txt"), Path.ChangeExtension(NewSvg, "txt")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "log"), Path.ChangeExtension(NewSvg, "log")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "nge"), Path.ChangeExtension(NewSvg, "nge")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "ddf"), Path.ChangeExtension(NewSvg, "ddf")) + Catch ex As Exception + End Try + End If + stopWatch.Stop() + End If + End If + End If End If End If End While @@ -777,53 +782,53 @@ Public Class ProcMan Private Sub UpdateThreadList(tId As String, tExeCam As Long, tOther As Long) synchronizationContext.Post(New SendOrPostCallback( Sub(o) - If Not isUpdatingThreads Then - isUpdatingThreads = True - ProcStats.RecordData(m_MaxCamInstances, tExeCam, tOther) - ProcStats.RecordList.Enqueue((tId, tExeCam, tOther)) - 'Begin the update - LISTThreadStatus.BeginUpdate() - LISTThreadStatus.Items.Clear() + If Not isUpdatingThreads Then + isUpdatingThreads = True + ProcStats.RecordData(m_MaxCamInstances, tExeCam, tOther) + ProcStats.RecordList.Enqueue((tId, tExeCam, tOther)) + 'Begin the update + LISTThreadStatus.BeginUpdate() + LISTThreadStatus.Items.Clear() - ' compilo in base al tipo di stat richiesta - If (chkStatAggr.Checked) Then - ' statistiche di sintesi - Dim sorted = From pair In ProcStats.ExeCumSum - Order By pair.Key - For Each item In sorted - LISTThreadStatus.Items.Add( + ' compilo in base al tipo di stat richiesta + If (chkStatAggr.Checked) Then + ' statistiche di sintesi + Dim sorted = From pair In ProcStats.ExeCumSum + Order By pair.Key + For Each item In sorted + LISTThreadStatus.Items.Add( New ListViewItem(New String() {item.Key, $"{item.Value.NumRec} x {item.Value.ExeTime / item.Value.NumRec:N2} ms", $"{item.Value.NumRec} x {item.Value.OthTime / item.Value.NumRec:N2} ms" })) - Next - Else - ' formato log - Dim maxItems As Integer = 15 - While ProcStats.RecordList.Count > maxItems - Dim oldItem As (String, Long, Long) = ("", 0, 0) - ProcStats.RecordList.TryDequeue(oldItem) - End While + Next + Else + ' formato log + Dim maxItems As Integer = 15 + While ProcStats.RecordList.Count > maxItems + Dim oldItem As (String, Long, Long) = ("", 0, 0) + ProcStats.RecordList.TryDequeue(oldItem) + End While - For Each item As (String, Long, Long) In ProcStats.RecordList.Reverse - LISTThreadStatus.Items.Add(New ListViewItem(New String() { + For Each item As (String, Long, Long) In ProcStats.RecordList.Reverse + LISTThreadStatus.Items.Add(New ListViewItem(New String() { item.Item1, $"{item.Item2} ms", $"{item.Item3} ms" })) - Next + Next - End If + End If - 'End the update - LISTThreadStatus.EndUpdate() - isUpdatingThreads = False - End If + 'End the update + LISTThreadStatus.EndUpdate() + isUpdatingThreads = False + End If End Sub ), "") - End Sub + End Sub #End Region @@ -869,14 +874,14 @@ Public Class ProcMan #Region "Private Structs" - Private Structure MyProc + Private Structure MyProc #Region "Public Fields" - Public bEnable As Boolean - Public nBar As Integer - Public Proc As Process - Public Thread As Thread + Public bEnable As Boolean + Public nBar As Integer + Public Proc As Process + Public Thread As Thread #End Region