Commit Contribution from Helicon
Includes: - complete re-write of Web Application Gallery - Addition of Web PI Installer in Server module
This commit is contained in:
parent
3b81883a25
commit
a2beec7fe4
80 changed files with 9236 additions and 1762 deletions
|
@ -38,6 +38,7 @@ using Microsoft.Web.Services3;
|
|||
using Microsoft.Web.Services3.Design;
|
||||
using Microsoft.Web.Services3.Security;
|
||||
using Microsoft.Web.Services3.Security.Tokens;
|
||||
using WebSecurity=Microsoft.Web.Services3.Security.Security;
|
||||
|
||||
namespace WebsitePanel.Server
|
||||
{
|
||||
|
@ -105,7 +106,7 @@ namespace WebsitePanel.Server
|
|||
this.filterContext = filterContext;
|
||||
}
|
||||
|
||||
public override void ValidateMessageSecurity(SoapEnvelope envelope, Security security)
|
||||
public override void ValidateMessageSecurity(SoapEnvelope envelope, WebSecurity security)
|
||||
{
|
||||
if (!ServerConfiguration.Security.SecurityEnabled)
|
||||
return;
|
||||
|
@ -145,7 +146,7 @@ namespace WebsitePanel.Server
|
|||
throw new SecurityFault("Message did not meet security requirements.");
|
||||
}
|
||||
|
||||
private bool CheckSignature(SoapEnvelope envelope, Security security, MessageSignature signature)
|
||||
private bool CheckSignature(SoapEnvelope envelope, WebSecurity security, MessageSignature signature)
|
||||
{
|
||||
//
|
||||
// Now verify which parts of the message were actually signed.
|
||||
|
|
807
WebsitePanel/Sources/WebsitePanel.Server/Code/WPIHelper.cs
Normal file
807
WebsitePanel/Sources/WebsitePanel.Server/Code/WPIHelper.cs
Normal file
|
@ -0,0 +1,807 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.Web.Deployment;
|
||||
using Microsoft.Web.PlatformInstaller;
|
||||
using Installer = Microsoft.Web.PlatformInstaller.Installer;
|
||||
|
||||
namespace WebsitePanel.Server.Code
|
||||
{
|
||||
public class WpiUpdatedDeploymentParameter
|
||||
{
|
||||
public string Name;
|
||||
public string Value;
|
||||
public DeploymentWellKnownTag WellKnownTags;
|
||||
}
|
||||
|
||||
public class WpiHelper
|
||||
{
|
||||
#region public consts
|
||||
|
||||
public const string DeafultLanguage = "en";
|
||||
|
||||
#endregion
|
||||
|
||||
#region private fields
|
||||
|
||||
private readonly List<string> _feeds;
|
||||
private string _webPIinstallersFolder;
|
||||
private const string MainWpiFeed = "https://www.microsoft.com/web/webpi/3.0/webproductlist.xml";
|
||||
private const string IisChoiceProduct = "StaticContent";
|
||||
private const string WebMatrixChoiceProduct = "WebMatrix";
|
||||
private ProductManager _productManager;
|
||||
private bool _installCompleted;
|
||||
private InstallManager _installManager;
|
||||
private string _LogFileDirectory = string.Empty;
|
||||
string _resourceLanguage = DeafultLanguage;
|
||||
private const DeploymentWellKnownTag databaseEngineTags =
|
||||
DeploymentWellKnownTag.Sql |
|
||||
DeploymentWellKnownTag.MySql |
|
||||
DeploymentWellKnownTag.SqLite |
|
||||
DeploymentWellKnownTag.VistaDB |
|
||||
DeploymentWellKnownTag.FlatFile;
|
||||
|
||||
#endregion private fields
|
||||
|
||||
public WpiHelper(IEnumerable<string> feeds)
|
||||
{
|
||||
_feeds = new List<string>();
|
||||
_feeds.AddRange(feeds);
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public void SetResourceLanguage(string resourceLanguage)
|
||||
{
|
||||
_resourceLanguage = resourceLanguage;
|
||||
_productManager.SetResourceLanguage(resourceLanguage);
|
||||
}
|
||||
|
||||
#region Public interface
|
||||
|
||||
public List<Product> GetProducts()
|
||||
{
|
||||
return GetProducts(null,null);
|
||||
}
|
||||
|
||||
public List<Language> GetLanguages()
|
||||
{
|
||||
List<Language> languages = new List<Language>();
|
||||
|
||||
foreach (Product product in GetProducts())
|
||||
{
|
||||
if (null!=product.Installers)
|
||||
{
|
||||
foreach (Installer installer in product.Installers)
|
||||
{
|
||||
Language lang = installer.Language;
|
||||
if (null!=lang && !languages.Contains(lang))
|
||||
{
|
||||
languages.Add(lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return languages;
|
||||
}
|
||||
|
||||
public void CancelInstallProducts()
|
||||
{
|
||||
if (_installManager!= null)
|
||||
{
|
||||
_installManager.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
public ReadOnlyCollection<Tab> GetTabs()
|
||||
{
|
||||
return _productManager.Tabs;
|
||||
}
|
||||
|
||||
public Tab GetTab(string tabId)
|
||||
{
|
||||
return _productManager.GetTab(tabId);
|
||||
}
|
||||
|
||||
// GetKeywords
|
||||
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,
|
||||
string languageId,
|
||||
EventHandler<InstallStatusEventArgs> installStatusUpdatedHandler,
|
||||
EventHandler<EventArgs> installCompleteHandler)
|
||||
{
|
||||
|
||||
// Get products & dependencies list to install
|
||||
List<Product> productsToInstall = GetProductsWithDependencies(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
|
||||
foreach (Product product in keyword.Products)
|
||||
{
|
||||
if (!product.IsApplication)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
#endregion Public interface
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
Keyword keyword = null;
|
||||
if (!string.IsNullOrEmpty(keywordId))
|
||||
{
|
||||
keyword = _productManager.GetKeyword(keywordId);
|
||||
}
|
||||
|
||||
List<Product> products = new List<Product>();
|
||||
|
||||
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<Product> GetProductsFiltered(string filter)
|
||||
{
|
||||
|
||||
List<Product> products = new List<Product>();
|
||||
|
||||
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");
|
||||
if (null != _installManager)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
_installManager.Dispose();
|
||||
} catch(Exception ex)
|
||||
{
|
||||
Log("InstallManager_InstallCompleted Exception: "+ex.ToString());
|
||||
}
|
||||
_installManager = null;
|
||||
*/
|
||||
}
|
||||
_installCompleted = true;
|
||||
}
|
||||
|
||||
private void InstallManager_InstallerStatusUpdated(object sender, InstallStatusEventArgs e)
|
||||
{
|
||||
Log(string.Format("{0}: {1}. {2} Progress: {3}",
|
||||
e.InstallerContext.ProductName,
|
||||
e.InstallerContext.InstallationState,
|
||||
e.InstallerContext.ReturnCode.DetailedInformation,
|
||||
e.ProgressValue));
|
||||
}
|
||||
|
||||
private static void AddProductWithDependencies(Product product, List<Product> productsToInstall, string skipProduct)
|
||||
{
|
||||
if (!productsToInstall.Contains(product))
|
||||
{
|
||||
productsToInstall.Add(product);
|
||||
}
|
||||
|
||||
ICollection<Product> missingDependencies = product.GetMissingDependencies(productsToInstall);
|
||||
if (missingDependencies != null)
|
||||
{
|
||||
foreach (Product dependency in missingDependencies)
|
||||
{
|
||||
if (string.Equals(dependency.ProductId, skipProduct, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Log(string.Format("Product {0} is iis express dependency, skip it", dependency.Title));
|
||||
continue;
|
||||
}
|
||||
|
||||
AddProductWithDependencies(dependency, productsToInstall, skipProduct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveLogDirectory()
|
||||
{
|
||||
Log("SaveLogDirectory");
|
||||
foreach (InstallerContext ctx in _installManager.InstallerContexts)
|
||||
{
|
||||
Log(ctx.LogFileDirectory);
|
||||
_LogFileDirectory = ctx.LogFileDirectory;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private DeploymentWellKnownTag GetDbTag(List<WpiUpdatedDeploymentParameter> parameters)
|
||||
{
|
||||
foreach (WpiUpdatedDeploymentParameter parameter in parameters)
|
||||
{
|
||||
if ((parameter.WellKnownTags & databaseEngineTags) != 0)
|
||||
{
|
||||
return (DeploymentWellKnownTag)Enum.Parse(
|
||||
typeof(DeploymentWellKnownTag),
|
||||
(parameter.WellKnownTags & databaseEngineTags).ToString().Split(',')[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return DeploymentWellKnownTag.None;
|
||||
}
|
||||
|
||||
private static bool IsAlienDbTaggedParameter(DeploymentWellKnownTag dbTag, DeclaredParameter parameter)
|
||||
{
|
||||
return (parameter.Tags & databaseEngineTags) != DeploymentWellKnownTag.None
|
||||
&&
|
||||
(parameter.Tags & dbTag) == DeploymentWellKnownTag.None;
|
||||
}
|
||||
|
||||
private static void RemoveUnusedProviders(MSDeployPackage msDeployPackage, DeploymentWellKnownTag dbTag)
|
||||
{
|
||||
List<string> providersToRemove = new List<string>();
|
||||
|
||||
switch (dbTag)
|
||||
{
|
||||
case DeploymentWellKnownTag.MySql:
|
||||
providersToRemove.Add("dbFullSql");
|
||||
providersToRemove.Add("DBSqlite");
|
||||
break;
|
||||
case DeploymentWellKnownTag.Sql:
|
||||
providersToRemove.Add("dbMySql");
|
||||
providersToRemove.Add("DBSqlite");
|
||||
break;
|
||||
case DeploymentWellKnownTag.FlatFile:
|
||||
providersToRemove.Add("dbFullSql");
|
||||
providersToRemove.Add("DBSqlite");
|
||||
providersToRemove.Add("dbMySql");
|
||||
break;
|
||||
case DeploymentWellKnownTag.SqLite:
|
||||
providersToRemove.Add("dbFullSql");
|
||||
providersToRemove.Add("dbMySql");
|
||||
break;
|
||||
case DeploymentWellKnownTag.VistaDB:
|
||||
providersToRemove.Add("dbFullSql");
|
||||
providersToRemove.Add("DBSqlite");
|
||||
providersToRemove.Add("dbMySql");
|
||||
break;
|
||||
case DeploymentWellKnownTag.SqlCE:
|
||||
providersToRemove.Add("dbFullSql");
|
||||
providersToRemove.Add("DBSqlite");
|
||||
providersToRemove.Add("dbMySql");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (string provider in providersToRemove)
|
||||
{
|
||||
msDeployPackage.SkipDirectives.Add(string.Format("objectName={0}", provider));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion private members
|
||||
}
|
||||
|
||||
class WpiAppInstallLogger
|
||||
{
|
||||
private StringBuilder sb;
|
||||
private InstallReturnCode _installReturnCode;
|
||||
private string _failedMessage = string.Empty;
|
||||
|
||||
public WpiAppInstallLogger()
|
||||
{
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
|
||||
public InstallReturnCode ReturnCode
|
||||
{
|
||||
get { return _installReturnCode; }
|
||||
}
|
||||
|
||||
public string FailedMessage
|
||||
{
|
||||
get { return _failedMessage; }
|
||||
}
|
||||
|
||||
public bool IsFailed
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != _installReturnCode)
|
||||
{
|
||||
return _installReturnCode.Status == InstallReturnCodeStatus.Failure ||
|
||||
_installReturnCode.Status == InstallReturnCodeStatus.FailureRebootRequired;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void HanlderInstallerStatusUpdated(object sender, InstallStatusEventArgs e)
|
||||
{
|
||||
sb.AppendFormat("{0}: {1}. {2} Progress: {3}",
|
||||
e.InstallerContext.ProductName,
|
||||
e.InstallerContext.InstallationState,
|
||||
e.InstallerContext.ReturnCode.DetailedInformation,
|
||||
e.ProgressValue).AppendLine();
|
||||
}
|
||||
|
||||
public void HandlerInstallCompleted(object sender, EventArgs e)
|
||||
{
|
||||
InstallManager installManager = sender as InstallManager;
|
||||
if (null != installManager)
|
||||
{
|
||||
InstallerContext installerContext;
|
||||
if (null != installManager.InstallerContexts && installManager.InstallerContexts.Count>0)
|
||||
{
|
||||
installerContext = installManager.InstallerContexts[0];
|
||||
_installReturnCode = installerContext.ReturnCode;
|
||||
}
|
||||
}
|
||||
|
||||
if (null != _installReturnCode)
|
||||
{
|
||||
_failedMessage = string.Format("{0}: {1}",
|
||||
_installReturnCode.Status,
|
||||
_installReturnCode.DetailedInformation);
|
||||
sb.AppendFormat("Return Code: {0}", _failedMessage).AppendLine();
|
||||
}
|
||||
sb.AppendLine("Installation completed");
|
||||
}
|
||||
|
||||
public string GetLog()
|
||||
{
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -119,7 +119,7 @@
|
|||
algorithmSuite="Default" />
|
||||
</security>
|
||||
</binding>
|
||||
</wsHttpBinding>
|
||||
</bindings>
|
||||
</wsHttpBinding>
|
||||
</bindings>
|
||||
</system.serviceModel>
|
||||
</configuration>
|
||||
|
|
|
@ -1062,12 +1062,62 @@ namespace WebsitePanel.Server
|
|||
|
||||
#region Web Application Gallery
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryCategoriesResult GetGalleryCategories()
|
||||
public void InitFeeds(int UserId, string[] feeds)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' InitFeeds", ProviderSettings.ProviderName);
|
||||
WebProvider.InitFeeds(UserId, feeds);
|
||||
Log.WriteEnd("'{0}' InitFeeds", ProviderSettings.ProviderName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(String.Format("'{0}' InitFeeds", ProviderSettings.ProviderName), ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public void SetResourceLanguage(int UserId, string resourceLanguage)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' SetResourceLanguage", ProviderSettings.ProviderName);
|
||||
WebProvider.SetResourceLanguage(UserId,resourceLanguage);
|
||||
Log.WriteEnd("'{0}' SetResourceLanguage", ProviderSettings.ProviderName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(String.Format("'{0}' SetResourceLanguage", ProviderSettings.ProviderName), ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryLanguagesResult GetGalleryLanguages(int UserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' GalleryLanguagesResult", ProviderSettings.ProviderName);
|
||||
GalleryLanguagesResult result = WebProvider.GetGalleryLanguages(UserId);
|
||||
Log.WriteEnd("'{0}' GalleryLanguagesResult", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(String.Format("'{0}' GalleryLanguagesResult", ProviderSettings.ProviderName), ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryCategoriesResult GetGalleryCategories(int UserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' GalleryCategoriesResult", ProviderSettings.ProviderName);
|
||||
GalleryCategoriesResult result = WebProvider.GetGalleryCategories();
|
||||
GalleryCategoriesResult result = WebProvider.GetGalleryCategories(UserId);
|
||||
Log.WriteEnd("'{0}' GalleryCategoriesResult", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
|
@ -1079,12 +1129,12 @@ namespace WebsitePanel.Server
|
|||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryApplicationsResult GetGalleryApplications(string categoryId)
|
||||
public GalleryApplicationsResult GetGalleryApplications(int UserId, string categoryId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' GetGalleryApplications", ProviderSettings.ProviderName);
|
||||
GalleryApplicationsResult result = WebProvider.GetGalleryApplications(categoryId);
|
||||
GalleryApplicationsResult result = WebProvider.GetGalleryApplications(UserId,categoryId);
|
||||
Log.WriteEnd("'{0}' GetGalleryApplications", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
|
@ -1094,7 +1144,26 @@ namespace WebsitePanel.Server
|
|||
throw;
|
||||
}
|
||||
}
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryApplicationsResult GetGalleryApplicationsFiltered(int UserId, string pattern)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' GetGalleryApplicationsFiltered", ProviderSettings.ProviderName);
|
||||
GalleryApplicationsResult result = WebProvider.GetGalleryApplicationsFiltered(UserId,pattern);
|
||||
Log.WriteEnd("'{0}' GetGalleryApplicationsFiltered", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(String.Format("'{0}' GetGalleryApplicationsFiltered", ProviderSettings.ProviderName), ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public bool IsMsDeployInstalled()
|
||||
{
|
||||
try
|
||||
|
@ -1111,13 +1180,13 @@ namespace WebsitePanel.Server
|
|||
}
|
||||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryApplicationResult GetGalleryApplication(string id)
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryApplicationResult GetGalleryApplication(int UserId, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' GetGalleryApplication", ProviderSettings.ProviderName);
|
||||
GalleryApplicationResult result = WebProvider.GetGalleryApplication(id);
|
||||
GalleryApplicationResult result = WebProvider.GetGalleryApplication(UserId,id);
|
||||
Log.WriteEnd("'{0}' GetGalleryApplication", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
|
@ -1128,13 +1197,13 @@ namespace WebsitePanel.Server
|
|||
}
|
||||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryWebAppStatus GetGalleryApplicationStatus(string id)
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryWebAppStatus GetGalleryApplicationStatus(int UserId, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' GetGalleryApplicationStatus", ProviderSettings.ProviderName);
|
||||
GalleryWebAppStatus result = WebProvider.GetGalleryApplicationStatus(id);
|
||||
GalleryWebAppStatus result = WebProvider.GetGalleryApplicationStatus(UserId,id);
|
||||
Log.WriteEnd("'{0}' GetGalleryApplicationStatus", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
|
@ -1144,14 +1213,14 @@ namespace WebsitePanel.Server
|
|||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryWebAppStatus DownloadGalleryApplication(string id)
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public GalleryWebAppStatus DownloadGalleryApplication(int UserId, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' DownloadGalleryApplication", ProviderSettings.ProviderName);
|
||||
GalleryWebAppStatus result = WebProvider.DownloadGalleryApplication(id);
|
||||
GalleryWebAppStatus result = WebProvider.DownloadGalleryApplication(UserId,id);
|
||||
Log.WriteEnd("'{0}' DownloadGalleryApplication", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
|
@ -1162,13 +1231,13 @@ namespace WebsitePanel.Server
|
|||
}
|
||||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public DeploymentParametersResult GetGalleryApplicationParameters(string id)
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public DeploymentParametersResult GetGalleryApplicationParameters(int UserId, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' GetGalleryApplicationParameters", ProviderSettings.ProviderName);
|
||||
DeploymentParametersResult result = WebProvider.GetGalleryApplicationParameters(id);
|
||||
DeploymentParametersResult result = WebProvider.GetGalleryApplicationParameters(UserId,id);
|
||||
Log.WriteEnd("'{0}' GetGalleryApplicationParameters", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
|
@ -1179,13 +1248,13 @@ namespace WebsitePanel.Server
|
|||
}
|
||||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public StringResultObject InstallGalleryApplication(string id, List<DeploymentParameter> updatedValues)
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public StringResultObject InstallGalleryApplication(int UserId, string id, List<DeploymentParameter> updatedValues, string languageId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("'{0}' InstallGalleryApplication", ProviderSettings.ProviderName);
|
||||
StringResultObject result = WebProvider.InstallGalleryApplication(id, updatedValues);
|
||||
StringResultObject result = WebProvider.InstallGalleryApplication(UserId,id, updatedValues, languageId);
|
||||
Log.WriteEnd("'{0}' InstallGalleryApplication", ProviderSettings.ProviderName);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,14 @@
|
|||
<WarningsAsErrors>618</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Web.Deployment, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\Lib\References\Microsoft\Microsoft.Web.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.PlatformInstaller, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\Lib\Microsoft.Web.PlatformInstaller.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\Lib\Microsoft.Web.Services3.dll</HintPath>
|
||||
|
@ -52,6 +60,8 @@
|
|||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Runtime.Remoting" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.DynamicData" />
|
||||
|
@ -113,6 +123,7 @@
|
|||
<DependentUpon>LyncServer.asmx</DependentUpon>
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Code\WPIHelper.cs" />
|
||||
<Compile Include="OCSEdgeServer.asmx.cs">
|
||||
<DependentUpon>OCSEdgeServer.asmx</DependentUpon>
|
||||
<SubType>Component</SubType>
|
||||
|
@ -206,6 +217,10 @@
|
|||
<Project>{E91E52F3-9555-4D00-B577-2B1DBDD87CA7}</Project>
|
||||
<Name>WebsitePanel.Server.Utils</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\WebsitePanel.Server.WPIServiceContract\WebsitePanel.Server.WPIServiceContract.csproj">
|
||||
<Project>{736FA0F0-ECA3-416E-B299-85CC425FFF44}</Project>
|
||||
<Name>WebsitePanel.Server.WPIServiceContract</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="WsePolicyCache.Config" />
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using System.Diagnostics;
|
||||
using System.Collections;
|
||||
|
@ -38,11 +41,20 @@ using System.Web.Services.Protocols;
|
|||
using System.ComponentModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.ServiceProcess;
|
||||
using System.ServiceModel;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Runtime.Remoting.Channels;
|
||||
using System.Runtime.Remoting.Channels.Tcp;
|
||||
using System.Management;
|
||||
using System.Collections.Specialized;
|
||||
using Microsoft.Web.PlatformInstaller;
|
||||
using Microsoft.Web.Services3;
|
||||
|
||||
using WebsitePanel.Providers.Utils;
|
||||
using WebsitePanel.Server.Code;
|
||||
using WebsitePanel.Server.Utils;
|
||||
using WebsitePanel.Providers;
|
||||
using WebsitePanel.Server.WPIService;
|
||||
|
||||
|
||||
namespace WebsitePanel.Server
|
||||
{
|
||||
|
@ -280,6 +292,554 @@ namespace WebsitePanel.Server
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region Web Platform Installer
|
||||
|
||||
|
||||
|
||||
private string makeHref(string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return value;
|
||||
|
||||
//" qweqwe http://www.helicontech.com/zoo/feed/ asdasdasd"
|
||||
Regex link =new Regex("(http[^\\s,]+)(?<![.,])");
|
||||
|
||||
return link.Replace(value,"<a href=\"$1\" target=\"_blank\">$1</a>");
|
||||
}
|
||||
|
||||
|
||||
private WPIProduct ProductToWPIProduct(Product product)
|
||||
{
|
||||
WPIProduct p = new WPIProduct();
|
||||
p.ProductId = product.ProductId;
|
||||
p.Summary = product.Summary;
|
||||
p.LongDescription = makeHref(product.LongDescription);
|
||||
p.Published = product.Published;
|
||||
p.Author = product.Author;
|
||||
p.AuthorUri = (product.AuthorUri != null) ? product.AuthorUri.ToString() : "";
|
||||
p.Title = product.Title;
|
||||
p.Link = (product.Link != null) ? product.Link.ToString() : "";
|
||||
p.Version = product.Version;
|
||||
|
||||
if (product.Installers.Count > 0)
|
||||
{
|
||||
if (product.Installers[0].EulaUrl != null)
|
||||
{
|
||||
p.EulaUrl = product.Installers[0].EulaUrl.ToString();
|
||||
|
||||
}
|
||||
|
||||
if (product.Installers[0].InstallerFile != null)
|
||||
{
|
||||
if (product.Installers[0].InstallerFile.InstallerUrl != null)
|
||||
{
|
||||
p.DownloadedLocation = product.Installers[0].InstallerFile.InstallerUrl.ToString();
|
||||
}
|
||||
p.FileSize = product.Installers[0].InstallerFile.FileSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (product.IconUrl != null)
|
||||
{
|
||||
p.Logo = product.IconUrl.ToString();
|
||||
}
|
||||
|
||||
p.IsInstalled = product.IsInstalled(true);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public WPIProduct[] GetWPIProducts(string tabId, string keywordId)
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Log.WriteStart("GetWPIProducts");
|
||||
List<WPIProduct> wpiProducts = new List<WPIProduct>();
|
||||
|
||||
|
||||
WpiHelper wpi = GetWpiFeed();
|
||||
|
||||
string feedLocation = null;
|
||||
if (tabId != null)
|
||||
{
|
||||
Tab tab = wpi.GetTab(tabId);
|
||||
ICollection<string> feeds = tab.FeedList;
|
||||
feedLocation = feeds.GetEnumerator().Current;
|
||||
}
|
||||
|
||||
List<Product> products = wpi.GetProducts(feedLocation, keywordId);
|
||||
|
||||
if (products != null)
|
||||
{
|
||||
|
||||
|
||||
foreach (Product product in products)
|
||||
{
|
||||
if (null != product && !product.IsApplication)
|
||||
{
|
||||
wpiProducts.Add(ProductToWPIProduct(product));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Log.WriteEnd("GetWPIProducts");
|
||||
return wpiProducts.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError("GetWPIProducts", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[WebMethod]
|
||||
public WPIProduct[] GetWPIProductsFiltered(string filter)
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Log.WriteStart("GetWPIProductsFiltered");
|
||||
List<WPIProduct> wpiProducts = new List<WPIProduct>();
|
||||
|
||||
|
||||
WpiHelper wpi = GetWpiFeed();
|
||||
|
||||
List<Product> products = wpi.GetProductsFiltered( filter);
|
||||
|
||||
if (products != null)
|
||||
{
|
||||
|
||||
|
||||
foreach (Product product in products)
|
||||
{
|
||||
if (null != product && !product.IsApplication)
|
||||
{
|
||||
wpiProducts.Add(ProductToWPIProduct(product));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Log.WriteEnd("GetWPIProductsFiltered");
|
||||
return wpiProducts.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError("GetWPIProductsFiltered", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public WPITab[] GetWPITabs()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("GetWPITabs");
|
||||
|
||||
WpiHelper wpi = GetWpiFeed();
|
||||
|
||||
List<WPITab> result = new List<WPITab>();
|
||||
|
||||
foreach (Tab tab in wpi.GetTabs())
|
||||
{
|
||||
result.Add(new WPITab(tab.Id, tab.Name));
|
||||
}
|
||||
|
||||
|
||||
Log.WriteEnd("GetWPITabs");
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError("GetWPITabs", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static string[] FEEDS = new string[]
|
||||
{
|
||||
// "https://www.microsoft.com/web/webpi/3.0/WebProductList.xml",
|
||||
// "http://www.helicontech.com/zoo/feed/"
|
||||
};
|
||||
|
||||
[WebMethod]
|
||||
public void InitWPIFeeds(string feedUrls)
|
||||
{
|
||||
if (string.IsNullOrEmpty(feedUrls))
|
||||
{
|
||||
throw new Exception("Empty feed list");
|
||||
}
|
||||
|
||||
string[] newFEEDS = feedUrls.Split(';');
|
||||
|
||||
if (newFEEDS.Length == 0)
|
||||
{
|
||||
throw new Exception("Empty feed list");
|
||||
}
|
||||
if (!ArraysEqual<string>(newFEEDS, FEEDS))
|
||||
{
|
||||
Log.WriteInfo("InitWPIFeeds - new value: " + feedUrls);
|
||||
|
||||
//Feeds settings have been channged
|
||||
FEEDS = newFEEDS;
|
||||
wpi = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool ArraysEqual<T>(T[] a1, T[] a2)
|
||||
{
|
||||
if (ReferenceEquals(a1, a2))
|
||||
return true;
|
||||
|
||||
if (a1 == null || a2 == null)
|
||||
return false;
|
||||
|
||||
if (a1.Length != a2.Length)
|
||||
return false;
|
||||
|
||||
EqualityComparer<T> comparer = EqualityComparer<T>.Default;
|
||||
for (int i = 0; i < a1.Length; i++)
|
||||
{
|
||||
if (!comparer.Equals(a1[i], a2[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public WPIKeyword[] GetWPIKeywords()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("GetWPIKeywords");
|
||||
|
||||
WpiHelper wpi = GetWpiFeed();
|
||||
|
||||
List<WPIKeyword> result = new List<WPIKeyword>();
|
||||
|
||||
result.Add(new WPIKeyword("", "All"));
|
||||
|
||||
foreach (Keyword keyword in wpi.GetKeywords())
|
||||
{
|
||||
if (!wpi.IsKeywordApplication(keyword))
|
||||
{
|
||||
result.Add(new WPIKeyword(keyword.Id, keyword.Text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Log.WriteEnd("GetWPIKeywords");
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError("GetWPIKeywords", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[WebMethod]
|
||||
public WPIProduct[] GetWPIProductsWithDependencies(string[] products)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("GetWPIProductsWithDependencies");
|
||||
|
||||
WpiHelper wpi = GetWpiFeed();
|
||||
|
||||
List<WPIProduct> result = new List<WPIProduct>();
|
||||
foreach (Product product in wpi.GetProductsWithDependencies(products))
|
||||
{
|
||||
result.Add(ProductToWPIProduct(product));
|
||||
}
|
||||
|
||||
Log.WriteEnd("GetWPIProductsWithDependencies");
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError("GetWPIProductsWithDependencies", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
static Process _WpiServiceExe = null;
|
||||
|
||||
[WebMethod]
|
||||
public void InstallWPIProducts(string[] products)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("InstallWPIProducts");
|
||||
|
||||
StartWpiService();
|
||||
|
||||
RegisterWpiService();
|
||||
|
||||
WPIServiceContract client = new WPIServiceContract();
|
||||
|
||||
client.Initialize(FEEDS);
|
||||
client.BeginInstallation(products);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Log.WriteEnd("InstallWPIProducts");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError("InstallWPIProducts", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void StartWpiService()
|
||||
{
|
||||
string binFolder = HttpContext.Current.Server.MapPath("/bin/");
|
||||
|
||||
string newUserProfile = Path.Combine(Environment.ExpandEnvironmentVariables("%SystemRoot%"), "Temp\\zoo.wpi");
|
||||
string newAppData = Path.Combine(newUserProfile, "Roaming");
|
||||
string newLocalAppData = Path.Combine(newUserProfile, "Local");
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(newUserProfile);
|
||||
Directory.CreateDirectory(newAppData);
|
||||
Directory.CreateDirectory(newLocalAppData);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//throw;
|
||||
}
|
||||
|
||||
|
||||
Process wpiServiceExe = new Process();
|
||||
wpiServiceExe.StartInfo = new ProcessStartInfo(Path.Combine(binFolder, "WebsitePanel.Server.WPIService.exe"));
|
||||
wpiServiceExe.StartInfo.UseShellExecute = false;
|
||||
wpiServiceExe.StartInfo.EnvironmentVariables["UserProfile"] = newUserProfile;
|
||||
wpiServiceExe.StartInfo.EnvironmentVariables["LocalAppData"] = newLocalAppData;
|
||||
wpiServiceExe.StartInfo.EnvironmentVariables["AppData"] = newAppData;
|
||||
if (wpiServiceExe.Start())
|
||||
{
|
||||
_WpiServiceExe = wpiServiceExe;
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public void CancelInstallWPIProducts()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("CancelInstallWPIProducts");
|
||||
|
||||
KillWpiService();
|
||||
|
||||
|
||||
Log.WriteEnd("CancelInstallWPIProducts");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError("CancelInstallWPIProducts", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void KillWpiService()
|
||||
{
|
||||
//kill own service
|
||||
if (_WpiServiceExe != null && !_WpiServiceExe.HasExited)
|
||||
{
|
||||
_WpiServiceExe.Kill();
|
||||
_WpiServiceExe = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
//find WebsitePanel.Server.WPIService.exe
|
||||
Process[] wpiservices = Process.GetProcessesByName("WebsitePanel.Server.WPIService");
|
||||
foreach (Process p in wpiservices)
|
||||
{
|
||||
p.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public string GetWPIStatus()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("GetWPIStatus");
|
||||
|
||||
RegisterWpiService();
|
||||
|
||||
WPIServiceContract client = new WPIServiceContract();
|
||||
|
||||
string status = client.GetStatus();
|
||||
|
||||
Log.WriteEnd("GetWPIStatus");
|
||||
|
||||
return status; //OK
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// done or error
|
||||
|
||||
if (_WpiServiceExe == null || _WpiServiceExe.HasExited)
|
||||
{
|
||||
// reset WpiHelper for refresh status
|
||||
wpi = null;
|
||||
return ""; //OK
|
||||
}
|
||||
|
||||
Log.WriteError("GetWPIStatus", ex);
|
||||
|
||||
return ex.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public string WpiGetLogFileDirectory()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("WpiGetLogFileDirectory");
|
||||
|
||||
RegisterWpiService();
|
||||
|
||||
WPIServiceContract client = new WPIServiceContract();
|
||||
|
||||
string result = client.GetLogFileDirectory();
|
||||
|
||||
Log.WriteEnd("WpiGetLogFileDirectory");
|
||||
|
||||
return result; //OK
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Log.WriteError("WpiGetLogFileDirectory", ex);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public SettingPair[] WpiGetLogsInDirectory(string Path)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.WriteStart("WpiGetLogsInDirectory");
|
||||
|
||||
ArrayList result = new ArrayList();
|
||||
|
||||
string[] filePaths = Directory.GetFiles(Path);
|
||||
foreach (string filePath in filePaths)
|
||||
{
|
||||
using (StreamReader streamReader = new StreamReader(filePath))
|
||||
{
|
||||
string fileContent = SecurityElement.Escape(StringUtils.CleanupASCIIControlCharacters(streamReader.ReadToEnd()));
|
||||
result.Add(new SettingPair(filePath, fileContent));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Log.WriteEnd("WpiGetLogFileDirectory");
|
||||
|
||||
return (SettingPair[])result.ToArray(typeof(SettingPair)); //OK
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Log.WriteError("WpiGetLogFileDirectory", ex);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static WpiHelper wpi = null;
|
||||
WpiHelper GetWpiFeed()
|
||||
{
|
||||
if (FEEDS.Length == 0)
|
||||
{
|
||||
throw new Exception("Empty feed list");
|
||||
}
|
||||
|
||||
if (null == wpi)
|
||||
{
|
||||
wpi = new WpiHelper(FEEDS);
|
||||
}
|
||||
return wpi;
|
||||
}
|
||||
|
||||
private static object _lockRegisterWpiService = new object();
|
||||
private void RegisterWpiService()
|
||||
{
|
||||
lock (_lockRegisterWpiService)
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
ChannelServices.RegisterChannel(new TcpChannel(), true);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
//ignor
|
||||
}
|
||||
|
||||
if (null == RemotingConfiguration.IsWellKnownClientType(typeof(WPIServiceContract)))
|
||||
{
|
||||
RemotingConfiguration.RegisterWellKnownClientType(typeof(WPIServiceContract), string.Format("tcp://localhost:{0}/WPIServiceContract", WPIServiceContract.PORT));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
WPIServiceContract client = new WPIServiceContract();
|
||||
client.Ping();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//unable to connect
|
||||
//try to restart service
|
||||
KillWpiService();
|
||||
//StartWpiService();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endregion GetWPIProducts
|
||||
|
||||
|
||||
#region Event Viewer
|
||||
[WebMethod]
|
||||
public List<string> GetLogNames()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue