- aggiunto log a ExecProcess

- commentato evento fine coda di esecuzione
- aggiunta gestione standarderror
- aggiunto flush dopo scrittura standardinput
- aggiunto Id su Question per facilitare debug
- aggiunto .Tray a file ini e log
- introdotta copia DataRoot se RemoteDebug in postbuild
This commit is contained in:
Emmanuele Sassi
2025-11-19 16:02:37 +01:00
parent 5942170618
commit bb16fbd02c
13 changed files with 83 additions and 36 deletions
@@ -26,6 +26,11 @@ Public Class ExecProcessManager
EVENT_ = 2
End Enum
Private Shared m_refEgtOutLog As Action(Of String)
Public Shared Sub SetEgtOutLog(value As Action(Of String))
m_refEgtOutLog = value
End Sub
Private m_StatisticsTimer As New DispatcherTimer(DispatcherPriority.Background)
Private disposedValue As Boolean
@@ -153,6 +158,12 @@ Public Class ExecProcessManager
#End Region ' CONSTRUCTORS
Friend Sub EgtOutLog(sMessage As String)
If Not IsNothing(m_refEgtOutLog) Then
m_refEgtOutLog(sMessage)
End If
End Sub
Public Function ArgumentsEnqueue(ProcessArgs As QuestionDTO) As Boolean
If ProcessArgs.nId <= 0 OrElse ProcessArgs.Args.Count = 0 Then Return False
SyncLock ArgumentsQueueLock
@@ -366,27 +377,28 @@ Public Class ExecProcessManager
Next
End If
' verifico se coda vuota e tutti i processi hanno finito
Dim nQueueArgs As Integer = 0
SyncLock ArgumentsQueueLock
nQueueArgs = m_ArgumentsQueue.Count
End SyncLock
If nQueueArgs = 0 Then
Dim bProcessWaiting As Boolean = False
For Each ThreadData In m_ThreadDataList
If ThreadData.ProcessStatus = ThreadData.ProcessStatuses.WAITINGANSWER OrElse ThreadData.ProcessStatus = ThreadData.ProcessStatuses.ANSWERRECEIVED Then
bProcessWaiting = True
Exit For
End If
Next
If Not bProcessWaiting Then
' creo thread per lanciare evento asincrono di fine calcolo
Dim AllArgsProcessedThread = New Thread(Sub()
RaiseEvent m_AllArgsProcessed()
End Sub)
AllArgsProcessedThread.SetApartmentState(ApartmentState.STA)
AllArgsProcessedThread.Start()
End If
End If
'Dim nQueueArgs As Integer = 0
'SyncLock ArgumentsQueueLock
' nQueueArgs = m_ArgumentsQueue.Count
'End SyncLock
'If nQueueArgs = 0 Then
' Dim bProcessWaiting As Boolean = False
' For Each ThreadData In m_ThreadDataList
' Dim CurrThreadData = ThreadData
' If Not IsNothing(CurrThreadData) OrElse CurrThreadData.ProcessStatus = ThreadData.ProcessStatuses.WAITINGANSWER OrElse CurrThreadData.ProcessStatus = ThreadData.ProcessStatuses.ANSWERRECEIVED Then
' bProcessWaiting = True
' Exit For
' End If
' Next
' If Not bProcessWaiting Then
' ' creo thread per lanciare evento asincrono di fine calcolo
' Dim AllArgsProcessedThread = New Thread(Sub()
' RaiseEvent m_AllArgsProcessed()
' End Sub)
' AllArgsProcessedThread.SetApartmentState(ApartmentState.STA)
' AllArgsProcessedThread.Start()
' End If
'End If
If Not m_bFirstStatistics Then
m_bFirstStatistics = True
RaiseEvent m_Statistics(New Statistics(nRunningProcesses, nCalculatingProcesses, 0, 0, 0, 0))
@@ -404,13 +416,16 @@ Public Class ExecProcessManager
Dim ProcInfo As New ProcessStartInfo(m_sProcessFileName, m_nGroupId.ToString() & ThreadIndex.ToString() & " " & m_sProcessArguments)
ProcInfo.RedirectStandardInput = True
ProcInfo.RedirectStandardOutput = True
ProcInfo.RedirectStandardError = True
ProcInfo.UseShellExecute = False
ProcInfo.CreateNoWindow = True
Dim Proc = Process.Start(ProcInfo)
AddHandler Proc.OutputDataReceived, AddressOf Thread_OutputDataReceived
AddHandler Proc.ErrorDataReceived, AddressOf Thread_ErrorDataReceived
If Not (Proc Is Nothing) Then
Proc.BeginOutputReadLine()
Proc.BeginErrorReadLine()
MyThreadData.SetProcess(Proc)
MyThreadData.SetProcessStatus(ThreadData.ProcessStatuses.NULL)
' ciclo per leggere coda ed eseguire
@@ -430,6 +445,7 @@ Public Class ExecProcessManager
MyThreadData.SetCurrRequest(NextProcessArgs)
NextProcessArgs.SetThreadIndex(ThreadIndex)
Proc.StandardInput.WriteLine("#8477271#" & NextProcessArgs.sProcessArgs & "#8477271#")
Proc.StandardInput.Flush()
MyThreadData.SetProcessStatus(ThreadData.ProcessStatuses.WAITINGANSWER)
End If
Case ThreadData.ProcessStatuses.WAITINGANSWER
@@ -451,6 +467,7 @@ Public Class ExecProcessManager
End While
If m_bStopProcess Then
Proc.StandardInput.WriteLine("quit")
Proc.StandardInput.Flush()
End If
End If
MyThreadData.SetProcess(Nothing)
@@ -463,9 +480,15 @@ Public Class ExecProcessManager
Dim Result As AnswerDTO = JsonConvert.DeserializeObject(Of AnswerDTO)(sResult)
m_ThreadDataList(Result.nThreadIndex).SetProcResult(Result)
m_ThreadDataList(Result.nThreadIndex).SetProcessStatus(ThreadData.ProcessStatuses.ANSWERRECEIVED)
Else
EgtOutLog("Riga su StandardOutput non riconosciuta " & e.Data)
End If
End Sub
Private Sub Thread_ErrorDataReceived(sender As Object, e As DataReceivedEventArgs)
EgtOutLog("Errore su StandardError! " & e.Data)
End Sub
Protected Overridable Sub Dispose(disposing As Boolean)
If Not disposedValue Then
If disposing Then
@@ -28,5 +28,5 @@ Imports System.Runtime.InteropServices
' Revision
'
<Assembly: AssemblyVersion("2.7.10.1")>
<Assembly: AssemblyFileVersion("2.7.10.1")>
<Assembly: AssemblyVersion("2.7.11.1")>
<Assembly: AssemblyFileVersion("2.7.11.1")>
@@ -5,10 +5,10 @@
<TargetFramework>netstandard2.0</TargetFramework>
<ApplicationManifest>My Project\app.manifest</ApplicationManifest>
<Copyright>Copyright © 2020-2025 by Egalware s.r.l.</Copyright>
<AssemblyVersion>2.7.10.1</AssemblyVersion>
<FileVersion>2.7.10.1</FileVersion>
<AssemblyVersion>2.7.11.1</AssemblyVersion>
<FileVersion>2.7.11.1</FileVersion>
<Company>Egalware s.r.l.</Company>
<Version>2.7.10.1</Version>
<Version>2.7.11.1</Version>
<Authors>Emmanuele Sassi</Authors>
<Description>Specifiche comunicazione con EgwMultiEngineManager</Description>
</PropertyGroup>
@@ -18,6 +18,9 @@ Public Class QuestionDTO
Return m_nId
End Get
End Property
Public Sub SetId(nId As Integer)
m_nId = nId
End Sub
Private m_ExecEnvironment As EXECENVIRONMENTS
Public ReadOnly Property ExecEnvironment As EXECENVIRONMENTS
@@ -19,7 +19,7 @@ Public Module ConstGen
Public Const K_DATAROOT As String = "DataRoot"
' File di log generale
Public Const GENLOG_FILE_NAME As String = "EgwMultiEngineManagerLog#.txt"
Public Const GENLOG_FILE_NAME As String = "EgwMultiEngineManager.TrayLog#.txt"
' Sottodirettorio di configurazione
Public Const CONF_DIR As String = "Config"
@@ -12,7 +12,7 @@
'----------------------------------------------------------------------------
Module ConstIni
Public Const INI_FILE_NAME As String = "EgwMultiEngineManagerTray.ini"
Public Const INI_FILE_NAME As String = "EgwMultiEngineManager.Tray.ini"
Public Const S_GENERAL As String = "General"
Public Const K_CAMEXEPATH As String = "CAMExePath"
@@ -66,8 +66,8 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="EgtDotNETBasis">
<HintPath>..\..\..\EgtProg\DllD32\EgtDotNETBasis.dll</HintPath>
<Reference Include="EgtDotNETBasis, Version=2.7.11.20, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EgtDotNETBasis.2.7.11.20\lib\EgtDotNETBasis.dll</HintPath>
</Reference>
<Reference Include="EgwWPFBaseLib">
<HintPath>..\..\EgwWPFBaseLib\EgwWPFBaseLib\bin\Debug\EgwWPFBaseLib.dll</HintPath>
@@ -230,8 +230,10 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\build\Microsoft.Extensions.Logging.Abstractions.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\build\Microsoft.Extensions.Logging.Abstractions.targets'))" />
<Error Condition="!Exists('..\packages\EgtDotNETBasis.2.7.11.20\build\EgtDotNETBasis.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EgtDotNETBasis.2.7.11.20\build\EgtDotNETBasis.targets'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File $(ProjectDir)\post-build.ps1 $(ConfigurationName) $(TargetDir)</PostBuildEvent>
</PropertyGroup>
<Import Project="..\packages\EgtDotNETBasis.2.7.11.20\build\EgtDotNETBasis.targets" Condition="Exists('..\packages\EgtDotNETBasis.2.7.11.20\build\EgtDotNETBasis.targets')" />
</Project>
@@ -127,6 +127,9 @@ Public Class MainWindowVM
RaiseEvent QuitApplication()
Return
End If
' imposto log per ExecProcessManager
ExecProcessManager.SetEgtOutLog(AddressOf EgtOutLog)
' carico ambienti
Dim nGroupIndex As Integer = 1
Dim sEnvironment As String = ""
Dim sPipeLuaFile As String = ""
@@ -52,5 +52,5 @@ Imports System.Windows
' Revision
'
<Assembly: AssemblyVersion("2.7.10.1")>
<Assembly: AssemblyFileVersion("2.7.10.1")>
<Assembly: AssemblyVersion("2.7.11.1")>
<Assembly: AssemblyFileVersion("2.7.11.1")>
@@ -19,6 +19,14 @@ Public Class ExecEnvironmentManager
Private disposedValue As Boolean
Private m_nRequestCounter As Integer = 0
Private ReadOnly Property nRequestCounter As Integer
Get
m_nRequestCounter += 1
Return m_nRequestCounter
End Get
End Property
Private m_ExecEnvironment As EXECENVIRONMENTS = EXECENVIRONMENTS.NULL
Friend ReadOnly Property ExecEnvironment As EXECENVIRONMENTS
Get
@@ -98,8 +106,9 @@ Public Class ExecEnvironmentManager
Private Sub EgwEngineInputHandler(RedisChannel As RedisChannel, RedisValue As RedisValue)
m_stopWatch.Restart()
Dim Request As QuestionDTO = JsonConvert.DeserializeObject(Of QuestionDTO)(RedisValue)
EgtOutLog(DateTime.Now.ToString("HH:mm:ss.fff") & " Environment=" & m_ExecEnvironment & " Channel=" & RedisChannel.ToString() & " Question Id=" & Request.nId)
If Request.ExecEnvironment = m_ExecEnvironment Then
Request.SetId(nRequestCounter)
EgtOutLog(DateTime.Now.ToString("HH:mm:ss.fff") & " Environment=" & m_ExecEnvironment & " Channel=" & RedisChannel.ToString() & " Question Id=" & Request.nId)
m_ExecProcessManager.ArgumentsEnqueue(Request)
End If
End Sub
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EgtDotNETBasis" version="2.7.11.20" targetFramework="net472" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="6.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="6.0.0" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.4" targetFramework="net472" />
+6 -3
View File
@@ -8,8 +8,8 @@ Write-Host "Inizio processing After Build: configurazione $config , directory $d
switch ($config) {
"Release" {
Write-Host "Release processing..."
Get-ChildItem -Path "$directory" -Recurse -Include *.pdb, *.xml | Remove-Item -Force
Get-ChildItem -Path "$directory\lib" -Recurse -Include *.pdb | Remove-Item -Force
#Get-ChildItem -Path "$directory" -Recurse -Include *.pdb, *.xml | Remove-Item -Force
#Get-ChildItem -Path "$directory\lib" -Recurse -Include *.pdb | Remove-Item -Force
Write-Host "Release: eliminato pdb + xml!!!"
}
"Debug" {
@@ -17,7 +17,10 @@ switch ($config) {
}
"RemoteDebug" {
Write-Host "RemoteDebug processing, effettuo copia script verso server remoto (ROBOCOPY)"
# copio DataRoot
$datarootdest = Join-Path $directory "DataRoot.ini"
Copy-Item "c:\EgtDev\EgwMultiEngineManager\ExtData\Tray.DataRoot.ini" $datarootdest -Force
# Uncomment the appropriate ROBOCOPY line(s) as needed
# Write-Host "Debug remoto: effettuo robocopy sync (verificare remote per cliente)"
ROBOCOPY "$directory" "\\w11-calc-01\c$\EgtProg\EgwMultiEngineManager" /MIR
+3
View File
@@ -0,0 +1,3 @@
; Commento per evitare BOM con UTF-8
[Data]
DataRoot=C:\EgtData\EgwMultiEngineManager.Tray