protected override void visitConfigurationSpecification(ConfigurationSpecification specification) { writer.Append(KeywordEnum.FOR.ToString()).Append(' '); output.writeComponentSpecification(specification.ComponentSpecification); if (specification.EntityAspect != null) { writer.Append(' ').Append(KeywordEnum.USE.ToString()).Append(' '); writer.Append(specification.EntityAspect.ToString()); } if (specification.GenericMap.Count != 0) { writer.NewLine(); writer.Append(KeywordEnum.GENERIC.ToString()).Append(KeywordEnum.MAP.ToString()).Append(" (").NewLine(); writer.Indent().BeginAlign(); output.getMiscellaneousElementOutput().genericMap(specification.GenericMap); writer.EndAlign().Dedent(); writer.Append(")"); } if (specification.PortMap.Count != 0) { writer.NewLine(); writer.Append(KeywordEnum.PORT.ToString()).Append(KeywordEnum.MAP.ToString()).Append(" (").NewLine(); writer.Indent().BeginAlign(); output.getMiscellaneousElementOutput().portMap(specification.PortMap); writer.EndAlign().Dedent(); writer.Append(")"); } writer.Append(';').NewLine(); }
public static XmlDocument AsXmlDocument(this ConfigurationSpecification specification) { var document = new XmlDocument(); var writer = new ConfigurationSpecificationWriter(document); writer.Write(specification); return(document); }
public Result Process() { var modifiedConfiguration = _configurationSpecification.TargetConfigurationFile.AsXmlDocument(); var commands = _configurationSpecification.IsUndo ? _configurationSpecification.Commands.Reverse() : _configurationSpecification.Commands; var undoConfigurationSpecification = new ConfigurationSpecification( _configurationSpecification.TargetConfigurationFile, commands.Select(command => command.Execute(modifiedConfiguration)).ToList(), true); return(new Result(modifiedConfiguration, undoConfigurationSpecification)); }
public void WriteSucceeds() { var targetConfigurationFile = new FileInfo("c:\\web.config"); var configurationSpecification = new ConfigurationSpecification( targetConfigurationFile, new ConfigurationCommand[] { new ElementInsertionCommand( "/*[local-name()='configuration']", new ElementSpecification("appSettings", string.Empty, Enumerable.Empty <AttributeSpecification>(), "*[local-name()='appSettings']")), new ElementUpdateCommand( "/*[local-name()='configuration']/*[local-name()='appSettings']/*[local-name()='add' and (@key = 'first_setting')]", new[] { new AttributeSpecification { Name = "key", Value = "first_setting", NamespaceUri = string.Empty }, new AttributeSpecification { Name = "value", Value = "updated-value", NamespaceUri = string.Empty } }), new ElementDeletionCommand("/*[local-name()='configuration']/*[local-name()='appSettings']/*[local-name()='add' and (@key = 'second_setting')]") }, false); var document = new XmlDocument(); new ConfigurationSpecificationWriter(document).Write(configurationSpecification); var mockedResolver = new Mock <IConfigurationFilesResolverStrategy>(); mockedResolver.Setup(resolver => resolver.CanResolve(It.IsAny <string>())).Returns(true); mockedResolver.Setup(resolver => resolver.Resolve(It.IsAny <string>())).Returns(new List <string> { targetConfigurationFile.FullName }); var specification = new ConfigurationSpecificationReader(document, new[] { mockedResolver.Object }).Read().Should().ContainSingle().Subject; specification.SpecificationSourceFile.Should().BeNull(); specification.TargetConfigurationFile.FullName.Should().Be(configurationSpecification.TargetConfigurationFile.FullName); specification.Commands.Should().BeEquivalentTo(configurationSpecification.Commands); }
public void Write(ConfigurationSpecification configurationSpecification) { Arguments.Validation.Constraints .IsNotNull(configurationSpecification, nameof(configurationSpecification)) .Check(); foreach (dynamic command in configurationSpecification.Commands) { Write(command); } _configurationSpecificationDocument.DocumentElement.AppendAttribute( XmlAttributeNames.FILES, Constants.NAMESPACE_URI, Constants.NAMESPACE_URI_PREFIX, $"file://{configurationSpecification.TargetConfigurationFile.FullName}"); _configurationSpecificationDocument.DocumentElement.AppendAttribute( XmlAttributeNames.UNDO, Constants.NAMESPACE_URI, Constants.NAMESPACE_URI_PREFIX, XmlConvert.ToString(configurationSpecification.IsUndo)); }
public static ConfigurationSpecificationProcessor.Result Apply(this ConfigurationSpecification specification) { var processor = new ConfigurationSpecificationProcessor(specification); return(processor.Process()); }
/// <summary> /// Visits a configuration specification. /// </summary> /// <param name="specification">the configuration specification</param> protected internal virtual void visitConfigurationSpecification(ConfigurationSpecification specification) { }
public ConfigurationSpecificationProcessor(ConfigurationSpecification configurationSpecification) { _configurationSpecification = configurationSpecification; }
internal Result(XmlDocument modifiedConfiguration, ConfigurationSpecification undoConfigurationSpecification) { ModifiedConfiguration = modifiedConfiguration; UndoConfigurationSpecification = undoConfigurationSpecification; }