Skip to content

FluentAPI User Guide

The FluentAPI is a user-friendly way of creating, executing, and viewing the results of Composable data flows in code. It is a set of C# classes that interact with Composable Analytics services in order to provide a versatile and lightweight way of using data flows.

The FluentAPI works in C# or F# running on .NET 4.5.

Getting Started

To begin, your project must reference the following:

  • CompAnalytics.Contracts
  • CompAnalytics.Execution
  • CompAnalytics.Extension
  • CompAnalytics.FluentAPI

from NuGet via the .dll's available on NuGet's public servers. You must also reference any Composable extension assemblies you wish to use in your application. Please note however that if you wish to run a custom extension that you've written, the .dll file you built must also be on the server in the /bin directory of your installations. Please contact your Composable Administrator for more information on this process.

After that is set up, you can begin writing code. Please see the complete API reference for any information not covered in this example.

Examples

Let's say you've created a C# console application and referenced the required assemblies. In this example, we've referenced:

  • CompAnalytics.FluentAPI
  • CompAnalytics.Contracts
  • CompAnalytics.Extension
  • CompAnalytics.Execution.Modules

Here is a complete example demonstrating how to define an app, run it, and view the outputs:

using System;
using CompAnalytics.FluentAPI;
using CompAnalytics.Execution.Modules;
using CompAnalytics.Contracts;

namespace FluentAPITest
{
    public class FluentAPISample
    {
        public static void Main(string[] args)
        {
            // Define the Application and add some Calculator modules to it
            var app = new Application();
            var firstCalculator = ModuleBuilder.Create<CalculatorModuleExecutor>()
                        .ConfigureInput(m => m.Param1).WithValue(8)
                        .ConfigureInput(m => m.Param2).WithValue(3)
                        .ConfigureInput(m => m.Operator).WithValue("-")
                        .AddToApp(app);

            var secondCalculator = ModuleBuilder.Create<CalculatorModuleExecutor>()
                                    .ConfigureInput(m => m.Param1).WithValue(-1)
                                    .ConfigureInput(m => m.Param2).WithConnection(firstCalculator.SelectOutput(m => m.Result))
                                    .ConfigureInput(m => m.Operator).WithValue("+")
                                    .AddToApp(app);

            // Create an ApplicationInspector out of the app we just made, configure it with the needed settings, and run it
            var appInspector = ApplicationInspector.Create(app).Configure(new Uri("http://localhost/Composable/"), "myusername", "mypassword").Run();

            // Get the outputs of the application (should print 5 followed by 4)
            Console.WriteLine(appInspector.GetModuleBuilder<CalculatorModuleExecutor>(0).SelectOutputValue<double>(m => m.Result));
            Console.WriteLine(appInspector.GetModuleBuilder<CalculatorModuleExecutor>(1).SelectOutputValue<double>(m => m.Result));

            Console.WriteLine("Done!");
            Console.ReadLine();
        }
    }
}

What we've done is made two Calculator modules, piping the results of the first one into the second parameter of the second Calculator. Note when we're getting the outputs of the Modules, since we have two calculator modules, we select the 0th calculator and the 1st calculator. If you leave the numeric parameter blank, it will select the 0th module of that type.

Here is another minimal example, this time we're loading the Application by importing a Json file that contains a StringInputExecutor module and a StringFormatter module:

using System;
using CompAnalytics.FluentAPI;
using CompAnalytics.Execution.Modules;

namespace FluentAPITest
{
    public class FluentAPISample
    {
        public static void Main(string[] args)
        {
            var appInspector = ApplicationInspector.Create().Configure(new Uri("http://localhost/Composable/"), "myusername", "mypassword")
                .ImportAppFromFile(@"C:\Dev\Product\Composable Analytics\Product\UnitTests\TestData\StringTest.json").Run();
            Console.WriteLine(appInspector.GetModuleBuilder<StringInputExecutor>().SelectOutputValue<string>(m => m.Result));
            Console.WriteLine(appInspector.GetModuleBuilder<StringFormatter>().SelectOutputValue<string>(m => m.Result));

            Console.WriteLine("Done!");
            Console.ReadLine();
        }
    }
}

We are able to import an application, run it, and view the outputs in just three lines of code!

We can also run the FluentAPI in other .NET languages, F# for instance:

open System
open CompAnalytics.FluentAPI
open CompAnalytics.Execution.Modules

[<EntryPoint>]
let main argv = 
    let appInspector = ApplicationInspector.Create ()
    ignore (appInspector.Configure (new Uri("http://localhost/Composable/"), "myusername", "mypassword"))
    ignore (appInspector.ImportAppFromFile ("C:\\Dev\\Product\\Composable Analytics\\Product\\UnitTests\\TestData\\StringTest.json"))
    ignore (appInspector.Run ())
    let stringInput = appInspector.GetModuleBuilder<StringInputExecutor> ()
    let stringFormatter = appInspector.GetModuleBuilder<StringFormatter> ()
    printfn "%s" (stringInput.SelectOutputValue<string> (fun si -> si.Result))
    printfn "%s" (stringFormatter.SelectOutputValue<string> (fun si -> si.Result))
    printfn "Done!"
    ignore (Console.ReadLine ())
    0