anchor.diff:  @echo off
   setlocal
   
  -set Id=%1
  -set IdMaster=Master
  -set WcfTestDir=c:\WCFTest
  -set RepoHome=c:\git
  -set CurrentRepo=%RepoHome%\wcf%Id%
  -set MasterRepo=%RepoHome%\wcf%IdMaster%
  -set PRServiceName=PRService%Id%
  -set WcfServiceName=WcfService%Id%
  -set PRServiceMaster=PRService%IdMaster%
  -set WcfServiceMaster=WcfService%IdMaster%
  -set LogFile="%~dp0%~n0.log"
  -set CertExpirationInDays=99
  -set ExitCode=0
  -set cmd=
  +set _id=%1
  +set _idMaster=Master
  +set _wcfTestDir=c:\WCFTest
  +set _repoHome=c:\git
  +set _currentRepo=%_repoHome%\wcf%_id%
  +set _masterRepo=%_repoHome%\wcf%_idMaster%
  +set _prServiceName=PRService%_id%
  +set _wcfServiceName=WcfService%_id%
  +set _prServiceMaster=PRService%_idMaster%
  +set _wcfServiceMaster=WcfService%_idMaster%
  +set _logFile="%~dp0%~n0.log"
  +set _certExpirationInDays=99
  +set _githubWcfRepoUrl=https://github.com/dotnet/wcf
  +set _exitCode=0
  +set _cmd=
   
   if '%1'=='' goto :Usage
   if '%1'=='/?' goto :Usage
  
