/// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     if (string.IsNullOrEmpty(this.Url))
     {
         errorProcesser.ProcessError("URL cannot be empty");
     }
 }
Пример #2
0
        private void VerifyDocumentHasValidRootElement(XmlDocument configXml, IConfigurationErrorProcesser errorProcesser)
        {
            var version = Assembly.GetExecutingAssembly().GetName().Version;

            if (configXml.DocumentElement == null || configXml.DocumentElement.Name != ROOT_ELEMENT)
            {
                throw new ConfigurationException("The configuration document has an invalid root element.  Expected <cruisecontrol>.");
            }
            else if (string.IsNullOrEmpty(configXml.DocumentElement.NamespaceURI))
            {
                // Tell the user there is no version information
                errorProcesser.ProcessWarning("Configuration does not have any version information - assuming the configuration is for version " + version.ToString(2));
            }
            else
            {
                // The last two items are the version number
                var parts         = configXml.DocumentElement.NamespaceURI.Split('/');
                var versionNumber = parts[parts.Length - 2] + "." + parts[parts.Length - 1];
                if (version.ToString(2) != versionNumber)
                {
                    // Tell the user the version does not match
                    errorProcesser.ProcessWarning(
                        "Version mismatch - CruiseControl.NET is version " + version.ToString(2) +
                        ", the configuration is for version " + versionNumber);
                }
            }
        }
Пример #3
0
 public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     if (this.RepeatCount <= 0)
     {
         errorProcesser.ProcessWarning("count is less than 1!");
     }
 }
 /// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     if ((this.Actions == null) || (this.Actions.Length == 0))
     {
         errorProcesser.ProcessWarning("This task will not do anything - no actions specified");
     }
 }
Пример #5
0
        /// <summary>
        /// Validate the internal consistency of the configuration.
        /// </summary>
        /// <param name="value">The configuration to check.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        /// <remarks>
        /// <para>
        /// This will add the following internal consistency checks:
        /// </para>
        /// <list type="bullet">
        /// <item>
        /// <description>Each queue definitition is used by at least one project.</description>
        /// </item>
        /// </list>
        /// </remarks>
        private void ValidateConfiguration(Configuration value, IConfigurationErrorProcesser errorProcesser)
        {
            var rootTrace = ConfigurationTrace.Start(value);

            // Validate the security manager - need to do this first
            if (value.SecurityManager is IConfigurationValidation)
            {
                (value.SecurityManager as IConfigurationValidation).Validate(value, rootTrace, errorProcesser);
            }

            // Validate all the projects
            foreach (IProject project in value.Projects)
            {
                var dummy = project as IConfigurationValidation;
                if (dummy != null)
                {
                    dummy.Validate(value, rootTrace, errorProcesser);
                }
            }

            // Validate all the queues
            foreach (IQueueConfiguration queue in value.QueueConfigurations)
            {
                var dummy = queue as IConfigurationValidation;
                if (dummy != null)
                {
                    dummy.Validate(value, rootTrace, errorProcesser);
                }
            }
        }
Пример #6
0
 public IConfiguration Read(XmlDocument document, IConfigurationErrorProcesser errorProcesser)
 {
     DisplayFileName();
     DisplayProgressMessage("Validating configuration, please wait...", 10);
     ValidateData(document);
     LoadCompleted();
     return(null);
 }
Пример #7
0
 public IConfiguration Read(XmlDocument document, IConfigurationErrorProcesser errorProcesser)
 {
     DisplayFileName();
     DisplayProgressMessage("Validating configuration, please wait...", 10);
     ValidateData(document);
     LoadCompleted();
     return null;
 }
Пример #8
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            // Get the name of the executable
            var canCheck = true;
            var fileName = this.GetProcessFilename();
            if (!Path.IsPathRooted(fileName))
            {
                var project = parent.GetAncestorValue<Project>();
                if (project != null)
                {
                    var result = ConfigurationValidationUtils.GenerateResultForProject(project);
                    var directory = this.GetProcessBaseDirectory(result);
                    fileName = Path.Combine(directory, fileName);
                }
                else
                {
                    // Can't generate the path, therefore can't check for the file
                    canCheck = false;
                }
            }

            // See if it exists - shortcut the process if there is an exact match (the remainder uses pattern matching to try and find the file)
            if (canCheck && !this.IOSystemActual.FileExists(fileName))
            {
                var fileExists = false;

                // This needs to be from the filename, just in case the path is a relative path and it has been joined to the base directory
                var directory = Path.GetDirectoryName(fileName);
                if (this.IOSystemActual.DirectoryExists(directory))
                {
                    // Get all the files and check each file
                    var files = this.IOSystemActual.GetFilesInDirectory(directory);
                    var executableName1 = Path.GetFileNameWithoutExtension(fileName);
                    var executableName2 = Path.GetFileName(fileName);
                    foreach (var file in files)
                    {
                        // Strip the extension so we can compare partial file names (since Windows does not need the .exe extension)
                        var fileToTest = Path.GetFileNameWithoutExtension(file);

                        // Need to perform two checks here as some Windows names have two multiple dots - therefore GetFileNameWithoutExtension will strip the last part,
                        // whether or not it is an extension
                        if (string.Equals(fileToTest, executableName1, StringComparison.InvariantCultureIgnoreCase) ||
                            string.Equals(fileToTest, executableName2, StringComparison.InvariantCultureIgnoreCase))
                        {
                            fileExists = true;
                            break;
                        }
                    }
                }

                if (!fileExists)
                {
                    errorProcesser.ProcessWarning("Unable to find executable '" + fileName + "'");
                }
            }
        }
