Saturday, June 24, 2006

Windows RSS Platform Events

The Microsoft Windows RSS Platform includes a rich eventing subsystem that developers can use to listen for and respond to feed and folder events.
Although the below places emphasis on the early-bound interfaces (IXFeed*), the event methods apply equally to the Component Object Model (COM) automation interfaces (IFeed*).

Registering for Events
Applications can register for events on folders and on feeds. The event sink interfaces are IXFeedFolderEvents (or IFeedFolderEvents) and IXFeedEvents (or IFeedEvents). The application must implement these interfaces.
IXFeedFolderEvents defines event methods for folders and subfolders (add, delete, rename, move, and so on) as well as event methods for feeds that belong to the folder or subfolders.
IXFeedEvents contains just the event methods for a particular feed.
To register for events, an application calls the IXFeedFolder.GetWatcher method on a folder or feed, specifying the scope and mask. The interface returned by GetWatcher is an IConnectionPointContainer which is the standard COM interface to register for events. In short, an application uses the IConnectionPointContainer to register its implementation of the event sink interface (IConnectionPoint). The eventing subsystem will then call back on the connection point. For more details, see Architecture of Connectable Objects.
Note that not all event sink methods will be called if they do not fall within the specified scope.

Scope and Mask
When registering for events on a folder, the application can specify a value from the FEEDS_EVENTS_SCOPE enumeration that indicates which of the events will be fired. It is possible to raise events for a single folder and its feeds only, or for the entire Common Feed List hierarchy recursively.

FES_SELF_ONLY:Raise events for this folder and its feeds.
FES_SELF_AND_CHILDREN_ONLY:Raise events for this folder and its feeds, and for its direct subfolders and their feeds.
FES_ALL:Raise events for this folder and its feeds, and all subfolders recursively and their feeds.

To limit which events are raised, applications can specify the FEEDS_EVENTS_MASK. This mask determines which events will be raised by the Windows RSS Platform.

FEM_FOLDEREVENTS:Raise folder events only (added, deleted, renamed, moved).
FEM_FEEDEVENTS:Raise feed events only (added, deleted, renamed, moved).

The following conceptual example, written in C++, demonstrates how to subscribe to the folder events for the entire Common Feed List hierarchy.
Note To receive the events for a single feed only, use the IConnectionPointContainer returned by IXFeed.GetWatcher and register your IXFeedEvents interface, rather than IXFeedFolderEvents interface as shown in the example.

IXFeedsManager* pfm;
HRESULT hr = CoCreateInstance(CLSID_FeedsManager,
NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pfm));
if (SUCCEEDED(hr))
{
// Get the root folder
IXFeedFolder* pff;
hr = pfm->RootFolder(IID_PPV_ARGS(&pff));
if (SUCCEEDED(hr))
{
// Get the ConnectionPointContainer
IConnectionPointContainer* pcpc;
hr = pff->GetWatcher(FES_ALL,
FEM_FOLDEREVENTS FEM_FEEDEVENTS,
IID_PPV_ARGS(&pcpc));
if (SUCCEEDED(hr))
{
// Get the ConnectionPoint
IConnectionPoint* pcp;
hr = pcpc->FindConnectionPoint(
__uuidof(IXFeedFolderEvents), &pcp);
if (SUCCEEDED(hr))
{
// Get COM class that implements the event callbacks
IXFeedFolderEvents* pffe;
pffe = static_cast(this);

// Register the callback event sink implementation
DWORD dwAdviseCookie = 0;
hr = pcp->Advise(pffe, &dwAdviseCookie);

// Release interfaces
pcp->Release();
}
pcpc->Release();
}
pff->Release();
}
pfm->Release();
}

For users of C#, the process of subscribing to the event sink is greatly simplified. The following example subscribes to the FeedItemCountChanged event with two lines of code.

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Declaration of FeedList objects
FeedsManager fm = new FeedsManager();
IFeedFolder rootFolder = (IFeedFolder)fm.RootFolder;
IFeedFolderEvents_Event fw;

fw = (IFeedFolderEvents_Event)rootFolder.GetWatcher(
FEEDS_EVENTS_SCOPE.FES_ALL,
FEEDS_EVENTS_MASK.FEM_FEEDEVENTS);

fw.FeedItemCountChanged += new
IFeedFolderEvents_FeedItemCountChangedEventHandler(fw_FeedItemCountChanged);

// Enumerate the feed list
DisplayFeeds();
}
void fw_FeedItemCountChanged(string bstrPath, int lItemCount, int lUnreadItemCount)
{
MessageBox.Show("Hmmm... Looks like a Refresh is needed...");

// Refresh the feed list
DisplayFeeds();
}

...

4 comments:

Term Papers said...

I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

Anonymous said...

medco pharmacy in alabama http://drugstore4.com/de/category/krebs.html snyders pharmacy [url=http://drugstore4.com/product/flonase.html]flonase[/url]
mallatt pharmacy http://drugstore4.com/fr/product/amaryl.html south dakota state pharmacy essay [url=http://drugstore4.com/de/product/imatinib.html]reprocicating florida pharmacy[/url]
pharmacy in life science http://drugstore4.com/fr/category/sante-de-femmes.html east tao herb pharmacy santa fe [url=http://drugstore4.com/fr/product/tricor.html]tricor[/url]
pharmacy technician home study program http://drugstore4.com/fr/product/actos.html fort meyers pharmacy [url=http://drugstore4.com/category/other.html?page=1]geneva woods pharmacy[/url]

Anonymous said...

time travel research organization http://kumus.eu/house/julianna-lean-to-green-house arbonne travel size products [url=http://kumus.eu/kitchens/soup-kitchens-in-suffolk-county]soup kitchens in suffolk county[/url]
concord travel agency http://kumus.eu/kitchen/kitchen-portable-chopping-boards travel sport and boat show [url=http://kumus.eu/kitchen/cost-of-kitchen-remodel]executive travel consultatnts[/url]
zagat travel guide http://kumus.eu/room/sizing-room-heaters travel magnet toys [url=http://kumus.eu/bathroom/cool-bathroom-sinks]cool bathroom sinks[/url]
travel bureaus in maine http://kumus.eu/siding/hardwood-lap-siding-at-home-depot kuoni travel agency [url=http://kumus.eu/decor/chinese-decor]ashville nc travel[/url]
grand travel station http://kumus.eu/floor/how-to-shine-your-vynil-floor spain travel safety [url=http://kumus.eu/moving/moving-company-baton-rouge]moving company baton rouge[/url]
thomas cook travel agencies http://kumus.eu/decoration/witches-that-hit-tree-halloween-decoration canada travel guide orlando hotel [url=http://kumus.eu/decorations/magazines-that-sell-home-decorations]discount travel online travel agency cheap airfare[/url]

Anonymous said...

travel lodge squamish http://icej.eu/storage/hanging-knife-storage colorado travel trailer 31rl m5 [url=http://icej.eu/house/what-to-call-rooms-in-your-house]what to call rooms in your house[/url]
manufacturers of travel trailers http://icej.eu/house/cottage-boat-house-plans travel guatamala [url=http://icej.eu/lawn-care/lawn-care-business-for-sale]govenment travel card services[/url]
printable travel brochures for france http://icej.eu/bathrooms/bathrooms-storage-australia baby trend travel system reviews [url=http://icej.eu/window/how-can-i-hang-curtains-in-a-corner-window]how can i hang curtains in a corner window[/url]
travel discounts british airways http://icej.eu/concrete/concrete-world-las-vegas travel to canada airline regulations [url=http://icej.eu/landscaping/gorgeous-grounds-landscaping]dreams travel trailer 35 ft[/url]
edinburgh england travel agency http://icej.eu/window/rebuilt-auto-window-parts-company-in-arizona travel easels pastel [url=http://icej.eu/paving/clc-paving-company]clc paving company[/url]
bca travel http://icej.eu/window/print-screen-and-just-window travel injections warrington [url=http://icej.eu/floor/my-rabbit-pees-on-the-floor]yha travel[/url]