Guest User

Untitled

a guest
Jun 13th, 2013
33
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <Environment name="cnv">
  2. <Files>
  3. <File uri="http://x/xqy_load.addressbook.vendor.div13.xquery"/>
  4. <File uri="http:/x/pip_load.vendor.div13.pipeline"/>
  5. </Files>
  6.  
  7. <Replacements>
  8. <Replacement match="ddtek:sql-insert(.*?)," replacement="ddtek:sql-insert(&quot;sqlserver_us09sqldev_1433:JDE_CNV.CNVDTA.F0101Z2&quot;,"/>
  9. <Replacement match="&lt;collection name=(.*?)url=(.*?)/&gt;" replacement="&lt;collection name=&quot;sqlserver_us09sqldev_1433&quot; url=&quot;jdbc:xquery:sqlserver://us09sqldev:1433;schema=CNVDTA;table=F0101Z2;user=sa;password=x;xmlforest=true;DatabaseName=JDE_CNV;urltype=.xml&quot;/&gt;"/>
  10. <Replacement match="&lt;xquery-collection name=(.*?)value=(.*?)/&gt;" replacement="&lt;xquery-collection name=&quot;sqlserver_us09sqldev_1433&quot; value=&quot;jdbc:xquery:sqlserver://us09sqldev:1433;schema=CNVDTA;table=F0101Z2;user=sa;password=x;xmlforest=true;DatabaseName=JDE_CNV;urltype=.xml&quot;/&gt;"/>
  11. <Replacement match="&lt;merged-xquery-collection name=(.*?)value=(.*?)/&gt;" replacement="&lt;merged-xquery-collection name=&quot;sqlserver_us09sqldev_1433&quot; value=&quot;jdbc:xquery:sqlserver://us09sqldev:1433;schema=CNVDTA;table=F0101Z2;user=sa;password=x;xmlforest=true;DatabaseName=JDE_CNV;urltype=.xml&quot;/&gt;"/>
  12. </Replacements>
  13.  
  14. </Environment>
  15.  
  16.  
  17.  
  18. function getFromUri([String]$uri, [System.Text.Encoding]$encoding = [System.Text.Encoding]::UTF8)
  19. {
  20. Write-Host "`t`t=> GET ($encoding) $([System.IO.Path]::GetFileName($uri))";
  21. $webClient = new-object System.Net.WebClient;
  22. $webClient.Encoding = $encoding
  23. $webClient.UseDefaultCredentials = $true;
  24. return $webClient.DownloadString($uri);
  25. };
  26.  
  27. function putToUri([String]$uri, [String]$data, [System.Text.Encoding]$encoding = [System.Text.Encoding]::UTF8)
  28. {
  29. Write-Host "`t`t=> PUT ($encoding) $([System.IO.Path]::GetFileName($uri))";
  30. $webClient = new-object System.Net.WebClient;
  31. $webClient.Encoding = $encoding;
  32. $webClient.UseDefaultCredentials = $true;
  33. return $webClient.UploadString($uri,"PUT",$data);
  34. };
  35.  
  36. function executeRegex([String]$uri, [System.Xml.XmlElement]$node)
  37. {
  38. Write-Host "`t=> Executing replacement on $([System.IO.Path]::GetFileName($uri))";
  39. $file = getFromUri -uri $uri;
  40. $node.Replacement | foreach { $file = $file -replace $_.match, $_.replacement };
  41. putToUri -uri $uri -data $file;
  42. };
  43.  
  44. # main entry
  45. function AriadneChangeEnvironment([string]$toEnvironment, [string]$adminXmlUri)
  46. {
  47. Write-Host "=> Changing Ariadne Environment => '$toEnvironment'";
  48. $adminXml = [xml](getFromUri -uri $adminXmlUri);
  49. $toEnvironmentXml = $adminXml.Administration.Environments.Environment | where { $_.name -eq $toEnvironment };
  50. $toEnvironmentXml.Files.File | foreach { executeRegex -uri $_.uri -node $toEnvironmentXml.Replacements };
  51. Write-Host "=> Finished.";
  52. };
RAW Paste Data