@Echo off
 Call Echo "****************************************************************************"
 Call Echo "* Excuting RfExcute.cmd Script for NX10 PLMJobManager Environ              *"
 Call Echo "* Version: 29.08.2017  (c)addPLM GmbH                                      *"
 Call Echo "****************************************************************************"
setlocal

 REM -- #Step: Farbe setzen IsIdel
 call ColorSet IsIdel
 call Echo "--- #Step: Setup Base ------------------------------------------------------"
 set JobMgr_TcUser=%~1
 set JobMgr_TcPw=%~2
 set JobMgr_TcGroup=%~3
 if not defined JobMgr_TcGroup     set JobMgr_TcGroup=dba
 if not defined JobMgr_RfDataSets  set JobMgr_RfDataSets=OFF
 if not defined JobMgr_RfPMon_USE  set JobMgr_RfPMon_USE=ON
 if not defined JobMgr_RfExtEvalROptForPrint  set JobMgr_RfExtEvalROptForPrint=OFF


 REM -- temp dir Organiesieren -------------------------------------------------
 rem #New: 11.07.2013 13:43 S.Gue
 set JobTemp1_SO_DP=%CmdCurRoot_DP%\JobTempSO
 set JobTemp2_RO_DP=%CmdCurRoot_DP%\JobTempRO
 set RfLogFile_NE=_Rf20_RefileJob.log
 set RfFailedLog_NE=_Rf21_RefileFailed.log
 set RfCmdJobLog_NE=_Rf23_RefileCmdJob.log

 rem #New 30.11.2013 /J.Fes
 set ExtractJobList_MsgLog_DPNE="%CmdCurRoot_DP%\JobData1_ExtractList.log"
 set EvaluateJobResult_MsgLog_DPNE="%CmdCurRoot_DP%\JobData2_ResultEvaluate.log"

 REM -- define cmd files to set variables --------------------------------------
 set RfSetEnv_cmd=%CmdCurRoot_DP%\RfSetEnv.cmd
 set RfCustomSetEnv_cmd=%CmdCurRoot_DP%\RfCustomSetEnv.cmd

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

 REM -- RefilePaketFile festlegen
 set RfInputList_NE=_Rf01_RefileList.txt
 set RfInputList1_SO_DPNE=%JobTemp1_SO_DP%\%RfInputList_NE%
 set RfInputList2_RO_DPNE=%JobTemp2_RO_DP%\%RfInputList_NE%

 REM -- Refile Logfiles für Owning Site festlegen ------------------------------
 set RfLogFile1_SO_DPNE=%JobTemp1_SO_DP%\%RfLogFile_NE%
 set RfFailedLog1_SO_DPNE=%JobTemp1_SO_DP%\%RfFailedLog_NE%
 set RfCmdJobLog_SO_DPNE=%JobTemp1_SO_DP%\%RfCmdJobLog_NE%

 REM -- Refile Logfiles für Replica festlegen ----------------------------------
 set RfLogFile2_RO_DPNE=%JobTemp2_RO_DP%\%RfLogFile_NE%
 set RfFailedLog2_RO_DPNE=%JobTemp2_RO_DP%\%RfFailedLog_NE%
 set RfCmdJobLog_RO_DPNE=%JobTemp2_RO_DP%\%RfCmdJobLog_NE%

 rem -- Execute first time RfCustomSetEnv.cmd
 call "%RfCustomSetEnv_cmd%" "DEFAULTS"

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
  call Echo "----------------------------------------------------------------------------"
  call Echo "#Debug..........................: %~0"
  call Echo "#Step...........................: Before Run TC-Refile"
  pause
 :JumbOverDebug

 call Echo "--- #Step: Extract Refile Input List ---------------------------------------"
 call :ExtractRfList

