private static void CreateFolderStructureContext(SolutionValidatorConfigurationSection configuration, ValidatorContext validatorContext)
        {
            Argument.IsNotNull(() => configuration);
            Argument.IsNotNull(() => validatorContext);

            validatorContext.FolderStructure.DefinitionFilePath = configuration.FolderStructure.DefinitionFilePath;
            validatorContext.FolderStructure.Check = configuration.FolderStructure.Check;
        }
        /// <summary>
        /// Create a <see cref="ValidatorContext" /> instance from a <see cref="ValidatorContext" />.
        /// </summary>
        /// <param name="configuration">The configuration instance.</param>
        /// <returns>A new <see cref="ValidatorContext" /> instance.</returns>
        public static ValidatorContext ToContext(this SolutionValidatorConfigurationSection configuration)
        {
            Argument.IsNotNull(() => configuration);

            var validatorContext = new ValidatorContext();

            if (configuration.FolderStructure != null)
            {
                CreateFolderStructureContext(configuration, validatorContext);
            }

            if (configuration.ProjectFile != null)
            {
                CreateProjectFileContext(configuration, validatorContext);
            }

            return(validatorContext);
        }
        private static void CreateProjectFileContext(SolutionValidatorConfigurationSection configuration, ValidatorContext validatorContext)
        {
            Argument.IsNotNull(() => configuration);
            Argument.IsNotNull(() => validatorContext);

            validatorContext.ProjectFile.CheckOutPutPath             = configuration.ProjectFile.OutputPath.Check;
            validatorContext.ProjectFile.OutputPath                  = configuration.ProjectFile.OutputPath.Value;
            validatorContext.ProjectFile.CheckRequiredConfigurations = configuration.ProjectFile.RequiredConfigurations.Check;
            validatorContext.ProjectFile.CheckIdentical              = configuration.ProjectFile.CheckIdentical.Check;
            validatorContext.ProjectFile.CheckPropertyValues         = configuration.ProjectFile.CheckForValue.Check;

            if (configuration.ProjectFile.RequiredConfigurations != null)
            {
                foreach (ConfigurationNameElement configurationNameElement in configuration.ProjectFile.RequiredConfigurations)
                {
                    validatorContext.ProjectFile.RequiredConfigurations.Add(configurationNameElement.Name);
                }
            }

            if (configuration.ProjectFile.CheckIdentical != null)
            {
                foreach (PropertiesToMatchElement propertiesToMatchElement in configuration.ProjectFile.CheckIdentical)
                {
                    validatorContext.ProjectFile.IdenticalChecks.Add(new IdenticalCheck {
                        PropertyName = propertiesToMatchElement.PropertyName, OtherPropertyName = propertiesToMatchElement.OtherPropertyName
                    });
                }
            }

            if (configuration.ProjectFile.CheckForValue != null)
            {
                foreach (PropertyToCheckElement propertyToCheckElement in configuration.ProjectFile.CheckForValue)
                {
                    validatorContext.ProjectFile.Properties.Add(new Property {
                        Name = propertyToCheckElement.PropertyName, Value = propertyToCheckElement.Value
                    });
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Checks the specified configuration for additional validation errors like invalid regex etc
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns>SolutionValidatorConfigurationSection.</returns>
        private static SolutionValidatorConfigurationSection Check(SolutionValidatorConfigurationSection configuration)
        {
            if (configuration == null)
            {
                configuration = new SolutionValidatorConfigurationSection();
            }

            if (configuration.ProjectFile.RequiredConfigurations.Count == 0 && configuration.ProjectFile.RequiredConfigurations.Check)
            {
                configuration.ProjectFile.RequiredConfigurations.Add(new ConfigurationNameElement {
                    Name = "Debug"
                });
                configuration.ProjectFile.RequiredConfigurations.Add(new ConfigurationNameElement {
                    Name = "Release"
                });
            }

            if (configuration.ProjectFile.CheckIdentical.Count == 0 && configuration.ProjectFile.CheckIdentical.Check)
            {
                // These expectations are commented out because they will not satisfied after namespace refactorings
                // For example both SolutionValidator.Core and SolutionValidator.UI.Console root namespace is SolutionValidator
                // so obviously can not identical with AssemblyName (we end with two identical assembly name)
                // Also SolutionValidator.UI.Console's

                configuration.ProjectFile.CheckIdentical.Add(new PropertiesToMatchElement
                {
                    PropertyName      = "AssemblyName",
                    OtherPropertyName = "RootNamespace"
                });

                configuration.ProjectFile.CheckIdentical.Add(new PropertiesToMatchElement
                {
                    PropertyName      = "AssemblyName",
                    OtherPropertyName = "ProjectName"
                });
            }

            if (configuration.ProjectFile.CheckForValue.Count == 0 && configuration.ProjectFile.CheckForValue.Check)
            {
                configuration.ProjectFile.CheckForValue.Add(new PropertyToCheckElement
                {
                    PropertyName = "AppDesignerFolder",
                    Value        = "Properties"
                });

                // TODO: Check for more, such as "iPhoneSimulator"
                configuration.ProjectFile.CheckForValue.Add(new PropertyToCheckElement
                {
                    PropertyName = "Platform",
                    Value        = "AnyCPU"
                });
            }

            if (configuration.CSharpFormatting.SourceFileFilters.Count == 0)
            {
                configuration.CSharpFormatting.SourceFileFilters.Add(new IncludeExcludeElement {
                    Include = @"^src\\.*", Exclude = @".*\\obj\\(Debug|Release)\\.*"
                });
            }

            return(configuration);
        }