Пример #9
0
 public void Validate(IConfiguration configuration,
     ConfigurationTrace parent,
     IConfigurationErrorProcesser errorProcesser)
 {
     if (this.MaximumValue <= 0)
     {
         errorProcesser.ProcessError(
             "The maximum value must be greater than zero");
     }
 }
Пример #10
0
        public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            if (this.ValidateAction != null)
            {
                this.ValidateAction(configuration, parent, errorProcesser);
                return;
            }

            throw new NotImplementedException();
        }
Пример #11
0
 public void Validate(IConfiguration configuration,
                      ConfigurationTrace parent,
                      IConfigurationErrorProcesser errorProcesser)
 {
     if (this.MaximumValue <= 0)
     {
         errorProcesser.ProcessError(
             "The maximum value must be greater than zero");
     }
 }
 public void Validate(IConfiguration configuration,
     ConfigurationTrace parent,
     IConfigurationErrorProcesser errorProcesser)
 {
     if (string.IsNullOrEmpty(this.MonitorFile))
     {
         errorProcesser.ProcessError("File cannot be empty");
     }
     else if (!File.Exists(this.MonitorFile))
     {
         errorProcesser.ProcessWarning(
             "File '" + this.MonitorFile + "' does not exist");
     }
 }
 public void Validate(IConfiguration configuration,
                      ConfigurationTrace parent,
                      IConfigurationErrorProcesser errorProcesser)
 {
     if (string.IsNullOrEmpty(this.MonitorFile))
     {
         errorProcesser.ProcessError("File cannot be empty");
     }
     else if (!File.Exists(this.MonitorFile))
     {
         errorProcesser.ProcessWarning(
             "File '" + this.MonitorFile + "' does not exist");
     }
 }
Пример #14
0
 /// <summary>
 /// Validates this task.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     // Validate all the child tasks
     if (Tasks != null)
     {
         foreach (var task in Tasks)
         {
             var validatorTask = task as IConfigurationValidation;
             if (validatorTask != null)
             {
                 validatorTask.Validate(configuration, parent.Wrap(this), errorProcesser);
             }
         }
     }
 }
 /// <summary>
 /// Validates some tasks.
 /// </summary>
 /// <param name="tasks">The tasks.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="errorProcesser">The error processer.</param>
 private void ValidateTasks(ITask[] tasks,
                            IConfiguration configuration,
                            ConfigurationTrace parent,
                            IConfigurationErrorProcesser errorProcesser)
 {
     if (tasks != null)
     {
         foreach (var task in tasks)
         {
             var validatorTask = task as IConfigurationValidation;
             if (validatorTask != null)
             {
                 validatorTask.Validate(configuration, parent, errorProcesser);
             }
         }
     }
 }
Пример #16
0
 /// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public void Validate(IConfiguration configuration,
                      ConfigurationTrace parent,
                      IConfigurationErrorProcesser errorProcesser)
 {
     if ((this.Conditions == null) || (this.Conditions.Length == 0))
     {
         errorProcesser
         .ProcessError("Validation failed for andCondition - at least one child condition must be supplied");
     }
     else
     {
         foreach (var child in this.Conditions.OfType <IConfigurationValidation>())
         {
             child.Validate(
                 configuration,
                 parent.Wrap(this),
                 errorProcesser);
         }
     }
 }
