Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gif, bmp, xls, xlsx and pdf @ Write-RSFolderContent & Write-RsCatalogItem #233

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Write-RsCatalogItem

.DESCRIPTION
Uploads an item from disk to a report server.
Currently, we are only supporting Report, DataSource, DataSet and jpg/png for uploads
Currently, we are only supporting Report, DataSource, DataSet, jpg/png/gif/bmp, xls/xlsx and pdf for upload

.PARAMETER Path
Path to item to upload on disk.
Expand Down Expand Up @@ -118,15 +118,20 @@ function Write-RsCatalogItem
$itemType -ne "Report" -and
$itemType -ne "DataSource" -and
$itemType -ne "DataSet" -and
$itemType -ne "Resource"
$itemType -ne "Resource" -and
$itemType -ne "ExcelWorkbook"
) -or
(
$itemType -eq "Resource" -and
$item.Extension -notin ('.png', '.jpg', '.jpeg')
$item.Extension -notin ('.png', '.jpg', '.jpeg', '.gif', '.bmp', '.pdf')
) -or
(
$itemType -eq "ExcelWorkbook" -and
$item.Extension -notin ('.xls', '.xlsx')
)
)
{
throw "Invalid item specified! You can only upload Report, DataSource, DataSet and jpg/png files using this command!"
throw "Invalid item specified! You can only upload Report, DataSource, DataSet, jpg/png/gif/bmp, xls/xlsx and pdf files using this command!"
}

if ($RsFolder -eq "/")
Expand Down Expand Up @@ -159,7 +164,7 @@ function Write-RsCatalogItem
{
throw "Data Source Definition not found in the specified file: $EntirePath!"
}