if not exist "%RfInputList1_SO_DPNE%" goto :JumbOver_RfSO
 echo.
 call Echo "--- #Step: Refile Site Owning (SO) -----------------------------------------"
 if not defined JobMgr_RfUse_for_SO_RO set JobMgr_RfUse_for_SO_RO=NO
 call :ExecuteRefile "%JobTemp1_SO_DP%" "%RfLogFile1_SO_DPNE%" "%RfFailedLog1_SO_DPNE%" "%RfCmdJobLog_SO_DPNE%" "%RfInputList1_SO_DPNE%"  "%JobMgr_RfUse_for_SO_RO%"
:JumbOver_RfSO

if not exist "%RfInputList2_RO_DPNE%" goto :JumbOver_RfRO
 echo.
 call Echo "--- #Step: Refile Replica Objects (RO) -------------------------------------"
 call :ExecuteRefile "%JobTemp2_RO_DP%" "%RfLogFile2_RO_DPNE%" "%RfFailedLog2_RO_DPNE%" "%RfCmdJobLog_RO_DPNE%" "%RfInputList2_RO_DPNE%"  "YES"
:JumbOver_RfRO

REM New 21.04.2015 S.Gueth
IF /I "%JobMgr_RfDataSets%" EQU "ON" goto :JumbOver_Eval
 rem on standard refile do evaluate Rf results
 echo.
 call Echo "--- #Step: Evaluate Refile Results -----------------------------------------"
 call :RfResEvaluate
:JumbOver_Eval

endlocal& set RfPrgExitCode=%RfPrgExitCode%
goto :end


rem ============================================================================
:ExecuteRefile
 rem #Doc: Main Script to run Refile
 rem #Doc get File Params
 set temp=%~1
 set tmp=%temp%
 rem #LUp: 04.01.17/J.Fes
 Call :Parse_D "%temp%" HOMEDRIVE
 Call :Parse_P "%temp%" HOMEPATH
 set HOME=%temp%

 set RfJobLog_DPNE=%~2
 set RfJobLog2_DPNE=%~dpn2_2%~x2
 set RfFailedLog_DPNE=%~3
 set RfCmdJobLog_DPNE=%~4
 set RfPaket_DPNE=%~5
 set RfReplica=%~6

 set RfErrLog_DPNE=%temp%\_RfErrLog.txt

 set UGII_TMP_DIR=%temp%
 SET UGII_KEEP_SYSTEM_LOG=TRUE
 set UGII_UGSOLIDS_TMP=%temp%

 REM disable eingefuegt 17.08.12 J.Fes/K.S
 set UGII_UGMGR_USE_CACHE=

 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 -- PFM vermeidet fehler beim refile von PFM Parts eingefuegt 29.11.2010 Info erhalten über IR1814812
 set UGII_UGMGR_ALLOW_PFM_IMPORT_EXPORT=1

 REM -- IMAN-Variablen umbiegen -------------------------------------------
 SET IMAN_SQL_DEBUG=
 set IMAN_TMP_DIR=%temp%
 SET IMAN_KEEP_SYSTEM_LOG=TRUE
 SET IMAN_Journalling=OFF
 SET IMAN_journaling=OFF
 SET IMAN_TRACEBACK=OFF
 SET IMAN_Journal_Modules=NONE
 SET API_JOURNAL=NONE
 set APB_SCHEMA=

 REM -- TC-Variablen umbiegen -------------------------------------------
 REM 11.08.10 SQL Debug on for Test's
 SET TC_SQL_DEBUG=
 set TC_TMP_DIR=%temp%
 SET TC_KEEP_SYSTEM_LOG=TRUE
 SET TC_Journalling=OFF
 SET TC_Journaling=OFF
 SET TC_TRACEBACK=OFF

 REM -- define Load_options -----------------------------------------------
 set UGII_LOAD_OPTIONS=%CmdCurRoot_DP%\startup\load_options_refile.def

 REM -- define nx_refile.dpv -----------------------------------------------
 SET UGII_LOCAL_USER_DEFAULTS=%CmdCurRoot_DP%\startup\nx_refile.dpv
 set UGII_USER_DIR=%CmdCurRoot_DP%
 set UGII_GROUP_DIR=

 REM -- def: TC LOG -------
 set TC_Administration_Logging=OFF
 set TC_System_Logging=OFF
 set TC_LOG=%TC_TMP_DIR%

 REM -- Use TcNx Debug Variables -------------------------------------------
 if /I "%JobMgr_TcNxDebug%" neq "ON" goto :JumbOver
   Banner TcNxDeb:ON
   set TC_Journalling=ON
   set TC_Journal_Modules=ALL
   set TC_TRACEBACK=ON

   REM -- (Note the small j and single l)
   set TC_journaling=ON
   REM  (Make sure it is N and not ON)
   set TC_POM_JOURNALLING=N
   set TC_Journal_Modules=ALL
   set TC_SQL_DEBUG=BJTP

   REM -- (SUMMARY for shorter list)
   set TC_JOURNAL=FULL
   set TC_JOURNAL_LINE_LIMIT=0
   set TC_DATASET_DEBUG=on
   set JOURNAL_dpat_report=on

   REM -- this variable prints the SOA based server calls timing information into the syslog
   set UGII_UGMGR_MONITOR_NETWORK_CALLS=1
   set UGII_DEBUG=OCC_update_structure
   set TC_SLOW_SQL=-1
   set TC_KEEP_SYSTEM_LOG=true
   set WhereReferencePOMPref=1
   REM !! Attention !!
   REM set UGII_CHECKING_LEVEL=1
