 REM -- #Doc: Inits all Basics of Job
 REM -- #New: 08.02.2017/J.Fes        first version
 REM    #LUp: 01.08.2017/J.Fes        Update set JobTitle
 REM    #LUp: 27.12.2017/J.Fes        Optimice
 REM    #LUp: 17.01.2018/J.Fes        add JobMgr_TcPwFile_NE
 REM -- #DOC: Paramter all Parameter must be used
 REM    P1 JobTitel                   YES/NO
 REM    P2 DoUpdate BinL              YES/NO
 REM    P3 DoUpdate BinL inc. Oracle  YES/NO
 REM    P4 Start WatchDog             YES/NO
 REM    P5 Start TaskMgr              YES/NO
 REM -- Usage: Call "%~dp0_JobInitial.cmd" "#Titel#" "YES" "YES" "YES" "YES"



 REM -- set root path ---------------------------------------------------------
 set CmdCurRoot_DP=%~dp0
 set CmdCurRoot_DP=%CmdCurRoot_DP:~0,-1%
 cd /D "%CmdCurRoot_DP%"

 REM -- #Step: Farbe setzen IsIdel
 call "%CmdCurRoot_DP%\ColorSet" "Init"

 if "%~5" equ "" (
   call %~dp0ColorSet ERR
   Call %~dp0Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
   Call %~dp0Echo "Missing required Para5 in.......: '%~0'"
   Call %~dp0Echo "please check....................: calling script"
   Call %~dp0Echo "END.............................: script stops Job via EXIT"
   Pause
   Exit
 )

 set JobTitleB=%~1
 set JobMgr_JobInitial_DoUpdBinL=%~2
 set JobMgr_JobInitial_DoUpdORABinL=%~3
 set JobMgr_start_PLMJobManagerWatchDog=%~4
 set JobMgr_start_TaskMgr=%~5

 REM -- temp dir Organisieren -------------------------------------------------
 set tempOrig_DP=%temp%
 set temp=%CmdCurRoot_DP%
 set tmp=%temp%

 REM -- JobServer Variablen ----------------------------------------------------
 set JobManagerRoot_DP=#00-ApplRoot_DP#
 set BinServer_DP=#01-BinServer_DP#
 set BinClient_DP=#02-BinClient_DP#
 set BinPublic_DP=#03-BinPublic_DP#
 set BinPublic_Custom_DP=#03-BinPublic_Custom_DP#
 set BinPublic_ClientServer_DP=#03_BinPublic_ClientServer_DP#
 set JobScriptTemplateMinus1_DP=#JobScriptTemplateMinus1_DP#
 set BinServer_Custom_DP=#01-BinServer_DP#.Custom
 set JobServerScripts_DP=#40-JobServerScripts_DP#
 set JobMgr_TcPwFile_NE=#TcPwFile_NE#

 REM -- JobData ----------------------------------------------------------------
 set JobScripts_DP=#10-JobScripts_DP#
 set JobName=#JobName#
 set JobPacket_NE=#JobPacket_NE#
 set JobParameter=#JobParameter#
 set JobMgrDataOrg_Root_DP_Custom=#12-Data#

 rem -- Defaults TC Prompt Data root
 set JobMgrDataOrg_Root_DP=#12-Data#\Archiv
 if exist "%CmdCurRoot_DP%\TCPrompt_Custom.cmd" set TCPrompt_Custom_DPNE=%CmdCurRoot_DP%\TCPrompt_Custom.cmd
 if exist "%CmdCurRoot_DP%\NxPrompt_Custom.cmd" set NxPrompt_Custom_DPNE=%CmdCurRoot_DP%\NxPrompt_Custom.cmd

 REM -- uebergabe SiteDef ------------------------------------------------------
 set TcSiteId=#TcSiteId#

 REM -- default Debug and Test
 set JobMgr_Debug=OFF
 set JobMgr_Test=OFF



 REM ---------- add JC.script(cmd).ParmaExt Start ------------------------------
#JobScriptParametersExtended#
 REM ---------- add JC.script(cmd).ParmaExt End --------------------------------

 rem -- #Doc: get if exist JobMgr_TcPwFile_DPNE
 if "%JobMgr_TcPwFile_NE%" equ "" goto :Next
 if exist "%CmdCurRoot_DP%\%JobMgr_TcPwFile_NE%" set JobMgr_TcPwFile_DPNE=%CmdCurRoot_DP%\%JobMgr_TcPwFile_NE%
 Call Echo "#Debug JobMgr_TcPwFile..........: %JobMgr_TcPwFile_DPNE%"
 Call Echo "#Debug JobMgr_TcPwFile_DPNE.....: %JobMgr_TcPwFile_DPNE%"
 goto :Next

:Next

 REM -- PathVariable erweitern
 Call "%CmdCurRoot_DP%\PathEnvAddPath.cmd" "%BinPublic_DP%"
 Call "%CmdCurRoot_DP%\PathEnvAddPath.cmd" "%BinPublic_ClientServer_DP%"
 Call "%CmdCurRoot_DP%\PathEnvAddPath.cmd" "%CmdCurRoot_DP%"

 if /i "%JobMgr_Test%" neq "ON" goto :JumbOverTest
  set JobTitleB=%JobTitleB%[Test:%JobMgr_Test%]
  Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
  Banner Test:%JobMgr_Test%
  Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
