public void CSharpTransformAdd()
        {
            // Problem is I am compiling code in advance,
            // but not remembering that there are actually two processes that run,
            // the entity processes,  and the calculated field process

            const string xml = @"
<add name='TestProcess' mode='default'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Field1='1' Field2='2' Field3='3' />
                <add Field1='4' Field2='5' Field3='6' />
            </rows>
            <fields>
                <add name='Field1' />
                <add name='Field2' />
                <add name='Field3' />
            </fields>
            <calculated-fields>
                <add name='Add' t='copy(Field1,Field2,Field3).cs(Field1+Field2+Field3;)' />
                <add name='Format' t='copy(Field1,Field2,Field3).cs(string.Format(&quot;{0}-{1}-{2}&quot;,Field1,Field2,Field3);)' />
            </calculated-fields>
        </add>
    </entities>
</add>";


            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml, LogLevel.Debug);
            var process    = composer.Process;

            controller.Execute();
            controller.Dispose();

            var entity = process.Entities.First();

            var row1 = entity.Rows[0];
            var row2 = entity.Rows[1];

            Assert.AreEqual("123", row1["Add"]);
            Assert.AreEqual("1-2-3", row1["Format"]);

            Assert.AreEqual("456", row2["Add"]);
            Assert.AreEqual("4-5-6", row2["Format"]);
        }
Beispiel #2
0
        public void Validator()
        {
            const string xml = @"
    <add name='TestSignature'>
      <entities>
        <add name='TestData'>
          <rows>
            <add args='10,0' />
          </rows>
          <fields>
            <add name='args' length='128'>
                <transforms>
                    <add method='fromsplit' separator=','>
                        <fields>
                            <add name='TotalWidth' />
                            <add name='PaddingChar' />
                        </fields>
                    </add>
                </transforms>
            </add>
          </fields>
          <calculated-fields>
            <add name='length' type='int' t='copy(args).splitlength(\,)' />
            <add name='TotalWidthCheck' type='bool' t='copy(TotalWidth).is(int)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var process    = composer.Process;
            var output     = controller.Read().ToArray();

            var field = process.Entities.First().CalculatedFields.First(cf => cf.Name == "length");

            Assert.AreEqual(2, output[0][field]);

            foreach (var row in output)
            {
                Console.WriteLine(row);
            }
        }
Beispiel #3
0
        public void FieldsAreIndexed()
        {
            var composer = new CompositionRoot();

            composer.Compose(@"Files\PersonAndPet.xml");

            var pet    = composer.Process.Entities.First();
            var person = composer.Process.Entities.Last();

            // system fields
            Assert.AreEqual(0, pet.Fields[0].Index);
            Assert.AreEqual(1, pet.Fields[1].Index);
            Assert.AreEqual(2, pet.Fields[2].Index);
            Assert.AreEqual(3, pet.Fields[3].Index);

            // fields
            Assert.AreEqual(4, pet.Fields[4].Index);
            Assert.AreEqual(5, pet.Fields[5].Index);
            Assert.AreEqual(6, pet.Fields[6].Index);
            Assert.AreEqual(7, pet.Fields[7].Index);
            Assert.AreEqual(8, pet.Fields[8].Index);

            // calc fields produced from xml
            Assert.AreEqual(9, pet.CalculatedFields[0].Index);
            Assert.AreEqual(10, pet.CalculatedFields[1].Index);


            Assert.AreEqual("Id", person.Fields[4].Name);

            // system fields
            Assert.AreEqual(0, person.Fields[0].Index);
            Assert.AreEqual(1, person.Fields[1].Index);
            Assert.AreEqual(2, person.Fields[2].Index);
            Assert.AreEqual(3, person.Fields[3].Index);

            // fields
            Assert.AreEqual(4, person.Fields[4].Index);
            Assert.AreEqual(5, person.Fields[5].Index);
            Assert.AreEqual(6, person.Fields[6].Index);
            Assert.AreEqual(7, person.Fields[7].Index);

            Assert.AreEqual(8, person.CalculatedFields[0].Index);
        }
Beispiel #4
0
        public void Try1()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData'>
          <rows>
            <add id='1' xml=""&lt;things&gt;&lt;add name='deez'/&gt;&lt;add name='nutz'/&gt;&lt;/things&gt;"" />
            <add id='2' xml=""&lt;things&gt;&lt;add name='got'/&gt;&lt;add name='eeee'/&gt;&lt;/things&gt;"" />
          </rows>
          <fields>
                <add name='id' type='int' />
                <add name='xml' length='max'>
                    <transforms>
                        <add method='fromxml' root='things' xml-mode='all'>
                            <fields>
                                <add name='name' node-type='attribute' />
                            </fields>
                        </add>
                    </transforms>
                </add>
            </fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            Assert.AreEqual(4, output.Length);

            var name = composer.Process.Entities.First().CalculatedFields.First();

            var first = output[0];

            Assert.AreEqual("deez", first[name]);

            var second = output[1];

            Assert.AreEqual("nutz", second[name]);
        }
