public InstallationSummary(ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup, ApplicationServer applicationServer, DateTime startTime)
 {
     this.ApplicationWithOverrideVariableGroup = applicationWithOverrideVariableGroup;
     this.ApplicationServer    = applicationServer;
     this.InstallationStart    = startTime;
     this.InstallationStartUtc = TimeZoneInfo.ConvertTimeToUtc(startTime);
 }
Example #2
0
        public override void Execute(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup)
        {
            if (applicationServer == null)
            {
                throw new ArgumentNullException("applicationServer");
            }

            try
            {
                this.AppWithGroup.Install(applicationServer, DateTime.Now, false);
                this.TaskSucceeded = true;
            }
            catch (Exception ex)
            {
                this.TaskSucceeded = false;
                this.TaskDetails   = ex.Message + Environment.NewLine;
                Logger.LogException(ex);
            }
            finally
            {
                string logMessage = string.Format(CultureInfo.CurrentCulture,
                                                  PrestoCommonResources.TaskAppLogMessage,
                                                  this.Description);
                this.TaskDetails += logMessage;
                Logger.LogInformation(logMessage);
            }
        }
Example #3
0
        private void SetProcessCredentials(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup appWithGroup, Process process)
        {
            string domainAndUser = CustomVariableGroup.ResolveCustomVariable(this.RunAsUser, applicationServer, appWithGroup);

            // If this task contains a user name, use those credentials.
            if (string.IsNullOrWhiteSpace(domainAndUser))
            {
                return;
            }

            int indexOfBackslash = domainAndUser.IndexOf(@"\", StringComparison.OrdinalIgnoreCase);

            if (indexOfBackslash < 0)
            {
                throw new InvalidOperationException("User name missing backslash. Unable to parse domain name.");
            }

            string domain = domainAndUser.Substring(0, indexOfBackslash);
            string user   = domainAndUser.Substring(indexOfBackslash + 1);

            process.StartInfo.Domain   = domain;
            process.StartInfo.UserName = user;
            process.StartInfo.Password = new SecureString();

            string password = CustomVariableGroup.ResolveCustomVariable(this.RunAsPassword, applicationServer, appWithGroup);

            foreach (char c in password)
            {
                process.StartInfo.Password.AppendChar(c);
            }
        }
Example #4
0
        public override void Execute(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup)
        {
            if (applicationServer == null)
            {
                throw new ArgumentNullException("applicationServer");
            }

            string sourcePath      = this.SourcePath;
            string sourceFileName  = this.SourceFileName;
            string destinationPath = this.DestinationPath;
            string status          = "Succeeded";

            try
            {
                sourcePath      = CustomVariableGroup.ResolveCustomVariable(this.SourcePath, applicationServer, applicationWithOverrideVariableGroup);
                sourceFileName  = CustomVariableGroup.ResolveCustomVariable(this.SourceFileName, applicationServer, applicationWithOverrideVariableGroup);
                destinationPath = CustomVariableGroup.ResolveCustomVariable(this.DestinationPath, applicationServer, applicationWithOverrideVariableGroup);

                List <string> listOfFilesToCopy = new List <string>();

                listOfFilesToCopy.AddRange(Directory.GetFiles(sourcePath, sourceFileName));  // Supports wildcards

                string fileNameOnly = string.Empty;

                foreach (string fileToCopy in listOfFilesToCopy)
                {
                    fileNameOnly = fileToCopy.Substring(fileToCopy.LastIndexOf(@"\", StringComparison.OrdinalIgnoreCase) + 1);  // Get just the file name
                    if (!destinationPath.EndsWith(@"\", StringComparison.OrdinalIgnoreCase))
                    {
                        destinationPath += @"\";
                    }
                    File.Copy(fileToCopy, destinationPath + fileNameOnly, true);
                }

                this.TaskSucceeded = true;
            }
            catch (Exception ex)
            {
                this.TaskSucceeded = false;
                status             = ex.Message;
                Logger.LogException(ex);
            }
            finally
            {
                string message = "Copy File\r\n" +
                                 "Task Desc  : " + this.Description + "\r\n" +
                                 "Source     : " + sourcePath + @"\" + sourceFileName + "\r\n" +
                                 "Destination: " + destinationPath + "\r\n" +
                                 "Result     : " + status;

                this.TaskDetails = message;
                Logger.LogInformation(message);
            }
        }
Example #5
0
        public static string ResolveCustomVariable(string rawString, ApplicationServer applicationServer,
                                                   ApplicationWithOverrideVariableGroup appWithGroup, bool leaveValueEncrypted = false)
        {
            if (applicationServer == null)
            {
                throw new ArgumentNullException("applicationServer");
            }
            if (appWithGroup == null)
            {
                throw new ArgumentNullException("appWithGroup");
            }

            if (String.IsNullOrWhiteSpace(rawString))
            {
                return(rawString);
            }

            if (!StringHasCustomVariable(rawString))
            {
                return(rawString);
            }

            List <CustomVariable> allCustomVariables = new List <CustomVariable>();

            // Add system variables
            AddSystemVariables(allCustomVariables, applicationServer, appWithGroup);

            // Add all custom variables associated with the app server.
            foreach (CustomVariableGroup customVariableGroup in applicationServer.CustomVariableGroups)
            {
                ThrowIfDuplicateCustomVariableKeyExists(allCustomVariables, customVariableGroup);
                allCustomVariables.AddRange(customVariableGroup.CustomVariables);
            }

            // Add all custom variables associated with the application.
            foreach (CustomVariableGroup customVariableGroup in appWithGroup.Application.CustomVariableGroups)
            {
                ThrowIfDuplicateCustomVariableKeyExists(allCustomVariables, customVariableGroup);
                allCustomVariables.AddRange(customVariableGroup.CustomVariables);
            }

            // Add the override custom variables. If they already exist in our list, replace them.
            // Since these are overrides, duplicates are okay here.
            AddRangeOverride(allCustomVariables, appWithGroup);

            if (!CustomVariableExistsInListOfAllCustomVariables(rawString, allCustomVariables))
            {
                LogMissingVariableAndThrow(rawString);
            }

            return(ResolveCustomVariable(rawString, allCustomVariables, leaveValueEncrypted));
        }
Example #6
0
        public override void Execute(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup appWithGroup)
        {
            if (applicationServer == null)
            {
                throw new ArgumentNullException("applicationServer");
            }

            using (Process process = new Process())
            {
                string processOutput = string.Empty;

                try
                {
                    process.StartInfo.FileName               = CustomVariableGroup.ResolveCustomVariable(this.DosExecutable, applicationServer, appWithGroup);
                    process.StartInfo.Arguments              = CustomVariableGroup.ResolveCustomVariable(this.Parameters, applicationServer, appWithGroup);
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardError  = true;
                    process.StartInfo.RedirectStandardInput  = true;  // See Note 1 at the bottom of this file.
                    process.StartInfo.RedirectStandardOutput = true;

                    SetProcessCredentials(applicationServer, appWithGroup, process);

                    process.Start();

                    processOutput = process.StandardOutput.ReadToEnd();

                    process.WaitForExit();

                    PossiblyPause();

                    // Used to check process.ExitCode here. See Note 2 at the bottom of this file for notes.

                    this.TaskSucceeded = true;
                }
                catch (Exception ex)
                {
                    this.TaskSucceeded = false;
                    this.TaskDetails   = ex.Message + Environment.NewLine;
                    Logger.LogException(ex);
                }
                finally
                {
                    string logMessage = string.Format(CultureInfo.CurrentCulture,
                                                      PrestoCommonResources.TaskDosCommandLogMessage,
                                                      this.Description, process.StartInfo.FileName,
                                                      process.StartInfo.Arguments, processOutput);
                    this.TaskDetails += logMessage;
                    Logger.LogInformation(logMessage);
                }
            }
        }
Example #7
0
 private static void AddSystemVariables(List <CustomVariable> allCustomVariables, ApplicationServer applicationServer,
                                        ApplicationWithOverrideVariableGroup appWithOverrideGroup)
 {
     allCustomVariables.Add(new CustomVariable()
     {
         Key = "sys:applicationName", Value = appWithOverrideGroup.Application.Name
     });
     allCustomVariables.Add(new CustomVariable()
     {
         Key = "sys:applicationVersion", Value = appWithOverrideGroup.Application.Version
     });
     allCustomVariables.Add(new CustomVariable()
     {
         Key = "sys:serverName", Value = applicationServer.Name
     });
     allCustomVariables.Add(new CustomVariable()
     {
         Key = "sys:installationTimestamp", Value = ApplicationWithOverrideVariableGroup.InstallationStartTimestamp
     });
 }
Example #8
0
        private static void AddRangeOverride(List <CustomVariable> allCustomVariables, ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup)
        {
            if (applicationWithOverrideVariableGroup.CustomVariableGroups == null ||
                applicationWithOverrideVariableGroup.CustomVariableGroups.Count < 1)
            {
                return;  // No custom variable group to add to main list.
            }

            // Add the new custom variables to the list, overwriting any duplicates.

            // ... but before we add the overrides, need to make sure the overrides don't
            // have any duplicates within themselves.
            var hashset = new HashSet <string>();

            foreach (var cvg in applicationWithOverrideVariableGroup.CustomVariableGroups)
            {
                foreach (var cv in cvg.CustomVariables)
                {
                    if (!hashset.Add(cv.Key))
                    {
                        LogDuplicateVariableAndThrow(cv.Key);
                    }
                }
            }

            var newCustomVariables = new List <CustomVariable>();

            foreach (var cvg in applicationWithOverrideVariableGroup.CustomVariableGroups)
            {
                newCustomVariables.AddRange(cvg.CustomVariables.ToList());
            }

            // First, remove variables that are the same as the new/override variables.
            foreach (CustomVariable newCustomVariable in newCustomVariables)
            {
                CustomVariable customVariable = allCustomVariables.Where(variable => variable.Key == newCustomVariable.Key).FirstOrDefault();
                if (customVariable != null)
                {
                    allCustomVariables.Remove(customVariable);
                }
            }

            // Now add all the new variables.
            allCustomVariables.AddRange(newCustomVariables);
        }
Example #9
0
 /// <summary>
 /// Executes this instance.
 /// </summary>
 public abstract void Execute(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup);
Example #10
0
 /// <summary>
 /// Finds the matching <see cref="ApplicationWithOverrideVariableGroup"/> from the force install list.
 /// </summary>
 /// <param name="appWithGroup">The <see cref="ApplicationWithOverrideVariableGroup"/></param>
 /// <returns>If a match is found, returns the <see cref="ApplicationWithOverrideVariableGroup"/> instance.
 ///          If no match is found, returns null.
 /// </returns>
 public ServerForceInstallation GetFromForceInstallList(ApplicationWithOverrideVariableGroup appWithGroup)
 {
     return(CommonUtility.GetForceInstallationContainingAppWithGroup(this.ForceInstallationsToDo, appWithGroup));
 }
Example #11
0
        public override void Execute(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup)
        {
            string sourceFileVersion      = string.Empty;
            string destinationFileVersion = string.Empty;

            string sourceFolder      = string.Empty;
            string destinationFolder = string.Empty;
            string fileName          = string.Empty;

            try
            {
                sourceFolder      = CustomVariableGroup.ResolveCustomVariable(this.SourceFolder, applicationServer, applicationWithOverrideVariableGroup);
                destinationFolder = CustomVariableGroup.ResolveCustomVariable(this.DestinationFolder, applicationServer, applicationWithOverrideVariableGroup);
                fileName          = CustomVariableGroup.ResolveCustomVariable(this.FileName, applicationServer, applicationWithOverrideVariableGroup);

                // Will throw if file doesn't exist
                string sourcePathAndFile = SetSourcePathAndFile(sourceFolder, fileName);

                sourceFileVersion = FileVersionInfo.GetVersionInfo(sourcePathAndFile).FileVersion;

                string destinationPathAndFile = destinationFolder + @"\" + fileName;

                // It's okay if the destination file doesn't exist. This just means (hopefully) that this is
                // the first time we're deploying this file.
                if (!File.Exists(destinationPathAndFile))
                {
                    this.TaskSucceeded = true;
                }
                else
                {
                    destinationFileVersion = FileVersionInfo.GetVersionInfo(destinationPathAndFile).FileVersion;

                    this.TaskSucceeded = false;  // default
                    // We want the file versions to be different. Otherwise we're just deploying the same thing again,
                    // which is what this is designed to detect.
                    if (sourceFileVersion != destinationFileVersion)
                    {
                        this.TaskSucceeded = true;
                    }
                }
            }
            catch (Exception ex)
            {
                this.TaskSucceeded = false;
                this.TaskDetails   = ex.Message + Environment.NewLine;
                Logger.LogException(ex);
            }
            finally
            {
                string logMessage = string.Format(CultureInfo.CurrentCulture,
                                                  PrestoCommonResources.TaskVersionCheckerLogMessage,
                                                  this.Description,
                                                  fileName,
                                                  sourceFileVersion,
                                                  sourceFolder,
                                                  destinationFileVersion,
                                                  destinationFolder);
                this.TaskDetails += logMessage;
                Logger.LogInformation(logMessage);
            }
        }
Example #12
0
 public ServerForceInstallation(ApplicationServer server, ApplicationWithOverrideVariableGroup appWithGroup)
 {
     this.ApplicationServer            = server;
     this.ApplicationWithOverrideGroup = appWithGroup;
 }
Example #13
0
        public override void Execute(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup)
        {
            string taskDetails = string.Empty;

            try
            {
                TaskXmlModify taskResolved = GetTaskXmlModifyWithCustomVariablesResolved(applicationServer, applicationWithOverrideVariableGroup);
                taskDetails = ConvertTaskDetailsToString(taskResolved);

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(taskResolved.XmlPathAndFileName);
                XmlElement rootElement = xmlDocument.DocumentElement;

                XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
                string prefix       = ""; // default
                string prefixSuffix = ""; // yes, a suffix for a prefix. Eat me.
                if (!string.IsNullOrWhiteSpace(taskResolved.NodeNamespace))
                {
                    prefix       = "nssnuh"; // use something that we'll never expect to see in an XML doc.
                    prefixSuffix = ":";
                    namespaceManager.AddNamespace(prefix, taskResolved.NodeNamespace);
                }

                if (this.AddNode)
                {
                    AddNewNode(xmlDocument, taskResolved, rootElement);
                }
                else
                {
                    ModifyExistingNode(taskResolved, rootElement, prefix, prefixSuffix, namespaceManager);
                }

                // If internal subset doesn't have a value, then make it null. Making it null will cause
                // <!DOCTYPE HTML> to be the result (which is what we want), instead of <!DOCTYPE HTML[]>.
                // The brackets enable quirks mode. We don't want quirks mode.
                // http://stackoverflow.com/q/38832479/279516
                // http://stackoverflow.com/a/16451790/279516
                if (xmlDocument.DocumentType != null && string.IsNullOrWhiteSpace(xmlDocument.DocumentType.InternalSubset))
                {
                    var name     = xmlDocument.DocumentType.Name;
                    var publicId = xmlDocument.DocumentType.PublicId;
                    var systemId = xmlDocument.DocumentType.SystemId;
                    var parent   = xmlDocument.DocumentType.ParentNode;
                    var documentTypeWithNullInternalSubset = xmlDocument.CreateDocumentType(name, publicId, systemId, null);
                    parent.ReplaceChild(documentTypeWithNullInternalSubset, xmlDocument.DocumentType);
                }

                xmlDocument.Save(taskResolved.XmlPathAndFileName);
                xmlDocument = null;

                this.TaskSucceeded = true;

                this.TaskDetails = taskDetails;
                Logger.LogInformation(taskDetails);
            }
            catch (Exception ex)
            {
                this.TaskSucceeded = false;
                this.TaskDetails   = ex.Message + Environment.NewLine + taskDetails;
                Logger.LogException(ex);
            }
        }
Example #14
0
        private TaskXmlModify GetTaskXmlModifyWithCustomVariablesResolved(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup)
        {
            TaskXmlModify taskXmlModifyResolved = new TaskXmlModify();

            taskXmlModifyResolved.Description          = this.Description;
            taskXmlModifyResolved.FailureCausesAllStop = this.FailureCausesAllStop;
            taskXmlModifyResolved.PrestoTaskType       = this.PrestoTaskType;
            taskXmlModifyResolved.Sequence             = this.Sequence;
            taskXmlModifyResolved.TaskSucceeded        = this.TaskSucceeded;

            taskXmlModifyResolved.AttributeKey           = CustomVariableGroup.ResolveCustomVariable(this.AttributeKey, applicationServer, applicationWithOverrideVariableGroup);
            taskXmlModifyResolved.AttributeKeyValue      = CustomVariableGroup.ResolveCustomVariable(this.AttributeKeyValue, applicationServer, applicationWithOverrideVariableGroup);
            taskXmlModifyResolved.AttributeToChange      = CustomVariableGroup.ResolveCustomVariable(this.AttributeToChange, applicationServer, applicationWithOverrideVariableGroup);
            taskXmlModifyResolved.AttributeToChangeValue = CustomVariableGroup.ResolveCustomVariable(this.AttributeToChangeValue, applicationServer, applicationWithOverrideVariableGroup);
            taskXmlModifyResolved.NodeNamespace          = CustomVariableGroup.ResolveCustomVariable(this.NodeNamespace, applicationServer, applicationWithOverrideVariableGroup);
            taskXmlModifyResolved.NodeToChange           = CustomVariableGroup.ResolveCustomVariable(this.NodeToChange, applicationServer, applicationWithOverrideVariableGroup);
            taskXmlModifyResolved.XmlPathAndFileName     = CustomVariableGroup.ResolveCustomVariable(this.XmlPathAndFileName, applicationServer, applicationWithOverrideVariableGroup);
            taskXmlModifyResolved.AddNode = this.AddNode;

            return(taskXmlModifyResolved);
        }
Example #15
0
 public TaskApp(ApplicationWithOverrideVariableGroup appWithGroup)
 {
     this.AppWithGroup   = appWithGroup;
     this.PrestoTaskType = TaskType.App;
 }