-- -- EEEEEEEEEE GGGGGG TTTTTTTTTTTTTT -- EEEEEEEEEE GGGGGGGGGG TTTTTTTTTTTTTT -- EEEE GGGG GGGG TTTT -- EEEE GGGG TTTT -- EEEEEEE GGGG GGGGGGG TTTT -- EEEEEEE GGGG GGGGGGG TTTT -- EEEE GGGG GGGG TTTT -- EEEE GGGG GGGG TTTT -- EEEEEEEEEE GGGGGGGGGG TTTT -- EEEEEEEEEE GGGGGG TTTT -- -- by Egalware s.r.l. -- Door manager by Egalware s.r.l. 2023/05/09 require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- modalita' di chiamata QUESTION_MODES = { NULL = 0, PREVIEW = 1, BOM = 2, HARDWARE = 3, CONFIG = 4, } QUESTION_CONFIG_SUBMODES = { NULL = 0, PROFILELIST = 1, } QUESTION_HARDWARE_SUBMODES = { NULL = 0, LIST = 1, CALCHARDWARE = 2, HARDWAREOPTION = 3, } -- produttore MANUFACTURERS = { NULL = 0, AGB = 1, MAICO = 2, ROTO = 3, } _G.package.loaded.JSON = nil local JSON = require( 'JSON') local sIniFilePath = EgtGetIniFile() local sBaseDir = EgtGetStringFromIni( 'Window', 'BaseDir', '', sIniFilePath) EgtAddToPackagePath( sBaseDir .. '\\Designing\\?.lua') --EgtAddToPackagePath( sBaseDir .. '\\Machining\\?.lua') _G.package.loaded.WinProject = nil local WinProject = require( 'WinProject') local function Calc_Preview( QuestionArgs) -- leggo argomenti passati local sJwd = QuestionArgs["Jwd"] if sJwd and #sJwd > 0 then -- imposto cartella profili local sProfileDir = '' sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath) if sProfileDir and #sProfileDir > 0 then WDG.PROFILEPATH = sProfileDir SetProfilePath() else local sErrorMsg = 'Errore! Cartella dei profili non trovata!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end -- carico jwd WDG.JWD = sJwd WinManage_LoadJwd() local AreaId = WDG.AREAID -- imposto opzioni visualizzazione WDG.VALUE = false _G.WinCalculate_SetCalcSolid() WDG.VALUE = false WinCalculate_SetSimplifiedSolid() WDG.VALUE = true WinCalculate_SetCalcPreview() -- creazione pezzi WDG.FRAMEID = AreaId WinCalculate_CreatePartFromArea() -- calcolo hardware --WDG.FRAMEID = AreaId WDG.CALC_HARDWARELIST=false WDG.CALC_POSITIONLIST=false WDG.CALC_MACHININGLIST=false WDG.CALC_OPTIONLIST=false --WinCalculate_AddHardware() -- creo file svg WDG.GROUPID = EgtGetFirstNameInGroup( GDB_ID.ROOT, WIN_PREVIEW) WDG.FILE = 'C:\\Temp\\TestSvgManager.svg' WinGetSvg() -- leggo il file local SouFh = io.open( WDG.FILE, "rb") local content if SouFh then content = SouFh:read( "*all") --EgtOutBox( 'Error opening ' .. sFilePath, 'ReadFromFile', 'ERROR') SouFh:close() --return false end -- do risultato return 1, { Svg = content} else local sErrorMsg = 'Errore! Jwd non trovato!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end end local function Calc_BOM( QuestionArgs) -- leggo argomenti passati local sJwd = QuestionArgs["Jwd"] if sJwd and #sJwd > 0 then -- imposto cartella profili local sProfileDir = '' sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath) if sProfileDir and #sProfileDir > 0 then WDG.PROFILEPATH = sProfileDir SetProfilePath() else local sErrorMsg = 'Errore! Cartella dei profili non trovata!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end -- carico jwd WDG.JWD = sJwd WinManage_LoadJwd() local AreaId = WDG.AREAID -- imposto opzioni visualizzazione WDG.VALUE = false _G.WinCalculate_SetCalcSolid() WDG.VALUE = false WinCalculate_SetSimplifiedSolid() WDG.VALUE = true WinCalculate_SetCalcPreview() -- creazione pezzi WDG.FRAMEID = AreaId WinCalculate_CreatePartFromArea() -- calcolo hardware WDG.FRAMEID = AreaId WDG.CALC_MACHINING=false WDG.CALC_HARDWARELIST=true WDG.CALC_POSITIONLIST=false WDG.CALC_OPTIONLIST=false WinCalculate_AddHardware() ---- creo file svg --WDG.GROUPID = EgtGetFirstNameInGroup( GDB_ID.ROOT, WIN_PREVIEW) --WDG.FILE = 'C:\\Temp\\TestSvgManager.svg' --WinGetSvg() ---- leggo il file --local SouFh = io.open( WDG.FILE, "rb") --local content --if SouFh then -- content = SouFh:read( "*all") -- --EgtOutBox( 'Error opening ' .. sFilePath, 'ReadFromFile', 'ERROR') -- SouFh:close() -- --return false --end WinGetSectionsTotalLenghts() WinGetGlassesList() -- do risultato local BOM = {} for Index = 1, #WDG.SECTIONS_LENGTHS do table.insert( BOM, { ClassCode = 'WindowTrunk', ItemCode = 'Pine-' .. WDG.SECTIONS_LENGTHS[Index].W .. 'x' .. WDG.SECTIONS_LENGTHS[Index].H, ItemQty = #WDG.SECTIONS_LENGTHS[Index].L, DescriptionCode = '', Qty = WDG.SECTIONS_LENGTHS[Index].TotL / 1000}) end for Index = 1, #WDG.GLASSES_LIST do table.insert( BOM, { ClassCode = 'WindowGlass', ItemCode = '6/14argon/6-' .. EgtIf( WDG.GLASSES_LIST[Index].Rect, 'Rect-', 'Special-') .. WDG.GLASSES_LIST[Index].T, ItemQty = 1, DescriptionCode = WDG.GLASSES_LIST[Index].W .. 'x' .. WDG.GLASSES_LIST[Index].L, Qty = WDG.GLASSES_LIST[Index].W * WDG.GLASSES_LIST[Index].L / 1000000}) end if WDG.HARDWAREKIT_LIST then for SashIndex = 1, #WDG.HARDWAREKIT_LIST do for HardwareIndex = 1, #WDG.HARDWAREKIT_LIST[SashIndex] do local Hardware = WDG.HARDWAREKIT_LIST[SashIndex][HardwareIndex] table.insert( BOM, { ClassCode = 'WindowHardware', ItemCode = '' .. Hardware['ArtCode'] .. '-' .. Hardware['Description'], ItemQty = 1, DescriptionCode = '', Price = Hardware['Price'], Qty = Hardware['Qty']}) end end end local JsonBOM = JSON:encode( BOM) return 1, { BOM = JsonBOM} else local sErrorMsg = 'Errore! Jwd non trovato!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end end local function Calc_Hardware( QuestionArgs, sReadLine) local nManufacturer = tonumber( QuestionArgs["Manufacturer"]) if nManufacturer == MANUFACTURERS.AGB then -- Canali local QuestionChannel = "EgwHardwareQuestion" local AnswerChannel = "EgwHardwareAnswer" .. os.time() local Question = JSON:decode( sReadLine) Question['Args'].OutputChannel = AnswerChannel local JsonQuestion = JSON:encode( Question) local bOk = EgtRedisAsyncPublish( QuestionChannel, JsonQuestion) local AnswerArgs if bOk then EgtOutLog('Messaggio Redis pubblicato:' .. QuestionChannel .. ' ' .. JsonQuestion) local bOk, Answer = EgtRedisAsyncSubscribeOneMessage( AnswerChannel, 10000) if bOk then EgtOutLog('Risposta Redis ricevuta:' .. Answer) local JsonAnswer = JSON:decode( Answer) AnswerArgs = JsonAnswer['Args'] AnswerArgs.OutputChannel = nil else local sErrorMsg = 'Errore! Risposta dal canale calcolo hardware Agb non arrivata!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end else local sErrorMsg = 'Errore! Pubblicazione sul canale calcolo hardware Agb fallita!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end return 1, AnswerArgs end end local function Calc_ProfileList() -- leggo cartella profili local sProfileDir = '' sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath) if sProfileDir and #sProfileDir > 0 then local Profiles = EgtFindAllFiles( sProfileDir) local ProfilesBOM = JSON:encode( Profiles) return 1, { ProfileList = ProfilesBOM} else local sErrorMsg = 'Errore! Cartella dei profili non trovata!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end end local function Calc_HardwareOptions( QuestionArgs, sReadLine) local sJwd = QuestionArgs["Jwd"] local nManufacturer = tonumber( QuestionArgs["Manufacturer"]) if sJwd and #sJwd > 0 then if nManufacturer and nManufacturer == MANUFACTURERS.AGB then -- imposto cartella profili local sProfileDir = '' sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath) if sProfileDir and #sProfileDir > 0 then WDG.PROFILEPATH = sProfileDir SetProfilePath() else local sErrorMsg = 'Errore! Cartella dei profili non trovata!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end -- carico jwd WDG.JWD = sJwd WinManage_LoadJwd() local AreaId = WDG.AREAID -- imposto opzioni visualizzazione WDG.VALUE = false _G.WinCalculate_SetCalcSolid() WDG.VALUE = false WinCalculate_SetSimplifiedSolid() WDG.VALUE = true WinCalculate_SetCalcPreview() -- creazione pezzi WDG.FRAMEID = AreaId WinCalculate_CreatePartFromArea() end end ---- leggo argomenti passati --local sJwd = QuestionArgs["Jwd"] --if sJwd and #sJwd > 0 then -- local sNow = os.date( '_%Y_%m_%d_%H_%M_%S', os.time()) -- local sInputFile = 'a:\\InputBatch\\Input' .. sNow .. '.txt' -- local sAGBOutputKitFile = 'C:\\AGB3000NG\\OutputBatch\\Output' .. sNow .. '.txt' -- local sOutputKitFile = 'a:\\OutputBatch\\Output' .. sNow .. '.txt' -- -- Apro file Input in scrittura -- local fhInput = io.open( sInputFile, 'w') -- if not fhInput then -- EgtOutLog( 'Error opening file ' .. sInputFile) -- return false -- end -- -- local sText = 'OUTPUTKIT=' .. sAGBOutputKitFile .. '\n' .. -- 'DATAREQUEST=SE\n' .. -- 'RUN' -- -- -- Scrittura nuova linea -- fhInput:write( sText .. '\n') -- -- -- Chiudo file -- fhInput:close() -- -- -- attendo scrittura output -- local nWait = 0 -- while not EgtExistsFile( sOutputKitFile) and nWait < 20 do -- nWait = nWait + 1 -- EgtPause( 500, true) -- end -- -- EgtPause( 500, true) -- -- local OutputKit = {} -- -- Apro file OutputKit in lettura -- local fhOutputKit = io.open( sOutputKitFile, 'r') -- if not fhOutputKit then -- EgtOutLog( 'Error opening file ' .. sOutputKitFile) -- return false -- end -- local nKitLineIndex = 1 -- for sLine in fhOutputKit:lines('l') do -- local KitParams = EgtSplitString( sLine, ';') -- local DescriptionSplit = EgtSplitString( KitParams[4], '_') -- OutputKit[nKitLineIndex] = { Id = KitParams[3], FamilyName = DescriptionSplit[1], Description = KitParams[4], OpeningType = KitParams[5], Shape = KitParams[6], SashQty = tonumber(KitParams[7]), SashPosition = tonumber(KitParams[8])} -- nKitLineIndex = nKitLineIndex + 1 -- end -- -- Chiudo file OutputKit in lettura -- fhOutputKit:close() -- -- local JsonOutputKit = JSON:encode( OutputKit) -- return 1, { HardwareModelList = JsonOutputKit} --else -- local sErrorMsg = 'Errore! Jwd non trovato!' -- EgtOutLog(sErrorMsg) -- return 0, { Error = sErrorMsg} --end end local nErr = 999 local nNilCount = 0 local bRun = true --local sRedisConnection = ENG.Param2 --local RedisConnectionParamList = EgtSplitString( sRedisConnection, ',') --local sRedisAddressPort = RedisConnectionParamList[1] --sRedisAddressPort, _ = EgtReplaceString( sRedisAddressPort, 'server=', '') --local RedisAddressPortLi st = EgtSplitString( sRedisAddressPort, ':') --local nDefaultDatabase = '' --for nIndex = 2, #RedisConnectionParamList do -- local sParam = '' -- local nParam = 0 -- sParam, nParam = EgtReplaceString( RedisConnectionParamList[nIndex], 'DefaultDatabase=', '') -- if nParam == 1 then -- nDefaultDatabase = tonumber( EgtTrim( sParam)) -- end --end local bRedisConnect = EgtRedisAsyncConnect( ENG.Param2) --local bRedisConnect = EgtRedisAsyncConnect( 'redis02.ufficio:6378, serviceName=devel, DefaultDatabase=0, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true') if not bRedisConnect then EgtOutLog('Errore! Impossibile connettersi con il server Redis dal Lua!') end local size = 2^13 -- good buffer size (8K) while bRun do local sReadLine = io.stdin:read( 'l') EgtOutLog( 'Letta riga da stdin') if sReadLine then if sReadLine == 'quit' then EgtOutLog( 'Chiusura processo') break end if sReadLine ~= '' and sReadLine:find( '^#8477271#') and sReadLine:find( '#8477271#$') then EgtOutLog( 'Lettura istruzione valida') sReadLine = string.sub( sReadLine, 10, #sReadLine - 9) local Question = JSON:decode( sReadLine) local nThreadIndex = -1 local nId = -1 local ExecEnvironment = -1 local nResult = 0 local AnswerArgs = {} if Question and Question.nThreadIndex and Question.nId and Question.Args then nThreadIndex = tonumber( Question["nThreadIndex"]) nId = tonumber( Question["nId"]) ExecEnvironment = tonumber( Question["ExecEnvironment"]) local QuestionArgs = Question["Args"] if QuestionArgs and QuestionArgs.Mode and QuestionArgs.UID then local sUid = QuestionArgs["UID"] local nMode = tonumber( QuestionArgs["Mode"]) _G.WDG = {} -- esecuzione della corretta modilita' EgtOutLog('Esecuzione calcolo') local Result = {} if nMode == QUESTION_MODES.PREVIEW then nResult, AnswerArgs = Calc_Preview( QuestionArgs) elseif nMode == QUESTION_MODES.BOM then nResult, AnswerArgs = Calc_BOM( QuestionArgs) elseif nMode == QUESTION_MODES.HARDWARE then nResult, AnswerArgs = Calc_Hardware( QuestionArgs, sReadLine) elseif nMode == QUESTION_MODES.CONFIG then if QuestionArgs.SubMode then local nSubMode = tonumber( QuestionArgs["SubMode"]) if nSubMode == QUESTION_CONFIG_SUBMODES.PROFILELIST then nResult, AnswerArgs = Calc_ProfileList() else nResult = 0 local sErrorMsg = 'Errore! Valore di SubMode errato!' AnswerArgs = { Error = sErrorMsg} EgtOutLog( sErrorMsg) end else nResult = 0 local sErrorMsg = 'Errore! Domanda senza SubMode che é obbligatorio!' AnswerArgs = { Error = sErrorMsg} EgtOutLog( sErrorMsg) end end AnswerArgs.UID = sUid else nResult = 0 local sErrorMsg = 'Errore! Domanda senza argomenti o senza UID o Mode che sono obbligatori!' AnswerArgs = { Error = sErrorMsg} EgtOutLog( sErrorMsg) end else nResult = 0 local sErrorMsg = 'Errore! Formato domanda non riconosciuto o senza nThreadIndex, nId o Args!' AnswerArgs = { Error = sErrorMsg} EgtOutLog( sErrorMsg) end -- do risultato local Result = { nThreadIndex = nThreadIndex, nId = nId, ExecEnvironment = ExecEnvironment, nResult = nResult, Args = AnswerArgs} -- invio risposta EgtOutLog( 'Invio risposta') local JsonResult = JSON:encode( Result) io.stdout:write( "#8376261#" .. JsonResult .. "#8376261#" .. '\n') io.stdout:flush() EgtOutLog( 'Risposta inviata') EgtNewFile() end else if nNilCount >= 20 then bRun = false EgtOutLog( 'Errore! Lettura da stdin fallita!') end nNilCount = nNilCount + 1 EgtPause( 100, true) end end EgtRedisAsyncDisconnect()