<commit_before>﻿<#
.Synopsis
   Retrieve the ARM Image reference for a given ASM image
.DESCRIPTION
   Do a search on the ARM image catalog, based on the input ASM VM Image.
.EXAMPLE
   Get-AzureArmImageRef -Location $vm.$location -Image $vmImage
#>
function Get-AzureArmImageRef
{
	[CmdletBinding()]
	Param
	(
		# Location to search the image reference in
		[Parameter(Mandatory=$true)]
		$Location,

		# Param2 help description
		[Microsoft.WindowsAzure.Commands.ServiceManagement.Model.OSImageContext]
		$Image
	)

	$asmToArmPublishersMap = @{
		"Barracuda Networks, Inc." = "barracudanetworks";
		"Bitnami" = "";
		"Canonical" = "Canonical";
		"Cloudera" = "cloudera";
		"CoreOS" = "CoreOS";
		"DataStax" = "datastax";
		"GitHub, Inc." = "GitHub";
		"Hortonworks" = "hortonworks";
		"Microsoft Azure Site Recovery group" = "MicrosoftAzureSiteRecovery";
		"Microsoft BizTalk Server Group" = "MicrosoftBizTalkServer";
		"Microsoft Dynamics AX" = "MicrosoftDynamicsAX";
		"Microsoft Dynamics GP Group" = "MicrosoftDynamicsGP";
		"Microsoft Dynamics NAV Group" = "MicrosoftDynamicsNAV";
		"Microsoft Hybrid Cloud Storage Group" = "MicrosoftHybridCloudStorage";
		"Microsoft Open Technologies, Inc." = "msopentech";
		"Microsoft SharePoint Group" = "MicrosoftSharePoint";
		"Microsoft SQL Server Group" = "MicrosoftSQLServer";
		"Microsoft Visual Studio Group" = "MicrosoftVisualStudio";
		"Microsoft Windows Server Essentials Group" = "MicrosoftWindowsServerEssentials";
		"Microsoft Windows Server Group" = "MicrosoftWindowsServer";
		"Microsoft Windows Server HPC Pack team" = "MicrosoftWindowsServerHPCPack";
		"Microsoft Windows Server Remote Desktop Group" = "MicrosoftWindowsServerRemoteDesktop";
		"OpenLogic" = "OpenLogic";
		"Oracle" = "Oracle";
		"Puppet Labs" = "PuppetLabs";
		"RightScale with Linux" = "RightScaleLinux";
		"RightScale with Windows Server" = "RightScaleWindowsServer";
		"Riverbed Technology" = "RiverbedTechnology";
		"SUSE" = "SUSE"}

	$publisher = $asmToArmPublishersMap[$Image.PublisherName]

	$offers = AzureResourceManager\Get-AzureVMImageOffer -Location $Location -PublisherName $publisher 

	$skus = @()
	$offers | ForEach-Object { $skus += AzureResourceManager\Get-AzureVMImageSku -Location $Location -PublisherName $publisher -Offer $_.Offer}

	$imageLabelTokens = $image.ImageFamily.Split()
	$skuRanks = @()     
	foreach ($sku in $skus)
	{
		$skuRank = @{
			'Skus' = $sku.Skus;
			'Offer' = $sku.Offer;
			'Rank' = 0;
			}
		
		foreach ($token in $imageLabelTokens)
		{
			if ($sku.Skus.Contains($token)) {
				$skuRank.Rank++                
			}    
		}

		if ($skuRank.Rank -gt 0) {
			$skuRanks += $skuRank
		}
	}

	$maximumRank = ($skuRanks | Measure-Object -Maximum Rank).Maximum
	$skusWithMaximumRank = $skuRanks | Where-Object {$_.Rank -eq $maximumRank}

	if ($skusWithMaximumRank.length -eq 0)
	{
		return $null
	}

	$images = @()
	$optionCount = 0
	foreach ($imageSku in $skusWithMaximumRank)
	{
		$imagesForSku = AzureResourceManager\Get-AzureVMImage -Location $Location -PublisherName $publisher -Offer $imageSku.Offer -Skus $imageSku.Skus -ErrorAction SilentlyContinue
		if ($imagesForSku.Length -gt 0) {  
			$latestImage = ($imagesForSku | Sort-Object -Property Version -Descending)[0]

			$images += @{
				'Publisher' = $latestImage.PublisherName
				'Offer' = $latestImage.Offer;
				'Skus' = $latestImage.Skus;
				'Version' = $latestImage.Version
				'Id' = $latestImage.Id;
				'Option' = $optionCount++;
			}
		}
	}

	if ($images.Length -gt 0)
	{
		Write-Output "Found the following potential images:"
		$images | Select-Object Option, Publisher, Offer, Skus, Version | Format-Table -AutoSize -Force | Out-Host
		$option = Read-Host -Prompt "Please type in the Option number and press Enter"

		return $images[$option]
	}

	if ($skusWithMaximumRank.length -eq 0)
	{
		return $null
	}
}



