Sitefinity 9 Sync with Gigya Data Store - DS

Skip to end of metadata
Go to start of metadata

Overview

If you are using Gigya's Data Store (DS) to store user-related data as well as Sitefinity 9 as a CMS, the DS Sync module adds the ability to pull data from Gigya's Data Store and map it into the user account database in Sitefinity. Synchronization between Sitefinity and Gigya's Data Store (DS) is provided through an optional, separate package that can be installed on top of the main Gigya core package for Sitefinity.

Customers who only use Gigya's account storage, and do not use the Gigya Data Store service, do not have to install this additional module.

Note that DS is supported by Gigya CMS module version 3.2.1 and up.

Installation and Implementation

To implement DS sync follow these steps:

1. Install DS Sync Module

The Data Store sync module is installed via NuGet. To install the package: 

  1. Right-click References on your web project and select Manage NuGet Packages

  2. Make sure the package source is nuget.org and type "gigya" in the search box.

  3. Select the DS package that corresponds to your Sitefinity version as shown in the table above and click Install.

  4. Build your project in Visual Studio. 

 

If your core Gigya module has not yet been updated to match the selected Sitefinity version, it will update automatically.

 

2. Configure DS Settings

In a multi-site environment, you can configure settings per site or globally. By default, all sites inherit the global settings, so you can configure the global settings, then set different configurations for individual sites. The global settings are accessed from the Basic Settings menu on the left-hand side. 

Data Extraction Method

In the Gigya DS Settings tab available on the left-hand menu, configure how to retrieve DS data from Gigya, whether search or get. The default is search

  • Search: This calls ds.search and is the recommended option when using more than one OID or DS type (table). 
  • Get: This calls ds.get and is the recommended option when using one OID and one DS type (table). 

Field Mapping

Map Gigya DS fields to the corresponding fields in Sitefinity. 

  1. Open the Gigya DS Settings tab from the menu on the left-hand side.  
  2. Under Gigya DS Field, specify the DS field to be mapped, in the following format: ds.type.field. If the field was assigned a suffix in the Gigya DS, denoting the field type (e.g., _i to denote an integer field), you should also add the suffix to the gigyaName field mapping. Examples:  
    • ds.userInfo.favouriteColour_s

    • ds.userInfo.extraData.subProperty.value1_s

    • ds.addressInfo.line1_s

    • ds.addressInfo.yearMoved_d

  3. Under Gigya DS OID, enter the Data Store Object
  4. Enter the Sitefinity field. 
  5. When you've finished adding fields, click 'Save changes'. Note that empty or partially filled mapping definitions will generate an error, so remove unnecessary lines by clicking 'Remove'. 

Caching

For performance reasons, the Gigya DS settings are cached in memory for a default of 60 minutes. This can be changed by adding an AppSetting with Gigya.DS.CacheMins as the key, e.g.:

<add key="Gigya.DS.CacheMins" value="5" />

When settings are updated through Sitefinity, the cached settings are cleared from memory. This is fine in a single server environment but won’t work for a load balanced environment as each server has its own cache. To clear the cache on the other servers you could republish the settings there or restart the app pool.

Manually Retrieving Gigya DS Data 

DS data can be manually retrieved using the Gigya.Module.DS.Helpers.GigyaDsHelper class. 

Below is an example of how you could retrieve DS data manually. If you want to use your own settings this can be done by passing your own settings models into the GigyaDsHelper constructor.

private dynamic ManuallyRetrieveDsData()

{
	// create a new helper Gigya DS Helper to retrieve DS data from Gigya
	var dsHelper = GigyaDsHelperFactory.Instance();
	// retrieve DS data for a user who is logged in
	var dsData = dsHelper.GetOrSearchForCurrentUser();
	// get DS data for a user whose UID is UID
	var anotherSample = dsHelper.GetOrSearch("UID");
	// do further processing here
	return dsData;
}

Using Hooks to Manipulate Data Before Mapping into Sitefinity

After the DS fields have been retrieved, an event is fired which can be subscribed to in order to manipulate the account info object before the fields are mapped to Sitefinity. The following code sample demonstrates how to do this. Usually this code would be added to Global.asax.cs. As this event is fired after DS data is merged with getAccountInfo data, the event will only be fired when user data is being synced with Sitefinity after login, register and edit profile events.

protected void Application_Start(object sender, EventArgs e)

{

Bootstrapper.Initialized += Bootstrapper_Initialized;

}

private void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)

{

	if (e.CommandName == "RegisterRoutes")

	{

	// register event to be called after Gigya DS data has been merged with

	Gigya.Module.Core.Connector.Events.GigyaEventHub.Instance.AccountInfoMergeCompleted +=

	Instance_AccountInfoMergeCompleted;

	}

}

private void Instance_AccountInfoMergeCompleted(object sender,

Gigya.Module.Core.Connector.Events.AccountInfoMergeCompletedEventArgs e)

{

// model representing Gigya DS data that has been merged with the getAccountInfo model

dynamic gigyaAccountInfoWithDsDataMerged = e.GigyaModel;

try

{

	// assuming I have a DS field called ds.addressInfo.line1_s then I would use this code to change the value

	gigyaAccountInfoWithDsDataMerged.ds.addressInfo.line1_s = "first line of address";

}

catch (Exception ex)

	{

	e.Logger.Error("Error in Instance_AccountInfoMergeCompleted.", ex);

	}

}

You can also subscribe to an event which is fired after DS data is retrieved manually as well as when retrieved to be merged with getAccountInfo. This is useful if you always want to run custom code after DS data is retrieved, regardless of whether it has been invoked manually or by the DS module.

The events described in the core module can also be used to manipulate data. See Gigya Connector for Sitefinity 9.

Here is a sample:

private void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e) 
	if (e.CommandName == "RegisterRoutes") 
		{ 
			Gigya.Module.Core.Connector.Events.GigyaEventHub.Instance.FetchDSCompleted += 
		Instance_FetchDSCompleted; 
		} 
	private static void Instance_FetchDSCompleted(object sender, 
Gigya.Module.Core.Connector.Events.FetchDSCompletedEventArgs e) 
		{ 
		// manipulate DS data if required e.g.: 
		try 
		{ 
			e.GigyaModel.ds.dsType.field = "updated"; 
		} 
		catch (Exception ex) 
		{ 
			e.Logger.Error("Failed to update DS data after fetch.", ex); 
		} 
	}

Troubleshooting

  • Turn on Debug mode in the Settings page and check the debug logs. 
  • If a Gigya field is not being saved to Sitefinity check the field mappings on the Settings page: 
    • Make sure field names are correct 
    • Make sure fields are of the same type (e.g., don’t map a string Gigya DS field to a numerical Sitefinity field). 

Uninstalling

The package can be uninstalled in the standard NuGet way:

  1. Open the project in Visual Studio and right-click on References.
  2. Click Manage Nuget Packages.
  3. Select the package to uninstall.
  4. Click Uninstall.

 

  • No labels