$NewRsDataSourceParam = @{
Proxy = $Proxy
RsFolder = $RsFolder
Expand All @@ -173,7 +178,7 @@ function Write-RsCatalogItem
}
elseif ($item.Extension -eq '.rds')
{
if ($content -eq $null -or
if ($content -eq $null -or
$content.RptDataSource -eq $null -or
$content.RptDataSource.Name -eq $null -or
$content.RptDataSource.ConnectionProperties -eq $null -or
Expand Down Expand Up @@ -226,20 +231,58 @@ function Write-RsCatalogItem
$additionalProperties = New-Object System.Collections.Generic.List[$propertyDataType]
$property = New-Object $propertyDataType

if ($itemType -eq 'Resource')
if ($itemType -in ('Resource', 'ExcelWorkbook'))
{
#If it is a resource we need to save the extension so the file can be recognized
$itemName = $item.Name
$property.Name = 'MimeType'
if ($item.Extension -eq ".png")
switch ($item.Extension)
{
$property.Value = 'image/png'
}
else
{
$property.Value = 'image/jpeg'
".png"
{
$property.Value = 'image/png'
break
}
".jpeg"
{
$property.Value = 'image/jpeg'
break
}
".jpg"
{
$property.Value = 'image/jpg'
break
}
".gif"
{
$property.Value = 'image/gif'
break
}
".bmp"
{
$property.Value = 'image/bmp'
break
}
".xls"
{
#To upload the item type needs to be 'Resource'
$itemType = "Resource"
$property.Value = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
break
}
".xlsx"
{
#To upload the item type needs to be 'Resource'
$itemType = "Resource"
$property.Value = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
break
}
".pdf"
{
$property.Value = 'application/pdf'
break
}
}
$errorMessageItemType = 'resource'
}
else
{
Expand All @@ -257,7 +300,7 @@ function Write-RsCatalogItem
$hiddenProperty.Value = $Hidden
$additionalProperties.Add($hiddenProperty)
}

$bytes = [System.IO.File]::ReadAllBytes($EntirePath)
$warnings = $null
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Write-RsFolderContent

.DESCRIPTION
Uploads all items in a folder on disk to a report server.
Currently, we are only supporting Report, DataSource, DataSet and jpg/png for uploads
Currently, we are only supporting Report, DataSource, DataSet, jpg/png/gif/bmp, xls/xlsx and pdf for upload

.PARAMETER Recurse
A description of the Recurse parameter.
Expand Down Expand Up @@ -131,7 +131,12 @@ function Write-RsFolderContent
$item.Extension -eq ".rds" -or
$item.Extension -eq ".jpg" -or
$item.Extension -eq ".jpeg" -or
$item.Extension -eq ".png" )
$item.Extension -eq ".png" -or
$item.Extension -eq ".gif" -or
$item.Extension -eq ".bmp" -or
$item.Extension -eq ".xls" -or
$item.Extension -eq ".xlsx" -or
$item.Extension -eq ".pdf" )
{
$relativePath = Clear-Substring -string $item.FullName -substring $sourceFolder.FullName.TrimEnd("\") -position front
$relativePath = Clear-Substring -string $relativePath -substring ("\" + $item.Name) -position back
Expand Down
84 changes: 79 additions & 5 deletions Tests/CatalogItems/Write-RsCatalogItem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Describe "Write-RsCatalogItem" {
$jpgImageResource = (Get-RsFolderContent -RsFolder $jpgFolderPath ) | Where-Object TypeName -eq 'Resource'
$jpgImageResource.Name | Should Be 'PowerShellHero.jpg'
$jpgImageResource.ItemMetadata.Name | Should Be 'MIMEType'
$jpgImageResource.ItemMetadata.Value | Should Be 'image/jpeg'
$jpgImageResource.ItemMetadata.Value | Should Be 'image/jpg'
}

$pngFolderName = 'SutWriteCatalogItem_PNGimages' + [guid]::NewGuid()
Expand All @@ -189,14 +189,88 @@ Describe "Write-RsCatalogItem" {
Write-RsCatalogItem -Path $localPNGImagePath -RsFolder $pngFolderPath

It "Should upload a local png image in ReportServer" {
$jpgImageResource = (Get-RsFolderContent -RsFolder $pngFolderPath ) | Where-Object TypeName -eq 'Resource'
$jpgImageResource.Name | Should Be 'SSRS.png'
$jpgImageResource.ItemMetadata.Name | Should Be 'MIMEType'
$jpgImageResource.ItemMetadata.Value | Should Be 'image/png'
$pngImageResource = (Get-RsFolderContent -RsFolder $pngFolderPath ) | Where-Object TypeName -eq 'Resource'
$pngImageResource.Name | Should Be 'SSRS.png'
$pngImageResource.ItemMetadata.Name | Should Be 'MIMEType'
$pngImageResource.ItemMetadata.Value | Should Be 'image/png'
}

$gifFolderName = 'SutWriteCatalogItem_GIFimages' + [guid]::NewGuid()
New-RsFolder -Path / -FolderName $gifFolderName
$gifFolderPath = '/' + $gifFolderName
$localPNGImagePath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\imagesResources\PBIOverview.gif'
Write-RsCatalogItem -Path $localPNGImagePath -RsFolder $gifFolderPath

It "Should upload a local gif image in ReportServer" {
$gifImageResource = (Get-RsFolderContent -RsFolder $gifFolderPath ) | Where-Object TypeName -eq 'Resource'
$gifImageResource.Name | Should Be 'PBIOverview.gif'
$gifImageResource.ItemMetadata.Name | Should Be 'MIMEType'
$gifImageResource.ItemMetadata.Value | Should Be 'image/gif'
}

$bmpFolderName = 'SutWriteCatalogItem_BMPimages' + [guid]::NewGuid()
New-RsFolder -Path / -FolderName $bmpFolderName
$bmpFolderPath = '/' + $bmpFolderName
$localPNGImagePath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\imagesResources\PowerShellHero.bmp'
Write-RsCatalogItem -Path $localPNGImagePath -RsFolder $bmpFolderPath

It "Should upload a local bmp image in ReportServer" {
$bmpImageResource = (Get-RsFolderContent -RsFolder $bmpFolderPath ) | Where-Object TypeName -eq 'Resource'
$bmpImageResource.Name | Should Be 'PowerShellHero.bmp'
$bmpImageResource.ItemMetadata.Name | Should Be 'MIMEType'
$bmpImageResource.ItemMetadata.Value | Should Be 'image/bmp'
}

# Removing folders used for testing
Remove-RsCatalogItem -RsFolder $jpgFolderPath -Confirm:$false
Remove-RsCatalogItem -RsFolder $pngFolderPath -Confirm:$false
Remove-RsCatalogItem -RsFolder $gifFolderPath -Confirm:$false
Remove-RsCatalogItem -RsFolder $bmpFolderPath -Confirm:$false
}

Context "Write-RsCatalogItem with other resources"{
$pdfFolderName = 'SutWriteCatalogItem_PDF' + [guid]::NewGuid()
New-RsFolder -Path / -FolderName $pdfFolderName
$pdfFolderPath = '/' + $pdfFolderName
$localPDFPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\SQL_Server_2016_Reporting_Services_datasheet_EN_US.pdf'
Write-RsCatalogItem -Path $localPDFPath -RsFolder $pdfFolderPath

It "Should upload a local pdf in ReportServer" {
$pdfResource = (Get-RsFolderContent -RsFolder $pdfFolderPath ) | Where-Object TypeName -eq 'Resource'
$pdfResource.Name | Should Be 'SQL_Server_2016_Reporting_Services_datasheet_EN_US.pdf'
$pdfResource.ItemMetadata.Name | Should Be 'MIMEType'
$pdfResource.ItemMetadata.Value | Should Be 'application/pdf'
}

$xlsxFolderName = 'SutWriteCatalogItem_XLSX' + [guid]::NewGuid()
New-RsFolder -Path / -FolderName $xlsxFolderName
$xlsxFolderPath = '/' + $xlsxFolderName
$localXLSXImagePath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\NewExcelWorkbook.xlsx'
Write-RsCatalogItem -Path $localXLSXImagePath -RsFolder $xlsxFolderPath

It "Should upload a local xlsx in ReportServer" {
$xlsxImageResource = (Get-RsFolderContent -RsFolder $xlsxFolderPath ) | Where-Object TypeName -eq 'Resource'
$xlsxImageResource.Name | Should Be 'NewExcelWorkbook.xlsx'
$xlsxImageResource.ItemMetadata.Name | Should Be 'MIMEType'
$xlsxImageResource.ItemMetadata.Value | Should Be 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
}

$xlsFolderName = 'SutWriteCatalogItem_XLS' + [guid]::NewGuid()
New-RsFolder -Path / -FolderName $xlsFolderName
$xlsFolderPath = '/' + $xlsFolderName
$localXLSImagePath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\OldExcelWorkbook.xls'
Write-RsCatalogItem -Path $localXLSImagePath -RsFolder $xlsFolderPath

It "Should upload a local xls in ReportServer" {
$xlsImageResource = (Get-RsFolderContent -RsFolder $xlsFolderPath ) | Where-Object TypeName -eq 'Resource'
$xlsImageResource.Name | Should Be 'OldExcelWorkbook.xls'
$xlsImageResource.ItemMetadata.Name | Should Be 'MIMEType'
$xlsImageResource.ItemMetadata.Value | Should Be 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
}

# Removing folders used for testing
Remove-RsCatalogItem -RsFolder $pdfFolderPath -Confirm:$false
Remove-RsCatalogItem -RsFolder $xlsxFolderPath -Confirm:$false
Remove-RsCatalogItem -RsFolder $xlsFolderPath -Confirm:$false
}
}
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.