Procedure
-
Implement the
ISiteSyncSnapIninterface
In both projects, create a class and name itCustomTypeSiteSyncSnapIn.cs.
This class must implements theISiteSyncSnapIninterface. -
Register the custom items in the
Global.asaxclass
Open theGlobal.asaxand onApplication_Start, attach anEventHandlermethod to theSystemManager.ApplicationStartevent.
This handler registers your custom items. -
Add the required members of the
CustomTypeSiteSyncSnapInclass. -
Subscribe to the
Createdevent.
This tutorial usesFileSystemWatcherthat provides the following file system events:Changed,Deleted,Created, andRenamed.To subscribe to the
Createdevent, in the constructor of theCustomTypeSiteSyncSnapInclass, add theApp_Data\Sitefinity\Testpath that will be watched by the watcher and subscribe to theCreatedevent. -
Create a
SiteSynclog entry
Every time you create a new item inside folderTest, the event handler for theCreatedevent is called. Inside this handler, you must create a site sync log entry for each target server.
To do this, you use thedataStoreobject and set the corresponding properties for the log entry.RESULT: Every time you create a new folder or file inside the
Testfolder, a log entry for the created item is logged in the database.NOTE: Immediately after you create a new folder or file, the event is raised. It gets the first (default) name of the item. Therefore, if you want to change the default name of the item, you must implement an event handler for the
Renamedevent of theFileSystemWatcherclass. -
Implement the methods of the
ISiteSyncSnapIninterface.
You implement the following methods:-
GetPendingItems
This method returns the items that are pending for synchronization for the current type. -
GetExportItemsCount
This is a method that you implement for your custom snap-in. It gives you the number of the items that you have checked for export.
Inside this method, you callGetExportItems, which gets only the items that you have checked for syncing. -
Export
This method is the method that exports the items for syncing.
Inside this method, you go through the log entries that are check for synchronization for the current type. For every log entry, you create aWrapperObjectthat you add to the export transaction. In this object, you can add properties and their values. You can also give an object with properties to the constructor of theWrapperobject. With theCommonItemLoaderyou can set the common properties for the log entry.
In the export transaction, you set the header for the current site sync snap-in and in the export transaction items you add the wrapper objects.NOTE: You can choose how you want to export the items – all items in one transaction, or a separate transaction for each entry.
-
-
Save the items on the target server
You must also implement the logic for saving the items on the target server. For each exported transaction from theExportmethod, you must implement anImportmethod. It takes as parameter the current transaction with the exported items.