<Project ToolsVersion="12.0" DefaultTargets="DownloadBlobsFromAzureTargets" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask TaskName="DownloadFromAzure" AssemblyFile="$(CloudTestTasksPath)"/>
  <UsingTask TaskName="ListAzureBlobs" AssemblyFile="$(CloudTestTasksPath)" />
  <UsingTask TaskName="ListAzureContainers" AssemblyFile="$(CloudTestTasksPath)"/>

  <PropertyGroup>
    <DownloadDirectory Condition="'$(DownloadDirectory)' == ''">$(PackagesDir)/AzureTransfer</DownloadDirectory>
  </PropertyGroup>

  <Target Name="DownloadBlobsFromAzureTargets" Condition="'$(ContainerName)' != ''">
    <ListAzureBlobs AccountName="$(AzureAccount)"
                    AccountKey="$(AzureToken)"
                    ContainerName="$(ContainerName)"
                    FilterBlobNames="$(BlobName)">
      <Output TaskParameter="BlobNames" ItemName="_BlobList" />
    </ListAzureBlobs>

    <ItemGroup>
      <_OSFilteredBlobNames Include="@(_BlobList)" 
                        Condition="'$(OSGroup)' == 'Windows_NT' AND 
                        ('%(_BlobList.Extension)' == '.zip' OR '%(_BlobList.Extension)' == '.exe' OR '%(_BlobList.Extension)' == '.version')" />
    </ItemGroup>

    <DownloadFromAzure AccountName="$(AzureAccount)"
                        AccountKey="$(AzureToken)"
                        ContainerName="$(ContainerName)"
                        BlobNames="@(_OSFilteredBlobNames)"
                        BlobNamePrefix="$(BlobName)"
                        DownloadDirectory="$(DownloadDirectory)" />
  </Target>
</Project>