:JumbOver

rem #New 04.08.2017/S.Gueth
if "%JobMgr_BOMCompair%" equ "ON" Call :BOM1ExtractPre

rem -- #New: 05.05.2017/J.Fes toMon also for DS refile
if /i "%JobMgr_RfPMon_USE%" NEQ "ON" goto :Next
 set toMonSearchPath=%temp%
 IF /I "%JobMgr_RfDataSets%" EQU "ON" set toMonSearchPath=%temp%\.

 rem #LUp: 05.05.2017/J.Fes
 rem Monitors NxCB_program_exe_NE
 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_DPNE%
 set toMon=%toMon% --titlePrefix "Job:[%JobName%][%TcSiteId%]"
 set toMon=%toMon% --waitForProcess 15000
 set toMon=%toMon% --processName ugmanager_refile_program
 set toMon=%toMon% --parentProcessId 0
 REM  set toMon=%toMon% --runtimeLimitSeconds 7200
 set toMon=%toMon% --killChildProcesses
 set toMon=%toMon% --fileLastWriteTime "%toMonSearchPath%\*.*;600"
 rem #LUp: 15.08.2016  / J.Fes
 set toMon=%toMon% --fileContainsString "%toMonSearchPath%\*ugmanager_refile_program*.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 "%toMonSearchPath%\*ugmanager_refile_program*.syslog"
