- aggiunto file di configurazione in console
- ripulito codice - aggiunto servizio
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
Imports System.IO
|
||||
Imports EgwMultiEngineManager.ExecProcessManager
|
||||
Imports EgwMultiEngineManager.ExecProcessManager
|
||||
Imports Newtonsoft.Json
|
||||
Imports Pipelines.Sockets.Unofficial.SocketConnection
|
||||
Imports StackExchange.Redis
|
||||
|
||||
Module MainModule
|
||||
|
||||
Private m_bDebug As Boolean = False
|
||||
Private Const Chn_EgwEngineInput As String = "EgwEngineInput"
|
||||
Private Const Chn_EgwEngineOutput As String = "EgwEngineOutput"
|
||||
|
||||
Private m_sDataRoot As String = String.Empty
|
||||
Friend ReadOnly Property sDataRoot As String
|
||||
Get
|
||||
Return m_sDataRoot
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private m_ExecProcessManager As ExecProcessManager
|
||||
|
||||
@@ -20,63 +26,47 @@ Module MainModule
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private InputChn As New RedisChannel("EgwEngineInput", RedisChannel.PatternMode.Auto)
|
||||
Private OutputChn As New RedisChannel("EgwEngineOutput", RedisChannel.PatternMode.Auto)
|
||||
Private OutputChn As New RedisChannel(Chn_EgwEngineOutput, RedisChannel.PatternMode.Auto)
|
||||
|
||||
Sub Main()
|
||||
If IsNothing(m_ExecProcessManager) Then
|
||||
Dim sCamExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe"
|
||||
Dim sMainLuaPath As String = "c:\Temp\EgwMultiEngineManager\Pipe.lua"
|
||||
m_ExecProcessManager = New ExecProcessManager(sCamExePath, sMainLuaPath, 1, ReturnModes.EVENT_)
|
||||
m_ExecProcessManager.StartExecutionThread()
|
||||
AddHandler m_ExecProcessManager.m_AnswerReceived, AddressOf ExecProcessManager_AnswerReceived
|
||||
End If
|
||||
Dim sConnection As String = "redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true"
|
||||
m_RedisManager = New RedisManager(sConnection, 1)
|
||||
m_RedisManager.SubscribeChannel("EgwEngineInput", AddressOf EgwEngineInputHandler)
|
||||
|
||||
'Dim sRettad As String = System.Console.ReadLine()
|
||||
|
||||
' funzionamento simulato
|
||||
If m_bDebug Then
|
||||
m_RedisManager.SubscribeChannel("EgwEngineOutput", AddressOf EgwEngineOutputHandler)
|
||||
Dim sRead As String = System.Console.ReadLine()
|
||||
While Not String.IsNullOrWhiteSpace(sRead)
|
||||
' passo dati per esecuzione
|
||||
Dim Args As New Dictionary(Of String, String)
|
||||
Dim ReadFile As String = File.ReadAllText("c:\Temp\EgwMultiEngineManager\AntaSingola.jwd")
|
||||
Args.Add("Mode", "1")
|
||||
Args.Add("Jwd", ReadFile)
|
||||
Dim InputValue As New RedisValue(New ProcessArgs(1, Args).sProcessArgs)
|
||||
|
||||
m_RedisManager.Subscriber.Publish(InputChn, InputValue)
|
||||
|
||||
sRead = System.Console.ReadLine()
|
||||
End While
|
||||
' Impostazione path radice per i dati
|
||||
m_sDataRoot = System.AppDomain.CurrentDomain.BaseDirectory
|
||||
IniFile.SetIniFile(m_sDataRoot & "\EgwMultiEngineManagerConsole.ini")
|
||||
Dim sCamExePath As String = ""
|
||||
GetMainPrivateProfileString(S_GENERAL, K_CAMEXEPATH, "", sCamExePath)
|
||||
System.Console.WriteLine("CAMExePath = " & sCamExePath)
|
||||
Dim sMainLuaPath As String = ""
|
||||
GetMainPrivateProfileString(S_GENERAL, K_MAINPIPELUA, "", sMainLuaPath)
|
||||
System.Console.WriteLine("MainPipeLua = " & sMainLuaPath)
|
||||
Dim nMaxCamInstances As Integer = GetMainPrivateProfileInt(S_GENERAL, K_MAXCAMINSTANCES, nMaxCamInstances)
|
||||
System.Console.WriteLine("MaxCAMInstances = " & nMaxCamInstances)
|
||||
m_ExecProcessManager = New ExecProcessManager(sCamExePath, sMainLuaPath, nMaxCamInstances, ReturnModes.EVENT_)
|
||||
m_ExecProcessManager.StartExecutionThread()
|
||||
AddHandler m_ExecProcessManager.m_AnswerReceived, AddressOf ExecProcessManager_AnswerReceived
|
||||
Dim sConnection As String = "localhost"
|
||||
GetMainPrivateProfileString(S_GENERAL, K_REDISCONNECTION, "", sConnection)
|
||||
System.Console.WriteLine("RedisConnection = " & sConnection)
|
||||
If String.IsNullOrWhiteSpace(sConnection) Then
|
||||
System.Console.WriteLine("Redis connection string is empty!")
|
||||
Else
|
||||
m_RedisManager = New RedisManager(sConnection)
|
||||
m_RedisManager.SubscribeChannel(Chn_EgwEngineInput, AddressOf EgwEngineInputHandler)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub ExecProcessManager_AnswerReceived(Answer As ProcessArgsResult)
|
||||
m_RedisManager.Subscriber.Publish(OutputChn, JsonConvert.SerializeObject(Answer))
|
||||
m_stopWatch.Stop()
|
||||
' Get the elapsed time as a TimeSpan value.
|
||||
Dim ts As TimeSpan = m_stopWatch.Elapsed
|
||||
|
||||
' Format and display the TimeSpan value.
|
||||
Dim elapsedTime As String = String.Format("{0:N3}", ts.TotalMilliseconds)
|
||||
System.Console.WriteLine("Risposto in " + elapsedTime)
|
||||
Dim elapsedTime As String = String.Format("{0:N3}", m_stopWatch.Elapsed.TotalMilliseconds)
|
||||
System.Console.WriteLine("Send answer in " & elapsedTime & "ms")
|
||||
End Sub
|
||||
|
||||
Private Sub EgwEngineInputHandler(RedisChannel As RedisChannel, RedisValue As RedisValue)
|
||||
'System.Console.WriteLine("Ricevuto valore " & RedisValue.ToString() & " dal canale " & RedisChannel.ToString())
|
||||
System.Console.WriteLine("Ricevuto valore dal canale " & RedisChannel.ToString())
|
||||
System.Console.WriteLine("Received value from channel " & RedisChannel.ToString())
|
||||
m_stopWatch.Restart()
|
||||
Dim Request As ProcessArgs = JsonConvert.DeserializeObject(Of ProcessArgs)(RedisValue)
|
||||
m_ExecProcessManager.ArgumentsEnqueue(Request)
|
||||
End Sub
|
||||
|
||||
Private Sub EgwEngineOutputHandler(RedisChannel As RedisChannel, RedisValue As RedisValue)
|
||||
System.Console.WriteLine("Ricevuto valore " & RedisValue.ToString() & " dal canale " & RedisChannel.ToString())
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
|
||||
Reference in New Issue
Block a user