<commit_before>﻿ Set-Variable -Name VerbosePreference -Value Continue

function PollingInterval()
{
   if ($env:AZURE_TEST_MODE -eq 'Playback') 
   {
      $pollingIntervalSecs = 5
   } 
   else 
   {
      $pollingIntervalSecs = 60 * 5
   }
   $pollingIntervalSecs
}

function Assert([ScriptBlock] $Condition)
{
   if ((& $Condition) -eq $false)
   {
        throw "Assertion Failed $($Condition.ToString()): $(Get-PSCallStack | Out-String)"
   }
}

<#
    This will pick a location, image, billing plan and create a ARA App collection and returns the collection name.
#>
function CreateCloudCollection([string] $Collection)
{

    Write-Verbose "Entering $($MyInvocation.MyCommand.name)" 
    [PSObject[]] $locationList = Get-AzureRemoteAppLocation | % Name
    Assert -Condition {$locationList -ne $null -or $locationList.Count -lt 1}    

    [PSObject[]] $templateImageList = Get-AzureRemoteAppTemplateImage | ? {$_.Type -eq 'Platform' -and $_.OfficeType -ne 'Office365'}
    Assert -Condition {$templateImageList -ne $null -or $templateImageList.Count -lt 1}    
 
    $templateImage = $null
    $locCounter = 0
    $imageCounter = 0
    $found = $false
    do
    {   
        $location = $locationList[$locCounter]
        do
        {
            $templateImage = $templateImageList[$imageCounter]
            if ($templateImage.RegionList -contains $location)
            {
               $found = $true
            }
            
            $imageCounter++
        } while ($imageCounter -lt $templateImageList.Count -and -not $found)

        $locCounter++
    } while ($locCounter -lt $locationList.Count -and -not $found)

    Assert -Condition {$found}

    $billingPlans = Get-AzureRemoteAppPlan | % Name
    $billingPlan = $billingPlans[0]
    Assert -Condition {-not [String]::IsNullOrWhiteSpace($billingPlan)}

    Write-Verbose "New-AzureRemoteAppCollection -CollectionName $Collection -ImageName $($templateImage.Name) -Plan $billingPlan -Location $location -Description 'Test Collection'"
    $trackIdCollection = New-AzureRemoteAppCollection -CollectionName $Collection -ImageName $templateImage.Name -Plan $billingPlan -Location $location -Description 'Test Collection' -ErrorAction SilentlyContinue -ErrorVariable er
    if ($? -eq $false)
    {
       throw $er
    }

    do
    {
        Write-Verbose "Waiting current time: $(Get-Date)"
        sleep -Seconds (PollingInterval)

        $collectionState = Get-AzureRemoteAppOperationResult -TrackingId $trackIdCollection.TrackingId -ErrorAction SilentlyContinue -ErrorVariable er
        if ($? -eq $false)
        {
           throw $er
        }

        Write-Verbose "Collection state: $($collectionState.Status)"
   } while ($collectionState.Status -eq 'InProgress' -or $collectionState.Status -eq 'Pending')

   Assert -Condition {$collectionState.Status -eq 'Success'}
   Write-Verbose "$($MyInvocation.MyCommand.name) succsssfully created this collection $Collection" 
}


<#
    This will pick a 5 applications to publish, verifies that they've been published and returns the Publishing Info.
#>
function PublishRemoteApplications([string] $Collection)
{
   Write-Verbose "Entering $($MyInvocation.MyCommand.name)" 
   $numOfApps = 5
   $availablePrograms = Get-AzureRemoteAppStartMenuProgram $Collection -ErrorAction SilentlyContinue -ErrorVariable er
   if ($? -eq $false)
   {
       throw $er
   }

   Assert({$availablePrograms.Count -ge $numOfApps})

   $currentPrograms =  Get-AzureRemoteAppProgram -CollectionName $Collection -ErrorAction SilentlyContinue -ErrorVariable er
   if ($? -eq $false)
   {
       throw $er
   }

   $programsToPublish = $availablePrograms[0..2]
   $programsToPublish += $availablePrograms[$($availablePrograms.Count-2)..$($availablePrograms.Count-1)] 
   Assert({$programsToPublish.Count -eq $numOfApps})
   $Script:applications = $programsToPublish | % { 
       Publish-AzureRemoteAppProgram -CollectionName $Collection -StartMenuAppId $_.StartMenuAppId -ErrorAction SilentlyContinue -ErrorVariable er
       if ($? -eq $false)<commit_msg>Adding Checkin Tests to Azure RemoteApp<commit_after>﻿ Set-Variable -Name VerbosePreference -Value Continue

function PollingInterval()
{
   if ($env:AZURE_TEST_MODE -eq 'Playback') 
   {
      $pollingIntervalSecs = 5
   } 
   else 
   {
      $pollingIntervalSecs = 60 * 5
   }
   $pollingIntervalSecs
}

function Assert([ScriptBlock] $Condition)
{
   if ((& $Condition) -eq $false)
   {
        throw "Assertion Failed $($Condition.ToString()): $(Get-PSCallStack | Out-String)"
   }
}

<#
    This will pick a location, image, billing plan and create a ARA App collection and returns the collection name.
#>
function CreateCloudCollection([string] $Collection)
{

    Write-Verbose "Entering $($MyInvocation.MyCommand.name)" 
    [PSObject[]] $locationList = Get-AzureRemoteAppLocation | % Name
    Assert -Condition {$locationList -ne $null -or $locationList.Count -lt 1}    

    [PSObject[]] $templateImageList = Get-AzureRemoteAppTemplateImage | ? {$_.Type -eq 'Platform' -and $_.OfficeType -ne 'Office365'}
    Assert -Condition {$templateImageList -ne $null -or $templateImageList.Count -lt 1}    
 
    $templateImage = $null
    $locCounter = 0
    $imageCounter = 0
    $found = $false
    do
    {   
        $location = $locationList[$locCounter]
        do
        {
            $templateImage = $templateImageList[$imageCounter]
            if ($templateImage.RegionList -contains $location)
            {
               $found = $true
            }
            
            $imageCounter++
        } while ($imageCounter -lt $templateImageList.Count -and -not $found)

        $locCounter++
    } while ($locCounter -lt $locationList.Count -and -not $found)

    Assert -Condition {$found}

    $billingPlans = Get-AzureRemoteAppPlan | % Name
    $billingPlan = $billingPlans[0]
    Assert -Condition {-not [String]::IsNullOrWhiteSpace($billingPlan)}

    Write-Verbose "New-AzureRemoteAppCollection -CollectionName $Collection -ImageName $($templateImage.Name) -Plan $billingPlan -Location $location -Description 'Test Collection'"
    $trackIdCollection = New-AzureRemoteAppCollection -CollectionName $Collection -ImageName $templateImage.Name -Plan $billingPlan -Location $location -Description 'Test Collection' -ErrorAction SilentlyContinue -ErrorVariable er
    if ($? -eq $false)
    {
       throw $er
    }

    do
    {
        Write-Verbose "Waiting current time: $(Get-Date)"
        sleep -Seconds (PollingInterval)

        $collectionState = Get-AzureRemoteAppOperationResult -TrackingId $trackIdCollection.TrackingId -ErrorAction SilentlyContinue -ErrorVariable er
        if ($? -eq $false)
        {
           throw $er
        }

        Write-Verbose "Collection state: $($collectionState.Status)"
   } while ($collectionState.Status -eq 'InProgress' -or $collectionState.Status -eq 'Pending')

   Assert -Condition {$collectionState.Status -eq 'Success'}
   Write-Verbose "$($MyInvocation.MyCommand.name) succsssfully created this collection $Collection" 
}


<#
    This will pick a 5 applications to publish, verifies that they've been published and returns the Publishing Info.
#>
function PublishRemoteApplications([string] $Collection)
{
   Write-Verbose "Entering $($MyInvocation.MyCommand.name)" 
   $numOfApps = 5
   $availablePrograms = Get-AzureRemoteAppStartMenuProgram $Collection -ErrorAction SilentlyContinue -ErrorVariable er
   if ($? -eq $false)
   {
       throw $er
   }

   Assert({$availablePrograms.Count -ge $numOfApps})

   $currentPrograms =  Get-AzureRemoteAppProgram -CollectionName $Collection -ErrorAction SilentlyContinue -ErrorVariable er
   if ($? -eq $false)
   {
       throw $er
   }

   $programsToPublish = $availablePrograms[0..2]
   $programsToPublish += $availablePrograms[$($availablePrograms.Count-2)..$($availablePrograms.Count-1)] 
   Assert({$programsToPublish.Count -eq $numOfApps})
   $applications = $programsToPublish | % { 
       Publish-AzureRemoteAppProgram -CollectionName $Collection -StartMenuAppId $_.StartMenuAppId -ErrorAction SilentlyContinue -ErrorVariable er
       if ($? -eq $false)
{'fraction_non_alphanumeric': 0.11152005888847995, 'fraction_numerical': 0.004416635995583364, 'mean_word_length': 3.268062827225131, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4046689', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2342, 'n_words': 590}