Пример #17
0
        private void LoadAndValidateProject(IConfigurationErrorProcesser errorProcesser,
                                            List <string> projectNames, Configuration configuration, object loadedItem)
        {
            IProject project = loadedItem as IProject;

            // Validate that the project name is unique
            string projectName = project.Name.ToLowerInvariant();

            if (projectNames.Contains(projectName))
            {
                errorProcesser.ProcessError(
                    new CruiseControlException(
                        string.Format(
                            CultureInfo.CurrentCulture, "A duplicate project name ({0})has been found - projects must be unique per server",
                            projectName)));
            }
            else
            {
                projectNames.Add(projectName);
            }

            configuration.AddProject(project);
        }
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser"></param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            foreach (IAuthentication user in users)
            {
                var dummy = user as IConfigurationValidation;
                if (dummy != null)
                {
                    dummy.Validate(configuration, parent.Wrap(this), errorProcesser);
                }
            }

            foreach (IPermission permission in permissions)
            {
                var dummy = permission as IConfigurationValidation;
                if (dummy != null)
                {
                    dummy.Validate(configuration, parent.Wrap(this), errorProcesser);
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            if (string.IsNullOrEmpty(this.Url))
            {
                errorProcesser.ProcessError("URL cannot be empty");
            }

            if (string.IsNullOrEmpty(this.HeaderKey))
            {
                errorProcesser.ProcessError("Header Key cannot be empty");
            }
        }
 private void VerifyDocumentHasValidRootElement(XmlDocument configXml, IConfigurationErrorProcesser errorProcesser)
 {
     var version = Assembly.GetExecutingAssembly().GetName().Version;
     if (configXml.DocumentElement == null || configXml.DocumentElement.Name != ROOT_ELEMENT)
     {
         throw new ConfigurationException("The configuration document has an invalid root element.  Expected <cruisecontrol>.");
     }
     else if (string.IsNullOrEmpty(configXml.DocumentElement.NamespaceURI))
     {
         // Tell the user there is no version information
         errorProcesser.ProcessWarning("Configuration does not have any version information - assuming the configuration is for version " + version.ToString(2));
     }
     else
     {
         // The last two items are the version number
         var parts = configXml.DocumentElement.NamespaceURI.Split('/');
         var versionNumber = parts[parts.Length - 2] + "." + parts[parts.Length - 1];
         if (version.ToString(2) != versionNumber)
         {
             // Tell the user the version does not match
             errorProcesser.ProcessWarning(
                 "Version mismatch - CruiseControl.NET is version " + version.ToString(2) +
                 ", the configuration is for version " + versionNumber);
         }
     }
 }
 /// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser"></param>
 public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     foreach (IPermission permission in permissions)
     {
         var dummy = permission as IConfigurationValidation;
         if (dummy != null)
         {
             dummy.Validate(configuration, parent.Wrap(this), errorProcesser);
         }
     }
 }
 /// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     if (!string.IsNullOrEmpty(refId))
     {
         IPermission refPermission = configuration.SecurityManager.RetrievePermission(refId);
         if (refPermission == null)
         {
             errorProcesser.ProcessError(new BadReferenceException(refId));
         }
     }
 }
Пример #23
0
        public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            string ErrorInfo = "Invalid chars in TFS workspace name. Look at http://msdn.microsoft.com/en-us/library/aa980550.aspx#SourceControl for naming restrictions.";

            bool AllOk = true;

            System.Collections.Generic.List <string> badchars = new System.Collections.Generic.List <string>();

            badchars.Add("/");
            badchars.Add(":");
            badchars.Add("<");
            badchars.Add(">");
            badchars.Add("|");
            badchars.Add(@"\");
            badchars.Add("*");
            badchars.Add("?");
            badchars.Add(";");


            if (workspaceName.Length > 64)
            {
                AllOk      = false;
                ErrorInfo += System.Environment.NewLine + "Max length is 64 chars";
            }
            if (workspaceName.EndsWith(" "))
            {
                AllOk      = false;
                ErrorInfo += System.Environment.NewLine + "can not end with space";
            }


            foreach (string s in badchars)
            {
                if (workspaceName.Contains(s))
                {
                    AllOk      = false;
                    ErrorInfo += System.Environment.NewLine + "can not contain character " + s;
                }
            }

            if (!AllOk)
            {
                errorProcesser.ProcessError(ErrorInfo);
            }
        }
 /// <summary>
 /// Validates some tasks.
 /// </summary>
 /// <param name="tasks">The tasks.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="errorProcesser">The error processer.</param>
 private void ValidateTasks(ITask[] tasks,
     IConfiguration configuration, 
     ConfigurationTrace parent, 
     IConfigurationErrorProcesser errorProcesser)
 {
     if (tasks != null)
     {
         foreach (var task in tasks)
         {
             var validatorTask = task as IConfigurationValidation;
             if (validatorTask != null)
             {
                 validatorTask.Validate(configuration, parent, errorProcesser);
             }
         }
     }
 }
Пример #25
0
 public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     IsValided = true;
 }
Пример #26
0
 /// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     if ((this.Actions == null) || (this.Actions.Length == 0))
     {
         errorProcesser.ProcessWarning("This task will not do anything - no actions specified");
     }
 }
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public override void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            base.Validate(configuration, parent, errorProcesser);
            if (this.Verbose && this.Quiet)
            {
                errorProcesser.ProcessError("Cannot have both verbose and quiet set");
            }

            if (this.ProfilerTimeOut < 0)
            {
                errorProcesser.ProcessError("profilerTimeout cannot be negative");
            }
        }
 /// <summary>
 /// Validates this task.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     // Validate all the child tasks
     if (Tasks != null)
     {
         foreach (var task in Tasks)
         {
             var validatorTask = task as IConfigurationValidation;
             if (validatorTask != null)
             {
                 validatorTask.Validate(configuration, parent.Wrap(this), errorProcesser);
             }
         }
     }
 }
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser"></param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            foreach (IAuthentication user in users)
            {
                if (user is IConfigurationValidation)
                {
                    (user as IConfigurationValidation).Validate(configuration, parent.Wrap(this), errorProcesser);
                }
            }

            foreach (IPermission permission in permissions)
            {
                if (permission is IConfigurationValidation)
                {
                    (permission as IConfigurationValidation).Validate(configuration, parent.Wrap(this), errorProcesser);
                }
            }
        }
Пример #30
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            var parentProject = parent.GetAncestorValue<Project>();
            if (parentProject != null)
            {
                // Attempt to find this publisher in the publishers section
                var isPublisher = false;
                foreach (var task in parentProject.Publishers)
                {
                    if (task == this)
                    {
                        isPublisher = true;
                        break;
                    }
                }

                // If not found then throw a validation exception
                if (!isPublisher)
                {
                    errorProcesser.ProcessWarning(
                        "Email publishers are best placed in the publishers section of the configuration");
                }
            }
            else
            {
                errorProcesser.ProcessError(new CruiseControlException("This publisher can only belong to a project"));
            }

            // Make sure the xslFiles are not empty
            if (this.xslFiles != null &&  this.XslFiles.Any(f => string.IsNullOrEmpty(f)))
            {
                errorProcesser.ProcessError("xslFiles cannot contain empty or null filenames");
            }
        }
 public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     if (!string.IsNullOrWhiteSpace(this.LogFile))
     {
         try
         {
             string dir = Path.GetDirectoryName(this.LogFile);
             if (!Directory.Exists(dir))
             {
                 Directory.CreateDirectory(dir);
             }
             Log("Validating permissions");
         }
         catch (Exception ex)
         {
             errorProcesser.ProcessWarning("Could not create log file: ", ex.ToString());
             this.LogFile = null;
         }
     }
 }
Пример #32
0
        public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            string ErrorInfo = "Invalid chars in TFS workspace name. Look at http://msdn.microsoft.com/en-us/library/aa980550.aspx#SourceControl for naming restrictions.";

            bool AllOk = true;
            System.Collections.Generic.List<string> badchars = new System.Collections.Generic.List<string>();

            badchars.Add("/");
            badchars.Add(":");
            badchars.Add("<");
            badchars.Add(">");
            badchars.Add("|");
            badchars.Add(@"\");
            badchars.Add("*");
            badchars.Add("?");
            badchars.Add(";");


            if (workspaceName.Length > 64)
            {
                AllOk = false;
                ErrorInfo += System.Environment.NewLine + "Max length is 64 chars";
            }
            if (workspaceName.EndsWith(" "))
            {
                AllOk = false;
                ErrorInfo += System.Environment.NewLine + "can not end with space";
            }


            foreach (string s in badchars)
            {
                if (workspaceName.Contains(s))
                {
                    AllOk = false;
                    ErrorInfo += System.Environment.NewLine + "can not contain character " + s;
                }
            }

            if (!AllOk) errorProcesser.ProcessError(ErrorInfo);
        }
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            // Get the name of the executable
            var canCheck = true;
            var fileName = this.GetProcessFilename().Trim();

            if (!Path.IsPathRooted(fileName))
            {
                var project = parent.GetAncestorValue <Project>();
                if (project != null)
                {
                    var result    = ConfigurationValidationUtils.GenerateResultForProject(project);
                    var directory = this.GetProcessBaseDirectory(result);
                    fileName = Path.Combine(directory, fileName);
                }
                else
                {
                    // Can't generate the path, therefore can't check for the file
                    canCheck = false;
                }
            }

            // See if it exists - shortcut the process if there is an exact match (the remainder uses pattern matching to try and find the file)
            if (canCheck && !this.IOSystemActual.FileExists(fileName))
            {
                var fileExists = false;

                // This needs to be from the filename, just in case the path is a relative path and it has been joined to the base directory
                var directory = Path.GetDirectoryName(fileName);
                if (this.IOSystemActual.DirectoryExists(directory))
                {
                    // Get all the files and check each file
                    var files           = this.IOSystemActual.GetFilesInDirectory(directory);
                    var executableName1 = Path.GetFileNameWithoutExtension(fileName);
                    var executableName2 = Path.GetFileName(fileName);
                    foreach (var file in files)
                    {
                        // Strip the extension so we can compare partial file names (since Windows does not need the .exe extension)
                        var fileToTest = Path.GetFileNameWithoutExtension(file);

                        // Need to perform two checks here as some Windows names have two multiple dots - therefore GetFileNameWithoutExtension will strip the last part,
                        // whether or not it is an extension
                        if (string.Equals(fileToTest, executableName1, StringComparison.InvariantCultureIgnoreCase) ||
                            string.Equals(fileToTest, executableName2, StringComparison.InvariantCultureIgnoreCase))
                        {
                            fileExists = true;
                            break;
                        }
                    }
                }

                if (!fileExists)
                {
                    errorProcesser.ProcessWarning("Unable to find executable '" + fileName + "'");
                }
            }
        }
 public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     if (this.RepeatCount <= 0)
     {
         errorProcesser.ProcessWarning("count is less than 1!");
     }
 }
