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

Improve use of Write-Log and exceptions #97

Merged
merged 9 commits into from
Jan 30, 2018
48 changes: 22 additions & 26 deletions Extensions/ConvertFrom-ExistingIapSubmission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function Add-ToElement
PS C:\>Add-ToElement -Element $root -Comment "Comment1", "Comment2" -Attribute @{ "Attrib1"="Val1"; "Attrib2"="Val2" }

Adds two comments and two attributes to the root element of the XML document.

#>
param(
[Parameter(Mandatory)]
Expand Down Expand Up @@ -268,7 +268,7 @@ function Add-Icon
be included with a non-empty value. This is fine if the Listing has an icon defined,
but if it doesn't, then we want to include the element, but commented out so that users
know later what they need to add if they wish to include an icon at some future time.
We will create/add the icon node the way we do in all other cases so that we have its XML,
We will create/add the icon node the way we do in all other cases so that we have its XML,
but if we then determine that there is no icon for that listing, we'll convert the element
to its XML string representation that we can add as a comment, and then remove the actual
node.
Expand Down Expand Up @@ -368,7 +368,7 @@ function ConvertFrom-Listing
xml:lang="{0}"
Release="{1}"/>', $Lang, $Release))

Add-Title -Xml $Xml -Listing $Listing
Add-Title -Xml $Xml -Listing $Listing
Add-Description -Xml $Xml -Listing $Listing
$icon = Add-Icon -Xml $Xml -Listing $Listing

Expand Down Expand Up @@ -482,11 +482,10 @@ function Show-ImageFileNames
return
}

$output = @()
$output += "You now need to find all of your images and place them here: <ImagesRootPath>\$Release\<langcode>\..."
$output += " where <ImagesRootPath> is the path defined in your config file,"
$output += " and <langcode> is the same langcode for the directory of the PDP file referencing those images."
Write-Log $($output -join [Environment]::NewLine)
Write-Log -Message @(
"You now need to find all of your images and place them here: <ImagesRootPath>\$Release\<langcode>\...",
" where <ImagesRootPath> is the path defined in your config file,",
" and <langcode> is the same langcode for the directory of the PDP file referencing those images.")

# Quick analysis to help teams out if they need to do anything special with their PDP's

Expand Down Expand Up @@ -514,28 +513,26 @@ function Show-ImageFileNames
# Now show the user the image filenames
if ($imagesDiffer)
{
$output = @()
$output += "It appears that you don't have consistent images across all languages."
$output += "While StoreBroker supports this scenario, some localization systems may"
$output += "not support this without additional work. Please refer to the FAQ in"
$output += "the documentation for more info on how to best handle this scenario."
Write-Log $($output -join [Environment]::NewLine) -Level Warning
Write-Log -Level Warning -Message @(
"It appears that you don't have consistent images across all languages.",
"While StoreBroker supports this scenario, some localization systems may",
"not support this without additional work. Please refer to the FAQ in",
"the documentation for more info on how to best handle this scenario.")

$output = @()
$output += "The currently referenced image filenames, per langcode, are as follows:"
foreach ($langCode in ($LangImageNames.Keys.GetEnumerator() | Sort-Object))
{
$output += " * [$langCode]: " + ($LangImageNames.$langCode -join ", ")
}
Write-Log $($output -join [Environment]::NewLine)

Write-Log $output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're here, I'd ask that you explicitly add the -Message at the same time, just to help us get up to the consistency we've been working towards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went all-in and replaced all instances of Write-Log that used implicit -Message parameter.

}
else
{
$output = @()
$output += "Every language that has a PDP references the following images:"
$output += "`t$($seenImages -join `"`n`t`")"
Write-Log $($output -join [Environment]::NewLine)
Write-Log -Message @(
"Every language that has a PDP references the following images:",
"`t$($seenImages -join `"`n`t`")")
}
}

Expand Down Expand Up @@ -580,7 +577,7 @@ function Main
}
catch
{
Write-Log "Error creating [$lang] PDP: $($Error[0].Exception.Message )" -Level Error
Write-Log "Error creating [$lang] PDP:" -Exception $_ -Level Error
throw
}
}
Expand All @@ -592,11 +589,10 @@ function Main
}
else
{
$output = @()
$output += "No PDPs were generated."
$output += "Please verify that this existing In-App Product has one or more language listings that this extension can convert,"
$output += "otherwise you can start fresh using the sample PDP\InAppProductDescription.xml as a starting point."
Write-Log $($output -join [Environment]::NewLine) -Level Warning
Write-Log -Level Warning -Message @(
"No PDPs were generated.",
"Please verify that this existing In-App Product has one or more language listings that this extension can convert,",
"otherwise you can start fresh using the sample PDP\InAppProductDescription.xml as a starting point.")
}
}

Expand Down
41 changes: 19 additions & 22 deletions Extensions/ConvertFrom-ExistingSubmission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function Add-ToElement
PS C:\>Add-ToElement -Element $root -Comment "Comment1", "Comment2" -Attribute @{ "Attrib1"="Val1"; "Attrib2"="Val2" }

Adds two comments and two attributes to the root element of the XML document.

#>
param(
[Parameter(Mandatory)]
Expand Down Expand Up @@ -229,7 +229,7 @@ function Add-ToChildren
}

Add-ToElement @params
$CountFrom++
$CountFrom++
}
}

Expand Down Expand Up @@ -502,7 +502,7 @@ function Add-ScreenshotCaptions
# https://github.com/PowerShell/PSScriptAnalyzer/issues/699
$captionImageMap[$description] = @{}
}

($captionImageMap[$description])[$imageType] = $fileName
}

Expand Down Expand Up @@ -903,7 +903,7 @@ function ConvertFrom-Listing
xml:lang="{0}"
Release="{1}"/>', $Lang, $Release))

Add-AppStoreName -Xml $Xml -Listing $Listing
Add-AppStoreName -Xml $Xml -Listing $Listing
Add-Keywords -Xml $Xml -Listing $Listing
Add-Description -Xml $Xml -Listing $Listing
Add-ReleaseNotes -Xml $Xml -Listing $Listing
Expand Down Expand Up @@ -1012,11 +1012,10 @@ function Show-ImageFileNames
return
}

$output = @()
$output += "You now need to find all of your images and place them here: <ImagesRootPath>\$Release\<langcode>\..."
$output += " where <ImagesRootPath> is the path defined in your config file,"
$output += " and <langcode> is the same langcode for the directory of the PDP file referencing those images."
Write-Log $($output -join [Environment]::NewLine)
Write-Log -Message @(
"You now need to find all of your images and place them here: <ImagesRootPath>\$Release\<langcode>\...",
" where <ImagesRootPath> is the path defined in your config file,",
" and <langcode> is the same langcode for the directory of the PDP file referencing those images.")

# Quick analysis to help teams out if they need to do anything special with their PDP's

Expand Down Expand Up @@ -1044,28 +1043,26 @@ function Show-ImageFileNames
# Now show the user the image filenames
if ($imagesDiffer)
{
$output = @()
$output += "It appears that you don't have consistent images across all languages."
$output += "While StoreBroker supports this scenario, some localization systems may"
$output += "not support this without additional work. Please refer to the FAQ in"
$output += "the documentation for more info on how to best handle this scenario."
Write-Log $($output -join [Environment]::NewLine) -Level Warning
Write-Log -Level Warning -Message @(
"It appears that you don't have consistent images across all languages.",
"While StoreBroker supports this scenario, some localization systems may",
"not support this without additional work. Please refer to the FAQ in",
"the documentation for more info on how to best handle this scenario.")

$output = @()
$output += "The currently referenced image filenames, per langcode, are as follows:"
foreach ($langCode in ($LangImageNames.Keys.GetEnumerator() | Sort-Object))
{
$output += " * [$langCode]: " + ($LangImageNames.$langCode -join ", ")
}
Write-Log $($output -join [Environment]::NewLine)

Write-Log $output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

}
else
{
$output = @()
$output += "Every language that has a PDP references the following images:"
$output += "`t$($seenImages -join `"`n`t`")"
Write-Log $($output -join [Environment]::NewLine)
Write-Log -Message @(
"Every language that has a PDP references the following images:",
"`t$($seenImages -join `"`n`t`")")
}
}

Expand Down Expand Up @@ -1105,7 +1102,7 @@ function Main
}
catch
{
Write-Log "Error creating [$lang] PDP: $($Error[0].Exception.Message )" -Level Error
Write-Log "Error creating [$lang] PDP:" -Exception $_ -Level Error
throw
}
}
Expand Down
Loading