PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Resources/Companion/AdminRole/VMManagerService/PHPExtensionInstaller.cs

https://bitbucket.org/zgramana/azure-accelerators-project
C# | 82 lines | 69 code | 7 blank | 6 comment | 3 complexity | fe391922f681ab5ed42aba5e52cee318 MD5 | raw file
Possible License(s): LGPL-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ServiceModel.Syndication;
  6. using System.Net;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Xml.Linq;
  10. namespace WindowsAzureCompanion.VMManagerService
  11. {
  12. class PHPExtensionInstaller : IInstaller
  13. {
  14. private SyndicationItem product = null;
  15. private string productVersion = null;
  16. private string downloadFolder = null;
  17. private string downloadUrl = null;
  18. private string downloadFileName = null;
  19. private string installationFolder = null;
  20. public PHPExtensionInstaller(string installationFolder, string downloadFolder, SyndicationItem product, string productVersion)
  21. {
  22. this.product = product;
  23. this.productVersion = productVersion;
  24. this.downloadFolder = downloadFolder;
  25. this.downloadUrl = WindowsAzureVMManager.GetDownloadUrlFromProductVersion(product, productVersion);
  26. this.downloadFileName = WindowsAzureVMManager.GetAttributeValueFromProductVersion(product, productVersion, "downloadFileName");
  27. this.installationFolder = installationFolder;
  28. }
  29. // Install PHP Custom Extension
  30. public void Install()
  31. {
  32. try
  33. {
  34. WindowsAzureVMManager.DownloadAndExtractWebArchive(downloadUrl,
  35. downloadFileName,
  36. downloadFolder,
  37. Path.Combine(installationFolder, WindowsAzureVMManager.ExtensionsFolderForPHP),
  38. null);
  39. // Get php.ini file name
  40. string phpIniFileName = Path.Combine(installationFolder, "php.ini");
  41. // Update php.ini and enabled all extension dll specified
  42. XElement downloadUrlsElement = product.ElementExtensions.Where<SyndicationElementExtension>
  43. (x => x.OuterName == "installerFileChoices").FirstOrDefault().GetObject<XElement>();
  44. // TODO: Use Linq Query instead of foreach loop
  45. foreach (XElement extension in downloadUrlsElement.Elements())
  46. {
  47. if (extension.Attribute("version").Value.Equals(productVersion))
  48. {
  49. // Iterate through properties
  50. foreach (XElement propertyExtension in extension.Elements().First().Elements())
  51. {
  52. if (propertyExtension.Attribute("name").Value.Equals("extensions"))
  53. {
  54. string dllNames = propertyExtension.Attribute("value").Value;
  55. foreach (string dllName in dllNames.Split(','))
  56. {
  57. // Add each extension to php.ini
  58. FileUtils.AppendToFile(phpIniFileName, "extension=" + dllName);
  59. Trace.TraceInformation("Enabled PHP extension {0}", dllName);
  60. }
  61. break;
  62. }
  63. }
  64. }
  65. }
  66. Trace.TraceInformation("Successfully installed PHP Extension {0}", product.Title.Text);
  67. }
  68. catch (Exception ex)
  69. {
  70. Trace.TraceError("Unable to install PHP Extension {0}: {1}", product.Title.Text, ex.Message);
  71. throw ex;
  72. }
  73. }
  74. }
  75. }