:Next

 REM -- set Rf Parameter ----------------
 set RfPrgExitCode=
 set RfPara=#JobParameter#

 REM -- set Rf.Contol defaults ----------
 set TC_SHARED_MEMORY_DIR_Disable=false
 set JobMgr_fccCheck_USE=true

 REM -- set Rf.Environ
 if exist "%RfSetEnv_cmd%" call "%RfSetEnv_cmd%"
 REM -- set Custom.Environ
 call "%RfCustomSetEnv_cmd%" "REFILE"

 REM -- Refile Programm --------------------------------------------------------
 set refile_program_exe_DPNE=%UGII_BASE_DIR%\UGMANAGER\ugmanager_refile_program.exe

 REM -- PreCheck's before Refile
 if not defined JobMgr_TCPromptGet_ResCode call ErrorHandel "S" "TcPromt:UNK"                      "[Missing -or- NOT executed -or- NOT working]"
 if "%JobMgr_TCPromptGet_ResCode%" neq "0" call ErrorHandel "S" "TcPromt:ERR"                      "TcPromptResCode:%JobMgr_TCPromptGet_ResCode% // TcPromptResMsg:%JobMgr_TCPromptGet_ResMsg%"

 if not exist "%RfSetEnv_cmd%"             call ErrorHandel "S" "RfSetEnv.cmd fnf"                 "File not found:[%RfSetEnv_cmd%]"
 if not exist "%RfCustomSetEnv_cmd%"       call ErrorHandel "S" "RfCustomSetEnv.cmd fnf"           "File not found:[%RfCustomSetEnv_cmd%]"

 REM #New: 21.02.2017 J.Fes check UGII_USER_DIR + UGII_SITE_DIR
 if not exist "%UGII_SITE_DIR%\startup"    call ErrorHandel "S" "UGII_SITE_DIR\startup dnf"        "Dir not found:[%UGII_SITE_DIR%\startup]"
 if not exist "%UGII_LOCAL_USER_DEFAULTS%" call ErrorHandel "S" "UGII_LOCAL_USER_DEFAULTS fnf"     "File not found:[%UGII_LOCAL_USER_DEFAULTS%]"
 if not exist "%UGII_LOAD_OPTIONS%"        call ErrorHandel "S" "UGII_LOAD_OPTIONS fnf"            "File not found:[%UGII_LOAD_OPTIONS%]"
 if not exist "%refile_program_exe_DPNE%"  call ErrorHandel "S" "ugmanager_refile_program.exe fnf" "File not found:[%refile_program_exe_DPNE%]"

 REM -- Run fccCheck
 call fccCheck.cmd
 REM -- Exit if Error happend
 if exist "%RfErrLog_DPNE%" goto :RfEnd

 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%][Replica:%RfReplica%][%Date% %time:~0,5%][\\%ComputerName%]
 title %titleTxt%

 Echo.                                                                               .
 call ColorSet IsExecuting
 Echo %titleTxt%
 call Echo "----------------------------------------------------------------------------"
 Call Echo "Refile Job Settings:"
 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Call Echo "JobName.........................: %JobName%"
 Call Echo "Computer........................: %ComputerName%"
 Call Echo "RfDir...........................: %temp:~-50%"
 Call Echo "##- - - - TC settings: - - - -##"
 Call Echo "TcSide..........................: #TcSite.SiteInfoWith_SiteId_and_pName#"
 Call Echo "TcUser..........................: %JobMgr_TcUser%"
 Call Echo "TC_ROOT.........................: %TC_ROOT%"
 Call Echo "TC_DATA.........................: %TC_DATA%"
 Call Echo "TC_SHARED_MEMORY Disable........: %TC_SHARED_MEMORY_DIR_Disable%"
 Call Echo "FMS FMS_HOME....................: %FMS_HOME%"
 Call Echo "FCC CHK.........................: %JobMgr_fccCheck_USE%//ParentFscAdr:%JobMgr_fccCheck_parentfsc_address%"
 Call Echo "##- - - - NX settings: - - - -##"
 Call Echo "UGII_ROOT_DIR...................: %UGII_ROOT_DIR%"
 Call Echo "UGII_LOAD_OPTIONS...............: ..\%UGII_LOAD_OPTIONS_NE%"
 Call Echo "UGII_SITE_DIR...................: %UGII_SITE_DIR%"
 Call Echo "UGII_LOCAL_USER_DEF.............: ..\%UGII_LOCAL_USER_DEFAULTS_NE%"
 Call Echo "##- - - - Rf settings: - - - -##"
 Call :JobParam_List "Refile Parameter................:" "%RfPara%"
 Call Echo "RfPart..........................: %JobMgr_RfDataSets%"
 Call Echo "Rf SiteObj as ReplicaObj........: %JobMgr_RfUse_for_SO_RO%"
 Call Echo "RfReplicaParts..................: %RfReplica%"
 Call Echo "RfEvalExtOpt....................: %JobMgr_RfExtEvalROptForPrint%"
 Call Echo "RfProc.Monitor..................: %JobMgr_RfPMon_USE%"

 cd /d "%temp%"
 
  rem New 16.01.2018 S.Gueth: JobMgr_TcPw variable removed before generating environment file
 setlocal
   set JobMgr_TcPw=
   set >>"%temp%\zzEnvironBeforeRefile.txt"
 endlocal

 REM New S.Gueth 17.04.2015 for refiling parts
 IF /I "%JobMgr_RfDataSets%" NEQ "ON" goto :RfPaket
 IF /I "%JobMgr_RfDataSets%" EQU "ON" goto :RfDataSets