:JumbOverTest

 REM -- set JobTitle -----------------------------------------------------------
 set JobTitleB=%JobTitleB%[%JobName%]
 set JobTitle=%JobTitleB%[%Date% %time:~0,5%][\\%ComputerName%]
 title %JobTitle%

 Call Echo "----------------------------------------------------------------------------"
 Call Echo "JobInitial for..................: %JobTitle%"
 Call Echo "Job settings....................: [BinL:%JobMgr_JobInitial_DoUpdBinL%][Ora:%JobMgr_JobInitial_DoUpdORABinL%][Debug:%JobMgr_Debug%][Test:%JobMgr_Test%]"

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOver
  Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
  Banner Debug:%JobMgr_Debug%
  Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
  Call Echo "#JobMgr_JobInitial..............: List of parameters"
  Call Echo "#P1 JobTitleB...................: %JobTitleB%"
  Call Echo "#P2 Do update BinL..............: %JobMgr_JobInitial_DoUpdBinL%"
  Call Echo "#P3 Do update ORA BinL..........: %JobMgr_JobInitial_DoUpdORABinL%"
  Call Echo "#P4 Start WatchDog..............: %JobMgr_start_PLMJobManagerWatchDog%"
  Call Echo "#P5 JobMgr_start_TaskMgr........: %JobMgr_start_TaskMgr%"
  Call Echo "#A1 Start Explorer..............: %CmdCurRoot_DP%"
  start "" Explorer "%CmdCurRoot_DP%"
  Call Echo "----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----"
  pause
:JumbOver

 if "%JobMgr_JobInitial_DoUpdBinL%" NEQ "YES" goto :JobMgr_JobInitial_DoUpdBinL_NO

 set BinL_DP=%CmdCurRoot_DP%\..\BinL
 if not exist "%BinL_DP%" md "%BinL_DP%"
 Call Echo "BinL dir........................: %BinL_DP%"

 rem -- #Step: JobMgr CmdTools local kopieren --------------------
 set JobManagerCmdTools_L=%BinL_DP%\JobManagerCmdTools.exe
 set robocopy_opt=/R:5 /W:1
 Call Echo "JobManagerCmdTools from.........: %BinPublic_ClientServer_DP%"
 robocopy %robocopy_opt% /NP /NJS /NJH /NDL /NFL "%BinPublic_ClientServer_DP%" "%BinL_DP%" "JobManagerCmdTools.*">nul 2>nul

 rem -- #New:07.11.2016/J.Fes copy RunLogged.exe to %BinL_DP%
 set RunLoggedL_DPNE=%BinL_DP%\RunLogged.exe
 set JFProcessMonitorL_DPNE=%BinL_DP%\JFProcessMonitor.exe
 set PLMJobManagerWatchDogL_DPNE=%BinL_DP%\PLMJobManagerWatchDog.exe
 Call Echo "RunLogged PMon PLMWatchDoc from.: %BinPublic_DP%"
 robocopy %robocopy_opt% /S /NP /NJS /NJH /NDL /NFL "%BinPublic_DP%" "%BinL_DP%" RunLogged.exe JFProcessMonitor.exe PLMJobManagerWatchDog.exe>nul 2>nul

 REM -- #NEW:08.02.2017/J.Fes Check if Update ORA Client ---------
if /I "%JobMgr_JobInitial_DoUpdORABinL%" neq "YES" goto :JobMgr_JobInitial_DoUpdORABinL_NO

 rem  -- OraClient  to:[%BinL_DP%\OraClient] ----
 set OraClient_DP=%BinL_DP%\OraClient
 set OraClient_S_DP=%BinPublic_DP%\OraClient\64Bit
 if exist "%BinPublic_Custom_DP%\OraClient" set OraClient_S_DP=%BinPublic_Custom_DP%\OraClient

 Call Echo "Oracle Client .dlls from........: %OraClient_S_DP%"
 robocopy %robocopy_opt% /S /NP /NJS /NJH /NDL /NFL "%OraClient_S_DP%" "%OraClient_DP%\64Bit">nul 2>nul

:JobMgr_JobInitial_DoUpdORABinL_NO
:JobMgr_JobInitial_DoUpdBinL_NO

 REM -- Option: Control software starten ---------------------------------------
 if /I "%JobMgr_start_PLMJobManagerWatchDog%" neq "YES" goto :JumbOver
   pushd "%BinL_DP%"
   call "ProgStart_If_NotRuning.cmd" "PLMJobManagerWatchDog" "%PLMJobManagerWatchDogL_DPNE%"
   popd
:JumbOver

 rem -- #Doc: Check Start: TaskMgr.exe
 if /I "%JobMgr_start_TaskMgr%" neq "YES" goto :JumbOver
   call "ProgStart_If_NotRuning.cmd" "TaskMgr" "taskmgr.exe"
:JumbOver

if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
 call Echo "---------------------------------------------------------------------------"
 call Echo "#Debug End of ..................: %~0"
 pause
:JumbOverDebug