Beispiel #5
0
        public void Try1()
        {
            const string xml = @"
    <add name='name'>
      <entities>
        <add name='Employee'>
          <rows>
            <add EmpId='1' FirstName='John' LastName='Doe' JobId='1' />
            <add EmpId='2' FirstName='Jane' LastName='Doe' JobId='2' />
          </rows>
          <fields>
            <add name='EmpId' type='int' primary-key='true' />
            <add name='FirstName' />
            <add name='LastName' />
            <add name='JobId' type='int' />
          </fields>
          <calculated-fields>
            <add name='FullName' t='copy(FirstName,LastName).format({0} {1})' />
          </calculated-fields>
        </add>
        <add name='Job'>
            <rows>
                <add JobId='1' Title='Carpenter' />
                <add JobId='2' Title='Seamstress' />
            </rows>
            <fields>
                <add name='JobId' type='int' primary-key='true' />
                <add name='Title' />
            </fields>
        </add>
      </entities>
      <relationships>
        <add left-entity='Employee' left-field='JobId' right-entity='Job' right-field='JobId' />
      </relationships>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            Assert.AreEqual(2, output.Length);
        }
Beispiel #6
0
        public void Test1()
        {
            const string xml        = @"<cfg>
    <processes>
        <add name='one' mode='init'>
            <connections>
                <add name='input' provider='solr' server='***change-me***' port='8080' path='solr' core='TimeCard' />
            </connections>
            <entities>
                <add name='TimeCard'>
                    <filter>
                        <add expression='fullnamesearch:christ' />
                    </filter>
                    <fields>
                        <add name='tflkey' alias='key' type='int' />
                        <add name='tflbatchid' alias='batchid' type='int' />
                        <add name='tfldeleted' alias='deleted' type='bool' />
                        <add name='tflhashcode' alias='hashcode' type='int' />
                        <add name='exportcode' />
                        <add name='weekending' />
                        <add name='costcode' />
                        <add name='jobcode' />
                        <add name='acct' />
                        <add name='sub' />
                        <add name='regularhours' type='decimal' />
                        <add name='overtimehours' type='decimal' />
                        <add name='worklocation' />
                        <add name='firstname' />
                        <add name='lastname' />
                    </fields>
                </add>
            </entities>
        </add>
    </processes>
</cfg>";
            var          composer   = new CompositionRoot();
            var          controller = composer.Compose(xml);
            var          rows       = controller.Read().ToArray();

            Assert.AreEqual(2, rows.Length);
        }
        public void DateDiff1()
        {
            var xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' >
          <rows>
            <add StartDate='2016-06-01' EndDate='2016-08-01' />
          </rows>
          <fields>
            <add name='StartDate' type='datetime' />
            <add name='EndDate' type='datetime' />
          </fields>
          <calculated-fields>
            <add name='Years' type='int' t='copy(StartDate,EndDate).datediff(year)' />
            <add name='Days' type='int' t='copy(StartDate,EndDate).datediff(day)' />
            <add name='Minutes' type='int' t='copy(StartDate,EndDate).datediff(minute)' />
            <add name='Hours' type='double' t='copy(StartDate,EndDate).datediff(hour)' />
            <add name='MovingUtc' type='int' t='copy(EndDate).datediff(hour,UTC)' />
            <add name='MovingEst' type='int' t='copy(EndDate).datediff(hour,Eastern Standard Time)' />
          </calculated-fields>
        </add>
      </entities>
    </add>
            ".Replace('\'', '"');

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            Assert.AreEqual(0, output[0][cf[0]]);
            Assert.AreEqual(61, output[0][cf[1]]);
            Assert.AreEqual(87840, output[0][cf[2]]);
            Assert.AreEqual(1464, output[0][cf[3]]);
            //Assert.AreEqual(1640, output[0][cf[4]]);
            //Assert.AreEqual(1644, output[0][cf[5]]);
        }
