예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }
예제 #4
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));
        }
예제 #5
0
        public PingResponse(string pingRequestId, DateTime responseTime, ApplicationServer applicationServer, string comment)
        {
            if (applicationServer == null)
            {
                throw new ArgumentNullException("applicationServer");
            }

            this.PingRequestId       = pingRequestId;
            this.ApplicationServer   = applicationServer;
            this.ApplicationServerId = applicationServer.Id;
            this.ResponseTime        = responseTime;
            this.Comment             = comment;
        }
예제 #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);
                }
            }
        }
예제 #7
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);
        }
예제 #8
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
     });
 }
예제 #9
0
 /// <summary>
 /// Executes this instance.
 /// </summary>
 public abstract void Execute(ApplicationServer applicationServer, ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup);
예제 #10
0
        /// <summary>
        /// Installs this instance.
        /// </summary>
        public InstallationResultContainer Install(ApplicationServer applicationServer, DateTime installationStartTime, bool calledFromAppInstaller)
        {
            SetInstallationStartTimestamp(installationStartTime);

            // Before 23-Jun-2014, the only caller to this method was the AppInstaller. Since a new task (TaskApp) was added, it
            // also calls this method now. We only want to initialize a new container when called by AppInstaller. TaskApp will
            // call this method, but it won't do anything with the result. So, we just want to capture all of the task details
            // here, including the ones generated by TaskApp, then return the whole thing to AppInstaller.
            if (calledFromAppInstaller)
            {
                _installationResultContainer = new InstallationResultContainer();
            }

            bool atLeastOneTaskFailed    = false;
            int  numberOfSuccessfulTasks = 0;

            try
            {
                // Note: We do a ToList() here because we get a "collection was modified" exception otherwise. The reason we
                //       get the exception is because, somewhere else in this processing, we make this call:
                //       CustomVariableGroupLogic.Get(application.Name)
                //       That method does a refresh on the CustomVariableGroup, which contains an app, which contains the tasks.
                //       Good times.
                foreach (TaskBase taskBase in this.Application.MainAndPrerequisiteTasks.ToList().OrderBy(task => task.Sequence))
                {
                    DateTime taskStartTime = DateTime.Now;

                    PossiblyAddTaskAppStartToInstallationResults(taskBase, taskStartTime);

                    taskBase.Execute(applicationServer, this);

                    _installationResultContainer.TaskDetails.Add(new TaskDetail(taskStartTime, DateTime.Now, taskBase.TaskDetails));

                    if (taskBase.TaskSucceeded == true)
                    {
                        numberOfSuccessfulTasks++;
                    }

                    // The reason this is here is because we're trying to detect when failures occur within the TaskApp types.
                    if (_atLeastOneTaskFailedWhereFailureCausesAllStop)
                    {
                        break;
                    }

                    if (taskBase.TaskSucceeded == false)
                    {
                        atLeastOneTaskFailed = true;
                        if (taskBase.FailureCausesAllStop == 1)
                        {
                            _atLeastOneTaskFailedWhereFailureCausesAllStop = true;
                            break;  // No more processing.
                        }
                    }
                }

                return(FinalInstallationResultContainer(_installationResultContainer, InstallationResult.Success, numberOfSuccessfulTasks, atLeastOneTaskFailed));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                return(FinalInstallationResultContainer(_installationResultContainer, InstallationResult.Failure, numberOfSuccessfulTasks, atLeastOneTaskFailed));
            }
            finally
            {
                // Clear this so we don't keep things hanging around in memory unnecessarily.
                if (calledFromAppInstaller)
                {
                    _installationResultContainer = null;
                }
                if (calledFromAppInstaller)
                {
                    _atLeastOneTaskFailedWhereFailureCausesAllStop = false;
                }                                                                                       // Reset for the next call
            }
        }
예제 #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);
            }
        }
예제 #12
0
 public InstallationSummary(ApplicationWithOverrideVariableGroup applicationWithOverrideVariableGroup, ApplicationServer applicationServer, DateTime startTime)
 {
     this.ApplicationWithOverrideVariableGroup = applicationWithOverrideVariableGroup;
     this.ApplicationServer    = applicationServer;
     this.InstallationStart    = startTime;
     this.InstallationStartUtc = TimeZoneInfo.ConvertTimeToUtc(startTime);
 }
예제 #13
0
 public ServerForceInstallation(ApplicationServer server, ApplicationWithOverrideVariableGroup appWithGroup)
 {
     this.ApplicationServer            = server;
     this.ApplicationWithOverrideGroup = appWithGroup;
 }
예제 #14
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);
            }
        }