Writing a Simple .NET Application

Top Previous Topic Next Topic  Print this topic

Using the Data Aggregation Server's .NET API is very easy. Below we will describe the steps needed to create a simple job application.

 

Step 1: Create a New Microsoft Visual Studio 2005 Project

 

Open Visual Studio 2005 and go to File > New > Project... and select Visual C# > Console Application.

 

Step 2: Add the Ecrion DAS References

 

ecrion_das_assembly_refference

 

Go to Project > Add Reference... and select Ecrion.DAS.NET in the list as shown in the screenshot above, then click OK.

 

Step 3: Type In The Code

 

First make sure that you have a valid XML input job. Valid input jobs can be found in Samples\Job Samples folder.

Then, copy the code listed below into the Program.cs file and hit F5 or Debug > Run and a XML file jobOut.xml will be written on your C:\ drive. Remember to first make sure that you have write access on C:\.

 

 

using System;

using System.Collections.Generic;

using System.Text;

using Ecrion.DAS;

using System.IO;

 

namespace TestDAS

{

  class Program

   {

      static void Main(string[] args)

       {

          try

           {

              Engine engine = new Engine();

 

              //parameters for the processing operation.

              JobParameters param = new JobParameters();

 

                  //Make sure that the path to the job is valid!!!                  

                  param.Diagram = new LocalDiagram(

                       @"C:\Users\Public\Documents\Ecrion\Data Aggregation Server 2012\Samples\Job Samples\SampleCSV.dax");

 

                  //Optional.

                  //Uncomment the following lines of code to override the CSV path.(make sure that the path is valid!!!)

                  //String csvPath = String.Format(

                  //        @"C:\Users\Public\Documents\Ecrion\Data Aggregation Server 2012\Samples\Database Samples\US Presidents.csv");

                  //param.Diagram.Properties.Add(new JobProperty("11", "src", csvPath));

 

              //set the XML output file

                   using (FileStream outputStream = new FileStream(@"C:\Temp\SampleCSV.xml", FileMode.Create))

                  engine.Aggregate(outputStream, param);

 

              Console.WriteLine("Output XML is ready!\n");

           }

          catch (Exception e)

           {        // Report any errors that may occur

              Console.WriteLine(e);

           }

       }

   }

}

 

 

Understanding the Above Code:

 

First we create our Engine object instance which will render the job file into output XML:

 

 

// create a new engine

Engine engine = new Engine();

 

 

 

Set some job parameters. Job Parameters are used to overwrite some key resources in your job, like connection-strings, web-service urls etc. The

purpose is to use the same job with various data sources, or to hide some critical aspects of your jobs (like username and password from XML job).

 

Next, create a LocalDiagram. SampleCSV.dax is a simple job sample form the Samples\Job Samples folder.  Verify that the paths provided are still correct.  The paths in the samples are the default paths which an installer could have changed during installation.

 

In this sample we will overwrite the CSV file  path from job <das:csv-url> element with the id 11.

 

 

JobParameters param = new JobParameters();

 

//Make sure that the path to the job is valid!!!                  

param.Diagram = new LocalDiagram(

       @"C:\Users\Public\Documents\Ecrion\Data Aggregation Server 2012\Samples\Job Samples\SampleCSV.dax");

 

String csvPath = String.Format(

       @"C:\Users\Public\Documents\Ecrion\Data Aggregation Server 2012\Samples\Database Samples\US Presidents.csv");

 

param.Diagram.Properties.Add(new JobProperty("11", "src", csvPath));

 

 

 

Now we'll create an output stream (we'll use a FileStream in this example) and call the Aggregate() method on our Engine object.

 

 

using (FileStream outputStream = new FileStream("C:\Temp\SampleCSV.xml", FileMode.Create))

    engine.Aggregate(outputStream, param);