PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Resources/Companion/AdminRole/VMManagerService/PHPApplicationInstaller.cs

https://bitbucket.org/zgramana/azure-accelerators-project
C# | 72 lines | 70 code | 2 blank | 0 comment | 1 complexity | bb3b8e3cd27ca0f96aee6cd4f30f00f7 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.IO;
  6. using System.Net;
  7. using System.Diagnostics;
  8. using System.ServiceModel.Syndication;
  9. using System.Collections.Specialized;
  10. namespace WindowsAzureCompanion.VMManagerService
  11. {
  12. class PHPApplicationInstaller : IInstaller
  13. {
  14. private SyndicationItem product = null;
  15. private string downloadFolder = null;
  16. private string downloadUrl = null;
  17. private string downloadFileName = null;
  18. private string installPath = null;
  19. private string installationFolder = null;
  20. private string applicationPath = null;
  21. private NameValueCollection productProperties = null;
  22. public PHPApplicationInstaller(string installationFolder,
  23. string installPath,
  24. string downloadFolder,
  25. SyndicationItem product,
  26. string productVersion,
  27. NameValueCollection productProperties)
  28. {
  29. this.product = product;
  30. this.productProperties = productProperties;
  31. this.downloadFolder = downloadFolder;
  32. this.downloadUrl = WindowsAzureVMManager.GetDownloadUrlFromProductVersion(product, productVersion);
  33. this.downloadFileName = WindowsAzureVMManager.GetAttributeValueFromProductVersion(product, productVersion, "downloadFileName");
  34. this.installPath = installPath;
  35. this.installationFolder = Path.Combine(installationFolder, installPath.Replace("/", "\\").Trim('\\'));
  36. this.applicationPath = WindowsAzureVMManager.GetAttributeValueFromProductVersion(product, productVersion, "applicationPath");
  37. }
  38. public void Install()
  39. {
  40. try
  41. {
  42. // Create folder for application if it does not exist
  43. if (!Directory.Exists(installationFolder))
  44. {
  45. Directory.CreateDirectory(installationFolder);
  46. }
  47. WindowsAzureVMManager.DownloadAndExtractWebArchive(downloadUrl, downloadFileName, downloadFolder, installationFolder, applicationPath);
  48. // Setup as application in IIS, if specified in the application properties
  49. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  50. string productId = product.ElementExtensions.ReadElementExtensions<string>("productId", "http://www.w3.org/2005/Atom")[0];
  51. if (vmManager.SetAsApplicationInIIS(installPath, installationFolder))
  52. {
  53. Trace.TraceInformation("Successfully installed {0} as IIS Application.", product.Title.Text);
  54. }
  55. else
  56. {
  57. Trace.TraceInformation("Successfully installed {0}", product.Title.Text);
  58. }
  59. }
  60. catch (Exception ex)
  61. {
  62. Trace.TraceError("Unable to install Web Application: {0}", downloadUrl);
  63. throw ex;
  64. }
  65. }
  66. }
  67. }