Param(
  [string]$mode,
  [string]$config
)

#todo: realize refresh wsp, site, web

$LIB_SUBFOLDER = ".."
$LOG_FILE_NAME = "script.log"
$CONFIG_FILE_NAME = "config.xml"
$MSG_LIB_FOLDER_NOT_FOUND = "Error! Script library folder '{0}' not found. Process terminated."

function ProcessStart($mode, $config)
{
	CheckPath
	
	. $("$libFolder\sharepoint\InitiatorService.ps1")
	. $("$libFolder\sharepoint\BaseDeployService.ps1")

	$settings = GetSettingsFromConfigFile $mode $config

	#Write-Host $MSG_LINE
	Write-Host "Config variables ..."

	$settings
	Write-Host $MSG_LINE
	Deploy $settings
}

function CheckPath
{	
	if (!(Test-Path -path $libFolder)) {
		  Write-Host ($MSG_LIB_FOLDER_NOT_FOUND -f $libFolder) -ForegroundColor Magenta
		  exit 
	}

	. $("$libFolder\sharepoint\CommonMsgConstants.ps1")
	$configFileFullPath = "$execFolder\$CONFIG_FILE_NAME"
	if ($config.Length -ne 0)
	{
		$configFileFullPath = $config
	}	
	if (!(Test-Path -path $configFileFullPath))
	{
		Write-Host ($MSG_CONFIG_FILE_NOT_FOUND -f $configFileFullPath) -ForegroundColor Magenta
		exit
	}
}

cls
$execFolder = $(Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
$libFolder = "$execFolder\$LIB_SUBFOLDER"
if ($config.Length -ne 0)
{
	$execFolder = $(Split-Path -Path $config)
}	


try
{
	start-transcript "$execFolder\$LOG_FILE_NAME"
}
catch{}
ProcessStart $mode $config
try
{
	stop-transcript
}
catch {}

#. $("$libFolder\sharepoint\FinalizerService.ps1")
#$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")


