Skip to content

Commit

Permalink
re-organize imported files
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeepku committed Sep 29, 2017
1 parent 9d12c28 commit 8823c06
Show file tree
Hide file tree
Showing 1,051 changed files with 44,541 additions and 0 deletions.
Binary file added .migrationtemp/AzureMarkdownRewriterTool.zip
Binary file not shown.
Binary file not shown.
14,588 changes: 14,588 additions & 0 deletions .migrationtemp/AzureMarkdownRewriterTool/AzureVideoRawInformation.json

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
2,468 changes: 2,468 additions & 0 deletions .migrationtemp/AzureMarkdownRewriterTool/HtmlAgilityPack.xml

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8,889 changes: 8,889 additions & 0 deletions .migrationtemp/AzureMarkdownRewriterTool/Newtonsoft.Json.xml

Large diffs are not rendered by default.

Binary file not shown.
12,902 changes: 12,902 additions & 0 deletions .migrationtemp/AzureMarkdownRewriterTool/System.Collections.Immutable.xml

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
3,927 changes: 3,927 additions & 0 deletions .migrationtemp/AzureMarkdownRewriterTool/YamlDotNet.xml

Large diffs are not rendered by default.

Binary file not shown.
241 changes: 241 additions & 0 deletions .migrationtemp/AzureMigrationCore.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
param(
[string]$parameters
)

$workingDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
$repositoryRoot = Split-Path -Parent $workingDirectory
$packagesDirectory = "$workingDirectory\packages"

$systemDefaultVariables = @{
AzureMigrationToolContainerUrl = "https://opbuildstoragesandbox2.blob.core.windows.net/azure-migration"
SourceFolder = $repositoryRoot;
OutputFolder = $repositoryRoot;
LogOutputFolder = "$repositoryRoot\log";
DownloadNugetExeTimeOutInSeconds= 300;
DownloadNugetConfigTimeOutInSeconds= 30;
DocumentUriPrefix = "https://docs.microsoft.com"
}

Function ConsoleErrorAndExit([string]$message, [int]$exitCode)
{
Write-Host -ForegroundColor Red $message
return $exitCode
}

function Write-HostWithTimestamp([string]$output)
{
Write-Host -NoNewline -ForegroundColor Magenta "[$(((get-date).ToUniversalTime()).ToString("HH:mm:ss.ffffffZ"))]: "
Write-Host $output
}

Filter timestamp
{
if (![string]::IsNullOrEmpty($_) -and ![string]::IsNullOrWhiteSpace($_))
{
Write-Host -NoNewline -ForegroundColor Magenta "[$(((get-date).ToUniversalTime()).ToString("HH:mm:ss.ffffffZ"))]: "
}

$_
}

Function GetValueFromVariableName([string]$variableValue, [string]$defaultStringValue)
{
if([string]::IsNullOrEmpty($variableValue))
{
$variableValue = $defaultStringValue
}
return $variableValue
}

Function ParseBoolValue([string]$variableName, [string]$stringValue, [bool]$defaultBoolValue)
{
if([string]::IsNullOrEmpty($stringValue))
{
return $defaultBoolValue
}

try
{
$parsedBoolValue = [System.Convert]::ToBoolean($stringValue)
}
catch
{
Write-Error "variable $variableName does not have a valid bool value: $stringValue. Exception: $($_.Exception.Message)"
}

return $parsedBoolValue
}

Function ParseParameters([string]$parameters)
{
if([string]::IsNullOrEmpty($parameters))
{
return
}

$parameterPortions = $parameters.Split(';')
foreach ($parameterPortion in $parameterPortions)
{
$keyValuePair = $parameterPortion.Split('=')
if ($keyValuePair.Length -eq 2)
{
Set-Variable -Name $keyValuePair[0] -Value $keyValuePair[1] -Scope "Script" -Force
Write-Host "Create script scope variable with input $keyValuePair"
}
else
{
Write-Host "Invalid variable with input $keyValuePair. Ignore it."
}
}
}

Function IsPathExists([string]$path)
{
return Test-Path $path
}

