Empty Data Source Connector
To connect to a REST API we recommend using the JSON API Designer to create the connection document needed to use the JSON API Connector.
The Empty Data Source provides a container that can be used as a dummy target or used for a custom data source when combined with .NET C# code in project automation.
You can use the Empty Data Source connector to connect to a REST API, however we now recommend using the JSON API Connector to provide a XML file describing the connection.
Columns
Since the Empty Data Source does not define any Schema you need to specify the schema columns. You can do this by clicking onto the ellipsis (...
) in the Columns field and then adding each column to the collection. Some examples are shown below:
Properties
You need to define the properties that can be accessed via project automation or dynamic columns, such as the URL to the API. This can be done by clicking onto onto the ellipsis (...
) in the Properties field and then adding each property to the collection.
UseDefaultJsonRequestFeature
This is a feature where this provider can provide read-only
access to a basic JSON-REST type service.
Configuration
The Properties collection is used to control the service endpoint and other basic parameters.
Property | Description | Example |
---|---|---|
URL | The url to the JSON service | https://jsonplaceholder.typicode.com/users |
Username | Username to use with BASIC AUTH | username |
Password | Password for Username | password123 |
AuthorizationToken | Set a Bearer HTTP Header for OAuth authentication | AaaaBBccc444566 |
DataTokenName | The Json Token that returns an Array of items to read | Required if the items array is a child of the json document data |
Project Automation
The Empty Data Source can be loaded with data via project automation code, this is if you need to quickly create a Data source from a service that is not supported in Data Sync.
class ProjectAutomationOverride : Simego.DataSync.Automation.ProjectAutomationShim //Do Not Change This Line
{
// Http Request Helper to call Json Service
private HttpWebRequestHelper helper = new HttpWebRequestHelper() { UseDefaultCredentials = true };
public override void Start()
{
// Set callback function implementation.
DataSourceA.GetDataTableCallback = GetDataTableSource;
}
public DataTableStore GetDataTableSource(DataTableStoreCallbackInfo info)
{
// Convert Datasource Properties to a Dictionary.
var prop = DataSourceA.Properties.ToDictionary(k => k.Name);
// Get a response from the Json Service
var jsonResponse = helper.GetRequestAsJson(prop["url"].Value);
//Enumerate the result json array (use jsonResponse["xxx'] if required)
foreach(var item_json in jsonResponse)
{
// Add the columns to the Data Row
info.Store.Rows.Add(info,
(o, columnName) =>
{
// Get the requested column from the Json Document
var value = item_json[columnName];
//Return the value.
return value != null ? value.ToObject(typeof(object)) : null;
});
}
return info.Store;
}
}
Download Json Demo Project Automation Project
Dynamic Columns
Another way of achieving the same result as by using Project Automation is to use Dynamic Columns. Override the loading of the data table with your own code.
partial class DataSourceRowOverride : Simego.DataSync.DynamicColumns.DataSourceRowInternal //Do Not Change This Line
{
//Every time DS3 calculates a row is runs this BeginRow method.
//You can use this to decide whether to include the row in the results
//Return true to process the row
//Return false to skip the row
public override bool BeginRow()
{
return true; // return false to skip row from results.
}
public override DataTableStore GetDataTable(DataTableStore dt, IDataSourceReader reader)
{
// Create a Callback Info Object to be used later during the data load.
var info = new DataTableStoreCallbackInfo()
{
Mapping = new DataSchemaMapping(reader.SchemaMap, reader.Side),
IncludedColumns = reader.SchemaMap.GetIncludedColumns()
};
// Convert Datasource Properties to a Dictionary to get the Endpoint URL
var prop = GetDataSourceA().Properties.ToDictionary(k => k.Name, v => v.Value, StringComparer.OrdinalIgnoreCase);
// Get a WebRequest Helper to call the Json API
var helper = new HttpWebRequestHelper() { UseDefaultCredentials = true, TraceEnabled = true };
// Get a response from the Json Service
var jsonResponse = helper.GetRequestAsJson(prop["url"]);
//Enumerate the result json array (use jsonResponse["xxx'] if required)
foreach(var item_json in jsonResponse)
{
// Add the columns to the Data Row
dt.Rows.Add(info,
(o, columnName) =>
{
// Get the requested column from the Json Document
var value = item_json[columnName];
//Return the value.
return value != null ? value.ToObject(typeof(object)) : null;
});
}
return dt;
}
Download Json Demo Dynamic Columns Project
Target
When used as a target the normal scenario is that the Null/Empty connector returns zero rows so all operations are ADD operations. These operations do not actually do anything however you can still override the action in project automation item events.
This scenario might be used simply for testing or for targeting a data source that is not currently supported by Data Sync.
You can setup the Empty Data Source as a Target using the quick create function in the Tools menu.
This will create column headers for any columns that are in the schema map at the time it is created. To do this add the columns to the schema and then open the tools menu. Click onto Create Null/Empty Data Source and the empty dataset will be created.