function Get-StorageAccountName
{
	[OutputType([string])]
	Param
	(
		$NamePrefix
	)

	# Decide if we need to create a storage account
	$storageAccountName = $NamePrefix.Substring(0,20) + 'arm'

	$storageAccountExists = $false

	$retryStorageAccountName = $true
	$index = 0

	do
	{
		$storageAccountExists = Azure\Test-AzureName -Storage $storageAccountName

		if ($storageAccountExists)
		{
			# Get-AzureStorageAccount -Name <name> always returns all of the V2 storage accounts on the subscription
			# at this time. Use a workaround to bring the accounts to an array and check instead.
			$storageAccounts = AzureResourceManager\Get-AzureStorageAccount | Select-Object Name
		
			if ($storageAccounts.Contains($storageAccountName))
			{
				# If we are here, this is a storage account on this subscription, and using V2
				$retryStorageAccountName = $false
			} 
			else
			{
				# If we are here, that means, storage account exists but some other subscription has it
				$retryStorageAccountName = $true
				$storageAccountName = "{0:00}{1}arm" -f $NamePrefix.Substring(0,18), $index++
			}
		}
		else
		{
			$retryStorageAccountName = $false
		}
	}
	until (-not $retryStorageAccountName)

	return $storageAccountName
}
<commit_msg>Fixed a bug in storage account name check<commit_after>﻿<#
.Synopsis
   Retrieve the ARM Image reference for a given ASM image
.DESCRIPTION
   Do a search on the ARM image catalog, based on the input ASM VM Image.
.EXAMPLE
   Get-AzureArmImageRef -Location $vm.$location -Image $vmImage
#>
function Get-AzureArmImageRef
{
	[CmdletBinding()]
	Param
	(
		# Location to search the image reference in
		[Parameter(Mandatory=$true)]
		$Location,

		# Param2 help description
		[Microsoft.WindowsAzure.Commands.ServiceManagement.Model.OSImageContext]
		$Image
	)

	$asmToArmPublishersMap = @{
		"Barracuda Networks, Inc." = "barracudanetworks";
		"Bitnami" = "";
		"Canonical" = "Canonical";
		"Cloudera" = "cloudera";
		"CoreOS" = "CoreOS";
		"DataStax" = "datastax";
		"GitHub, Inc." = "GitHub";
		"Hortonworks" = "hortonworks";
		"Microsoft Azure Site Recovery group" = "MicrosoftAzureSiteRecovery";
		"Microsoft BizTalk Server Group" = "MicrosoftBizTalkServer";
		"Microsoft Dynamics AX" = "MicrosoftDynamicsAX";
		"Microsoft Dynamics GP Group" = "MicrosoftDynamicsGP";
		"Microsoft Dynamics NAV Group" = "MicrosoftDynamicsNAV";
		"Microsoft Hybrid Cloud Storage Group" = "MicrosoftHybridCloudStorage";
		"Microsoft Open Technologies, Inc." = "msopentech";
		"Microsoft SharePoint Group" = "MicrosoftSharePoint";
		"Microsoft SQL Server Group" = "MicrosoftSQLServer";
		"Microsoft Visual Studio Group" = "MicrosoftVisualStudio";
		"Microsoft Windows Server Essentials Group" = "MicrosoftWindowsServerEssentials";
		"Microsoft Windows Server Group" = "MicrosoftWindowsServer";
		"Microsoft Windows Server HPC Pack team" = "MicrosoftWindowsServerHPCPack";
		"Microsoft Windows Server Remote Desktop Group" = "MicrosoftWindowsServerRemoteDesktop";
		"OpenLogic" = "OpenLogic";
		"Oracle" = "Oracle";
		"Puppet Labs" = "PuppetLabs";
		"RightScale with Linux" = "RightScaleLinux";
		"RightScale with Windows Server" = "RightScaleWindowsServer";
		"Riverbed Technology" = "RiverbedTechnology";
		"SUSE" = "SUSE"}

	$publisher = $asmToArmPublishersMap[$Image.PublisherName]

	$offers = AzureResourceManager\Get-AzureVMImageOffer -Location $Location -PublisherName $publisher 

	$skus = @()
	$offers | ForEach-Object { $skus += AzureResourceManager\Get-AzureVMImageSku -Location $Location -PublisherName $publisher -Offer $_.Offer}

	$imageLabelTokens = $image.ImageFamily.Split()
	$skuRanks = @()     
	foreach ($sku in $skus)
	{
		$skuRank = @{
			'Skus' = $sku.Skus;
			'Offer' = $sku.Offer;
			'Rank' = 0;
			}
		
		foreach ($token in $imageLabelTokens)
		{
			if ($sku.Skus.Contains($token)) {
				$skuRank.Rank++                
			}    
		}

		if ($skuRank.Rank -gt 0) {
			$skuRanks += $skuRank
		}
	}

	$maximumRank = ($skuRanks | Measure-Object -Maximum Rank).Maximum
	$skusWithMaximumRank = $skuRanks | Where-Object {$_.Rank -eq $maximumRank}

	if ($skusWithMaximumRank.length -eq 0)
	{
		return $null
	}

	$images = @()
	$optionCount = 0
	foreach ($imageSku in $skusWithMaximumRank)
	{
		$imagesForSku = AzureResourceManager\Get-AzureVMImage -Location $Location -PublisherName $publisher -Offer $imageSku.Offer -Skus $imageSku.Skus -ErrorAction SilentlyContinue
		if ($imagesForSku.Length -gt 0) {  
			$latestImage = ($imagesForSku | Sort-Object -Property Version -Descending)[0]

			$images += @{
				'Publisher' = $latestImage.PublisherName
				'Offer' = $latestImage.Offer;
				'Skus' = $latestImage.Skus;
				'Version' = $latestImage.Version
				'Id' = $latestImage.Id;
				'Option' = $optionCount++;
			}
		}
	}

	if ($images.Length -gt 0)
	{
		Write-Output "Found the following potential images:"
		$images | Select-Object Option, Publisher, Offer, Skus, Version | Format-Table -AutoSize -Force | Out-Host
		$option = Read-Host -Prompt "Please type in the Option number and press Enter"

		return $images[$option]
	}

	if ($skusWithMaximumRank.length -eq 0)
	{
		return $null
	}
}



function Get-StorageAccountName
{
	[OutputType([string])]
	Param
	(
		$NamePrefix
	)

	# Decide if we need to create a storage account
	$storageAccountName = $NamePrefix.Substring(0,[math]::Min(20, $NamePrefix.Length-1)) + 'arm'

	$storageAccountExists = $false

	$retryStorageAccountName = $true
	$index = 0

	do
	{
		$storageAccountExists = Azure\Test-AzureName -Storage $storageAccountName

		if ($storageAccountExists)
		{
			# Get-AzureStorageAccount -Name <name> always returns all of the V2 storage accounts on the subscription
			# at this time. Use a workaround to bring the accounts to an array and check instead.
            $storageAccounts = @()
			$storageAccounts += AzureResourceManager\Get-AzureStorageAccount | Select-Object Name
		
			if ($storageAccounts.Contains($storageAccountName))
			{
				# If we are here, this is a storage account on this subscription, and using V2
				$retryStorageAccountName = $false
			} 
			else
			{
				# If we are here, that means, storage account exists but some other subscription has it
				$retryStorageAccountName = $true
				$storageAccountName = "{0}{1:00}arm" -f $NamePrefix.Substring(0,[math]::Min(18, $NamePrefix.Length-1)), $index++
			}
		}
		else
		{
			$retryStorageAccountName = $false
		}
	}
	until (-not $retryStorageAccountName)

	return $storageAccountName
}

{'fraction_non_alphanumeric': 0.1198371146015125, 'fraction_numerical': 0.004459957339538492, 'mean_word_length': 4.170426065162907, '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': '1435306', 'n_tokens_mistral': 3763, 'n_tokens_neox': 3334, 'n_words': 864}