positive.code: )
  
  :: Clone a WCF repo
  set cmd=git clone https://github.com/dotnet/wcf %CurrentRepo%
  call %cmd%
  if ERRORLEVEL 1 goto :Failure
  pushd %CurrentRepo%
  call :Run git config --add origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"
  if ERRORLEVEL 1 goto :Failure
  popd
  
  :: Create a new application pool and an application for the WCF test service
  echo Create IIS application pool: %WcfServiceName%
  call :Run %appcmd% add apppool /name:%WcfServiceName% /processModel.IdentityType:LocalSystem /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated
  if ERRORLEVEL 1 goto :Failure
  echo Create IIS application: %WcfServiceName%
  call :Run %appcmd% add app /site.name:"Default Web Site" /path:/%WcfServiceName% /physicalPath:%CurrentRepo%\src\System.Private.ServiceModel\tools\IISHostedWcfService /applicationPool:%WcfServiceName% /enabledProtocols:"http,net.tcp"
  if ERRORLEVEL 1 goto :Failure
  
  :: Grant app pool %WcfServiceName% "Read and Execute" access to the IISHostedWcfService and its subdirectories
  echo Grant app pool %WcfServiceName% "Read and Execute" access to the IISHostedWcfService and its subdirectories
  call :Run icacls %CurrentRepo%\src\System.Private.ServiceModel\tools\IISHostedWcfService /grant:r "IIS APPPOOL\%WcfServiceName%":RX /T /Q
  if ERRORLEVEL 1 goto :Failure
  
  :: Setup PR service only if this is a master repo
  :: Uncomment line below when we switch to use one central PRService
  REM if /I NOT '%MasterRepo%'=='%CurrentRepo%' goto :SkipPRService
  
  :: Create a new application pool and an application for the PR service
  echo Create IIS applicaton pool: %PRServiceName%
  call :Run %appcmd% add apppool /name:%PRServiceName% /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated
  if ERRORLEVEL 1 goto :Failure
  echo Create IIS applicatoin: %PRServiceName%
  call :Run %appcmd% add app /site.name:"Default Web Site" /path:/%PRServiceName% /physicalPath:%CurrentRepo%\src\System.Private.ServiceModel\tools\PRService -applicationPool:%PRServiceName%
  if ERRORLEVEL 1 goto :Failure
  
  :: Grant app pool %PRServiceName% "Modify" access to %CurrentRepo% and its subdirectories
  echo Grant app pool %PRServiceName% "Modify" access to %CurrentRepo% and its subdirectories
  call :Run icacls %CurrentRepo% /grant:r "IIS APPPOOL\%PRServiceName%":M /T /Q
  if ERRORLEVEL 1 goto :Failure
  :: Uncomment below and delete above when we switch to central PR service
  REM echo Grant app pool %PRServiceName% "Read and Execute" access to the PRService and its subdirectories
  REM call :Run icacls %CurrentRepo%\src\System.Private.ServiceModel\tools\PRService /grant:r "IIS APPPOOL\%PRServiceName%":RX /T /Q
  REM if ERRORLEVEL 1 goto :Failure
  
  :SkipPRService
  
  :: Grant master PR service's app pool access to current repo if master PRService exists
  if /I '%MasterRepo%'=='%CurrentRepo%' goto :SkipGrantAccess
  if NOT EXIST %MasterRepo% goto :SkipGrantAccess
  %appcmd% list apppool %PRServiceMaster% >nul
  if ERRORLEVEL 1 goto :SkipGrantAccess
  echo Grant master PRServer app pool: %PRServiceMaster% "Modify" access to %CurrentRepo% and its sudirectories
  call :Run icacls %CurrentRepo% /grant:r "IIS APPPOOL\%PRServiceMaster%":M /T /Q
  if ERRORLEVEL 1 goto :Failure
  
  :SkipGrantAccess
  
  :: Install certificates if %WcfTestDir% does not exist; otherwise, assume certs are installed already
  if EXIST %WcfTestDir% goto :SkipCertInstall
  
  :: Make sure there is an HTTPS binding in IIS site "Default Web Site"
  %appcmd% list site "Default Web Site" /text:* | findstr /i bindings | findstr /i https >nul
  if ERRORLEVEL 1 (
      echo Add an HTTPS binding to "Default Web Site"
      call :Run %appcmd% set site "Default Web Site" /+bindings.[protocol='https',bindingInformation='*:443:']
      if ERRORLEVEL 1 goto :Failure
  )
  
  :: Use current repo for cert gen if master repo does not exist
  if NOT EXIST %MasterRepo% (
      set MasterRepo=%CurrentRepo%
      set WcfServiceMaster=%WcfServiceName%
  )
  
  echo Build CertificateGenerator tool
  call :Run %MasterRepo%\src\System.Private.ServiceModel\tools\scripts\BuildCertUtil.cmd
  if ERRORLEVEL 1 goto :Failure
  
  echo Run CertificateGenerator tool. This will take a little while...
  md %WcfTestDir%
  set certGen=%MasterRepo%\bin\Wcf\tools\CertificateGenerator\CertificateGenerator.exe
  echo ^<?xml version="1.0" encoding="utf-8"?^>^<configuration^>^<appSettings^>^<add key="testserverbase" value="%WcfServiceMaster%"/^>^<add key="CertExpirationInDay" value="%CertExpirationInDays%"/^>^<add key="CrlFileLocation" value="%WcfTestDir%\test.crl"/^>^</appSettings^>^<startup^>^<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/^>^</startup^>^</configuration^>>%certGen%.config
  call :Run %certGen%
  if ERRORLEVEL 1 goto :Failure
  
  echo Configue SSL certificate ports
  call :Run powershell -NoProfile -ExecutionPolicy unrestricted %MasterRepo%\src\System.Private.ServiceModel\tools\scripts\ConfigHttpsPort.ps1
  if ERRORLEVEL 1 goto :Failure
  
  :: TODO: Grant all existing app pools named WCFService# 'Read' access to %WcfTestDir%. This is not needed for now
  
  :SkipCertInstall
  
  :: Grant app pool %WcfServiceName% "Read" access to %WcfTestDir% and its subdirectories
  echo Grant app pool %WcfServiceName% "Read" access to %WcfTestDir% and its subdirectories
  call :Run icacls %WcfTestDir% /grant:r "IIS APPPOOL\WcfService%Id%":R /T /Q
  if ERRORLEVEL 1 goto :Failure
  
  :: Clean up log file if everything worked perfectly
  if EXIST %LogFile% del %LogFile% /f /q
  
  echo.
  echo All operations completed successfully!
  
negative.code: if '%1'=='/help' goto :Usage
  if '%1'=='-help' goto :Usage
  
  :: Make sure this script is running in elevated
  net session>nul
  if ERRORLEVEL 1 (
      echo Exiting... Please run this script with elevated permission.
      goto :Failure
  )
  
  :: Make sure IIS appcmd.exe is accessible
  set _appcmd=%windir%\System32\inetsrv\appcmd.exe
  if NOT EXIST %_appcmd% (
      echo Could not find: %_appcmd%.
      echo Please make sure IIS is installed.
      goto :Failure
  )
  
  :: Clean up any existing setup
  echo Deleting WCF repo at %_currentRepo% if exists and associated application pools and services hosted on IIS...
  %_appcmd% delete app "Default Web Site/%_prServiceName%" >nul
  %_appcmd% delete apppool %_prServiceName% >nul
  %_appcmd% delete app "Default Web Site/%_wcfServiceName%" >nul
  %_appcmd% delete apppool %_wcfServiceName% >nul
  if exist %_currentRepo% rmdir /s /q %_currentRepo%
  if exist %_wcfTestDir% if /I '%_masterRepo%'=='%_currentRepo%' rmdir /s /q %_wcfTestDir%
  echo Clean up done.
  if /I '%2'=='/c' goto :Done
  
  