Пример #35
0
 /// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     try
     {
         this.GetFBVersion();
         this.GetFBPath();
     }
     catch (Exception error)
     {
         errorProcesser.ProcessError(error);
     }
 }
        void IConfigurationValidation.Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            string projectName = "(Unknown)";

            var project = parent.GetAncestorValue <Project>();

            if (project != null)
            {
                projectName = project.Name;
            }

            if (integrationTime.Minutes + RandomOffSetInMinutesFromTime >= 60)
            {
                errorProcesser.ProcessError("Scheduled time {0}:{1} + randomOffSetInMinutesFromTime {2} would exceed the hour, this is not allowed. Conflicting project {3}", integrationTime.Hours, integrationTime.Minutes, RandomOffSetInMinutesFromTime, projectName);
            }
        }
Пример #37
0
        private bool RunValidationCheck(Configuration configuration, IConfigurationValidation validator, string name, ref int row, IConfigurationErrorProcesser errorProcesser)
        {
            bool isValid = true;

            try
            {
                validator.Validate(configuration, ConfigurationTrace.Start(configuration), errorProcesser);
            }
            catch (Exception error)
            {
                var message = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Internal validation failed for {0}: {1}",
                                            name,
                                            error.Message);
                HtmlAttribute rowClass = new HtmlAttribute("class", (row % 2) == 1 ? "even" : "odd");
                myBodyEl.AppendChild(
                    GenerateElement("div",
                                    rowClass,
                                    GenerateElement("div",
                                                    new HtmlAttribute("class", "error"),
                                                    message)));
                LogMessage(message);
                isValid = false;
                row++;
            }
            return(isValid);
        }
Пример #38
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            var parentProject = parent.GetAncestorValue <Project>();

            if (parentProject != null)
            {
                // Attempt to find this publisher in the publishers section
                var isPublisher = false;
                foreach (var task in parentProject.Publishers)
                {
                    if (task == this)
                    {
                        isPublisher = true;
                        break;
                    }
                }

                // If not found then throw a validation exception
                if (!isPublisher)
                {
                    errorProcesser.ProcessWarning(
                        "Email publishers are best placed in the publishers section of the configuration");
                }
            }
            else
            {
                errorProcesser.ProcessError(new CruiseControlException("This publisher can only belong to a project"));
            }

            // Make sure the xslFiles are not empty
            if (this.xslFiles != null && this.XslFiles.Any(f => string.IsNullOrEmpty(f)))
            {
                errorProcesser.ProcessError("xslFiles cannot contain empty or null filenames");
            }
        }
Пример #39
0
 /// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     try
     {
         this.GetFBVersion();
         this.GetFBPath();
     }
     catch (Exception error)
     {
         errorProcesser.ProcessError(error);
     }
 }
Пример #40
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            if (string.IsNullOrEmpty(AwsAccessKey))
            {
                errorProcesser.ProcessError("awsAccessKey cannot be empty");
            }

            if (string.IsNullOrEmpty(AwsSecretAccessKey))
            {
                errorProcesser.ProcessError("awsSecretAccessKey cannot be empty");
            }

            if (!Uri.IsWellFormedUriString(QueueUrl, UriKind.Absolute))
            {
                errorProcesser.ProcessError("queueUrl is not well-formed");
            }
        }
Пример #41
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser"></param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            var isInitialised = false;

            try
            {
                Initialise();
                isInitialised = true;
            }
            catch (Exception error)
            {
                errorProcesser.ProcessError(error);
            }

            if (isInitialised)
            {
                foreach (IAuthentication user in this.loadedUsers.Values)
                {
                    var config = user as IConfigurationValidation;
                    if (config != null)
                    {
                        config.Validate(configuration, parent.Wrap(this), errorProcesser);
                    }
                }

                foreach (IPermission permission in this.loadedPermissions.Values)
                {
                    var config = permission as IConfigurationValidation;
                    if (config != null)
                    {
                        config.Validate(configuration, parent.Wrap(this), errorProcesser);
                    }
                }
            }
        }
Пример #42
0
        private bool RunValidationCheck(Configuration configuration, IConfigurationValidation validator, string name, ref int row, IConfigurationErrorProcesser errorProcesser)
        {
            bool isValid = true;

            try
            {
                validator.Validate(configuration, ConfigurationTrace.Start(configuration), errorProcesser);
            }
            catch (Exception error)
            {
                var message = string.Format("Internal validation failed for {0}: {1}",
                            name,
                            error.Message);
                HtmlAttribute rowClass = new HtmlAttribute("class", (row % 2) == 1 ? "even" : "odd");
                myBodyEl.AppendChild(
                    GenerateElement("div",
                        rowClass,
                        GenerateElement("div",
                        new HtmlAttribute("class", "error"),
                        message)));
                LogMessage(message);
                isValid = false;
                row++;
            }
            return isValid;
        }
