@Echo off

 rem new 18.01.2010 J.Fes
 setlocal EnableDelayedExpansion EnableExtensions

 rem ---------------------------------------------------------
 rem Basisscript JobManager V2 fuer den Refile mit NX6
 rem (c) J.Feuerstein 24.11.2009
 rem
 rem Aenderungs Info:
 rem User    Date/Time (Shift+strg+T)  Infotext:
 rem J.Fes   24.11.2006 00:05:59       Ersterstellung 24.11.2006
 rem ---------------------------------------------------------
 rem Variablen ersetzungs Abschnitt
 rem Info die mit "#" Gitter eingeschlossenen Variablen werden vom JobServer
 rem vor dem senden an den JobClient ersetzt
 echo Native Refile

 rem # hier können Netzwerkpfade richtig gestellt werden !!
 rem if not exist U:\Zeichnung\Ich-bin-das-UGProduktivVerzeichniss.txt Echo U: wird zugewiesen& net use U: /d /y& net use U: \\dgavm001\ug
 rem if     exist U:\Zeichnung\Ich-bin-das-UGProduktivVerzeichniss.txt Echo U: OK

 set JobName=#JobName#
 set JobParameter=#JobParameter#
 set RefilePaket_NE=#RefilePaket_NE#

 rem ---------------------------------------------------------
 rem Rootpfade setzen
 set CmdCurRoot_DP=%~dp0
 set CmdCurRoot_DP=%CmdCurRoot_DP:~0,-1%
 rem set CmdCurRoot_DP=%NXData_DP%\IR1881380_NxParts
 set path=%CmdCurRoot_DP%;%Path%


 rem ---------------------------------------------------------
 rem ## anpassen NXPrompt durchlaufen
 set NXPromtCmd=C:\UGS\nx75\UGII\ugiicmd.bat
 if exist %NXPromtCmd% call "%NXPromtCmd%" "C:\UGS\nx75\" AUTO
 @echo off

 rem ---------------------------------------------------------
 rem Data Dir
 set NXData_DP=D:\NxData
 set TP=IR1881380_NxParts
 set NXCash_DP=%NXData_DP%\NXCash
 set RfIn_DP=%NXData_DP%\%TP%
 set RfOut_DP=%NXData_DP%\%TP%_NX75_Rf
REM  dir "%NXCash_DP%"
REM  pause

 rem temp dir Organiesieren
 set temp_Orig_DP=%temp%
 set temp=%RfOut_DP%\JobTemp
 if not exist "%temp%" md "%temp%"
 cd /d "%temp%"


 rem ## --------------------------------
 rem UG Umgebungsvariablen setzen (wenn Erforderlich !!)
 rem if "%UGII_BASE_DIR%"=="" set UGII_BASE_DIR=d:\ugs\UGNX7.5
 rem if "%UGII_ROOT_DIR%"=="" set UGII_ROOT_DIR=C:\UGS\nx75\UGII

 rem Suchpath angepasst erforderlich da sonst der refile nicht startet
 rem set Path=%UGII_BASE_DIR%;%UGII_ROOT_DIR%;%Path%

 rem ------ Anwenderstandards *.dpv umbiegen --- wichtig muss mit ..\StartUp\.. Enden
 rem Hinweis die beim Refile verwendeten Anwenderstandars sind in das Verzeichniss:
 rem %Refile_ROOT_DP%\Settings.global\StartUp\.. zu legen !!
REM  set UGII_USER_DIR=%CmdCurRoot_DP%
REM  set UGII_GROUP_DIR=%CmdCurRoot_DP%
REM  set UGII_SITE_DIR=%CmdCurRoot_DP%
 rem ##Debug

REM  SET UGII_LOCAL_USER_DEFAULTS=%CmdCurRoot_DP%\startup\NX75_refile_Native.dpv
REM  copy "%UGII_LOCAL_USER_DEFAULTS%"  "%UGII_SITE_DIR%\startup\NX75_site.dpv">nul
REM  copy "%UGII_LOCAL_USER_DEFAULTS%"  "%UGII_GROUP_DIR%\startup\NX75_group.dpv">nul
REM  copy "%UGII_LOCAL_USER_DEFAULTS%"  "%UGII_USER_DIR%\startup\NX75_user.dpv">nul
 rem set UGII_PV_TESS_CONFIG_FILE=

 rem -- UG-Variablen umbiegen --
 set UGII_TMP_DIR=%temp%


 set UGII_UGMGR_USE_CACHE=
 set UGII_DISABLE_PREVIEW=on
 set UGII_DISABLE_QAF_NAMED_REFS=on

 rem -- IMAN-Variablen umbiegen --
 SET IMAN_SQL_DEBUG=
 set IMAN_TMP_DIR=%temp%
 SET IMAN_KEEP_SYSTEM_LOG=TRUE
 SET UGII_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=

 set RECORD_PART_MODIFICATION=

 rem -- Special Optionen für Refile setzen
 SET UGII_LOCAL_USER_DEFAULTS=%CmdCurRoot_DP%\startup\NX75_refile_Native.dpv
 set UGII_LOAD_OPTIONS=%CmdCurRoot_DP%\load_options_refile_Native.def
 set RefileLog_DPNE=%temp%\_zzRefileNative_Log.txt
 del  "%RfOut_DP%\*.prt"

 if not exist "%RfOut_DP%" md "%RfOut_DP%"
 set JobParameter=-d "%RfIn_DP%" -o "%RfOut_DP%" -r -regen_lw -y
 set JobParameter=-d "%RfIn_DP%" -o "%RfOut_DP%" -r -us -y -ll "%RefileLog_DPNE%"
 set JobParameter=-d "%RfIn_DP%" -o "%RfOut_DP%" -r -us -y -ll "%RefileLog_DPNE%"
REM  set JobParameter="%NXData_DP%\%TP%\W5504793_0.prt" -o "%RfOut_DP%\W5504793_0.prt" -y
 rem -- Refile Logfiles festlegen --
 set RefileJobLog_DPNE=%temp%\_RefileJob.LOG
 set RefileFailedLog_DPNE=%temp%\failed_refiles.log
 rem -- RefilePaketFile festlegen
 set RefilePaket_DPNE=%CmdCurRoot_DP%\%RefilePaket_NE%

 rem -- start Refile Programme ----------------------------------
 set refile_program_exe_DPNE=%UGII_BASE_DIR%\UGII\refile_part.exe
REM  echo refile_program_exe_DPNE:[%refile_program_exe_DPNE%]
 set run_refile=%refile_program_exe_DPNE% %JobParameter%


 if exist "%NXPromtCmd%"               Echo NXPrompt                 Ok: "%NXPromtCmd%"
 if exist "%refile_program_exe_DPNE%"  Echo RefileProg               Ok: "%refile_program_exe_DPNE%"
 if exist "%UGII_LOCAL_USER_DEFAULTS%" Echo UGII_LOCAL_USER_DEFAULTS Ok:

 if exist "%refile_program_exe_DPNE%" if exist "%NXPromtCmd%" goto StartRefileOk
 goto StartRefileError

:StartRefileOk
 set title_str=RefileJob:[%JobName%] [Start:%Date%/%time:~0,8%] [\\%ComputerName%]
 title %title_str%
 Echo %title_str%
 Echo --------------------------------------------------------------------------
 Echo RefileJob Info:
 Echo.
 Echo JobName    : %JobName%
 Echo Computer   : %ComputerName%
 Echo RefileDir  : %temp%
 Echo Side       : %TceSiteId%
 Echo.
 Echo RefileOpt  : %JobParameter%
 Echo Start time : %Date%/%time:~0,8%
 Echo.
REM  pause
 rem -- hier wird das Refileprogram gestartet --
 rem -ll=%RefileJobLog_DPNE%

 rem for /F "eol=; tokens=2,3* delims=," %i in (meineDat.txt) do @echo %i %j %k
 rem startet fuer jedes item im Paket den Native Refile
 rem for /F "delims=;" %%i in (%RefilePaket_DPNE%) do set RefilePart_DPNE=%%i& call :NativeRefileExecute
 Echo %run_refile%
 %run_refile%

 Echo.
 Echo --------------------------------------------------------------------------
 Echo Refile was executed:
 pause
 exit
 goto :end

:NativeRefileExecute
 rem führt ein Native refile aus

 rem set RefilePart_DPNE=%1
 rem Echo [%RefilePart_DPNE%]
 rem Dir "%RefilePart_DPNE%"
 rem pause
 call :NativeRefileLogFileGet RefilePartLog_DPNE "%RefilePart_DPNE%"

 Echo Native Refile:
 Echo Temp      : %temp%
 Echo Partfile  : %RefilePart_DPNE%
 Echo Logfile   : %RefilePartLog_DPNE%

 if /I "%JobParameter%"=="-AllPartsInDir" goto :RefileViaDir
 goto :RefilePartByPart


:RefilePartByPart
 rem Refile Part by Part for eatch Part an single process will be started
 set toRun=%refile_program_exe_DPNE% "%RefilePart_DPNE%" -ll "%RefilePartLog_DPNE%"
 goto :RefileStart

:RefileViaDir
 rem Refile all parts in Directory
 rem Info do select only 1 part for JobProcess
 Echo Refile all Parts in:
 Echo Refile Dir: %RefileRoot_DP%
 set toRun=%refile_program_exe_DPNE% -d %RefileRoot_DP% -ll "%RefilePartLog_DPNE%"
 goto :RefileStart

 rem Echo %toRun%
:RefileStart
 rem Echo %toRun%
 rem pause
 %toRun%

 goto :eof

:NativeRefileLogFileGet
 rem setzt den Logfile für den Native Refile zusammen
 rem P1 = uebergabe Variable fuer den LogFile
 rem P2 = RefilePart_DPNE für den der Logfile zusammen gesetzt werden soll
 set %1=%temp%\%~n2.NativeRefile.log
 set RefileRoot_DP=%~dp2
 goto :eof


:StartRefileError
 set title_str=ERR: !! cannot start refile on: [\\%ComputerName%] missing refile installation [%Date%/%time:~0,8%] !!
 title %title_str%
 Echo -----------------------------------------------------------
 Echo %title_str%
 rem Error in die Datei schreiben!
 Echo %title_str%>>%temp%\__ErrorUp-ReadMeFirst-DeaktivateComputer.txt
 goto :end


:end
 Echo -----------------------------------------------------------
 Echo Info:
 Echo all files in: %temp%
 Echo will be zipt by JobManager_Clinet and send to JobServer