rem -------------------------------------------------------------------------------
:RfPaket
 rem  #Doc: Execute Refile via List

 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 call Echo "TC.Refile via RfPaket...........: Protocol"

 IF /i "%JobMgr_Debug%" EQU "ON" (
  Call Echo "#Debug:.........................: Before TC.Refile via Rf.List"
  pause
 )
 REM -- Start JobMgr PMon #LUp21.03.17 start min based on JobMgr_WIMode
 if /i "%JobMgr_RfPMon_USE%" EQU "ON" (
  if /i "%JobMgr_WIMode%" equ "Normal" (
    start "PMon Job:[%JobName%][%TcSiteId%]" %toMon%
  ) else (
    start "PMon Job:[%JobName%][%TcSiteId%]" /min %toMon%
  )
 )

 REM -- #Step: now start refile with usage of RunLogged.exe
 Call Echo "Using...........................: additional Log file %RfJobLog2_DPNE%"
 call RunLogged.exe "%RfJobLog2_DPNE%" "%refile_program_exe_DPNE%" %RfPara% -i="%RfPaket_DPNE%" -log="%RfJobLog_DPNE%" -out="%RfFailedLog_DPNE%" -u=%JobMgr_TcUser% -p=%JobMgr_TcPw% -g=%JobMgr_TcGroup%
 set RfPrgExitCode=%errorlevel%

 IF /i "%JobMgr_Debug%" EQU "ON" (
  Call Echo "#Debug:.........................: After TC.Refile via RfPaket/IrList"
  pause
 )
goto :RfExit

rem -------------------------------------------------------------------------------
:RfDataSets
 rem  #Doc: Execute Refile via Datasets
 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Call Echo "TC.Refile via DataSets:"

 set RfPrgExitCode=0
 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "RefileTC_2012_01"
 set toRun=%toRun% -SubAction "Refile_Part"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -JobTemp_DP "%temp%"
 set toRun=%toRun% -RfProg_DPNE "%refile_program_exe_DPNE%"
 set toRun=%toRun% -RfPara "'%RfPara%'"
 set toRun=%toRun% -u "%JobMgr_TcUser%"
 set toRun=%toRun% -p "%JobMgr_TcPw%"
 set toRun=%toRun% -g "%JobMgr_TcGroup%"
 set toRun=%toRun% -ShellMaxDurationSEC "-1"
REM  set toRun=%toRun% -JobMgr_RfPMon_USE "%JobMgr_RfPMon_USE%"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -RfInputList_DPNE "%RfPaket_DPNE%"
 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% -JobParaDoPrint -verbose -pauseOnEnd
   set toRunForPrint=%toRun:"='%
   Call Echo "#Debug:.........................: Before TC.Refile via DataSets"
   Call Echo "toRun...........................: %toRunForPrint%"
   set Debug_DPNE=%CmdCurRoot_DP%\zzDebug_02_RfDataSets_cmd.txt
   Echo %toRun% >>"%Debug_DPNE%"
   pause
 :JumbOverDebug

 REM -- Start JobMgr PMon #LUp:05.05.2017 start min based on JobMgr_WIMode
 if /i "%JobMgr_RfPMon_USE%" EQU "ON" (
  if /i "%JobMgr_WIMode%" equ "Normal" (
    start "PMon Job:[%JobName%][%TcSiteId%]" %toMon%
  ) else (
    start "PMon Job:[%JobName%][%TcSiteId%]" /min %toMon%
  )
 )
 REM #Doc: Refile via Dataset controled by JobManagerCmdTools
 call %toRun%


 IF /i "%JobMgr_Debug%" EQU "ON" (
  Call Echo "#Debug:.........................: After TC.Refile via DataSets"
  pause
 )
