@Echo off

 Echo **************************************************************************
 Echo * Excuting NX12-PartUpdate Native Script for  PLMJobManager Environ      *
 Echo * Version: 21.03.2018 addPLM GmbH (c)                                    *
 Echo **************************************************************************

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

 call Echo "--- #Step: Nx-PartUpdate Nativ Set Up Base ---------------------------------"

 REM -- temp dir Organiesieren -------------------------------------------------
 set JobTemp=%CmdCurRoot_DP%\zzJobTemp
 if not exist "%JobTemp%" md "%JobTemp%"

 rem #New: 16.03.2016 set default NXPuMaxDuration
 if not defined NXPuMaxDuration set NXPuMaxDuration=-1

 REM -- define cmd files to set variables --------------------------------------
 set NxPartUtilNativCustomSetEnv_cmd=%CmdCurRoot_DP%\NxPartUtilNativCustomSetEnv.cmd

 Rem -- define ResultClassification_DPNE JobMgr --------------------------------
 set ResultClassification_DPNE=%CmdCurRoot_DP%\Resources\NxPartUtilNativSylog_ResClRules.xml

 call Echo "--- #Step: Execute Nx-PartUpdate Nativ -------------------------------------"
 rem #Doc: JobParameter is to set on this line
 call :ExecutePartUpdate "%JobTemp%"
 endlocal& set NXPuPrgExitCode=%NXPuPrgExitCode%
goto :end