Beispiel #8
0
        public void Test()
        {
            const string xml = @"
    <add name='TestProcess'>
        <connections>
            <add name='input' provider='web' url='' user='' password='' />
            <add name='output' provider='log' />
        </connections>
      <entities>
        <add name='TestData' >
          <fields>
            <add name='Content' length='max' output='false'>
                <transforms>
                    <add method='fromXml' xml-mode='all'>
                        <fields>
                            <add name='name' node-type='attribute' />
                            <add name='consumerCount' type='int' node-type='attribute' />
                        </fields>
                    </add>
                </transforms>
            </add>
          </fields>
          <calculated-fields>
            <add name='pass' type='bool' t='copy(pass,consumerCount).js(consumerCount &gt; 0).filter(false)' />
            <add name='message' length='128' t='copy(name,consumerCount).format({0} queue has {1} consumers!)' />
            <add name='level' default='error' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            controller.Execute();
        }
        public void AnyEqual()
        {
            var xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='1' Field2='2' Field3='3' />
          </rows>
          <fields>
            <add name='Field1' />
            <add name='Field2' />
            <add name='Field3' />
          </fields>
          <calculated-fields>
            <add name='Has1' type='bool' t='copy(*).any(1)' />
            <add name='Has2' type='bool' t='copy(Field1,Field2,Field3).any(2)' />
            <add name='Has3' type='bool' t='copy(*).any(3)' />
            <add name='Has4' type='bool' t='copy(Field1,Field2,Field3).any(4)' />
          </calculated-fields>
        </add>
      </entities>
    </add>
            ".Replace('\'', '"');

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            Assert.AreEqual(true, output[0][cf[0]]);
            Assert.AreEqual(true, output[0][cf[1]]);
            Assert.AreEqual(true, output[0][cf[2]]);
            Assert.AreEqual(false, output[0][cf[3]]);
        }
