refactoring
This commit is contained in:
parent
bebb9efb6f
commit
43e3728c24
4 changed files with 287 additions and 281 deletions
|
@ -237,7 +237,7 @@ namespace WebsitePanel.Providers.Web.WPIWebApplicationGallery
|
|||
WpiHelper wpi = GetWpiHelper(UserId);
|
||||
|
||||
List<string> missingDeps = new List<string>();
|
||||
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;
|
||||
|
|
|
@ -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<string> _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<string> feeds)
|
||||
{
|
||||
_feeds = new List<string>();
|
||||
|
@ -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);
|
||||
return _LogFileDirectory;
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
public void SetResourceLanguage(string resourceLanguage)
|
||||
{
|
||||
_resourceLanguage = resourceLanguage;
|
||||
_productManager.SetResourceLanguage(resourceLanguage);
|
||||
}
|
||||
|
||||
#region Public interface
|
||||
|
||||
public List<Product> GetProducts()
|
||||
{
|
||||
return GetProducts(null,null);
|
||||
}
|
||||
|
||||
#region Languages
|
||||
public List<Language> GetLanguages()
|
||||
{
|
||||
List<Language> languages = new List<Language>();
|
||||
|
||||
foreach (Product product in GetProducts())
|
||||
foreach (Product product in GetProductsToInstall(null, null))
|
||||
{
|
||||
if (null!=product.Installers)
|
||||
{
|
||||
|
@ -162,111 +114,15 @@ 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<Installer> GetInstallers(List<Product> productsToInstall, Language lang)
|
||||
{
|
||||
List<Installer> installersToUse = new List<Installer>();
|
||||
foreach (Product product in productsToInstall)
|
||||
{
|
||||
Installer installer = product.GetInstaller(lang);
|
||||
if (null != installer)
|
||||
{
|
||||
installersToUse.Add(installer);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
return installersToUse;
|
||||
}
|
||||
|
||||
public List<Product> GetProducts(IEnumerable<string> productIdsToInstall)
|
||||
{
|
||||
List<Product> productsToInstall = new List<Product>();
|
||||
|
||||
foreach (string productId in productIdsToInstall)
|
||||
{
|
||||
Log(string.Format("Product {0} to be installed", productId));
|
||||
|
||||
Product product = _productManager.GetProduct(productId);
|
||||
if (null == product)
|
||||
{
|
||||
Log(string.Format("Product {0} not found", productId));
|
||||
continue;
|
||||
}
|
||||
if (product.IsInstalled(true))
|
||||
{
|
||||
Log(string.Format("Product {0} is installed", product.Title));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(string.Format("Adding product {0}", product.Title));
|
||||
|
||||
productsToInstall.Add(product);
|
||||
}
|
||||
}
|
||||
|
||||
return productsToInstall;
|
||||
}
|
||||
|
||||
|
||||
public List<Product> GetProductsWithDependencies(IEnumerable<string> productIdsToInstall )
|
||||
{
|
||||
List<string> updatedProductIdsToInstall = new List<string>();
|
||||
// add iis chioce product to force iis (not-iisexpress/webmatrix) branch
|
||||
updatedProductIdsToInstall.Add(IisChoiceProduct);
|
||||
updatedProductIdsToInstall.AddRange(productIdsToInstall);
|
||||
|
||||
List<Product> productsToInstall = new List<Product>();
|
||||
|
||||
foreach (string productId in updatedProductIdsToInstall)
|
||||
{
|
||||
Log(string.Format("Product {0} to be installed", productId));
|
||||
|
||||
Product product = _productManager.GetProduct(productId);
|
||||
if (null == product)
|
||||
{
|
||||
Log(string.Format("Product {0} not found", productId));
|
||||
continue;
|
||||
}
|
||||
if (product.IsInstalled(true))
|
||||
{
|
||||
Log(string.Format("Product {0} is installed", product.Title));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(string.Format("Adding product {0} with dependencies", product.Title));
|
||||
// search and add dependencies but skip webmatrix/iisexpress branches
|
||||
AddProductWithDependencies(product, productsToInstall, WebMatrixChoiceProduct);
|
||||
}
|
||||
}
|
||||
|
||||
return productsToInstall;
|
||||
}
|
||||
|
||||
public string GetLogFileDirectory()
|
||||
{
|
||||
return _LogFileDirectory;
|
||||
}
|
||||
|
||||
|
||||
private Language GetLanguage(string languageId)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(languageId))
|
||||
{
|
||||
return _productManager.GetLanguage(languageId);
|
||||
}
|
||||
|
||||
return _productManager.GetLanguage(DeafultLanguage);
|
||||
}
|
||||
|
||||
|
||||
// GetTabs
|
||||
#region Tabs
|
||||
public ReadOnlyCollection<Tab> GetTabs()
|
||||
{
|
||||
return _productManager.Tabs;
|
||||
|
@ -276,234 +132,15 @@ namespace WebsitePanel.Server.Code
|
|||
{
|
||||
return _productManager.GetTab(tabId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
// GetKeywords
|
||||
|
||||
#region Keywords
|
||||
public ReadOnlyCollection<Keyword> GetKeywords()
|
||||
{
|
||||
return _productManager.Keywords;
|
||||
}
|
||||
|
||||
public List<Product> GetApplications(string keywordId)
|
||||
{
|
||||
|
||||
Keyword keyword = null;
|
||||
if (!string.IsNullOrEmpty(keywordId))
|
||||
{
|
||||
keyword = _productManager.GetKeyword(keywordId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<Product> products = new List<Product>();
|
||||
|
||||
Language lang = GetLanguage(_resourceLanguage);
|
||||
Language langDefault = GetLanguage(DeafultLanguage);
|
||||
|
||||
foreach (Product product in _productManager.Products)
|
||||
{
|
||||
if (!product.IsApplication)
|
||||
{
|
||||
// skip
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check language
|
||||
if (
|
||||
lang.AvailableProducts.Contains(product) ||
|
||||
langDefault.AvailableProducts.Contains(product)
|
||||
)
|
||||
{
|
||||
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 Product GetProduct(string productId)
|
||||
{
|
||||
|
||||
return _productManager.GetProduct(productId);
|
||||
}
|
||||
|
||||
public IList<DeclaredParameter> GetAppDecalredParameters(string productId)
|
||||
{
|
||||
Product app = _productManager.GetProduct(productId);
|
||||
Installer appInstaller = app.GetInstaller(GetLanguage(null));
|
||||
return appInstaller.MSDeployPackage.DeclaredParameters;
|
||||
}
|
||||
|
||||
public void InstallProducts(
|
||||
IEnumerable<string> productIdsToInstall,
|
||||
bool installDependencies,
|
||||
string languageId,
|
||||
EventHandler<InstallStatusEventArgs> installStatusUpdatedHandler,
|
||||
EventHandler<EventArgs> installCompleteHandler)
|
||||
{
|
||||
|
||||
List<Product> productsToInstall = null;
|
||||
if (installDependencies)
|
||||
{
|
||||
// Get products & dependencies list to install
|
||||
productsToInstall = GetProductsWithDependencies(productIdsToInstall);
|
||||
}
|
||||
else
|
||||
{
|
||||
productsToInstall = GetProducts(productIdsToInstall);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get installers
|
||||
Language lang = GetLanguage(languageId);
|
||||
List<Installer> 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<WpiUpdatedDeploymentParameter> updatedValues,
|
||||
string languageId,
|
||||
EventHandler<InstallStatusEventArgs> installStatusUpdatedHandler,
|
||||
EventHandler<EventArgs> installCompleteHandler,
|
||||
out string log,
|
||||
out string failedMessage
|
||||
)
|
||||
{
|
||||
|
||||
Product app = GetProduct(appId);
|
||||
Installer appInstaller = app.GetInstaller(GetLanguage(languageId));
|
||||
WpiAppInstallLogger logger = new WpiAppInstallLogger();
|
||||
|
||||
|
||||
|
||||
if (null != installStatusUpdatedHandler)
|
||||
{
|
||||
_installManager.InstallerStatusUpdated += installStatusUpdatedHandler;
|
||||
}
|
||||
_installManager.InstallerStatusUpdated += logger.HanlderInstallerStatusUpdated;
|
||||
|
||||
if (null != installCompleteHandler)
|
||||
{
|
||||
_installManager.InstallCompleted += installCompleteHandler;
|
||||
}
|
||||
_installManager.InstallCompleted += logger.HandlerInstallCompleted;
|
||||
|
||||
// set updated parameters
|
||||
foreach (WpiUpdatedDeploymentParameter parameter in updatedValues)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(parameter.Value))
|
||||
{
|
||||
appInstaller.MSDeployPackage.SetParameters[parameter.Name] = parameter.Value;
|
||||
}
|
||||
}
|
||||
|
||||
DeploymentWellKnownTag dbTag = (DeploymentWellKnownTag)GetDbTag(updatedValues);
|
||||
|
||||
// remove parameters with alien db tags
|
||||
foreach (DeclaredParameter parameter in appInstaller.MSDeployPackage.DeclaredParameters)
|
||||
{
|
||||
if (IsAlienDbTaggedParameter(dbTag, parameter))
|
||||
{
|
||||
appInstaller.MSDeployPackage.RemoveParameters.Add(parameter.Name);
|
||||
}
|
||||
}
|
||||
|
||||
// skip alien directives
|
||||
RemoveUnusedProviders(appInstaller.MSDeployPackage, dbTag);
|
||||
|
||||
_installCompleted = false;
|
||||
Log("_installManager.StartApplicationInstallation()");
|
||||
_installManager.StartApplicationInstallation();
|
||||
while (!_installCompleted)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
Log("_installManager.StartApplicationInstallation() _installCompleted");
|
||||
|
||||
//save logs
|
||||
SaveLogDirectory();
|
||||
|
||||
_installCompleted = false;
|
||||
|
||||
log = logger.GetLog();
|
||||
failedMessage = logger.FailedMessage;
|
||||
|
||||
return !logger.IsFailed;
|
||||
}
|
||||
|
||||
public bool IsKeywordApplication(Keyword keyword)
|
||||
{
|
||||
//if all products are Application
|
||||
|
@ -518,56 +155,12 @@ namespace WebsitePanel.Server.Code
|
|||
return true;
|
||||
|
||||
}
|
||||
|
||||
#endregion Public interface
|
||||
#endregion
|
||||
|
||||
|
||||
#region private members
|
||||
|
||||
private void LogDebugInfo()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.Append("Products: ");
|
||||
|
||||
sb.Append("Tabs: ").AppendLine();
|
||||
foreach (Tab tab in _productManager.Tabs)
|
||||
{
|
||||
sb.AppendFormat("\t{0}, FromCustomFeed = {1}", tab.Name, tab.FromCustomFeed).AppendLine();
|
||||
foreach (string f in tab.FeedList)
|
||||
{
|
||||
sb.AppendFormat("\t\t{0}", f).AppendLine();
|
||||
}
|
||||
sb.AppendLine();
|
||||
}
|
||||
sb.AppendLine();
|
||||
|
||||
sb.Append("Keywords: ").AppendLine().Append("\t");
|
||||
foreach (Keyword keyword in _productManager.Keywords)
|
||||
{
|
||||
sb.Append(keyword.Id).Append(",");
|
||||
}
|
||||
sb.AppendLine();
|
||||
|
||||
sb.Append("Languages: ").AppendLine().Append("\t");
|
||||
foreach (Language language in _productManager.Languages)
|
||||
{
|
||||
sb.Append(language.Name).Append(",");
|
||||
}
|
||||
sb.AppendLine();
|
||||
|
||||
Log(sb.ToString());
|
||||
}
|
||||
|
||||
private static void Log(string message)
|
||||
{
|
||||
//#if DEBUG
|
||||
Debug.WriteLine(string.Format("[{0}] WpiHelper: {1}", Process.GetCurrentProcess().Id, message));
|
||||
Console.WriteLine(message);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public List<Product> GetProducts(string FeedLocation, string keywordId)
|
||||
#region Products
|
||||
public List<Product> GetProductsToInstall(string FeedLocation, string keywordId)
|
||||
{
|
||||
Keyword keyword = null;
|
||||
if (!string.IsNullOrEmpty(keywordId))
|
||||
|
@ -645,6 +238,415 @@ namespace WebsitePanel.Server.Code
|
|||
return products;
|
||||
}
|
||||
|
||||
public List<Product> GetProductsToInstall(IEnumerable<string> productIdsToInstall)
|
||||
{
|
||||
List<Product> productsToInstall = new List<Product>();
|
||||
|
||||
foreach (string productId in productIdsToInstall)
|
||||
{
|
||||
Log(string.Format("Product {0} to be installed", productId));
|
||||
|
||||
Product product = _productManager.GetProduct(productId);
|
||||
if (null == product)
|
||||
{
|
||||
Log(string.Format("Product {0} not found", productId));
|
||||
continue;
|
||||
}
|
||||
if (product.IsInstalled(true))
|
||||
{
|
||||
Log(string.Format("Product {0} is installed", product.Title));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(string.Format("Adding product {0}", product.Title));
|
||||
|
||||
productsToInstall.Add(product);
|
||||
}
|
||||
}
|
||||
|
||||
return productsToInstall;
|
||||
}
|
||||
|
||||
public List<Product> GetProductsToInstallWithDependencies(IEnumerable<string> productIdsToInstall )
|
||||
{
|
||||
List<string> updatedProductIdsToInstall = new List<string>();
|
||||
// add iis chioce product to force iis (not-iisexpress/webmatrix) branch
|
||||
updatedProductIdsToInstall.Add(IisChoiceProduct);
|
||||
updatedProductIdsToInstall.AddRange(productIdsToInstall);
|
||||
|
||||
List<Product> productsToInstall = new List<Product>();
|
||||
|
||||
foreach (string productId in updatedProductIdsToInstall)
|
||||
{
|
||||
Log(string.Format("Product {0} to be installed", productId));
|
||||
|
||||
Product product = _productManager.GetProduct(productId);
|
||||
if (null == product)
|
||||
{
|
||||
Log(string.Format("Product {0} not found", productId));
|
||||
continue;
|
||||
}
|
||||
if (product.IsInstalled(true))
|
||||
{
|
||||
Log(string.Format("Product {0} is installed", product.Title));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(string.Format("Adding product {0} with dependencies", product.Title));
|
||||
// search and add dependencies but skip webmatrix/iisexpress branches
|
||||
AddProductWithDependencies(product, productsToInstall, WebMatrixChoiceProduct);
|
||||
}
|
||||
}
|
||||
|
||||
return productsToInstall;
|
||||
}
|
||||
|
||||
public Product GetProduct(string productId)
|
||||
{
|
||||
return _productManager.GetProduct(productId);
|
||||
}
|
||||
|
||||
public void InstallProducts(
|
||||
IEnumerable<string> productIdsToInstall,
|
||||
bool installDependencies,
|
||||
string languageId,
|
||||
EventHandler<InstallStatusEventArgs> installStatusUpdatedHandler,
|
||||
EventHandler<EventArgs> installCompleteHandler)
|
||||
{
|
||||
|
||||
List<Product> productsToInstall = null;
|
||||
if (installDependencies)
|
||||
{
|
||||
// Get products & dependencies list to install
|
||||
productsToInstall = GetProductsToInstallWithDependencies(productIdsToInstall);
|
||||
}
|
||||
else
|
||||
{
|
||||
productsToInstall = GetProductsToInstall(productIdsToInstall);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get installers
|
||||
Language lang = GetLanguage(languageId);
|
||||
List<Installer> 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 void CancelInstallProducts()
|
||||
{
|
||||
if (_installManager != null)
|
||||
{
|
||||
_installManager.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Applications
|
||||
public List<Product> GetApplications(string keywordId)
|
||||
{
|
||||
|
||||
Keyword keyword = null;
|
||||
if (!string.IsNullOrEmpty(keywordId))
|
||||
{
|
||||
keyword = _productManager.GetKeyword(keywordId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<Product> products = new List<Product>();
|
||||
|
||||
Language lang = GetLanguage(_resourceLanguage);
|
||||
Language langDefault = GetLanguage(DeafultLanguage);
|
||||
|
||||
foreach (Product product in _productManager.Products)
|
||||
{
|
||||
if (!product.IsApplication)
|
||||
{
|
||||
// skip
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check language
|
||||
if (
|
||||
lang.AvailableProducts.Contains(product) ||
|
||||
langDefault.AvailableProducts.Contains(product)
|
||||
)
|
||||
{
|
||||
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 IList<DeclaredParameter> GetAppDecalredParameters(string productId)
|
||||
{
|
||||
Product app = _productManager.GetProduct(productId);
|
||||
Installer appInstaller = app.GetInstaller(GetLanguage(null));
|
||||
return appInstaller.MSDeployPackage.DeclaredParameters;
|
||||
}
|
||||
|
||||
public bool InstallApplication(
|
||||
string appId,
|
||||
List<WpiUpdatedDeploymentParameter> updatedValues,
|
||||
string languageId,
|
||||
EventHandler<InstallStatusEventArgs> installStatusUpdatedHandler,
|
||||
EventHandler<EventArgs> installCompleteHandler,
|
||||
out string log,
|
||||
out string failedMessage
|
||||
)
|
||||
{
|
||||
|
||||
Product app = GetProduct(appId);
|
||||
Installer appInstaller = app.GetInstaller(GetLanguage(languageId));
|
||||
WpiAppInstallLogger logger = new WpiAppInstallLogger();
|
||||
|
||||
|
||||
|
||||
if (null != installStatusUpdatedHandler)
|
||||
{
|
||||
_installManager.InstallerStatusUpdated += installStatusUpdatedHandler;
|
||||
}
|
||||
_installManager.InstallerStatusUpdated += logger.HanlderInstallerStatusUpdated;
|
||||
|
||||
if (null != installCompleteHandler)
|
||||
{
|
||||
_installManager.InstallCompleted += installCompleteHandler;
|
||||
}
|
||||
_installManager.InstallCompleted += logger.HandlerInstallCompleted;
|
||||
|
||||
// set updated parameters
|
||||
foreach (WpiUpdatedDeploymentParameter parameter in updatedValues)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(parameter.Value))
|
||||
{
|
||||
appInstaller.MSDeployPackage.SetParameters[parameter.Name] = parameter.Value;
|
||||
}
|
||||
}
|
||||
|
||||
DeploymentWellKnownTag dbTag = (DeploymentWellKnownTag)GetDbTag(updatedValues);
|
||||
|
||||
// remove parameters with alien db tags
|
||||
foreach (DeclaredParameter parameter in appInstaller.MSDeployPackage.DeclaredParameters)
|
||||
{
|
||||
if (IsAlienDbTaggedParameter(dbTag, parameter))
|
||||
{
|
||||
appInstaller.MSDeployPackage.RemoveParameters.Add(parameter.Name);
|
||||
}
|
||||
}
|
||||
|
||||
// skip alien directives
|
||||
RemoveUnusedProviders(appInstaller.MSDeployPackage, dbTag);
|
||||
|
||||
_installCompleted = false;
|
||||
Log("_installManager.StartApplicationInstallation()");
|
||||
_installManager.StartApplicationInstallation();
|
||||
while (!_installCompleted)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
Log("_installManager.StartApplicationInstallation() _installCompleted");
|
||||
|
||||
//save logs
|
||||
SaveLogDirectory();
|
||||
|
||||
_installCompleted = false;
|
||||
|
||||
log = logger.GetLog();
|
||||
failedMessage = logger.FailedMessage;
|
||||
|
||||
return !logger.IsFailed;
|
||||
}
|
||||
|
||||
#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<Installer> GetInstallers(List<Product> productsToInstall, Language lang)
|
||||
{
|
||||
List<Installer> installersToUse = new List<Installer>();
|
||||
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();
|
||||
|
||||
sb.Append("Products: ");
|
||||
|
||||
sb.Append("Tabs: ").AppendLine();
|
||||
foreach (Tab tab in _productManager.Tabs)
|
||||
{
|
||||
sb.AppendFormat("\t{0}, FromCustomFeed = {1}", tab.Name, tab.FromCustomFeed).AppendLine();
|
||||
foreach (string f in tab.FeedList)
|
||||
{
|
||||
sb.AppendFormat("\t\t{0}", f).AppendLine();
|
||||
}
|
||||
sb.AppendLine();
|
||||
}
|
||||
sb.AppendLine();
|
||||
|
||||
sb.Append("Keywords: ").AppendLine().Append("\t");
|
||||
foreach (Keyword keyword in _productManager.Keywords)
|
||||
{
|
||||
sb.Append(keyword.Id).Append(",");
|
||||
}
|
||||
sb.AppendLine();
|
||||
|
||||
sb.Append("Languages: ").AppendLine().Append("\t");
|
||||
foreach (Language language in _productManager.Languages)
|
||||
{
|
||||
sb.Append(language.Name).Append(",");
|
||||
}
|
||||
sb.AppendLine();
|
||||
|
||||
Log(sb.ToString());
|
||||
}
|
||||
|
||||
private static void Log(string message)
|
||||
{
|
||||
//#if DEBUG
|
||||
Debug.WriteLine(string.Format("[{0}] WpiHelper: {1}", Process.GetCurrentProcess().Id, message));
|
||||
Console.WriteLine(message);
|
||||
//#endif
|
||||
}
|
||||
|
||||
private void InstallManager_InstallCompleted(object sender, EventArgs e)
|
||||
{
|
||||
|
|
|
@ -376,7 +376,7 @@ namespace WebsitePanel.Server
|
|||
feedLocation = feeds.GetEnumerator().Current;
|
||||
}
|
||||
|
||||
List<Product> products = wpi.GetProducts(feedLocation, keywordId);
|
||||
List<Product> products = wpi.GetProductsToInstall(feedLocation, keywordId);
|
||||
|
||||
if (products != null)
|
||||
{
|
||||
|
@ -573,7 +573,7 @@ namespace WebsitePanel.Server
|
|||
WpiHelper wpi = GetWpiFeed();
|
||||
|
||||
List<WPIProduct> result = new List<WPIProduct>();
|
||||
foreach (Product product in wpi.GetProductsWithDependencies(products))
|
||||
foreach (Product product in wpi.GetProductsToInstallWithDependencies(products))
|
||||
{
|
||||
result.Add(ProductToWPIProduct(product));
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue