How to: Create an Unmanaged Feed Producer

This topic shows how to use an unmanaged language, such as C++, to create an application that uses Sync Framework to produce an RSS feed from a list of files in a folder. The RSS feed produced by this application contains an item for each file in the specified folder. Each item in the feed contains the contents of its associated file as well as FeedSync metadata about the item.

This topic assumes a basic familiarity with C++ and COM concepts.

The examples in this topic focus on the following Sync Framework Web synchronization components:

Understanding Feed Producers

A feed producer is a software component that produces a FeedSync feed that contains items that are provided by a synchronization provider. The application implements the IFeedIdConverter interface to convert IDs from the format of the provider to the FeedSync format, and implements IFeedItemConverter to convert item data from the format of the provider to the FeedSync format.

For more information about producing a FeedSync feed, see Producing RSS and Atom Feeds.

For more information about synchronization providers, see Implementing a Standard Custom Provider.

Build Requirements

  • Synchronization.h, FeedSync.h, FileSyncProvider.h: declarations for Sync Framework core components, Web synchronization components, and the file synchronization provider.

  • Synchronization.lib, FeedSync.lib, FileSyncProvider.lib: import libraries.

Example

The example code in this topic shows how to use an IFeedProducer object to produce an RSS feed that contains items provided by an IFileSyncProvider object. The example also shows how to implement the interfaces that convert IDs and item data from the format of the file synchronization provider to the FeedSync format.

Implementing IFeedIdConverter

The IDs that a provider uses can be in any format. Therefore, Sync Framework requires that an application implement the IFeedIdConverter interface to convert the IDs from the provider format to the FeedSync format and vice versa.

Declaring IFeedIdConverter

Add IFeedIdConverter to the class inheritance list.

Add the IFeedIdConverter methods to the class declaration.

GetIdParameters Method

Sync Framework calls IFeedIdConverter::GetIdParameters to obtain the ID format schema used by the provider. The implementation in this example returns the ID format schema retrieved from the IFileSyncProvider object. For the code that retrieves and stores the schema, see the section "Producing an RSS Feed" later in this topic.

ConvertReplicaIdToString Method

Sync Framework calls IFeedIdConverter::ConvertReplicaIdToString to convert a replica ID from the provider format to a string. The string representation of the ID can be of any form and is written verbatim to the feed. The implementation in this example uses the OLE32 function StringFromGUID2 to convert the replica ID from a GUID to a WCHAR string. It returns the resulting string by using the IFeedIdConverterCallback::ConvertReplicaIdToStringComplete method.

ConvertItemIdToString Method

Sync Framework calls IFeedIdConverter::ConvertItemIdToString to convert an item ID from the provider format to a string. The string representation of the ID can be of any form and is written verbatim to the feed. The implementation in this example converts an item ID formatted as a SYNC_GID structure to a WCHAR string. It uses the CRT function _ui64tow_s to convert the prefix part from a ULONGLONG to a WCHAR string. It also uses the OLE32 function StringFromGUID2 to convert the GUID part of the ID to a WCHAR string. The example concatenates these two strings into one and returns the resulting string by using IFeedIdConverterCallback::ConvertItemIdToStringComplete.

ConvertStringToReplicaId Method

Sync Framework calls IFeedIdConverter::ConvertStringToReplicaId to convert a replica ID from a string to the provider format. The string representation is exactly what was returned to Sync Framework in the ConvertReplicaIdToString method. The implementation in this example uses the OLE32 function CLSIDFromString to convert the replica ID from a WCHAR string to a GUID. It returns the resulting ID by using the IFeedIdConverterCallback::ConvertStringToReplicaIdComplete method.

ConvertStringToItemId Method

Sync Framework calls IFeedIdConverter::ConvertStringToItemId to convert an item ID from a string to the provider format. The string representation is exactly what was returned to Sync Framework in the ConvertItemIdToString method. The implementation in this example uses the CRT function wcstoui64 to convert the prefix part of the ID from a WCHAR string to a ULONGLONG. It also uses the OLE32 function CLSIDFromString to convert the GUID part of the ID from a WCHAR string to a GUID. The example returns the resulting ID formatted as a SYNC_GID by using the IFeedIdConverterCallback::ConvertStringToItemIdComplete method.

Methods That Are Not Implemented

The following method is not required for basic feed producer scenarios. This method can return E_NOTIMPL:

Implementing IFeedItemConverter

Item data from a provider can be in any format. Therefore, Sync Framework requires that an application implement the IFeedItemConverter interface to convert item data from the provider format to the FeedSync format and vice versa.

Declaring IFeedItemConverter

Add IFeedItemConverter to the class inheritance list.

Add the IFeedItemConverter methods to the class declaration.

ConvertItemDataToXmlText

Sync Framework calls IFeedItemConverter::ConvertItemDataToXmlText to convert item data from the provider format to XML text. ConvertItemDataToXmlText is called when IFeedItemConverter::ConvertItemDataToXml returns E_NOTIMPL. The implementation in this example expects the files that are being produced to contain valid XML for an RSS item, in a Unicode format. An example of the file contents follows.

IFileSyncProvider provides the contents of a file as an IFileDataRetriever object. The implementation in this example gets an IStream object from the IFileDataRetriever object and uses it to read the contents of the file into a WCHAR string. It returns the resulting string by using the IFeedItemConverterCallback::ConvertItemDataToXmlTextComplete method.

Methods That Are Not Implemented

The following methods are not required for basic feed producer scenarios. These methods can return E_NOTIMPL:

Producing an RSS Feed

Sync Framework supplies the IFeedProducer interface to help a provider produce items from its associated replica to a FeedSync feed. The implementation in this example uses an IFileSyncProvider object as the provider, and a folder in the file system as the replica. The example code takes the following steps to produce the feed:

  1. Creates an IFileSyncProvider object and configures it by specifying the folder to synchronize, and a filter that only includes files that have a .txt extension.

  2. Creates an IStream object and initializes it with an empty RSS feed. The following code declares the empty RSS feed.

  3. Creates an IFeedProducer object and calls its IFeedProducer::ProduceFeed method.

  4. Writes the feed, which has been written to the IStream object by Sync Frameworkto a file in the replica folder.

The following code produces the feed.

Next Steps

Now that you have created a FeedSync producer, you might want to create a feed consumer. A feed consumer is a software component that extracts items from a FeedSync feed and applies them to a destination replica by using a synchronization provider. For more information, see Consuming RSS and Atom Feeds.

Vea también

Conceptos

Synchronizing Web Feeds

Producing RSS and Atom Feeds

Consuming RSS and Atom Feeds

Converting IDs and Items for RSS and Atom Feeds

Sync Framework Web Synchronization Components