public static string DifferencesBetweenTwoCustomVariableGroups(CustomVariableGroup oldGroup, CustomVariableGroup newGroup) { if (newGroup == null) { throw new ArgumentNullException("newGroup"); } if (oldGroup == null) { return("New group created" + Environment.NewLine + Environment.NewLine + ObjectDump(newGroup)); } var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("DELETED"); stringBuilder.AppendLine("Variables in the old group, but not in the new group:"); foreach (var oldVariable in oldGroup.CustomVariables) { var newVariable = newGroup.CustomVariables.FirstOrDefault(x => x.Key == oldVariable.Key); if (newVariable == null) { stringBuilder.AppendLine(oldVariable.Key + ": " + oldVariable.Value); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("ADDED"); stringBuilder.AppendLine("Variables in the new group, but not in the old group:"); foreach (var newVariable in newGroup.CustomVariables) { var oldVariable = oldGroup.CustomVariables.FirstOrDefault(x => x.Key == newVariable.Key); if (oldVariable == null) { stringBuilder.AppendLine(newVariable.Key + ": " + newVariable.Value); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("CHANGED"); stringBuilder.AppendLine("Variables that exist in the old and new groups, but are different:"); foreach (var oldVariable in oldGroup.CustomVariables) { var newVariable = newGroup.CustomVariables.FirstOrDefault(x => x.Key == oldVariable.Key); if (newVariable == null) { continue; } if (oldVariable.Value == newVariable.Value) { continue; } stringBuilder.AppendLine("Key: " + oldVariable.Key); stringBuilder.AppendLine("Old value: " + oldVariable.Value); stringBuilder.AppendLine("New value: " + newVariable.Value); stringBuilder.AppendLine(); } return(stringBuilder.ToString()); }
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); } }
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); } }
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); } } }
private static string ObjectDump(CustomVariableGroup customVariableGroup) { var dump = new StringBuilder(); dump.AppendLine(customVariableGroup.Name); dump.AppendLine(); dump.AppendLine("Custom Variables:"); dump.AppendLine(); foreach (var customVariable in customVariableGroup.CustomVariables) { dump.AppendLine(customVariable.Key + ": " + customVariable.Value); } return(dump.ToString()); }
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); }
private static string DuplicateCustomVariableKey(IEnumerable <CustomVariable> masterVariableList, CustomVariableGroup newGroup) { foreach (CustomVariable customVariable in newGroup.CustomVariables) { if (masterVariableList.Any(x => x.Key == customVariable.Key)) { return(customVariable.Key); } } return(string.Empty); }
private static void ThrowIfDuplicateCustomVariableKeyExists(List <CustomVariable> allCustomVariables, CustomVariableGroup customVariableGroup) { string duplicateKey = DuplicateCustomVariableKey(allCustomVariables, customVariableGroup); if (!string.IsNullOrEmpty(duplicateKey)) { LogDuplicateVariableAndThrow(duplicateKey); } }
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); } }