From 43e3728c2481fae875dbf494a539f46ce9063f88 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 28 Aug 2012 13:45:14 +0300 Subject: [PATCH 1/2] refactoring --- .../WPIApplicationGallery.cs | 7 +- .../WebsitePanel.Server/Code/WPIHelper.cs | 554 +++++++++--------- .../WebsitePanel.Server/WindowsServer.asmx.cs | 4 +- .../WebApplicationGalleryInstall.ascx.cs | 3 +- 4 files changed, 287 insertions(+), 281 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIs60/WPIWebApplicationGallery/WPIApplicationGallery.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIs60/WPIWebApplicationGallery/WPIApplicationGallery.cs index 2b3d8410..1006c683 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIs60/WPIWebApplicationGallery/WPIApplicationGallery.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIs60/WPIWebApplicationGallery/WPIApplicationGallery.cs @@ -237,7 +237,7 @@ namespace WebsitePanel.Providers.Web.WPIWebApplicationGallery WpiHelper wpi = GetWpiHelper(UserId); List missingDeps = new List(); - foreach (Product product in wpi.GetProductsWithDependencies(new string[] { id })) + foreach (Product product in wpi.GetProductsToInstallWithDependencies(new string[] { id })) { if (product.ProductId != id) { @@ -400,13 +400,16 @@ namespace WebsitePanel.Providers.Web.WPIWebApplicationGallery protected static DeploymentParameter MakeDeploymentParameterFromDecalredParameter(DeclaredParameter d) { + + DeploymentParameter r = new DeploymentParameter(); r.Name = d.Name; r.FriendlyName = d.FriendlyName; r.DefaultValue = d.DefaultValue; r.Description = d.Description; + #pragma warning disable 612,618 - r.WellKnownTags = (DeploymentParameterWellKnownTag) d.Tags; + r.WellKnownTags = DeploymentParameterWellKnownTag.ALLKNOWN & (DeploymentParameterWellKnownTag) d.Tags; if (null != d.Validation) { r.ValidationKind = (DeploymentParameterValidationKind) d.Validation.Kind; diff --git a/WebsitePanel/Sources/WebsitePanel.Server/Code/WPIHelper.cs b/WebsitePanel/Sources/WebsitePanel.Server/Code/WPIHelper.cs index 8d948c78..61f66d31 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/Code/WPIHelper.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/Code/WPIHelper.cs @@ -50,12 +50,8 @@ namespace WebsitePanel.Server.Code public class WpiHelper { - #region public consts - public const string DeafultLanguage = "en"; - #endregion - #region private fields private readonly List _feeds; @@ -68,7 +64,7 @@ namespace WebsitePanel.Server.Code private bool _installCompleted; private InstallManager _installManager; private string _LogFileDirectory = string.Empty; - string _resourceLanguage = DeafultLanguage; + private string _resourceLanguage = DeafultLanguage; private const DeploymentWellKnownTag databaseEngineTags = DeploymentWellKnownTag.Sql | DeploymentWellKnownTag.MySql | @@ -78,6 +74,8 @@ namespace WebsitePanel.Server.Code #endregion private fields + #region Public interface + public WpiHelper(IEnumerable feeds) { _feeds = new List(); @@ -86,65 +84,19 @@ namespace WebsitePanel.Server.Code Initialize(); } - private void Initialize() + public string GetLogFileDirectory() { - // insert Main WebPI xml file - if (!_feeds.Contains(MainWpiFeed, StringComparer.OrdinalIgnoreCase)) - { - _feeds.Insert(0, MainWpiFeed); - } - - // create cache folder if not exists - //_webPIinstallersFolder = Environment.ExpandEnvironmentVariables(@"%LocalAppData%\Microsoft\Web Platform Installer\installers"); - _webPIinstallersFolder = Path.Combine( - Environment.ExpandEnvironmentVariables("%SystemRoot%"), - "Temp\\zoo.wpi\\AppData\\Local\\Microsoft\\Web Platform Installer\\installers" ); - - if (!Directory.Exists(_webPIinstallersFolder)) - { - Directory.CreateDirectory(_webPIinstallersFolder); - } - - // load feeds - _productManager = new ProductManager(); - - - foreach (string feed in _feeds) - { - Log(string.Format("Loading {0}", feed)); - if (feed.StartsWith("https://www.microsoft.com", StringComparison.OrdinalIgnoreCase)) - { - _productManager.Load(new Uri(feed), true, true, true, _webPIinstallersFolder); - } - else - { - _productManager.LoadExternalFile(new Uri(feed)); - } - } - - Log(string.Format("{0} products loaded", _productManager.Products.Count)); - - LogDebugInfo(); + return _LogFileDirectory; } - public void SetResourceLanguage(string resourceLanguage) - { - _resourceLanguage = resourceLanguage; - _productManager.SetResourceLanguage(resourceLanguage); - } - - #region Public interface - - public List GetProducts() - { - return GetProducts(null,null); - } + + #region Languages public List GetLanguages() { List languages = new List(); - foreach (Product product in GetProducts()) + foreach (Product product in GetProductsToInstall(null, null)) { if (null!=product.Installers) { @@ -162,30 +114,131 @@ namespace WebsitePanel.Server.Code return languages; } - public void CancelInstallProducts() + public void SetResourceLanguage(string resourceLanguage) { - if (_installManager!= null) - { - _installManager.Cancel(); - } + _resourceLanguage = resourceLanguage; + _productManager.SetResourceLanguage(resourceLanguage); } - private List GetInstallers(List productsToInstall, Language lang) + #endregion + + #region Tabs + public ReadOnlyCollection GetTabs() { - List installersToUse = new List(); - foreach (Product product in productsToInstall) + return _productManager.Tabs; + } + + public Tab GetTab(string tabId) + { + return _productManager.GetTab(tabId); + } + #endregion + + + #region Keywords + public ReadOnlyCollection GetKeywords() + { + return _productManager.Keywords; + } + + public bool IsKeywordApplication(Keyword keyword) + { + //if all products are Application + foreach (Product product in keyword.Products) { - Installer installer = product.GetInstaller(lang); - if (null != installer) + if (!product.IsApplication) { - installersToUse.Add(installer); + return false; } } - return installersToUse; + return true; + + } + #endregion + + + + #region Products + public List GetProductsToInstall(string FeedLocation, string keywordId) + { + Keyword keyword = null; + if (!string.IsNullOrEmpty(keywordId)) + { + keyword = _productManager.GetKeyword(keywordId); + } + + List products = new List(); + + foreach (Product product in _productManager.Products) + { + if (!string.IsNullOrEmpty(FeedLocation) && string.Compare(product.FeedLocation, FeedLocation, StringComparison.OrdinalIgnoreCase) != 0) + { + // if FeedLocation defined, then select products only from this feed location + continue; + } + + if (null == product.Installers || product.Installers.Count == 0) + { + // skip this product + // usually product without intsallers user as product detection + continue; + } + + if (null == keyword) + { + products.Add(product); + } + else if (product.Keywords.Contains(keyword)) + { + products.Add(product); + } + } + + //Sort by Title + products.Sort(delegate(Product a, Product b) + { + return a.Title.CompareTo(b.Title); + }); + + return products; } - public List GetProducts(IEnumerable productIdsToInstall) + public List GetProductsFiltered(string filter) + { + + List products = new List(); + + foreach (Product product in _productManager.Products) + { + if (null == product.Installers || product.Installers.Count == 0) + { + // skip this product + // usually product without intsallers user as product detection + continue; + } + + if (string.IsNullOrEmpty(filter)) + { + products.Add(product); + } + else if (product.Title.ToLower().Contains(filter.ToLower())) + { + products.Add(product); + } + } + + //Sort by Title + products.Sort(delegate(Product a, Product b) + { + return a.Title.CompareTo(b.Title); + }); + + + return products; + } + + public List GetProductsToInstall(IEnumerable productIdsToInstall) { List productsToInstall = new List(); @@ -213,9 +266,8 @@ namespace WebsitePanel.Server.Code return productsToInstall; } - - - public List GetProductsWithDependencies(IEnumerable productIdsToInstall ) + + public List GetProductsToInstallWithDependencies(IEnumerable productIdsToInstall ) { List updatedProductIdsToInstall = new List(); // add iis chioce product to force iis (not-iisexpress/webmatrix) branch @@ -249,40 +301,105 @@ namespace WebsitePanel.Server.Code return productsToInstall; } - public string GetLogFileDirectory() + public Product GetProduct(string productId) { - return _LogFileDirectory; + return _productManager.GetProduct(productId); } - - private Language GetLanguage(string languageId) + public void InstallProducts( + IEnumerable productIdsToInstall, + bool installDependencies, + string languageId, + EventHandler installStatusUpdatedHandler, + EventHandler installCompleteHandler) { - if (!string.IsNullOrEmpty(languageId)) + + List productsToInstall = null; + if (installDependencies) { - return _productManager.GetLanguage(languageId); + // Get products & dependencies list to install + productsToInstall = GetProductsToInstallWithDependencies(productIdsToInstall); + } + else + { + productsToInstall = GetProductsToInstall(productIdsToInstall); + } + + + + // Get installers + Language lang = GetLanguage(languageId); + List installersToUse = GetInstallers(productsToInstall, lang); + + + // Prepare install manager & set event handlers + _installManager = new InstallManager(); + _installManager.Load(installersToUse); + + + if (null != installStatusUpdatedHandler) + { + _installManager.InstallerStatusUpdated += installStatusUpdatedHandler; + } + _installManager.InstallerStatusUpdated += InstallManager_InstallerStatusUpdated; + + if (null != installCompleteHandler) + { + _installManager.InstallCompleted += installCompleteHandler; + } + _installManager.InstallCompleted += InstallManager_InstallCompleted; + + // Download installer files + foreach (InstallerContext installerContext in _installManager.InstallerContexts) + { + if (null != installerContext.Installer.InstallerFile) + { + string failureReason; + if (!_installManager.DownloadInstallerFile(installerContext, out failureReason)) + { + Log(string.Format("DownloadInstallerFile '{0}' failed: {1}", + installerContext.Installer.InstallerFile.InstallerUrl, failureReason)); + } + } + } + + if (installersToUse.Count > 0) + { + // Start installation + _installCompleted = false; + Log("_installManager.StartInstallation()"); + _installManager.StartInstallation(); + + Log("_installManager.StartInstallation() done"); + while (!_installCompleted) + { + Thread.Sleep(100); + } + + //save logs + SaveLogDirectory(); + + + _installCompleted = false; + } + else + { + Log("Nothing to install"); } - return _productManager.GetLanguage(DeafultLanguage); } - - // GetTabs - public ReadOnlyCollection GetTabs() + public void CancelInstallProducts() { - return _productManager.Tabs; + if (_installManager != null) + { + _installManager.Cancel(); + } } - public Tab GetTab(string tabId) - { - return _productManager.GetTab(tabId); - } - - // GetKeywords - public ReadOnlyCollection GetKeywords() - { - return _productManager.Keywords; - } + #endregion + #region Applications public List GetApplications(string keywordId) { @@ -336,12 +453,6 @@ namespace WebsitePanel.Server.Code return products; } - public Product GetProduct(string productId) - { - - return _productManager.GetProduct(productId); - } - public IList GetAppDecalredParameters(string productId) { Product app = _productManager.GetProduct(productId); @@ -349,89 +460,6 @@ namespace WebsitePanel.Server.Code return appInstaller.MSDeployPackage.DeclaredParameters; } - public void InstallProducts( - IEnumerable productIdsToInstall, - bool installDependencies, - string languageId, - EventHandler installStatusUpdatedHandler, - EventHandler installCompleteHandler) - { - - List productsToInstall = null; - if (installDependencies) - { - // Get products & dependencies list to install - productsToInstall = GetProductsWithDependencies(productIdsToInstall); - } - else - { - productsToInstall = GetProducts(productIdsToInstall); - } - - - - // Get installers - Language lang = GetLanguage(languageId); - List installersToUse = GetInstallers(productsToInstall, lang ); - - - // Prepare install manager & set event handlers - _installManager = new InstallManager(); - _installManager.Load(installersToUse); - - - if (null != installStatusUpdatedHandler) - { - _installManager.InstallerStatusUpdated += installStatusUpdatedHandler; - } - _installManager.InstallerStatusUpdated += InstallManager_InstallerStatusUpdated; - - if (null != installCompleteHandler) - { - _installManager.InstallCompleted += installCompleteHandler; - } - _installManager.InstallCompleted += InstallManager_InstallCompleted; - - // Download installer files - foreach (InstallerContext installerContext in _installManager.InstallerContexts) - { - if (null != installerContext.Installer.InstallerFile) - { - string failureReason; - if (!_installManager.DownloadInstallerFile(installerContext, out failureReason)) - { - Log(string.Format("DownloadInstallerFile '{0}' failed: {1}", - installerContext.Installer.InstallerFile.InstallerUrl, failureReason)); - } - } - } - - if (installersToUse.Count > 0) - { - // Start installation - _installCompleted = false; - Log("_installManager.StartInstallation()"); - _installManager.StartInstallation(); - - Log("_installManager.StartInstallation() done"); - while (!_installCompleted) - { - Thread.Sleep(100); - } - - //save logs - SaveLogDirectory(); - - - _installCompleted = false; - } - else - { - Log("Nothing to install"); - } - - } - public bool InstallApplication( string appId, List updatedValues, @@ -504,26 +532,79 @@ namespace WebsitePanel.Server.Code return !logger.IsFailed; } - public bool IsKeywordApplication(Keyword keyword) - { - //if all products are Application - foreach (Product product in keyword.Products) - { - if (!product.IsApplication) - { - return false; - } - } - - return true; - - } - + #endregion #endregion Public interface #region private members + private void Initialize() + { + // insert Main WebPI xml file + if (!_feeds.Contains(MainWpiFeed, StringComparer.OrdinalIgnoreCase)) + { + _feeds.Insert(0, MainWpiFeed); + } + + // create cache folder if not exists + //_webPIinstallersFolder = Environment.ExpandEnvironmentVariables(@"%LocalAppData%\Microsoft\Web Platform Installer\installers"); + _webPIinstallersFolder = Path.Combine( + Environment.ExpandEnvironmentVariables("%SystemRoot%"), + "Temp\\zoo.wpi\\AppData\\Local\\Microsoft\\Web Platform Installer\\installers"); + + if (!Directory.Exists(_webPIinstallersFolder)) + { + Directory.CreateDirectory(_webPIinstallersFolder); + } + + // load feeds + _productManager = new ProductManager(); + + + foreach (string feed in _feeds) + { + Log(string.Format("Loading {0}", feed)); + if (feed.StartsWith("https://www.microsoft.com", StringComparison.OrdinalIgnoreCase)) + { + _productManager.Load(new Uri(feed), true, true, true, _webPIinstallersFolder); + } + else + { + _productManager.LoadExternalFile(new Uri(feed)); + } + } + + Log(string.Format("{0} products loaded", _productManager.Products.Count)); + + LogDebugInfo(); + } + + private Language GetLanguage(string languageId) + { + if (!string.IsNullOrEmpty(languageId)) + { + return _productManager.GetLanguage(languageId); + } + + return _productManager.GetLanguage(DeafultLanguage); + } + + + private List GetInstallers(List productsToInstall, Language lang) + { + List installersToUse = new List(); + foreach (Product product in productsToInstall) + { + Installer installer = product.GetInstaller(lang); + if (null != installer) + { + installersToUse.Add(installer); + } + } + + return installersToUse; + } + private void LogDebugInfo() { StringBuilder sb = new StringBuilder(); @@ -567,85 +648,6 @@ namespace WebsitePanel.Server.Code //#endif } - public List GetProducts(string FeedLocation, string keywordId) - { - Keyword keyword = null; - if (!string.IsNullOrEmpty(keywordId)) - { - keyword = _productManager.GetKeyword(keywordId); - } - - List products = new List(); - - foreach (Product product in _productManager.Products) - { - if (!string.IsNullOrEmpty(FeedLocation) && string.Compare(product.FeedLocation, FeedLocation, StringComparison.OrdinalIgnoreCase) != 0) - { - // if FeedLocation defined, then select products only from this feed location - continue; - } - - if (null == product.Installers || product.Installers.Count == 0) - { - // skip this product - // usually product without intsallers user as product detection - continue; - } - - if (null == keyword) - { - products.Add(product); - } - else if (product.Keywords.Contains(keyword)) - { - products.Add(product); - } - } - - //Sort by Title - products.Sort(delegate(Product a, Product b) - { - return a.Title.CompareTo(b.Title); - }); - - return products; - } - - public List GetProductsFiltered(string filter) - { - - List products = new List(); - - foreach (Product product in _productManager.Products) - { - if (null == product.Installers || product.Installers.Count == 0) - { - // skip this product - // usually product without intsallers user as product detection - continue; - } - - if (string.IsNullOrEmpty(filter)) - { - products.Add(product); - } - else if (product.Title.ToLower().Contains(filter.ToLower())) - { - products.Add(product); - } - } - - //Sort by Title - products.Sort(delegate(Product a, Product b) - { - return a.Title.CompareTo(b.Title); - }); - - - return products; - } - - private void InstallManager_InstallCompleted(object sender, EventArgs e) { Log("Installation completed"); diff --git a/WebsitePanel/Sources/WebsitePanel.Server/WindowsServer.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/WindowsServer.asmx.cs index 01827978..8940e917 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/WindowsServer.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/WindowsServer.asmx.cs @@ -376,7 +376,7 @@ namespace WebsitePanel.Server feedLocation = feeds.GetEnumerator().Current; } - List products = wpi.GetProducts(feedLocation, keywordId); + List products = wpi.GetProductsToInstall(feedLocation, keywordId); if (products != null) { @@ -573,7 +573,7 @@ namespace WebsitePanel.Server WpiHelper wpi = GetWpiFeed(); List result = new List(); - foreach (Product product in wpi.GetProductsWithDependencies(products)) + foreach (Product product in wpi.GetProductsToInstallWithDependencies(products)) { result.Add(ProductToWPIProduct(product)); } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebApplicationGalleryInstall.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebApplicationGalleryInstall.ascx.cs index fdb04326..f20058b4 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebApplicationGalleryInstall.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebApplicationGalleryInstall.ascx.cs @@ -46,7 +46,8 @@ namespace WebsitePanel.Portal { try { - GalleryApplicationResult appResult = ES.Services.WebApplicationGallery.GetGalleryApplicationDetails(PanelSecurity.PackageId, + GalleryApplicationResult appResult = + ES.Services.WebApplicationGallery.GetGalleryApplicationDetails(PanelSecurity.PackageId, PanelRequest.ApplicationID); // check for errors if (!appResult.IsSuccess) From c4c1424eb461005239aadae7abcf4560de94023c Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 28 Aug 2012 13:46:04 +0300 Subject: [PATCH 2/2] fix for Joomla installation --- .../WebAppGallery/DeploymentParameter.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebAppGallery/DeploymentParameter.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebAppGallery/DeploymentParameter.cs index 53949106..4fa34ef8 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebAppGallery/DeploymentParameter.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebAppGallery/DeploymentParameter.cs @@ -44,6 +44,7 @@ namespace WebsitePanel.Providers.WebAppGallery public enum DeploymentParameterWellKnownTag : long { None = 0L, + AppHostConfig = 1L, AppPoolConfig = 2L, Boolean = 4L, @@ -83,6 +84,49 @@ namespace WebsitePanel.Providers.WebAppGallery Ignore = 68719476736L, AutoGenerated = 137438953472L, SingleLineConnectionString = 274877906944L, + //SiteUserPassword = 549755813888, + + + ALLKNOWN = + AppHostConfig | + AppPoolConfig | + Boolean | + ComObject32 | + ComObject64 | + DBAdminPassword | + DBAdminUserName | + DBConnectionString | + DBName | + DBServer | + DBUserName | + DBUserPassword | + FlatFile | + Hidden | + IisApp | + MetaKey | + MySql | + MySqlConnectionString | + New | + RegKey | + SetAcl | + Sql | + SqLite | + SqlConnectionString | + Password | + PhysicalPath | + VistaDB | + Validate | + SqLiteConnectionString | + SqlCE | + NoStore | + AppURL | + NoProtocol | + DBUserConnectionString | + DBAdminConnectionString | + WebPIApplicationID | + Ignore | + AutoGenerated | + SingleLineConnectionString } [Serializable]