goto :RfExit

REM --#Doc: Script below controls end of Refile process --------------------------------
:RfExit

 if "%JobMgr_BOMCompair%" equ "ON" Call :BOM2ExtractPost

 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Banner "Rf:End"
 Call Echo "RfPrgExitCode...................: %RfPrgExitCode%"
 Call Echo "Refile..........................: End"  "" "NOECHO"

 REM -- #Doc: in case of Refile via Datasets jumb to :RfEnd
 IF /I "%JobMgr_RfDataSets%" EQU "ON" goto :RfEnd

 if defined titelTxt title %titelTxt%
 if exist "%temp%\%UserName%2TierTV" (
   Call Echo "CleanUp.........................: rd /S /Q %temp%\%UserName%2TierTV"
   rd /S /Q "%temp%\%UserName%2TierTV" >nul 1>nul 2>nul
 )
 if exist "%temp%\%userName%2TierTransientVolume" (
   Call Echo "CleanUp.........................: rd /S /Q %temp%\%userName%2TierTransientVolume"
   rd /S /Q "%temp%\%userName%2TierTransientVolume" >nul 1>nul 2>nul
 )

 if "%RfPrgExitCode%" neq "0" call :RfPrgExit_WRN
 if "%RfPrgExitCode%" equ "0" call :RfPrgExit_OK

:RfEnd
 REM -- #Doc: in case of Refile via
 IF /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
  Call Echo "#Debug:.........................: Refile Results Info"
  Call Echo "RfPrg...........................: %refile_program_exe_DPNE%"
  Call Echo "RfPrgExitCode...................: %RfPrgExitCode%"
  Call :TypeFile "%RfJobLog_DPNE%"     "Rf Job Log:"
  Call :TypeFile "%RfFailedLog_DPNE%"  "Rf Failed Log:"
  Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
  Call Echo "#Debug..........................: %~0 Rf:Execute END"
  pause
:JumbOverDebug

goto :eof

REM ============================================================================
:RfPrgExit_OK
 call ColorSet OK
 REM -- delete alle files not to send to JobServer
 rem 20.09.2016 / J.Fes disabled del %temp%\tcserver.*
REM  if /I "%JobMgr_TcNxDebug%" equ "ON"  goto :eof
REM  if /I "%JobMgr_Debug%" equ "ON"  goto :eof
 Call Echo "CleanUp.........................: %temp%\.."
 del /S /Q "%temp%\*.prt","%temp%\XXtcserver.*","%temp%\XXtcserver.*.*","%temp%\*.bak","%temp%\*.tmp" >nul 1>nul 2>nul
goto :eof


REM ============================================================================
:RfPrgExit_WRN
 set titelTxt=WRN:%RfPrgExitCode% !! ugmanager_refile_program.exe [%Date%/%time:~0,8%] !!
 rem #New 11.11.2015/J.Fes Prevent Issues of 'dead Sessions' in TC.DB
 Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
 Call Echo "%titelTxt%"
 Banner Clearlocks
 Call Echo "Run Clearlocks..................: -verbose"
 call Clearlocks -verbose
