@if "%_echo%" == "" echo off

REM Set up environment

REM Create events directory (if not present) and delete any existing event files in it
if not exist "%BaseDirectoryPath%\Test\Events" md "%BaseDirectoryPath%\Test\Events"
del "%BaseDirectoryPath%\Test\Events" /q

REM Create notifications directory (if not present) and delete any existing notification files in it
if not exist "%BaseDirectoryPath%\Test\Notifications" md "%BaseDirectoryPath%\Test\Notifications"
del "%BaseDirectoryPath%\Test\Notifications" /q

echo.
echo **** Create the application databases
echo "%NSConfigFile%"
call %NSControlPath%\NSControl.exe create -in "%NSConfigFile%"
if %ERRORLEVEL% GEQ 1 goto Error

echo.
echo Registering the instance and installing the service
call %NSControlPath%\NSControl.exe Register -n "%InstanceName%" -s "%SqlServer%" -serviceusername %ServiceUserName% -servicepassword  %ServicePassWord% -service  
if %ERRORLEVEL% GEQ 1 goto Error

echo.
echo **** Enable the instance
call %NSControlPath%\NSControl.exe enable -name %InstanceName% 
if %ERRORLEVEL% GEQ 1 goto Error

exit /B 0

:Error
exit /B 1

