DSCResources/STWebTier/STWebTier.schema.psm1

configuration STWebTier
{
param(
 
     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$Ensure, 

     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$WebsiteName,

     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$Port,

     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$WebAppName,

     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$WebAppPoolName,

     
     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$PhysicalPathWebsite,
     
     
     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$DestinationPath,  

     
     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$DeploymentPath, 

     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$State,

     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [string]$SqlServerName,

     [Parameter(Mandatory)]
     [ValidateNotNullOrEmpty()]
     [hashtable]$SqlLogin)

    Import-DscResource -Module xPSDesiredStateConfiguration
    Import-DscResource -Module xWebAdministration
          
        xPackage InstallAzureEmulator
        {
                Ensure = $Ensure
                Name = "Windows Azure Emulator 2.2"
                Path = Join-Path $DeploymentPath "WindowsAzureEmulator-x64.exe"
                ProductId = ""                
                Arguments = "/quiet /norestart"                
                InstalledCheckRegKey = "SOFTWARE\Microsoft\Windows Azure Emulator"
            InstalledCheckRegValueName = "FullVersion"
                InstalledCheckRegValueData = "2.2.6492.2"
        }

        WindowsFeature IIS
        {

            Ensure               =  $Ensure
            Name                 =  "Web-Server"
            IncludeAllSubFeature =  $true
        }

        WindowsFeature AspNet45
        {
            Ensure               =  $Ensure
            Name                 =  "Web-Asp-Net45"
        }

        File WebsiteCopy
        {         
            Ensure               =  $Ensure
            Type                 =  "Directory"
            Recurse              =  $true
            SourcePath           =  Join-Path $DeploymentPath $WebAppName
            DestinationPath      =  $DestinationPath
            DependsOn            =  @("[WindowsFeature]IIS", "[WindowsFeature]AspNet45")
            Checksum             =  "modifiedDate"
        }
        
        xWebAppPool StockTraderAppPool
        {
            Name                 =  $WebAppPoolName
            Ensure               =  $Ensure
            State                =  $State
            DependsOn            =  "[File]WebsiteCopy"
        }

    xWebSite DefaultWebsite
        {
            Name                 =  "Default Web Site"            
            PhysicalPath         =  "C:\inetpub\wwwroot"
            State                =  "Stopped"            
        }

        xWebSite StockTraderWebsite
        {
            Name                 =  $WebsiteName
            Ensure               =  $Ensure
            BindingInfo          =  MSFT_xWebBindingInformation
                                    {
                                         Port = $Port
                                    }
            PhysicalPath         =  $PhysicalPathWebsite
            State                =  $State
            DependsOn            =  @("[xWebAppPool]StockTraderAppPool", "[xWebSite]DefaultWebsite")
        }

    xWebConnectionString LoggingConnectionString
    {
        WebSite = $WebsiteName
        Name = "LOGGING_SQL_CONN_STRING"
        ConnectionString = "Data Source=" +  $SqlServerName + ",1433;Network Library=DBMSSOCN;Database=Logging;User ID=" + $SqlLogin.login + ";Password=" + $SqlLogin.password + ";Trusted_Connection=False;Encrypt=True;TrustServerCertificate=True;Connect Timeout=60;min pool size=10;max pool size=50;"
        DependsOn            =  @("[xWebSite]StockTraderWebsite")
    }

    xWebConnectionString WebAppRepositoryConnectionStringValue
    {
        WebSite = $WebsiteName
        Name = "CONFIGDB_SQL_CONN_STRING"
        ConnectionString = "Data Source=" +  $SqlServerName + ",1433;Network Library=DBMSSOCN;Database=AzureStockTraderWebAppRepository;User ID=" + $SqlLogin.login + ";Password=" + $SqlLogin.password + ";Trusted_Connection=False;Encrypt=True;TrustServerCertificate=True;Connect Timeout=60;min pool size=10;max pool size=50;"
        DependsOn            =  @("[xWebSite]StockTraderWebsite")
    }

    xWebConnectionString BusinessServiceRepositoryConnectionStringValue
    {
        WebSite = $WebsiteName
        Name = "BSL_CONFIGDB_SQL_CONN_STRING"
        ConnectionString = "Data Source=" +  $SqlServerName + ",1433;Network Library=DBMSSOCN;Database=AzureBusinessServiceRepository;User ID=" + $SqlLogin.login + ";Password=" + $SqlLogin.password + ";Trusted_Connection=False;Encrypt=True;TrustServerCertificate=True;Connect Timeout=60;min pool size=10;max pool size=50;"
        DependsOn            =  @("[xWebSite]StockTraderWebsite")
    }

    xWebConnectionString OrderProcessorRepositoryConnectionStringValue   
    {
        WebSite = $WebsiteName
        Name = "OPS_CONFIGDB_SQL_CONN_STRING"
        ConnectionString = "Data Source=" +  $SqlServerName + ",1433;Network Library=DBMSSOCN;Database=AzureOrderProcessorRepository;User ID=" + $SqlLogin.login + ";Password=" + $SqlLogin.password + ";Trusted_Connection=False;Encrypt=True;TrustServerCertificate=True;Connect Timeout=60;min pool size=10;max pool size=50;"
        DependsOn            =  @("[xWebSite]StockTraderWebsite")
    }
}