Пример #43
0
        /// <summary>
        /// Validates the configuration of an item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="errorProcesser">The error processer.</param>
        private void ValidateItem(object item, IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            if (item == null) return;

            var dummy = item as IConfigurationValidation;
            if (dummy != null)
            {
                dummy.Validate(configuration, parent.Wrap(this), errorProcesser);
            }
        }
Пример #44
0
        public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            if (this.ValidateAction != null)
            {
                this.ValidateAction(configuration, parent, errorProcesser);
                return;
            }

            throw new NotImplementedException();
        }
Пример #45
0
 /// <summary>
 /// Validates the configuration of an enumerable.
 /// </summary>
 /// <param name="items">The items.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="errorProcesser">The error processer.</param>
 private void ValidateItems(IEnumerable items, IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     if (items != null)
     {
         foreach (object item in items)
         {
             this.ValidateItem(item, configuration, parent, errorProcesser);
         }
     }
 }
        /// <summary>
        /// Validates this task.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            // Validate the conditions
            var trace = parent.Wrap(this);

            foreach (var condition in this.TaskConditions ?? new ITaskCondition[0])
            {
                var validation = condition as IConfigurationValidation;
                if (validation != null)
                {
                    validation.Validate(
                        configuration,
                        trace,
                        errorProcesser);
                }
            }

            // Validate the tasks
            this.ValidateTasks(this.Tasks, configuration, trace, errorProcesser);
            this.ValidateTasks(this.ElseTasks, configuration, trace, errorProcesser);
        }
Пример #47
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser"></param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            // Ensure that the queue has at least one project in it
            var queueFound = false;

            foreach (IProject projectDef in configuration.Projects)
            {
                if (string.Equals(this.Name, projectDef.QueueName, StringComparison.InvariantCulture))
                {
                    queueFound = true;
                    break;
                }
            }

            if (!queueFound)
            {
                errorProcesser.ProcessError(new ConfigurationException(
                                                string.Format(System.Globalization.CultureInfo.CurrentCulture, "An unused queue definition has been found: name '{0}'", this.Name)));
            }
        }
Пример #48
0
 /// <summary>
 /// Checks the internal validation of the item.
 /// </summary>
 /// <param name="configuration">The entire configuration.</param>
 /// <param name="parent">The parent item for the item being validated.</param>
 /// <param name="errorProcesser">The error processer to use.</param>
 public void Validate(IConfiguration configuration,
     ConfigurationTrace parent,
     IConfigurationErrorProcesser errorProcesser)
 {
     if ((this.Conditions == null) || (this.Conditions.Length == 0))
     {
         errorProcesser
             .ProcessError("Validation failed for andCondition - at least one child condition must be supplied");
     }
     else
     {
         foreach (var child in this.Conditions.OfType<IConfigurationValidation>())
         {
             child.Validate(
                 configuration,
                 parent.Wrap(this),
                 errorProcesser);
         }
     }
 }
 public void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
 {
     IsValided = true;
 }
        /// <summary>
        /// Reads an XML config document.
        /// </summary>
        /// <param name="document">The document to read.</param>
        /// <param name="errorProcesser">The error processer to use (can be null).</param>
        /// <returns>The loaded configuration.</returns>
        public IConfiguration Read(XmlDocument document, 
            IConfigurationErrorProcesser errorProcesser)
        {
            Configuration configuration = new Configuration();
            string ConflictingXMLNode = string.Empty;
            List<string> projectNames = new List<string>();

            // Validate the document element
            var actualErrorProcesser = errorProcesser ?? new DefaultErrorProcesser();
            VerifyDocumentHasValidRootElement(document, actualErrorProcesser);

            InvalidNodeEventHandler invalidNodeHandler = (args) =>
            {
                if (!actualErrorProcesser.ProcessUnhandledNode(args.Node))
                {
                    actualErrorProcesser.ProcessError(args.Message);
                }
            };
            typeTable.InvalidNode += invalidNodeHandler;
            try
            {
                foreach (XmlNode node in document.DocumentElement)
                {
                    ConflictingXMLNode = string.Empty;

                    if (!(node is XmlComment))
                    {
                        ConflictingXMLNode = "Conflicting project data : " + node.OuterXml;

                        object loadedItem = reader.Read(node);
                        if (loadedItem is IProject)
                        {
                            LoadAndValidateProject(actualErrorProcesser, projectNames, configuration, loadedItem);
                        }
                        else if (loadedItem is IQueueConfiguration)
                        {
                            LoadAndValidateQueue(configuration, loadedItem);
                        }
                        else if (loadedItem is ISecurityManager)
                        {
                            LoadAndValidateSecurityManager(configuration, loadedItem);
                        }
                        else
                        {
                            actualErrorProcesser.ProcessError(
                                new ConfigurationException(
                                    "\nUnknown configuration item found\n" + node.OuterXml));
                        }
                    }
                }

                // Do a validation check to ensure internal configuration consistency
                ValidateConfiguration(configuration, actualErrorProcesser);
            }
            catch (NetReflectorException ex)
            {
                actualErrorProcesser.ProcessError(new ConfigurationException("\nUnable to instantiate CruiseControl projects from configuration document." +
                    "\nConfiguration document is likely missing Xml nodes required for properly populating CruiseControl configuration.\n"
                    + ex.Message +
                    "\n " + ConflictingXMLNode, ex));
            }
            finally
            {
                typeTable.InvalidNode -= invalidNodeHandler;
            }

            return configuration;
        }
        /// <summary>
        /// Validates this task.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            // Validate the conditions
            var trace = parent.Wrap(this);
            foreach (var condition in this.TaskConditions ?? new ITaskCondition[0])
            {
                var validation = condition as IConfigurationValidation;
                if (validation != null)
                {
                    validation.Validate(
                        configuration,
                        trace,
                        errorProcesser);
                }
            }

            // Validate the tasks
            this.ValidateTasks(this.Tasks, configuration, trace, errorProcesser);
            this.ValidateTasks(this.ElseTasks, configuration, trace, errorProcesser);
        }