Function CreateFolderIfNotExists([string]$folder)
{
if(!(Test-Path "$folder"))
{
New-Item "$folder" -ItemType Directory
}
}

Function IsNullOrEmptyValue([string]$value)
{
if([String]::IsNullOrEmpty($value))
{
return $true
}
return $false
}

Function RetryCommand
{
param (
[Parameter(Mandatory=$true)][string]$command,
[Parameter(Mandatory=$true)][hashtable]$args,
[Parameter(Mandatory=$false)][int]$maxRetryCount = $systemDefaultVariables.DefaultMaxRetryCount,
[Parameter(Mandatory=$false)][ValidateScript({$_ -ge 0})][int]$retryIncrementalIntervalInSeconds = 10
)

# Setting ErrorAction to Stop is important. This ensures any errors that occur in the command are
# treated as terminating errors, and will be caught by the catch block.
$args.ErrorAction = "Stop"

$currentRetryIteration = 1
$retryIntervalInSeconds = 0

Write-HostWithTimestamp ("Start to run command [{0}] with args [{1}]." -f $command, $($args | Out-String))
do{
try
{
Write-HostWithTimestamp "Calling iteration $currentRetryIteration"
& $command @args

Write-HostWithTimestamp "Command ['$command'] succeeded at iteration $currentRetryIteration."
return
}
Catch
{
Write-HostWithTimestamp "Calling iteration $currentRetryIteration failed, exception: '$($_.Exception.Message)'"
}

if ($currentRetryIteration -ne $maxRetryCount)
{
$retryIntervalInSeconds += $retryIncrementalIntervalInSeconds
Write-HostWithTimestamp "Command ['$command'] failed. Retrying in $retryIntervalInSeconds seconds."
Start-Sleep -Seconds $retryIntervalInSeconds
}
} while (++$currentRetryIteration -le $maxRetryCount)

Write-HostWithTimestamp "Command ['$command'] failed. Maybe the network issues, please retry the build later."
exit 1
}

Function DownloadFile([string]$source, [string]$destination, [bool]$forceDownload, [int]$timeoutSec = -1)
{
if($forceDownload -or !(IsPathExists($destination)))
{
Write-Host "Download file to $destination from $source with force: $forceDownload"
$destinationFolder = Split-Path -Parent $destination
CreateFolderIfNotExists($destinationFolder)
if ($timeoutSec -lt 0)
{
RetryCommand -Command 'Invoke-WebRequest' -Args @{ Uri = $source; OutFile = $destination; }
}
else
{
RetryCommand -Command 'Invoke-WebRequest' -Args @{ Uri = $source; OutFile = $destination; TimeoutSec = $timeoutSec }
}
}
}

echo "Default system value:" $systemDefaultVariables | timestamp
echo "Parse parameters $parameters" | timestamp
ParseParameters($parameters)

# Download azure migration tool
$AzureMigrationToolContainerUrl = GetValueFromVariableName($AzureMigrationToolContainerUrl) ($systemDefaultVariables.AzureMigrationToolContainerUrl)
$AzureMarkdownRewriterToolSource = "$AzureMigrationToolContainerUrl/AzureMarkdownRewriterTool.zip"
$AzureMarkdownRewriterToolDestination = "$workingDirectory\AzureMarkdownRewriterTool.zip"
DownloadFile($AzureMarkdownRewriterToolSource) ($AzureMarkdownRewriterToolDestination) ($true)
$AzureMarkdownRewriterToolUnzipFolder = "$workingDirectory\AzureMarkdownRewriterTool"
if((Test-Path "$AzureMarkdownRewriterToolUnzipFolder"))
{
Remove-Item $AzureMarkdownRewriterToolUnzipFolder -Force -Recurse
}

# Unzip the tool to specified folder
Add-type -AssemblyName "System.IO.Compression.FileSystem"
[System.IO.Compression.ZipFile]::ExtractToDirectory($AzureMarkdownRewriterToolDestination, $AzureMarkdownRewriterToolUnzipFolder)
$AzureMarkdownRewriterTool = "$AzureMarkdownRewriterToolUnzipFolder\AzureMarkdownRewriterTool.exe"

# Prepare configuration file
$sourceFolder = GetValueFromVariableName($SourceFolder) ($systemDefaultVariables.SourceFolder)
$outputFolder = GetValueFromVariableName($OutputFolder) ($systemDefaultVariables.OutputFolder)
$logOutputFolder = GetValueFromVariableName($LogOutputFolder) ($systemDefaultVariables.LogOutputFolder)
$azureTransformArgsJsonContent = "{`"azure_transform_arguments_list`": [{`"source_dir`":`"$sourceFolder`",`"dest_dir`": `"$outputFolder`",`"docs_host_uri_prefix`": `"https://docspilot.azurewebsites.net/en-us/fenxu_azure_migration`"}],`"is_migration`": true}"

$tempJsonFilePostFix = (Get-Date -Format "yyyyMMddhhmmss") + "-" + [System.IO.Path]::GetRandomFileName() + ".json"
$auzreTransformArgsJsonPath = "$AzureMarkdownRewriterToolUnzipFolder\azureTransformArgs$tempJsonFilePostFix"
$azureTransformArgsJsonContent = $azureTransformArgsJsonContent.Replace("\", "\\")
Out-File -FilePath $auzreTransformArgsJsonPath -InputObject $azureTransformArgsJsonContent -Force

# Prepare azure video file
$azureVideoFileDestination = "$AzureMarkdownRewriterToolUnzipFolder\AzureVideoRawInformation.json"
if (IsNullOrEmptyValue($AzureVideoFile))
{
echo "No AzureVideoFile specified. Use the default version in system." | timestamp
$azureVideoFileSource = "$AzureMigrationToolContainerUrl/AzureVideoRawInformation.json"
DownloadFile($azureVideoFileSource) ($azureVideoFileDestination) ($true)
}
else
{
$azureVideoFileDestination = $AzureVideoFile
}
if(!(Test-Path $azureVideoFileDestination))
{
exit ConsoleErrorAndExit("Can't find azure video file in path: $azureVideoFileSource. Stop migration.") (1)
}

# Prepare parameters
$documentUriPrefix = GetValueFromVariableName($DocumentUriPrefix) ($systemDefaultVariables.DocumentUriPrefix)
if(!(Test-Path $logOutputFolder))
{
New-Item $logOutputFolder -ItemType directory
}
$logFile = "$logOutputFolder\migrationRawLog.txt"


&"$AzureMarkdownRewriterTool" "$repositoryRoot" "$auzreTransformArgsJsonPath" "$documentUriPrefix" "$azureVideoFileDestination" | Tee-Object -file $logFile


if ($LASTEXITCODE -ne 0)
{
exit ConsoleErrorAndExit("Migration has some warnings or errors. Please see the detail in log file at `"$logFile`".") (1)
}

echo "Migration succeed." | timestamp
exit 0
23 changes: 23 additions & 0 deletions AzureMigration.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param(
[string]$azureMigrationCorePowershellUrl = "https://opbuildstoragesandbox2.blob.core.windows.net/azure-migration/AzureMigrationCore.ps1",
[string]$parameters
)
# Main
$errorActionPreference = 'Stop'

# Step-1 Download buildcore script to local
echo "download azure migration core script to local with source url: $azureMigrationCorePowershellUrl"
$workingRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition

$azureMigrationCoreDestinationFolder = "$workingRoot\.migrationtemp"
if(!(Test-Path "$azureMigrationCoreDestinationFolder"))
{
New-Item "$azureMigrationCoreDestinationFolder" -ItemType Directory
}
$azureMigrationCoreDestination = "$azureMigrationCoreDestinationFolder\AzureMigrationCore.ps1"
Invoke-WebRequest $azureMigrationCorePowershellUrl -OutFile "$azureMigrationCoreDestination"

# Step-2: Run build core
echo "run auzre migration core script with parameters: $parameters"
& "$azureMigrationCoreDestination" "$parameters"
exit $LASTEXITCODE
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8823c06

Please sign in to comment.