rem ============================================================================
:ExecutePartUpdate
 rem #Doc: Main Script to run part_utility.exe

 rem #Doc get File Params
 set temp=%~1
 rem #New 15.04.2014 13:48
 set tmp=%temp%
 set HOME=%temp%

 set PartUpdateErrLog_DPNE=%temp%\_PartUpdateErrLog.txt
 set UGII_TMP_DIR=%temp%
 SET UGII_KEEP_SYSTEM_LOG=TRUE
 set UGII_UGSOLIDS_TMP=%UGII_TMP_DIR%


 REM -- Symetric Multi-Processing (SMP) disable
 REM diabled 07.02.2011
 set UGII_SMP_ENABLE=

 REM -- CGM erstellung deaktiveren eingefuegt 09.02.10 J.fes
 set UGII_IMAGE_CREATE_CGM=
 set UGII_IMAGE_CREATE_CGM_DRAW=
 set UGII_IMAGE_CREATE_CGM_OPTIONS=
 set UGII_IMAGE_CREATE_NAME=
 set UGII_IMAGE_CREATE_ORIGINAL_BACKGROUND=


 REM -- define Load_options ----------------------------------------------------
 if defined UGII_LOAD_OPTIONS_NE set UGII_LOAD_OPTIONS=%CmdCurRoot_DP%\startup\%UGII_LOAD_OPTIONS_NE%

 REM -- define nx.dpv ----------------------------------------------------------
 if defined UGII_LOCAL_USER_DEFAULTS_NE set UGII_LOCAL_USER_DEFAULTS=%CmdCurRoot_DP%\startup\%UGII_LOCAL_USER_DEFAULTS_NE%
 set UGII_USER_DIR=%CmdCurRoot_DP%
 set UGII_GROUP_DIR=


 rem 21.01.2014
 rem  - mit max 2 Std Laufzeit
 rem  - mit max 6gb Memory usage für 5 min
 rem  - mit max 5 min ohne das neue files im JobTemp entstehen oder editiert werden
 set toMon=%JFProcessMonitorL_exe%
 set toMon=%toMon% --waitForProcess 15000
 set toMon=%toMon% --processName part_utility
 set toMon=%toMon% --parentProcessId 0
 REM  set toMon=%toMon% --runtimeLimitSeconds 7200
 set toMon=%toMon% --killChildProcesses
 set toMon=%toMon% --fileLastWriteTime "%temp%\*.*;600"
 rem #New 23/11/2014 19:21 / J.Fes
 set toMon=%toMon% --fileContainsString "%temp%\%username%*.syslog;This is most likely the result of a crash of the Teamcenter server, or the Teamcenter server encountering an unrecoverable error"
 rem set toMon=%toMon% --monitorExistingFiles
 REM  set toMon=%toMon% --memoryUsageHigh 6000;300
 set toMon=%toMon% --saveResultsTo "%temp%\zzJFProcessMonitor_log.xml"
 set toMon=%toMon% --tailTextFile "%temp%\*part_utility*.syslog"
 set toMon=%toMon% --titlePrefix "Job:[%JobName%][%TcSiteId%]"

 REM -- set Rf Parameter ----------------
 set NXPuPrgExitCode=

 REM -- set Rf.Contol defaults ----------
 set JobMgr_RfPMon_USE=true

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

 REM -- part_utility.exe Programm ----------------------------------------------
 set part_utility_exe_DPNE=%UGII_BASE_DIR%\nxbin\part_utility.exe

 call :Parse_NE %UGII_LOAD_OPTIONS%        UGII_LOAD_OPTIONS
 call :Parse_NE %UGII_LOCAL_USER_DEFAULTS% UGII_LOCAL_USER_DEFAULTS

 set titleTxt=Job:[%JobName%][%TcSiteId%][%Date% %time:~0,5%][\\%ComputerName%]
 title %titleTxt%

 Echo.                                                                               .
 call ColorSet "IsExecuting"
 Echo %titleTxt%
 call Echo "----------------------------------------------------------------------------"
 Call Echo "NXPart Utility Job Settings:"
 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Call Echo "JobName.........................: %JobName%"
 Call Echo "Computer........................: %ComputerName%"
 Call Echo "Process Dir.....................: %temp%"
 Call Echo "Site............................: #TcSiteId#"
 Call Echo "EvalExtOpt......................: %JobMgr_RfExtEvalROpt%"
 Call Echo "Proc.Monitor....................: %JobMgr_RfPMon_USE%"
 Call Echo "UGII_BASE_DIR...................: %UGII_BASE_DIR%"
 Call Echo "UGII_SITE_DIR...................: %UGII_SITE_DIR%"
 Call Echo "UGII_LOAD_OPTIONS...............: ..\%UGII_LOAD_OPTIONS_NE%"
 Call Echo "UGII_LOCAL_USER_DEFAULTS........: ..\%UGII_LOCAL_USER_DEFAULTS_NE%"
 Call Echo "Using Program...................: %part_utility_exe_DPNE%"
 Call Echo "Using Parameter.................: -managed_mode=no %JobParameter%"


 cd /d "%temp%"
 set >>"%temp%\zzEnvironBeforRunPart_utility.txt"

 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Call Echo "Nativ part_utility.exe Protocol:"

 set NXPuPrgExitCode=0
 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "RefileNative_2016_02"
 set toRun=%toRun% -SubAction "PartByPart"
 rem -d Convert all parts/UDFs in directory <dirname>.
 rem #New: Option after 09.09.2019
 rem set toRun=%toRun% -SubAction "viaConvertAllPartsInDir"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -JobTemp_DP "%temp%"
 set toRun=%toRun% -RfProg_DPNE "%part_utility_exe_DPNE%"

 rem -- #Doc: add additional parameters
 if defined RfTarget_DP                 set toRun=%toRun% -RfTarget_DP %RfTarget_DP%
 if defined RfTargetReplSource_DP       set toRun=%toRun% -RfTargetReplSource_DP %RfTargetReplSource_DP%
 if defined RfTargetReplSourceWith_DP   set toRun=%toRun% -RfTargetReplSourceWith_DP %RfTargetReplSourceWith_DP%
 if defined JobParameter                set toRun=%toRun% -RfParam "''-managed_mode=no %JobParameter%''"
 if defined RfEnv_JobMgr_nRfNXcash_DP   set toRun=%toRun% -RfEnv_JobMgr_nRfNXcash_DP %RfEnv_JobMgr_nRfNXcash_DP%

 set toRun=%toRun% -ShellMaxDurationSEC "%NXPuMaxDuration%"
 set toRun=%toRun% -JobData1ToProcessDoPrint
 set toRun=%toRun% -JobData2ResultsDoPrint

 if exist "%ResultClassification_DPNE%" set toRun=%toRun% -ResultClassification_DPNE "%ResultClassification_DPNE%"
 if defined ResultClassificationCustom_DPNE set toRun=%toRun% -ResultClassificationCustom_DPNE "%ResultClassificationCustom_DPNE%"
 if defined JobMgr_RfExtEvalROpt set toRun=%toRun% %JobMgr_RfExtEvalROpt%

if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
 set toRun=%toRun% -verbose -pauseOnEnd
 call Echo "---------------------------------------------------------------------------"
 call Echo "#Debug..........................: before NxPuJob (%~0)"
 pause
:JumbOverDebug

 rem --#Step: Now run JobMgrCmdTool for Nativ part_utility.exe
 call %toRun%
 set NXPuPrgExitCode=%errorlevel%


if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
 set toRun=%toRun% -verbose -pauseOnEnd
 call Echo "---------------------------------------------------------------------------"
 call Echo "#Debug..........................: before NxPuJob (%~0)"
 pause
:JumbOverDebug

 call Echo "--- #Res.: NXPuPrgExitCode.: [%NXPuPrgExitCode%] ---------------------------------------------"

 REM  Echo ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----
 Call Echo "before NxPu:End" "" "NOECHO"
 call "%BinPublic_DP%\Banner.exe" "NxPu:End"

 Call ColorSet "END"

goto :eof

REM ####### ------------ Standard Subroutines ---------------------- ###########
:Parse_NE
 set %2_NE=%~nx1
 goto :eof

:end