Пример #52
0
        /// <summary>
        /// Validates this task.
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="parent"></param>
        /// <param name="errorProcesser"></param>
        public override void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            base.Validate(configuration, parent, errorProcesser);
            var project = parent.GetAncestorValue<Project>();

            if (project != null)
            {
                // Check if this task is set in the publishers section
                var isPublisher = false;
                foreach (var publisher in project.Publishers)
                {
                    if (object.ReferenceEquals(publisher, this))
                    {
                        isPublisher = true;
                        break;
                    }
                }

                // Display a warning
                if (isPublisher)
                {
                    errorProcesser.ProcessWarning("Putting the parallel task in the publishers section may cause unpredictable results");
                }
            }
        }
Пример #53
0
        /// <summary>
        /// Reads an XML config document.
        /// </summary>
        /// <param name="document">The document to read.</param>
        /// <param name="errorProcesser">The error processer to use (can be null).</param>
        /// <returns>The loaded configuration.</returns>
        public IConfiguration Read(XmlDocument document,
                                   IConfigurationErrorProcesser errorProcesser)
        {
            Configuration configuration      = new Configuration();
            string        conflictingXmlNode = string.Empty;
            List <string> projectNames       = new List <string>();

            // Validate the document element
            var actualErrorProcesser = errorProcesser ?? new DefaultErrorProcesser();

            VerifyDocumentHasValidRootElement(document, actualErrorProcesser);

            InvalidNodeEventHandler invalidNodeHandler = (args) =>
            {
                if (!actualErrorProcesser.ProcessUnhandledNode(args.Node))
                {
                    actualErrorProcesser.ProcessError(args.Message);
                }
            };

            typeTable.InvalidNode += invalidNodeHandler;
            try
            {
                var sha = new SHA1CryptoServiceProvider();
                foreach (XmlNode node in document.DocumentElement)
                {
                    conflictingXmlNode = string.Empty;

                    if (!(node.NodeType == XmlNodeType.Comment || node.NodeType == XmlNodeType.Text))
                    {
                        conflictingXmlNode = "Conflicting project data : " + node.OuterXml;

                        // Load the item and generate the hash if required
                        var loadedItem = this.ParseElement(node);
                        var hashStore  = loadedItem as IHashStore;
                        if (hashStore != null)
                        {
                            var data = Encoding.Unicode.GetBytes(node.OuterXml);
                            var hash = sha.ComputeHash(data);
                            hashStore.Hash = hash;
                        }

                        // Add the item to the configuration
                        if (loadedItem is IProject)
                        {
                            this.LoadAndValidateProject(actualErrorProcesser, projectNames, configuration, loadedItem);
                        }
                        else if (loadedItem is IQueueConfiguration)
                        {
                            this.LoadAndValidateQueue(configuration, loadedItem);
                        }
                        else if (loadedItem is ISecurityManager)
                        {
                            this.LoadAndValidateSecurityManager(configuration, loadedItem);
                        }
                        else
                        {
                            actualErrorProcesser.ProcessError(
                                new ConfigurationException(
                                    "\nUnknown configuration item found\n" + node.OuterXml));
                        }
                    }
                }

                // Do a validation check to ensure internal configuration consistency
                ValidateConfiguration(configuration, actualErrorProcesser);
            }
            catch (NetReflectorException ex)
            {
                actualErrorProcesser.ProcessError(new ConfigurationException("\nUnable to instantiate CruiseControl projects from configuration document." +
                                                                             "\nConfiguration document is likely missing Xml nodes required for properly populating CruiseControl configuration.\n"
                                                                             + ex.Message +
                                                                             "\n " + conflictingXmlNode, ex));
            }
            finally
            {
                typeTable.InvalidNode -= invalidNodeHandler;
            }

            return(configuration);
        }
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser"></param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            // Ensure that the queue has at least one project in it
            var queueFound = false;
            foreach (IProject projectDef in configuration.Projects)
            {
                if (string.Equals(this.Name, projectDef.QueueName, StringComparison.InvariantCulture))
                {
                    queueFound = true;
                    break;
                }
            }

            if (!queueFound)
            {
                errorProcesser.ProcessError(new ConfigurationException(
                    string.Format(System.Globalization.CultureInfo.CurrentCulture,"An unused queue definition has been found: name '{0}'", this.Name)));
            }
        }