Beispiel #10
0
        public void StarSql()
        {
            var composer   = new CompositionRoot();
            var controller = composer.Compose(@"Files\Northwind.xml");

            Assert.AreEqual(0, composer.Process.Errors().Length);

            var pipe   = new PipelineContext(new TraceLogger(), composer.Process);
            var actual = new SqlFormattingManager().Format(pipe.SqlCreateStarView(new SqlServerConnectionFactory(new Connection().WithDefaults())));

            Assert.IsNotNull(controller);
            const string expected = @"CREATE VIEW [NorthWindStar]
AS
SELECT A.[A1] AS [TflKey]
	,A.[A2] AS [TflBatchId]
	,A.[A3] AS [TflHashCode]
	,A.[A4] AS [TflDeleted]
	,A.[A5] AS [OrderDetailsDiscount]
	,A.[A6] AS [OrderDetailsOrderID]
	,A.[A7] AS [OrderDetailsProductID]
	,A.[A8] AS [OrderDetailsQuantity]
	,A.[A9] AS [OrderDetailsRowVersion]
	,A.[A10] AS [OrderDetailsUnitPrice]
	,A.[A11] AS [OrderDetailsExtendedPrice]
	,A.[A20] AS [CountryExchange]
	,A.[A21] AS [Test]
	,A.[B5] AS [OrdersCustomerID]
	,A.[B6] AS [OrdersEmployeeID]
	,A.[E12] AS [ProductsSupplierID]
	,A.[E5] AS [ProductsCategoryID]
	,A.[B19] AS [OrdersShipVia]
	,COALESCE(B.[B7], 0.0) AS [OrdersFreight]
	,COALESCE(B.[B8], '9999-12-31T00:00:00Z') AS [OrdersOrderDate]
	,COALESCE(B.[B10], '9999-12-31T00:00:00Z') AS [OrdersRequiredDate]
	,COALESCE(B.[B12], '') AS [OrdersShipAddress]
	,COALESCE(B.[B13], '') AS [OrdersShipCity]
	,COALESCE(B.[B14], '') AS [OrdersShipCountry]
	,COALESCE(B.[B15], '') AS [OrdersShipName]
	,COALESCE(B.[B16], '9999-12-31T00:00:00Z') AS [OrdersShippedDate]
	,COALESCE(B.[B17], '') AS [OrdersShipPostalCode]
	,COALESCE(B.[B18], '') AS [OrdersShipRegion]
	,COALESCE(B.[B20], '12-DEC') AS [TimeOrderMonth]
	,COALESCE(B.[B21], '9999-12-31') AS [TimeOrderDate]
	,COALESCE(B.[B22], '9999') AS [TimeOrderYear]
	,COALESCE(C.[C5], '') AS [CustomersAddress]
	,COALESCE(C.[C6], '') AS [CustomersCity]
	,COALESCE(C.[C7], '') AS [CustomersCompanyName]
	,COALESCE(C.[C8], '') AS [CustomersContactName]
	,COALESCE(C.[C9], '') AS [CustomersContactTitle]
	,COALESCE(C.[C10], '') AS [CustomersCountry]
	,COALESCE(C.[C12], '') AS [CustomersFax]
	,COALESCE(C.[C13], '') AS [CustomersPhone]
	,COALESCE(C.[C14], '') AS [CustomersPostalCode]
	,COALESCE(C.[C15], '') AS [CustomersRegion]
	,COALESCE(D.[D5], '') AS [EmployeesAddress]
	,COALESCE(D.[D6], '9999-12-31T00:00:00Z') AS [EmployeesBirthDate]
	,COALESCE(D.[D7], '') AS [EmployeesCity]
	,COALESCE(D.[D8], '') AS [EmployeesCountry]
	,COALESCE(D.[D10], '') AS [EmployeesExtension]
	,COALESCE(D.[D11], '') AS [EmployeesFirstName]
	,COALESCE(D.[D12], '9999-12-31T00:00:00Z') AS [EmployeesHireDate]
	,COALESCE(D.[D13], '') AS [EmployeesHomePhone]
	,COALESCE(D.[D14], '') AS [EmployeesLastName]
	,COALESCE(D.[D15], '') AS [EmployeesNotes]
	,COALESCE(D.[D18], '') AS [EmployeesPostalCode]
	,COALESCE(D.[D19], '') AS [EmployeesRegion]
	,COALESCE(D.[D21], '') AS [EmployeesTitle]
	,COALESCE(D.[D22], '') AS [EmployeesTitleOfCourtesy]
	,COALESCE(D.[D23], 0) AS [EmployeesReportsTo]
	,COALESCE(D.[D24], '') AS [EmployeesManager]
	,COALESCE(D.[D25], '') AS [Employee]
	,COALESCE(E.[E6], 0) AS [ProductsDiscontinued]
	,COALESCE(E.[E8], '') AS [ProductsProductName]
	,COALESCE(E.[E9], '') AS [ProductsQuantityPerUnit]
	,COALESCE(E.[E10], 0) AS [ProductsReorderLevel]
	,COALESCE(E.[E13], 0.0) AS [ProductsUnitPrice]
	,COALESCE(E.[E14], 0) AS [ProductsUnitsInStock]
	,COALESCE(E.[E15], 0) AS [ProductsUnitsOnOrder]
	,COALESCE(F.[F5], '') AS [SuppliersAddress]
	,COALESCE(F.[F6], '') AS [SuppliersCity]
	,COALESCE(F.[F7], '') AS [SuppliersCompanyName]
	,COALESCE(F.[F8], '') AS [SuppliersContactName]
	,COALESCE(F.[F9], '') AS [SuppliersContactTitle]
	,COALESCE(F.[F10], '') AS [SuppliersCountry]
	,COALESCE(F.[F11], '') AS [SuppliersFax]
	,COALESCE(F.[F12], '') AS [SuppliersHomePage]
	,COALESCE(F.[F13], '') AS [SuppliersPhone]
	,COALESCE(F.[F14], '') AS [SuppliersPostalCode]
	,COALESCE(F.[F15], '') AS [SuppliersRegion]
	,COALESCE(G.[G6], '') AS [CategoriesCategoryName]
	,COALESCE(G.[G7], '') AS [CategoriesDescription]
	,COALESCE(H.[H5], '') AS [ShippersCompanyName]
	,COALESCE(H.[H6], '') AS [ShippersPhone]
FROM [NorthWindOrder DetailsTable] A
LEFT OUTER JOIN [NorthWindOrdersTable] B ON (A.[A6] = B.[B9])
LEFT OUTER JOIN [NorthWindCustomersTable] C ON (A.[B5] = C.[C11])
LEFT OUTER JOIN [NorthWindEmployeesTable] D ON (A.[B6] = D.[D9])
LEFT OUTER JOIN [NorthWindProductsTable] E ON (A.[A7] = E.[E7])
LEFT OUTER JOIN [NorthWindSuppliersTable] F ON (A.[E12] = F.[F17])
LEFT OUTER JOIN [NorthWindCategoriesTable] G ON (A.[E5] = G.[G5])
LEFT OUTER JOIN [NorthWindShippersTable] H ON (A.[B19] = H.[H8]);
";

            Assert.AreEqual(expected, actual);
        }
Beispiel #11
0
        public void RunInit()
        {
            var composer = new CompositionRoot();

            composer.Compose(Cfg + @"?Mode=init", LogLevel.Info).Execute();
        }