diff --git a/src/SIM.Base/WebRequestHelper.cs b/src/SIM.Base/WebRequestHelper.cs index 5f0318b0..cacf92aa 100644 --- a/src/SIM.Base/WebRequestHelper.cs +++ b/src/SIM.Base/WebRequestHelper.cs @@ -7,6 +7,7 @@ using System.Threading; using Sitecore.Diagnostics.Base; using Sitecore.Diagnostics.Logging; + using System.Collections.Generic; public static class WebRequestHelper { @@ -130,9 +131,9 @@ public static void DownloadFile(string destFileName, Stream responseStream, Canc } } - public static string DownloadString(string url, int? timeout = null, int? readWriteTimeout = null) + public static string DownloadString(string url, int? timeout = null, int? readWriteTimeout = null, string cookies = null, IDictionary headers = null) { - using (var response = RequestAndGetResponse(url, timeout, readWriteTimeout)) + using (var response = RequestAndGetResponse(url, timeout, readWriteTimeout, cookies: cookies, headers: headers)) { Assert.IsNotNull(response, "No response provided"); var stream = response.GetResponseStream(); @@ -193,14 +194,14 @@ public static string GetFileName(WebResponse response) return GetCookieValue(contentDisposition, "filename").Trim('"'); } - public static HttpWebResponse RequestAndGetResponse(string url, int? timeout = null, int? readWriteTimeout = null, string cookies = null) + public static HttpWebResponse RequestAndGetResponse(string url, int? timeout = null, int? readWriteTimeout = null, string cookies = null, IDictionary headers = null) { - return RequestAndGetResponse(new Uri(url), timeout, readWriteTimeout, cookies); + return RequestAndGetResponse(new Uri(url), timeout, readWriteTimeout, cookies, headers); } - public static HttpWebResponse RequestAndGetResponse(Uri uri, int? timeout = null, int? readWriteTimeout = null, string cookies = null) + public static HttpWebResponse RequestAndGetResponse(Uri uri, int? timeout = null, int? readWriteTimeout = null, string cookies = null, IDictionary headers = null) { - var webRequest = CreateRequest(uri, timeout, readWriteTimeout, cookies); + var webRequest = CreateRequest(uri, timeout, readWriteTimeout, cookies, headers); return webRequest.GetResponse() as HttpWebResponse; } @@ -214,16 +215,25 @@ private static HttpWebRequest CreateRequest(string url, int? timeout = null, int return CreateRequest(new Uri(url), timeout, readWriteTimeout, cookies); } - private static HttpWebRequest CreateRequest(Uri url, int? timeout = null, int? readWriteTimeout = null, string cookies = null) + private static HttpWebRequest CreateRequest(Uri url, int? timeout = null, int? readWriteTimeout = null, string cookies = null, IDictionary headers = null) { var webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Timeout = timeout ?? Settings.CoreWebDownloadConnectionTimeout.Value; webRequest.ReadWriteTimeout = readWriteTimeout ?? Settings.CoreWebDownloadTimeoutMinutes.Value * Minute; + if (cookies != null) { webRequest.Headers.Add(HttpRequestHeader.Cookie, cookies); } + if (headers != null) + { + foreach (KeyValuePair header in headers) + { + webRequest.Headers.Add(header.Key, header.Value); + } + } + return webRequest; } diff --git a/src/SIM.Instances/Instance.cs b/src/SIM.Instances/Instance.cs index 349c5fee..37005cb0 100644 --- a/src/SIM.Instances/Instance.cs +++ b/src/SIM.Instances/Instance.cs @@ -414,25 +414,30 @@ public virtual string ModulesNames { get { - try - { - var omsVersions = new[] {"6.2", "6.3", "6.4"}; - var dmsVersions = new[] {"6.5", "6.6", "7.0", "7.1", "7.2"}; - var dmsName = omsVersions.Any(x => ProductFullName.Contains(x)) - ? "OMS" - : (dmsVersions.Any(x => ProductFullName.Contains(x)) ? "DMS" : "xDB"); - - var modulesNames = Modules.Select(x => x.Name.TrimStart("Sitecore ")); - return (string.Join(", ", modulesNames) + - (File.Exists(Path.Combine(WebRootPath, "App_Config\\Include\\Sitecore.Analytics.config")) - ? $", {dmsName}" - : string.Empty)).TrimStart(" ,".ToCharArray()); - } - catch (Exception ex) + if (this.Type == InstanceType.Sitecore8AndEarlier) { - Log.Error(ex, $"Issue with reading ModulesNames propery of {this.Name} instance."); - return string.Empty; + try + { + var omsVersions = new[] { "6.2", "6.3", "6.4" }; + var dmsVersions = new[] { "6.5", "6.6", "7.0", "7.1", "7.2" }; + var dmsName = omsVersions.Any(x => ProductFullName.Contains(x)) + ? "OMS" + : (dmsVersions.Any(x => ProductFullName.Contains(x)) ? "DMS" : "xDB"); + + var modulesNames = Modules.Select(x => x.Name.TrimStart("Sitecore ")); + return (string.Join(", ", modulesNames) + + (File.Exists(Path.Combine(WebRootPath, "App_Config\\Include\\Sitecore.Analytics.config")) + ? $", {dmsName}" + : string.Empty)).TrimStart(" ,".ToCharArray()); + } + catch (Exception ex) + { + Log.Error(ex, $"Issue with reading ModulesNames propery of {this.Name} instance."); + return string.Empty; + } } + + return string.Empty; } } diff --git a/src/SIM.Instances/InstanceManager.cs b/src/SIM.Instances/InstanceManager.cs index 6c2c6254..04297966 100644 --- a/src/SIM.Instances/InstanceManager.cs +++ b/src/SIM.Instances/InstanceManager.cs @@ -105,17 +105,23 @@ public Instance GetInstance([NotNull] string name) Assert.ArgumentNotNull(name, nameof(name)); Log.Debug($"InstanceManager:GetInstance('{name}')"); - if (Instances == null) + if (PartiallyCachedInstances == null) { Initialize(); } - if (Instances == null) + if (PartiallyCachedInstances == null) { return null; } - return PartiallyCachedInstances?[name]; + // This is needed to make sure that the newly installed Sitecore instance is added to the collection. + if (!PartiallyCachedInstances.Keys.Contains(name)) + { + Initialize(); + } + + return PartiallyCachedInstances.Keys.Contains(name) ? PartiallyCachedInstances[name] : null; } public void Initialize([CanBeNull] string defaultRootFolder = null) diff --git a/src/SIM.Pipelines/Agent/AgentFiles.cs b/src/SIM.Pipelines/Agent/AgentFiles.cs index 28a981d1..8c9053ca 100644 --- a/src/SIM.Pipelines/Agent/AgentFiles.cs +++ b/src/SIM.Pipelines/Agent/AgentFiles.cs @@ -112,6 +112,112 @@ private string GetFilePath(string name) #endregion +"; + + public const string InstallPackageContentsForSitecore9AndLater = @" +<%@ Page Language=""C#"" AutoEventWireup=""true"" %> +<%@ Import Namespace=""System.IO"" %> +<%@ Import Namespace=""Sitecore.Configuration"" %> +<%@ Import Namespace=""Sitecore.Data.Engines"" %> +<%@ Import Namespace=""Sitecore.Diagnostics"" %> +<%@ Import Namespace=""Sitecore.Install"" %> +<%@ Import Namespace=""Sitecore.Install.Files"" %> +<%@ Import Namespace=""Sitecore.Install.Framework"" %> +<%@ Import Namespace=""Sitecore.Install.Items"" %> +<%@ Import Namespace=""Sitecore.Install.Utils"" %> +<%@ Import Namespace=""Sitecore.SecurityModel"" %> +<%@ Import Namespace=""Sitecore.Security.Accounts"" %> + +"; public const string InstallPackageFileName = @"InstallPackage.aspx"; diff --git a/src/SIM.Pipelines/Agent/AgentHelper.cs b/src/SIM.Pipelines/Agent/AgentHelper.cs index 92f1a0b2..b84bef7b 100644 --- a/src/SIM.Pipelines/Agent/AgentHelper.cs +++ b/src/SIM.Pipelines/Agent/AgentHelper.cs @@ -52,7 +52,7 @@ public static void CopyAgentFiles([NotNull] Instance instance) new { FileName = AgentFiles.InstallPackageFileName, - Contents = AgentFiles.InstallPackageContents + Contents = instance.Type == Instance.InstanceType.Sitecore9AndLater ? AgentFiles.InstallPackageContentsForSitecore9AndLater : AgentFiles.InstallPackageContents }, new { @@ -101,7 +101,7 @@ public static void DeleteAgentFiles([NotNull] Instance instance) #region Package installation - public static void InstallPackage([NotNull] Instance instance, [NotNull] Product module) + public static void InstallPackage([NotNull] Instance instance, [NotNull] Product module, [CanBeNull] string cookies = null, [CanBeNull] IDictionary headers = null) { Assert.ArgumentNotNull(instance, nameof(instance)); Assert.ArgumentNotNull(module, nameof(module)); @@ -113,10 +113,10 @@ public static void InstallPackage([NotNull] Instance instance, [NotNull] Product var statusUrl = GetUrl(instance, AgentFiles.StatusFileName); - ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.InstallPackageFileName, installPackageUrl, PackageInstalling, PackageInstalled); + ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.InstallPackageFileName, installPackageUrl, PackageInstalling, PackageInstalled, cookies: cookies, headers: headers); } - public static void PerformPostStepAction([NotNull] Instance instance, [NotNull] Product module) + public static void PerformPostStepAction([NotNull] Instance instance, [NotNull] Product module, [CanBeNull] string cookies = null, [CanBeNull] IDictionary headers = null) { XmlDocument xmlDocument = module.Manifest; bool skipPostActions = module.SkipPostActions; @@ -160,7 +160,7 @@ public static void PerformPostStepAction([NotNull] Instance instance, [NotNull] { var value = custom.Aggregate(string.Empty, (current, pair) => current + ($";{pair[0]}-{pair[1]}")); var postInstallUrl = GetUrl(instance, AgentFiles.PostInstallActionsFileName, value.TrimStart(';'), "custom"); - ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.PostInstallActionsFileName, postInstallUrl, ActionsPerforming, ActionsPerformed); + ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.PostInstallActionsFileName, postInstallUrl, ActionsPerforming, ActionsPerformed, cookies: cookies, headers: headers); return; } } @@ -174,7 +174,7 @@ public static void PerformPostStepAction([NotNull] Instance instance, [NotNull] var fileName = Path.GetFileName(module.PackagePath); Assert.IsNotNull(fileName, nameof(fileName)); var url = GetUrl(instance, AgentFiles.PostInstallActionsFileName, fileName); - ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.PostInstallActionsFileName, url, ActionsPerforming, ActionsPerformed); + ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.PostInstallActionsFileName, url, ActionsPerforming, ActionsPerformed, cookies: cookies, headers: headers); } #endregion @@ -190,7 +190,7 @@ public static string GetUrl(Instance instance, string pageName, string value = n } [NotNull] - public static string Request([NotNull] string url, [NotNull] string pageName) + public static string Request([NotNull] string url, [NotNull] string pageName, [CanBeNull] string cookies = null, [CanBeNull] IDictionary headers = null) { Assert.ArgumentNotNull(url, nameof(url)); Assert.ArgumentNotNullOrEmpty(pageName, nameof(pageName)); @@ -200,7 +200,7 @@ public static string Request([NotNull] string url, [NotNull] string pageName) try { Log.Info($"Requesting URL {url}"); - result = WebRequestHelper.DownloadString(url).Trim(); + result = WebRequestHelper.DownloadString(url, cookies: cookies, headers: headers).Trim(); if (result.ToLower().StartsWith("error:")) { throw new InvalidOperationException(errorPrefix + result); @@ -222,10 +222,10 @@ public static string Request([NotNull] string url, [NotNull] string pageName) #region Private methods - private static void ExecuteAgent(string statusFileName, string statusUrl, string agentName, string operationUrl, string operationStartedStatus, string operationCompletedStatus) + private static void ExecuteAgent(string statusFileName, string statusUrl, string agentName, string operationUrl, string operationStartedStatus, string operationCompletedStatus, string cookies = null, IDictionary headers = null) { // Call agent main operation - var status = Request(operationUrl, agentName); + var status = Request(operationUrl, agentName, cookies: cookies, headers: headers); // If the package installation process takes more than http timeout, retrive status if (status != operationCompletedStatus) @@ -233,7 +233,7 @@ private static void ExecuteAgent(string statusFileName, string statusUrl, string // Retrive status while the previous request timed out, status is in progress or package is already being installed while (status == TimedOut || status == InProgress || status == operationStartedStatus) { - status = Request(statusUrl, statusFileName); + status = Request(statusUrl, statusFileName, cookies: cookies, headers: headers); Thread.Sleep(2000); } diff --git a/src/SIM.Pipelines/Install/Modules/InstallPackages.cs b/src/SIM.Pipelines/Install/Modules/InstallPackages.cs index 0e1cfcdd..36ee3810 100644 --- a/src/SIM.Pipelines/Install/Modules/InstallPackages.cs +++ b/src/SIM.Pipelines/Install/Modules/InstallPackages.cs @@ -6,13 +6,14 @@ namespace SIM.Pipelines.Install.Modules using SIM.Products; using Sitecore.Diagnostics.Base; using JetBrains.Annotations; + using SIM.Pipelines.InstallModules; #region #endregion [UsedImplicitly] - public class InstallPackages : InstallProcessor + public class InstallPackages : InstallModulesProcessor { #region Fields @@ -22,7 +23,7 @@ public class InstallPackages : InstallProcessor #region Methods - protected override void Process([NotNull] InstallArgs args) + protected override void Process([NotNull] InstallModulesArgs args) { Assert.ArgumentNotNull(args, nameof(args)); @@ -35,7 +36,7 @@ protected override void Process([NotNull] InstallArgs args) continue; } - AgentHelper.InstallPackage(args.Instance, module); + AgentHelper.InstallPackage(args.Instance, module, args.Cookies, args.Headers); _Done.Add(module); } diff --git a/src/SIM.Pipelines/InstallModules/InstallModulesArgs.cs b/src/SIM.Pipelines/InstallModules/InstallModulesArgs.cs index 1027480e..db1b1d46 100644 --- a/src/SIM.Pipelines/InstallModules/InstallModulesArgs.cs +++ b/src/SIM.Pipelines/InstallModules/InstallModulesArgs.cs @@ -23,11 +23,15 @@ public class InstallModulesArgs : ProcessorArgs private string instanceName { get; } + public string Cookies { get; } + + public IDictionary Headers { get; } + #endregion #region Constructors - public InstallModulesArgs([NotNull] Instance instance, [NotNull] IEnumerable modules, [CanBeNull] SqlConnectionStringBuilder connectionString = null) + public InstallModulesArgs([NotNull] Instance instance, [NotNull] IEnumerable modules, [CanBeNull] SqlConnectionStringBuilder connectionString = null, [CanBeNull] string cookies = null, [CanBeNull] IDictionary headers = null) { Assert.ArgumentNotNull(instance, nameof(instance)); Assert.ArgumentNotNull(modules, nameof(modules)); @@ -36,6 +40,8 @@ public InstallModulesArgs([NotNull] Instance instance, [NotNull] IEnumerable uninstallTasksNames = Directory.GetFiles(unInstallParamsPath, "*.json") .Where(name => !Path.GetFileName(name).Equals("globals.json", StringComparison.InvariantCultureIgnoreCase)) .ToList(); @@ -122,10 +122,10 @@ public Tasker(string unInstallParamsPath) : this() EventManager.Instance.ParamValueUpdated += this.GlobalParamValueUpdated; } - private Task CreateTask(int order, JProperty taskDescriptor) + private Task CreateTask(int order, JProperty taskDescriptor, string taskFolder) { TaskDefinition definition = new TaskDefinition(taskDescriptor); - return definition.CreateTask(order, this.GlobalParams, this.FilesRoot, this.UnInstall, this.mapping); + return definition.CreateTask(order, this.GlobalParams, taskFolder, this.UnInstall, this.mapping); } private void LoadValidators() @@ -323,13 +323,13 @@ public void GenerateScripts() } } - private void LoadTasks() + private void LoadTasks(string path) { int order = 0; foreach (JProperty param in doc["ExecSequense"].Children()) { string realName = GetTaskRealName(param); - string taskFile = Directory.GetFiles(FilesRoot, string.Format("{0}.json", realName), SearchOption.AllDirectories) + string taskFile = Directory.GetFiles(path, string.Format("{0}.json", realName), SearchOption.AllDirectories) .FirstOrDefault(); if (!string.IsNullOrEmpty(taskFile)) { @@ -340,7 +340,7 @@ private void LoadTasks() } } - Task t = this.CreateTask(order, param); + Task t = this.CreateTask(order, param, path); t.UnInstall = UnInstall; this.Tasks.Add(t); if (order != t.ExecutionOrder && t.ExecutionOrder >= 0) diff --git a/src/SIM.Sitecore9Installer/Tasks/TaskDefinition.cs b/src/SIM.Sitecore9Installer/Tasks/TaskDefinition.cs index c07a2c0c..87ae66b3 100644 --- a/src/SIM.Sitecore9Installer/Tasks/TaskDefinition.cs +++ b/src/SIM.Sitecore9Installer/Tasks/TaskDefinition.cs @@ -72,7 +72,7 @@ private LocalParameters GetTaskParameters(string taskFolder, GlobalParameters gl p.Value = globalParams[p.Name].Value; installParams.Add(p); - if (p.Name == "Package") + if (p.Name == "Package" && !unInstall) { p.Value = mapping.Map(this.TaskName, taskFolder); } diff --git a/src/SIM.Tool.Base/Pipelines/InstallModulesWizardArgs.cs b/src/SIM.Tool.Base/Pipelines/InstallModulesWizardArgs.cs index 98333d48..4f481746 100644 --- a/src/SIM.Tool.Base/Pipelines/InstallModulesWizardArgs.cs +++ b/src/SIM.Tool.Base/Pipelines/InstallModulesWizardArgs.cs @@ -21,6 +21,10 @@ public class InstallModulesWizardArgs : WizardArgs private string _WebRootPath; + public string Cookies { get; } + + public IDictionary Headers { get; } + #endregion #region Constructors @@ -29,13 +33,16 @@ public InstallModulesWizardArgs() { } - public InstallModulesWizardArgs(Instance instance) + public InstallModulesWizardArgs(Instance instance, string cookies = null, IDictionary headers = null) { Instance = instance; if (instance != null) { WebRootPath = instance.WebRootPath; } + + Cookies = cookies; + Headers = headers; } #endregion @@ -81,7 +88,7 @@ public override ProcessorArgs ToProcessorArgs() products.Add(product); } - return new InstallModulesArgs(Instance, products, connectionString); + return new InstallModulesArgs(Instance, products, connectionString, Cookies, Headers); } #endregion diff --git a/src/SIM.Tool.Windows/Dialogs/CredentialsContext.cs b/src/SIM.Tool.Windows/Dialogs/CredentialsContext.cs new file mode 100644 index 00000000..87085eca --- /dev/null +++ b/src/SIM.Tool.Windows/Dialogs/CredentialsContext.cs @@ -0,0 +1,18 @@ +namespace SIM.Tool.Windows.Dialogs +{ + public class CredentialsContext + { + public string UserName { get; } + + public string Password { get; } + + public string Uri { get; } + + public CredentialsContext(string userName, string password, string uri = null) + { + this.UserName = userName; + this.Password = password; + this.Uri = uri; + } + } +} \ No newline at end of file diff --git a/src/SIM.Tool.Windows/Dialogs/CredentialsDialog.xaml b/src/SIM.Tool.Windows/Dialogs/CredentialsDialog.xaml new file mode 100644 index 00000000..d7e54d83 --- /dev/null +++ b/src/SIM.Tool.Windows/Dialogs/CredentialsDialog.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + +