Training

Project Automation

The below tutorial will cover what Project Automation is and how it can be used.

The Project Automation feature allows you to run your own .NET C# code at certain points in the Data Sync process.

Project automation can be opened by going to View > Project Automation Window. To then begin using this you need to click Enable Project Automation.

Enable Project Automation

This will then open the code view.

Code View Project Automation

The Start() method allows you to adjust configuration settings on your source and target data connections before the project runs. This can be used to change a filter dynamically at runtime.

The End() Method allows you to run something when the process is complete. This can be used to call a SQL Stored Procedure or Log the result somewhere else.

The standard events contained within Project Automation are as follows :-

  • Start()
  • BeforeCompare(ProjectAutomationLoadResult loadResult)
  • AfterCompare(ProjectAutomationCompareResult compareResult)
  • BeforeSynchronisation(ProjectAutomationCompareResult compareResult)
  • End(ProjectAutomationResult result)
  • Error(ProjectAutomationException e)

Item Events

Item Events allow you to intercept before and after an operation during the sync process.

You can cancel an operation by setting the Sync property to false in the Before() event this is the same as unchecking the Sync flag in the comapre results window except this allows you to do it programatically.

  • BeforeAddItem(object sender, DataCompareItemInvariant item, object identity)
  • AfterAddItem(object sender, DataCompareItemInvariant item, object identity)
  • BeforeUpdateItem(object sender, DataCompareItemInvariant item, object identity)
  • AfterUpdateItem(object sender, DataCompareItemInvariant item, object identity)
  • BeforeDeleteItem(object sender, DataCompareItemInvariant item, object identity)
  • AfterDeleteItem(object sender, DataCompareItemInvariant item, object identity)
NB: Not all Data Connectors support Item Events

The item field contains details about the item to be either Added, Updated or Deleted.

  • Sync - If the item is to be synchronised.
  • Key - The Key value for the item
  • Row - A list of Columns for Update
  • SourceRow - A list of columns in the source row
  • GetTargetIdentifier() - Get the ID value for the Target Item

The identity field may contain the ID value of the target item this depends on the provider implementation.

One use-case is where you want to update the source system with the created ID value from the target, for example where in Dynamics CRM you want to add the Entity Guid to your source SQL Table whenever a new account is added. This can be done easily via the UpdateSourceRow helper function on the SQL Data Connector.

public override void AfterAddItem(object sender, DataCompareItemInvariant item, object identity)
{
    DataSourceA.UpdateSourceRow("CRM_ID", identity, item);        
}

Another Example is using this to clear a Sync flag on the source SQL Table after it has been written to the target.

public override void AfterAddItem(object sender, DataCompareItemInvariant item, object identity)
{
    DataSourceA.ExecuteNonQuery(string.Format("UPDATE {0} SET [Sync]=0 WHERE [ID]=?", DataSourceA.SourceTable), item.Key);    
}