@Echo off
 REM ===========================================================================
 REM BasisSkript für PLM Performance Analyse V3
 REM (c) J.Feuerstein/S.Gueth 14.12.2015
 rem
 REM Aenderungs Info:
 REM User    Date/Time (Alt+D)  Infotext:
 REM J.Fes   25.05.2022 Ersterstellung
 REM ===========================================================================


 Echo **************************************************************************
 Echo * Excuting PLMPerformace Analyse V4 Script                               *
 Echo * Version: 25.05.2022 addPLM GmbH (c)                                    *
 Echo **************************************************************************

setlocal
 REM -- #Step: Farbe setzen IsIdel
 call :ColorSet IsIdel

REM  call Echo "--- #Step: Set Up Base ---------------------------------------------------"
REM  if exist "%TCPrompt_Custom_DPNE%" Call "%TCPrompt_Custom_DPNE%"

 if not defined NxPLMPerfClient_CustomSetEnv_cmd set NxPLMPerfClient_CustomSetEnv_cmd=%CmdCurRoot_DP%\NxPLMPerfClient_CustomSetEnv.cmd

 call Echo "--- #Step: ExecutePLMPerfViaJournal --------------------------------------"


 if not defined JobTemp_TP set JobTemp_TP=JobTemp
 call :ExecutePLMPerfViaUgrafAndJournal "%CmdCurRoot_DP%\%JobTemp_TP%"

 endlocal& set PrgExitCode=%PrgExitCode%
goto :end


rem ============================================================================
:ExecutePLMPerfViaUgrafAndJournal
 rem #Doc: Main Function to run PLMPerf vie NX Journal
 rem #Doc get File Params
 set temp=%~1
 if not exist "%temp%" md "%temp%"

 set tmp=%temp%
 set HOME=%temp%

 REM -- set Custom.Environ
 if exist "%NxPLMPerfClient_CustomSetEnv_cmd%" call "%NxPLMPerfClient_CustomSetEnv_cmd%"

 if "%fccCache_Clear_DO%" neq "YES" goto :fccCache_Clear_DO_JumpOver
   setlocal
   set fccCache_Clear_log_DPNE=%temp%\zzfccCache_Clear_log.txt
   Call Echo "do fccCache clear on............: \\%ComputerName%"
   call Echo "fccCache_Clear_log_DPNE.........: %fccCache_Clear_log_DPNE%"
   REM call fccstat -restart
   call fccstat -status>>"%fccCache_Clear_log_DPNE%"
   call fccstat -clear>>"%fccCache_Clear_log_DPNE%"
   call fccstat -purge>>"%fccCache_Clear_log_DPNE%"
   call fccstat -status>>"%fccCache_Clear_log_DPNE%"

   if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
    REM set toRun=%toRun% -verbose -pauseOnEnd
    call Echo "---------------------------------------------------------------------------"
    call Echo "#Debug..........................: fccCache_Clear done"
    pause
   :JumbOverDebug
   endlocal
:fccCache_Clear_DO_JumpOver

:SetPmon
 set PMon_exeL_DPNE=%BinL_DP%\JFProcessMonitor.exe
 set PMon_log_DPNE=%temp%\zzPLMPerf_%JobMgr_PLMPerfJobNo%_PMon_log.xml
	set toMon=%PMon_exeL_DPNE%
 rem  - wartet fuer 5 sec ob ein neuer process startet
 set toMon=%toMon% --waitForProcess 15000
 rem set toMon=%toMon% --parentProcessId 0
 set toMon=%toMon% --processName ugraf
	set toMon=%toMon% --killChildProcesses
 set toMon=%toMon% --tailTextFile "%temp%\%username%*.syslog"
 set toMon=%toMon% --titlePrefix "JobMon:[%JobName%][Start:%Date%/%time:~0,8%]"
	set toMon=%toMon% --saveResultsTo "%PMon_log_DPNE%"
 set toMon=%toMon% --runtimeLimitSeconds 600
 set toMon=%toMon% --fileLastWriteTime "%temp%\*.*;120"
 Call Echo "CB.P.Mon use setting............: 31.05.2022"

:Excute
 call :ColorSet IsExecuting
 Echo.
REM  Echo %titleTxt%
 call Echo "----------------------------------------------------------------------------"
 Call Echo "Journal Job Settings:"
 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Call Echo "JobName.........................: %JobName%"
 Call Echo "Computer........................: %ComputerName%"
 Call Echo "JobDir..........................: %temp%"
 Call Echo "TcSide..........................: %TcSiteId%"
 Call Echo "TcUser..........................: %JobMgr_TcUser%"
 Call Echo "FMS_HOME........................: %FMS_HOME%"
 Call Echo "TC_ROOT.........................: %TC_ROOT%"
 Call Echo "TC_DATA.........................: %TC_DATA%"
 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Call Echo "UGII_LOAD_OPTIONS...............: %UGII_LOAD_OPTIONS%"
 Call Echo "UGII_SITE_DIR...................: %UGII_SITE_DIR%"
 Call Echo "UGII_LOCAL_USER_DEF.............: %UGII_LOCAL_USER_DEFAULTS%"
 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Call Echo "fccCache_Clear_DO...............: %fccCache_Clear_DO%"
 rem Call Echo "PLMPerf ImportConfigName........: %ImportConfigName%"
 Call Echo "NXJournalMaxDuration_min........: %NXJournalMaxDuration_min% (min)"

 cd /d "%temp%"

 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "NxDataProcessing_2013_09"
 set toRun=%toRun% -SubAction "NXJournalExecute"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -ShellExecMaxDuration_min %NXJournalMaxDuration_min%
 set toRun=%toRun% -NXJournalExcuteViaUgrafExe "YES"
 set toRun=%toRun% -NXMacroTemplate_DPNE   "%NXMacroTemplate_DPNE%"
 set toRun=%toRun% -NXJournalTemplate_DPNE "%NXJournalTemplate_DPNE%"
 set toRun=%toRun% -JobParaDoPrint
 set toRun=%toRun% -JobTemp_DP "%temp%"
 set toRun=%toRun% -NXCB_UGII_LOAD_OPTIONS_NE "%UGII_LOAD_OPTIONS_NE%"

 if "%TC_ROOT%" equ "" goto :NextStep
   set toRun=%toRun% -u "%JobMgr_TcUser%" -p "%JobMgr_TcPw%"
   if defined JobMgr_TcGroup set toRun=%toRun% -g "%JobMgr_TcGroup%"
:NextStep

REM  if "%UGII_UGMGR_HTTP_URL%" equ "" goto :NextStep
REM    set toRun=%toRun% -u "%JobMgr_TcUser%" -p "%JobMgr_TcPw%"
REM    if defined JobMgr_TcGroup set toRun=%toRun% -g "%JobMgr_TcGroup%"
REM :NextStep

 set toRun=%toRun% -JobData1ToProcessDoPrint
 set toRun=%toRun% -JobData2ResultsDoPrint

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
  REM set toRun=%toRun% -verbose -pauseOnEnd
  set toRunForPrint=%toRun:"='%
  call Echo "---------------------------------------------------------------------------"
  call Echo "#Debug..........................: BeforeProcess"
  call Echo "#toRun..........................: %toRunForPrint%"
  pause
 :JumbOverDebug

 set >>"%temp%\zzEnvBeforeProcess.txt"
REM  set PMon_Use=ON
REM  if /I "%PMon_Use%" equ "ON" start "PMon Job:[%JobName%][%TcSiteId%]" %toMon%

 call %toRun%
 set PrgExitCode=%errorlevel%

 call Echo "--- #Res.: PrgExitCode.: [%PrgExitCode%] ---------------------------------------------"
 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
  call Echo "---------------------------------------------------------------------------"
  call Echo "#Debug..........................: "
  call Echo "#PrgExitCode....................: %PrgExitCode%"
  pause
 :JumbOverDebug




call Echo "--- #Evaluate PLMPerf Result -----------------------------------------------------------------"

 set ImportConfigXml_DPNE=%PLMPerf_Custom_DP%\ImportConfig.x*
 set ImportConfigXmlL_DPNE=%temp%\ImportConfig.xml
 copy "%ImportConfigXml_DPNE%" "%temp%\*.*"
 set ReturnResultCmdFile_DPNE=%temp%\PLMPerfResult_Vaules.cmd

 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "PLMPerfSyslogParser_2012_01"
 set toRun=%toRun% -SubAction "ViaNxSyslogPLMPerfImportConfigKeys"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -SyslogFindMask "%temp%\%UserName%*.syslog"
 set toRun=%toRun% -ImportConfigXml "%ImportConfigXmlL_DPNE%"
rem  set toRun=%toRun% -ImportConfigName "%ImportConfigName%"
 set toRun=%toRun% -ReturnResultCmdFile "%ReturnResultCmdFile_DPNE%"
 set toRun=%toRun% -TotalReal_SendMail_IFGT "%MailToUserIfValueGT%"
 set toRun=%toRun% -LoadUpdCpuReal_SendMail_IFGT "%MailToUserIfValueGT%"
 set toRun=%toRun% -LoadUpdCpu_SendMail_IFGT "%MailToUserIfValueGT%"
 rem new 27.05.2016 S.Gueth added support for 4 tier list users
 if defined ListUsers_4Tier_prog set toRun=%toRun% -ShellExecProg_DPNE "%ListUsers_4Tier_prog%"
 if defined ListUsers_4Tier_args set toRun=%toRun% -ShellExecArguments "%ListUsers_4Tier_args%"
 set toRun=%toRun% -JobData1ToProcessDoPrint
 set toRun=%toRun% -JobData2ResultsDoPrint
 set toRun=%toRun% -JobParaDoPrint
 if /I "%UserCount_Custom%" equ "YES"  set toRun=%toRun% -UserCount

 if "%TC_ROOT%" equ "" goto :NextStep
   set toRun=%toRun% -u "%JobMgr_TcUser%" -p "%JobMgr_TcPw%"
   if defined JobMgr_TcGroup set toRun=%toRun% -g "%JobMgr_TcGroup%"
:NextStep

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   set Debug_DPNE=%CmdCurRoot_DP%\zzDebug_02NXJournalEval.txt
   set toRun=%toRun% -verbose -pauseOnEnd
   Echo #Debug.: before: [PLMPerfSyslogParser]
   Echo %toRun% >>"%Debug_DPNE%"
   Echo %toRun%
   set toRunForPrint=%toRun:"=%
   call Echo " %~0 toRun:%toRunForPrint% " "" "NOECHO"
   pause
:JumbOverDebug

 call %toRun%

 Call Echo "End NxPLMPerfClient_Execute" "" "NOECHO"

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOver
   Echo #Debug: Job Results Info:
   Echo #Debug: PrgExitCode: %PrgExitCode%
   pause
:JumbOver


goto :eof

REM ####### ------------ Standard Subroutines ---------------------- ###########
REM ============================================================================


REM ============================================================================
:ColorSet
Rem Stand 25.06.2011
 REM call :ColorSet Standard
 REM call :ColorSet IsExecuting
 REM call :ColorSet IsIdel
 REM call :ColorSet End
 REM call :ColorSet Ende
 REM call :ColorSet Ok
 REM call :ColorSet Err

 if /I "%~1" equ "Standard"    set JobColorLast=70
 if /I "%~1" equ "IsExecuting" set JobColorLast=E0
 if /I "%~1" equ "ExtractLi"   set JobColorLast=B0
 if /I "%~1" equ "EvalResult"  set JobColorLast=B1
 if /I "%~1" equ "IsIdel"      set JobColorLast=70
 if /I "%~1" equ "End"         set JobColorLast=70
 if /I "%~1" equ "Ende"        set JobColorLast=70
 if /I "%~1" equ "Ok"          set JobColorLast=A0
 if /I "%~1" equ "Err"         set JobColorLast=C0

 REM set color
 if "%JobColorLast%" neq "" color %JobColorLast%
 goto :eof

REM ============================================================================
:end