Пример #55
0
        void IConfigurationValidation.Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            string projectName = "(Unknown)";

            var project = parent.GetAncestorValue<Project>();
            if (project != null)
            {
                projectName = project.Name;
            }

            if (integrationTime.Minutes + RandomOffSetInMinutesFromTime >= 60)
            {
                errorProcesser.ProcessError("Scheduled time {0}:{1} + randomOffSetInMinutesFromTime {2} would exceed the hour, this is not allowed. Conflicting project {3}", integrationTime.Hours, integrationTime.Minutes, RandomOffSetInMinutesFromTime, projectName);
            }
        }
Пример #56
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser">The error processer to use.</param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            var parentProject = parent.GetAncestorValue<Project>();
            if (parentProject != null)
            {
                // Attempt to find this publisher in the publishers section
                var isPublisher = false;
                foreach (var task in parentProject.Publishers)
                {
                    if (task == this)
                    {
                        isPublisher = true;
                        break;
                    }
                }

                // If not found then throw a validation exception
                if (!isPublisher)
                {
                    errorProcesser.ProcessWarning("Email publishers are best placed in the publishers section of the configuration");
                }
            }
            else
            {
                errorProcesser.ProcessError(
                    new CruiseControlException("This publisher can only belong to a project"));
            }
        }
Пример #57
0
        /// <summary>
        /// Checks the internal validation of the item.
        /// </summary>
        /// <param name="configuration">The entire configuration.</param>
        /// <param name="parent">The parent item for the item being validated.</param>
        /// <param name="errorProcesser"></param>
        public virtual void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            if (security.RequiresServerSecurity &&
                (configuration.SecurityManager is NullSecurityManager))
            {
                errorProcesser.ProcessError(
                    new ConfigurationException(
                        string.Format(System.Globalization.CultureInfo.CurrentCulture, "Security is defined for project '{0}', but not defined at the server", this.Name)));
            }

            this.ValidateProject(errorProcesser);
            this.ValidateItem(sourceControl, configuration, parent, errorProcesser);
            this.ValidateItem(labeller, configuration, parent, errorProcesser);
            this.ValidateItems(PrebuildTasks, configuration, parent, errorProcesser);
            this.ValidateItems(tasks, configuration, parent, errorProcesser);
            this.ValidateItems(publishers, configuration, parent, errorProcesser);
            this.ValidateItem(state, configuration, parent, errorProcesser);
            this.ValidateItem(security, configuration, parent, errorProcesser);

            var mt = (MultipleTrigger)this.Triggers;
            if (mt != null)
            {
                this.ValidateItems(mt.Triggers, configuration, parent, errorProcesser);
            }

            this.configuration = configuration;
        }
Пример #58
0
        /// <summary>
        /// Validates this task.
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="parent"></param>
        /// <param name="errorProcesser"></param>
        public override void Validate(IConfiguration configuration, ConfigurationTrace parent, IConfigurationErrorProcesser errorProcesser)
        {
            base.Validate(configuration, parent, errorProcesser);
            var project = parent.GetAncestorValue <Project>();

            if (project != null)
            {
                // Check if this task is set in the publishers section
                var isPublisher = false;
                foreach (var publisher in project.Publishers)
                {
                    if (object.ReferenceEquals(publisher, this))
                    {
                        isPublisher = true;
                        break;
                    }
                }

                // Display a warning
                if (isPublisher)
                {
                    errorProcesser.ProcessWarning("Putting the parallel task in the publishers section may cause unpredictable results");
                }
            }
        }
Пример #59
0
 /// <summary>
 /// Validate the project details.
 /// </summary>
 /// <remarks>
 /// Currently the only check is the project name does not contain any invalid characters.
 /// </remarks>
 private void ValidateProject(IConfigurationErrorProcesser errorProcesser)
 {
     if (ContainsInvalidChars(this.Name))
     {
         errorProcesser.ProcessWarning(
             string.Format(System.Globalization.CultureInfo.CurrentCulture, "Project name '{0}' contains some chars that could cause problems, better use only numbers and letters",
                 Name));
     }
 }