GithubHelp home page GithubHelp logo

soundarkarunagaran / automation-transform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ritterim/automation-transform

0.0 1.0 0.0 182 KB

Apply configuration transforms in memory to any xml document

License: MIT License

Batchfile 2.83% C# 97.17%

automation-transform's Introduction

Automation : Transform

This library is designed to allow the modification of configuration files via the Microsoft.Web.Xdt library. It uses the transform syntax that we all know and love. You can utilize this library in memory with no need to access any files, but you can do that as well.

NuGet Version NuGet Download Count

Quick Start

You can install this package via Nuget under the package id of RimDev.Automation.Transform.

 PM> Install-Package RimDev.Automation.Transform

Next step is to have a source and a transform file ready. Please read the transformation documentation before attempting to use this library.

When you have your files ready, you can perform a transformation with the following code.

using (var transformer = new ConfigurationTransformer()) {
  var result
  = transformer
  .SetSourceFromFile("web.config")
  .SetTransformFromFile("web.debug.config")
  .Apply("web.transformed.config");
}

Transformation Extensions

You get a few methods that allow you to construct transformations programatically.

  1. InsertAppSetting
  2. ReplaceAppSetting
  3. InsertSqlConnectionString
  4. ReplaceSqlConnectionString
  5. InsertConnectionString
  6. ReplaceConnectionString
  7. InsertCustomErrorSetting
  8. ReplaceCustomErrorSetting
  9. InsertSmtpSetting
  10. ReplaceSmtpSetting
using (var transformer = new ConfigurationTransformer()) {
  transformer
  .SetSourceFromFile("web.config")
  .Transform.InsertAppSetting("hello", "world");

  var result =   transformer.Apply("web.transformed.config");
}

The methods utilize the transform syntax, and append it to your transformation config. You can load an existing transform while still appending additional programatic values.

using (var transformer = new ConfigurationTransformer()) {
  transformer
  .SetSourceFromFile("web.config")
  .Transform
  .InsertCustomErrorsSetting("ON", "~/error", customErrors =>
            {
                customErrors.AddError(400, "~/error/400");
                customErrors.AddError(500, "~/error/500");
            })
  .InsertSmtpSetting(smtpDeliveryMethod: SmtpDeliveryMethod.SpecifiedPickupDirectory,
            from: "[email protected]",
            smtpBuilder: smtpBuilder =>
            {
                smtpBuilder.AddSpecifiedPickupDirectory(@"c:\email");
                smtpBuilder.AddNetwork(host: "localhost");
            });

  var result =   transformer.Apply("web.transformed.config");
}

The CustomError and Smtp setting methods allow you to pass an Action to specify the child elements of the respective parent elements.

Thanks

Thanks to Ritter IM for supporting OSS.

automation-transform's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.