Click here to Skip to main content
15,895,084 members
Articles / Web Development / HTML

Transformalizing NorthWind

Rate me:
Please Sign up or sign in to vote.
4.95/5 (29 votes)
24 Jul 2014GPL37 min read 57.8K   341   53  
Combining de-normalization, transformation, replication, and awesome-ness.
<?xml version="1.0"?>
<configuration>

  <configSections>
    <section name="transformalize" type="Transformalize.Configuration.TransformalizeConfiguration, Transformalize"/>
    <section name="nlog" type="Transformalize.Libs.NLog.Config.ConfigSectionHandler, Transformalize"/>
  </configSections>

  <transformalize>
    <processes>

      <add name="Test">

        <providers>
          <add name="sqlserver" type="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
          <add name="mysql" type="MySql.Data.MySqlClient.MySqlConnection, MySql.Data"></add>
        </providers>

        <connections>
          <add name="input" database="TestInput"/>
          <add name="output" database="TestOutput"/>
        </connections>

        <scripts path="Scripts">
          <add name="test" file="test.js"></add>
        </scripts>

        <templates path="Templates">
          <add name="double" file="double.cshtml"></add>
          <add name="solr-data-handler" file="solr-data-handler.cshtml" cache="true">
            <actions>
              <add action="copy" file="C:\Solr\Test\conf\data-config.xml"/>
            </actions>
          </add>
          <add name="solr-schema" file="solr-schema.cshtml" cache="true">
            <actions>
              <add action="copy" file="C:\Solr\Test\conf\schema.xml"/>
              <add action="open" file="C:\Solr\Test\conf\schema.xml"/>
            </actions>
          </add>
        </templates>

        <search-types>
          <add name="default"/>
          <add name="facet" type="lowercase" store="true" index="true"/>
          <add name="standard" type="standard_lowercase" store="false" index="true"/>
        </search-types>

        <entities>

          <add name="OrderDetail" connection="input" version="RowVersion">
            <fields>
              <add name="OrderDetailKey" type="System.Int32" primary-key="true"/>
              <add name="OrderKey" type="system.Int32"></add>
              <add name="ProductKey" type="System.Int32"></add>
              <add name="Qty" alias="Quantity" type="System.Int32"></add>
              <add name="Price" type="System.Decimal" precision="10" scale="5"></add>
              <add name="Properties" type="System.Xml">
                <transforms>
                  <add method="fromXml">
                    <fields>
                      <add name="Color"></add>
                      <add name="Size"></add>
                      <add name="Gender"></add>
                    </fields>
                  </add>
                </transforms>
              </add>
              <add name="RowVersion" alias="OrderDetailRowVersion" type="RowVersion" length="8" search-type="none"></add>
            </fields>
          </add>

          <add name="Order" connection="input" version="RowVersion">
            <fields>
              <add name="OrderKey" type="System.Int32" primary-key="true"/>
              <add name="CustomerKey" type="System.Int32"></add>
              <add name="OrderDate" type="System.DateTime"></add>
              <add name="RowVersion" alias="OrderRowVersion" type="RowVersion" length="8" search-type="none"></add>
            </fields>
          </add>

          <add name="Customer" connection="input" version="RowVersion">
            <fields>
              <add name="CustomerKey" type="System.Int32" primary-key="true"/>
              <add name="First" alias="FirstName" length="50">
                <transforms>
                  <add method="map" map="FirstNames"></add>
                </transforms>
              </add>
              <add name="Last" alias="LastName" length="50"></add>
              <add name="Address" length="100">
              </add>
              <add name="City" length="50">
                <transforms>
                  <add method="insert" index="0" value="Town ofs "></add>
                  <add method="remove" start-index="7" length="1"></add>
                  <add method="replace" old-value="Town" new-value="City"></add>
                  <add method="trimStart" trim-chars="Ci"></add>
                </transforms>
              </add>
              <add name="State" length="4">
                <transforms>
                  <add method="template" template="@Double(State)">
                    <templates>
                      <add name="double"></add>
                    </templates>
                  </add>
                </transforms>
              </add>
              <add name="Country" length="2"></add>
              <add name="RowVersion" alias="CustomerRowVersion" type="RowVersion" length="8" search-type="none"></add>
            </fields>
          </add>

          <add name="Product" connection="input" version="RowVersion">
            <fields>
              <add name="ProductKey" type="System.Int32" primary-key="true"/>
              <add name="Name" alias="ProductName" length="100" default="None">
                <transforms>
                  <add method="javascript" script="if(ProductName.length == 8) { '8 chars not allowed!' } else { ProductName };"/>
                </transforms>
              </add>
              <add name="RowVersion" alias="ProductRowVersion" type="RowVersion" length="8" search-type="none"></add>
            </fields>
          </add>

        </entities>

        <relationships>
          <add leftEntity="OrderDetail" rightEntity="Order">
            <join>
              <add leftField="OrderKey" rightField="OrderKey"/>
            </join>
          </add>
          <add leftEntity="OrderDetail" rightEntity="Product">
            <join>
              <add leftField="ProductKey" rightField="ProductKey"/>
            </join>
          </add>
          <add leftEntity="Order" rightEntity="Customer">
            <join>
              <add leftField="CustomerKey" rightField="CustomerKey"/>
            </join>
          </add>
        </relationships>

        <maps>
          <add name="FirstNames">
            <items>
              <add from="Cha" to="Chuck" operator="StartsWith"></add>
              <add from="topher" to="Chris" operator="EndsWith"></add>
              <add from="Thomas" to="Tom"></add>
              <add from="*" to="John"></add>
            </items>
          </add>
        </maps>

        <calculated-fields>

          <add name="Result" type="System.Byte">
            <transforms>
              <add method="javascript" script="if(LastName == 'Newman' &amp;&amp; ProductName == 'Resharper') { 1 } else { 2 };">
                <parameters>
                  <add entity="Customer" field="LastName"></add>
                  <add entity="Product" field="ProductName"></add>
                </parameters>
              </add>
            </transforms>
          </add>

        </calculated-fields>

      </add>

      <add name="File">

        <providers>
          <add name="sqlserver" type="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
          <add name="file" type="System.IO"/>
        </providers>

        <connections>
          <add name="input" file="c:\temp\hellog.txt" provider="file"/>
          <add name="output" connection-string="Server=localhost;Database=TestOutput;Trusted_Connection=True;"/>
        </connections>

        <entities>
          <add name="log" connection="input" version="HashCode">
            <fields>
              <add name="Line" length="512">
                <transforms>
                  <add method="fromRegex" pattern="^(?&lt;Date&gt;.{23}).*(?&lt;Level&gt; INFO | DEBUG | WARN | ERROR | TRACE )(?&lt;Message&gt; log - .*$)">
                    <fields>
                      <add name="Date" length="23">
                        <transforms>
                          <add method="replace" old-value="," new-value="."></add>
                        </transforms>
                      </add>
                      <add name="Level" length="10">
                        <transforms>
                          <add method="trim" trim-chars=" "></add>
                        </transforms>
                      </add>
                      <add name="Message" length="500">
                        <transforms>
                          <add method="trimStart" trim-chars="log -"/>
                          <add method="trimEnd" trim-chars=" "/>
                        </transforms>
                      </add>
                    </fields>
                  </add>
                </transforms>
              </add>
            </fields>
            <calculated-fields>
              <add name="HashCode" type="System.Int32" input="false" primary-key="true">
                <transforms>
                  <add method="GetHashCode" parameter="Line"></add>
                </transforms>
              </add>
            </calculated-fields>
          </add>
        </entities>
      </add>

      <add name="MyLogs">

        <providers>
          <add name="sqlserver" type="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
          <add name="file" type="System.IO"/>
        </providers>

        <connections>
          <add name="input" file="x.log" provider="file" delimiter=" | "/>
          <add name="output" connection-string="Server=localhost;Database=TestOutput;Trusted_Connection=True;"/>
        </connections>

        <entities>
          <add name="TflLog" connection="input" version="HashCode">
            <fields>
              <add name="Process" input="false" default="DplGas" length="20"/>
              <add name="Time" length="8" variable-length="false"/>
              <add name="Level" length="5"/>
              <add name="Entity" length="30">
                <transforms>
                  <add method="TrimEnd" trim-chars="."></add>
                </transforms>
              </add>
              <add name="Message" length="512"/>
            </fields>
            <calculated-fields>
              <add name="HashText" length="550" output="false">
                <transforms>
                  <add method="Concat">
                    <parameters>
                      <add field="Time"></add>
                      <add field="Process"></add>
                      <add field="Entity"></add>
                      <add field="Message"></add>
                    </parameters>
                  </add>
                </transforms>
              </add>
              <add name="HashCode" type="System.Int32" input="false" primary-key="true">
                <transforms>
                  <add method="GetHashCode" parameter="HashText"></add>
                </transforms>
              </add>
            </calculated-fields>
          </add>
        </entities>
      </add>

    </processes>
  </transformalize>

  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets async="false">
      <target name="file" xsi:type="File" fileName="${basedir}/nlog/${date:format=yyyy}/${date:format=MM}/${date:format=dd}/Transformalize.log" layout="${date:format=HH\:mm\:ss} | ${level} | ${gdc:item=process} | ${gdc:item=entity} |${message}"/>
      <target xsi:type="BufferingWrapper" name="mailBuffer" slidingTimeout="True" bufferSize="100" flushTimeout="12000">
        <target name="mail" xsi:type="Mail" smtpServer="x" from="x" subject="Tfl Error!" to="x"/>
      </target>
      <target name="console" xsi:type="ColoredConsole" layout="${date:format=HH\:mm\:ss} | ${level} | ${gdc:item=process} | ${gdc:item=entity} | ${message}"/>
    </targets>
    <rules>
      <logger name="*" minlevel="Info" writeTo="console"/>
      <logger name="*" minlevel="Info" writeTo="file"/>
      <logger name="*" minlevel="Error" writeTo="mailBuffer"/>
    </rules>
  </nlog>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>

</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions