@echo off
set ProjectRoot=C:\JenkinsHomeDir\workspace\RCCP\
set EF6Directory=packages\EntityFramework.6.4.4\tools\net45\any\
set BuildDirectory=RetailCamControlPanel\bin\
set EF6exeName=ef6.exe
set RCCPdll=RetailCamControlPanel.dll
set DBCon="Data Source=dbcontent6848.footfallcam.com,41433;Initial Catalog=RetailCamControlPanel;User ID=sa;Password=cFg7unduUE;Max Pool Size=3000"

REM For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%b%%a)
REM For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
REM For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set folderName=%ldt:~0,4%%ldt:~4,2%%ldt:~6,2%_%ldt:~8,2%%ldt:~10,2%%ldt:~12,2%
echo %folderName%
set DBMigrationDirectory=C:\DBMigrations\RCCP\
set DBMigrationFile=%DBMigrationDirectory%Migration_RCCP_%folderName%.txt
echo %DBMigrationFile%

if not exist %DBMigrationDirectory% (
    echo create dir %DBMigrationDirectory%
    mkdir %DBMigrationDirectory%
) 

@echo off
echo Waiting for 10 seconds...
timeout /t 10 /nobreak
echo Done waiting.

cd %ProjectRoot%%BuildDirectory%

if not exist %ProjectRoot%%BuildDirectory%%EF6exeName% (
    echo not exist file
    copy %ProjectRoot%%EF6Directory%%EF6exeName% %ProjectRoot%%BuildDirectory%%EF6exeName%
)

REM set /A output=""
if exist %ProjectRoot%%BuildDirectory%%EF6exeName% (
    echo exist file
    REM set output=""
    %EF6exeName% database update --assembly RetailCamControlPanel.dll --connection-string=%DBCon% --connection-provider="System.Data.SqlClient" --script >> %DBMigrationFile%
    REM for /f "tokens=* delims=" %%a in (%DBMigrationFile%) do set temp=%%a
    REM echo %temp%
    
    REM for /F "tokens=*" %%A in (%DBMigrationFile%) do [process] %%A
    REM set /p VAR=%DBMigrationFile%
    REM echo %VAR%
)

REM echo %ProjectRoot%%EF6Directory%%EF6exeName%