REM  call ErrorHandel "RfPrg.End with '%RfPrgExitCode%'" ""  "ugmanager_refile_program: End with [errorlevel:%RfPrgExitCode%]"
goto :eof
REM ============================================================================
:ExtractRfList
 rem #Doc: Extracts the IR lists for Refile input
 rem #New: 15.07.2013

 call ColorSet ExtractLi

 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "RefileTC_2012_01"
 set toRun=%toRun% -SubAction "EXTRACT"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -JobTemp1_SO_DP "%JobTemp1_SO_DP%"
 set toRun=%toRun% -JobTemp2_RO_DP "%JobTemp2_RO_DP%"
 set toRun=%toRun% -RfInputList_NE "%RfInputList_NE%"
 set toRun=%toRun% -RfInputList1_SO_DPNE "%RfInputList1_SO_DPNE%"
 set toRun=%toRun% -RfInputList2_RO_DPNE "%RfInputList2_RO_DPNE%"
 set toRun=%toRun% -JobData1ToProcessDoPrint
 REM New 21.04.2015 S.Gueth
 IF /I "%JobMgr_RfDataSets%" == "ON" (
   set JobMgr_RfListContent=DS
 )

 REM 07.12.2015/J.Fes/S.Gueth
 REM #Doc: if RF Param -refile_specified_non_master_only is used then add Dataset CliNames into RfList.txt
 if "%JobParameter%" NEQ  "%JobParameter: -refile_specified_non_master_only=%" (
    set JobMgr_RfListContent=DS
 )

 REM New 25.09.2015 J.Fes
 IF /I "%JobMgr_RfListContent%" equ "DS" (
   set toRun=%toRun% -RfListContent DS
 )


 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   set Debug_DPNE=%CmdCurRoot_DP%\zzDebug_01_ExtractList.txt
   set toRun=%toRun% -verbose -pauseOnEnd
   set toRunForPrint=%toRun:"='%
   Call Echo "#Debug:.........................: Before: [%~0]"
   call Echo "#ToRun..........................: %toRunForPrint%"
   Echo %toRun% >>"%Debug_DPNE%"
:JumbOverDebug

 call %toRun%
 set toRun=
goto :eof

rem ============================================================================
:BOM1ExtractPre
 REM #New: 08.08.2017 S.Gueth

 set BOMDataRoot_DP=%temp%\BOMData
 md %BOMDataRoot_DP%

 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "TcExtractData_2013_10"
 set toRun=%toRun% -SubAction "BOMs_eXtract_for_JobData1ToProcess"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -BOMs_eXtract_prePost "pre"
 set toRun=%toRun% -BOMs_eXtract_IrData_Root_DP "%BOMDataRoot_DP%"
 set toRun=%toRun% -TcSQL_DP #TcSQL_DP#
 set toRun=%toRun% -JobData2ResultsDoPrint

  if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   set Debug_DPNE=%CmdCurRoot_DP%\zzDebug_04_BOM1ExtractPre.txt
   set toRun=%toRun% -verbose -pauseOnEnd
   set toRunForPrint=%toRun:"='%
   Call Echo "#Debug:.........................: Before: [%~0]"
   call Echo "#ToRun..........................: %toRunForPrint%"
   Echo %toRun% >>"%Debug_DPNE%"
:JumbOverDebug

 call %toRun%

goto :eof

:BOM2ExtractPost
 REM #New: 08.08.2017 S.Gueth

 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "TcExtractData_2013_10"
 set toRun=%toRun% -SubAction "BOMs_eXtract_for_JobData1ToProcess"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -BOMs_eXtract_prePost "post"
 set toRun=%toRun% -BOMs_eXtract_IrData_Root_DP "%BOMDataRoot_DP%"
 set toRun=%toRun% -TcSQL_DP #TcSQL_DP#
 set toRun=%toRun% -JobData2ResultsDoPrint

  if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   set Debug_DPNE=%CmdCurRoot_DP%\zzDebug_05_BOM2ExtractPost.txt
   set toRun=%toRun% -verbose -pauseOnEnd
   set toRunForPrint=%toRun:"='%
   Call Echo "#Debug:.........................: Before: [%~0]"
   call Echo "#ToRun..........................: %toRunForPrint%"
   Echo %toRun% >>"%Debug_DPNE%"
:JumbOverDebug

 call %toRun%

goto :eof


rem ============================================================================
:RfResEvaluate
 rem #Doc: Evaluate the refile results
 rem #New: 15.07.2013/J.Fes
 rem #LUp: 02.06.2014/J.Fes
 call ColorSet EvalResult

 REM #Doc: if RfErrLog exist and no Rf.Prg did run then Get Err Result
 if exist "%RfErrLog_DPNE%" if "%RfPrgExitCode%" equ "" goto :RfResEvaluate_ERR
 REM -- set Custom.Environ
 call "%RfCustomSetEnv_cmd%" "EVALUATE"

:RfResEvaluate_Rf
 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "RefileTC_2012_01"
 set toRun=%toRun% -SubAction "EVALUATE"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -JobData2ResultsDoPrint
 rem #New:12.02.2014/J.Fes
 if exist "%ResultClassification_DPNE%" set toRun=%toRun% -ResultClassification_DPNE "%ResultClassification_DPNE%"
 rem #New:05.06.2015/S.Gueth + J.Fes
 if defined ResultClassificationCustom_DPNE set toRun=%toRun% -ResultClassificationCustom_DPNE "%ResultClassificationCustom_DPNE%"
 rem #New:28.04.2014/J.Fes
 if defined JobMgr_RfExtEvalROpt set toRun=%toRun% %JobMgr_RfExtEvalROpt%

 if "%JobMgr_BOMCompair%" neq "ON" goto :next
   Call Echo "RfResEvaluate...................: uses BOMCompair"
   set toRun=%toRun% -BOMCompair
   set toRun=%toRun% -BOMs_eXtract_IrData_Root_DP "%BOMDataRoot_DP%"
   rem set toRun=%toRun% -BOMCompairBOMRefFindMethode "M1_byBOMPuid"
   rem set toRun=%toRun% -BOMCompairBOMRefFindMethode "M2_byBOMData"
   set toRun=%toRun% -CBConfigXml CBMgrConfig.xml
:next

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   set Debug_DPNE=%CmdCurRoot_DP%\zzDebug_03_EvaluateRefileResult.txt
   set toRun=%toRun% -verbose -pauseOnEnd
   set toRunForPrint=%toRun:"='%
   Call Echo "#Before:........................: Evaluate: [%~0]"
   call Echo "#ToRun..........................: %toRunForPrint%"
   Echo %toRun% >>"%Debug_DPNE%"
:JumbOverDebug

 call %toRun%

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   set Debug_DPNE=%CmdCurRoot_DP%\zzDebug_03_EvaluateRefileResult.txt
   set toRun=%toRun% -verbose -pauseOnEnd
   set toRunForPrint=%toRun:"='%
   Call Echo "#After:.........................: Evaluate: [%~0]"
   Echo %toRun% >>"%Debug_DPNE%"
:JumbOverDebug


goto :eof


REM ####### ------------ Standard Subroutines ---------------------- ###########
REM ============================================================================
:JobParam_List
 setlocal
  set ParmListTitle=%~1
  set JobParams=%~2
  rem " ersetzen durch '
  set JobParams=%JobParams:"='%
  set NCur=0
:JobParam_List_PrintNext
  set /a NCur=%NCur%+1
  FOR /F "tokens=%NCur% delims=-" %%i IN ("%JobParams%") do Call :JobParam_Print "%%i"
  if %NCur% LEQ 10 goto :JobParam_List_PrintNext
 endlocal
 goto :eof

:JobParam_Print
 setlocal
  set JobParaCur=%~1
  if "%NCur%" equ "1" (
                            Call Echo "%ParmListTitle% -%JobParaCur%"
  ) else (
   if "%JobParaCur%" neq "" Call Echo "................................: -%JobParaCur%"
  )
 endlocal
 goto :eof

REM ============================================================================
:TypeFile
 REM Types the description and the contens of a file
 setlocal
  set FileToType_DPNE=%~1
  set FileDescription=%~2
  Echo ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ----
  Echo File Content Description........: %FileDescription%
  Echo Content of File.................: %FileToType_DPNE%
  if     exist "%FileToType_DPNE%" type "%FileToType_DPNE%"
  if not exist "%FileToType_DPNE%" Echo ERROR:fnf file not found........: [%FileToType_DPNE%]

 endlocal
 goto :eof

REM ============================================================================
:Parse_NE
 set %2_NE=%~nx1
 goto :eof

:Parse_D
 set %2=%~d1
 goto :eof

:Parse_P
 set %2=%~p1
 goto :eof

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