Creating a Custom Data Source

17 June 2013

If you have a system that your trying to integrate that is not supported by Data Sync it is quite easy to create a custom Data Provider to read data from this system and return it to Data Sync.

The First Step is to Connect Data Source A to the Empty/Dynamic Data source Provider. This provider does not return any rows but allows you to define the returned schema and override the row loading in Dynamic Columns.

Connect

Define your Schema Columns within the Columns property window.

Column Properties

When you preview the data in Data Sync you will get an empty result.

Preview

However switching to the Dynamic Columns view you can override the GetDataTable method to provide your own Row Loading implementation and by using this you can integrate with virtually anything you like.

The code below is what you would require to implement your own data source. This code simply returns ID and Name columns but it could easily be expanded for any other use.

#region Usings
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Text;
using System.Linq;

using Simego.DataSync;
#endregion

using Simego.DataSync.Providers.Null;

/// <summary>
/// This module of code allows you to define some columns in code or Dynamic Columns
/// To Create new Dynamic Columns simply expose them as properties in this class.
/// </summary>
partial class DataSourceRowOverride : Simego.DataSync.DynamicColumns.DataSourceRowInternal //Do Not Change This Line
{            
    public override DataTableStore GetDataTable(DataTableStore dt, IDataSourceReader reader) 
    {
        //Get the Actual Reader Instance.
        NullDataSourceReader SourceReader = (NullDataSourceReader)reader;
        
        //Create a Schema Mapping Helper
        DataSchemaMapping mapping = new DataSchemaMapping(reader.SchemaMap, reader.Side);
            
        for(int i=0; i<1000; i++) 
        {            
            var row = dt.NewRow();
            foreach (DataSchemaItem item in reader.SchemaMap.GetIncludedColumns())
            {
                string columnName = mapping.MapColumnToDestination(item);
                            
                switch(columnName) 
                {
                    case "ID": 
                    {
                        row[item.ColumnName] = DataSchemaTypeConverter.ConvertTo(i, item.DataType);                                                    
                        break;
                    }
                    
                    case "Name": 
                    {
                        row[item.ColumnName] = DataSchemaTypeConverter.ConvertTo(string.Format("Item-{0}", i), item.DataType);                                                    
                        break;
                    }
                    
                    default:
                    {
                        break;    
                    }
                }
                
            }

            if (dt.Rows.Add(row) == DataTableStore.ABORT)
                break;                    
            
        }
        
        return dt;
    }
}


Now when you preview the data you will get data from your source system which you can then connect to a Target system just like any other provider.

Preview

| |