Tuesday, September 12, 2006

I should've posted this earlier, but I’ve been running into some health issues lately that precluded me from doing it.

 

I was wrong when I said before that the RSS API (events interface) was not working with VFP; as a matter of fact,  Alan Griver indicated in my previous post that he had it working and was about to do a presentation with it, so to me that was the confirmation of my previous suspicions, i.e., that I was not using the right code.

 

Using the correct events interface invocation “made the trick” to make it work.

 

There is still an outstanding issue that I have to figure out: I get the same error described in previous posts that pops up after I try to download several feeds individually, I have a couple of things in mind that I am going to try.

 

Here’s a sample of the code that will allow you to see on the VFP screen the RSS activity and also record it to a csv file for later review in a table format (for example you could use these 2 lines of code

CREATE TABLE feedslog (Occurred t,EventMess c(150),FeedPath c(200),FeedOldpat c(200),ItemCount n(9),ErrorNo n(9))

APPEND FROM FeedEventsLog.CSV TYPE csv):

 

 

* RSS Events

CLEAR

 

#DEFINE FES_ALL 0

#DEFINE FES_SELF_ONLY 1

#DEFINE FES_SELF_AND_CHILDREN_ONLY  2

#DEFINE FEM_FOLDEREVENTS  0x00000001

#DEFINE FEM_FEEDEVENTS  0x00000002

 

PUBLIC FeedErrors

DIMENSION FeedErrors(13,2)

FeedErrors(1,1)= 0

FeedErrors(1,2)= "OK" 

FeedErrors(2,1)= 1

FeedErrors(2,2)= "DOWNLOAD FAILED" 

FeedErrors(3,1)= 2

FeedErrors(3,2)= "INVALID FEED FORMAT" 

FeedErrors(4,1)= 3

FeedErrors(4,2)= "NORMALIZATION FAILED" 

FeedErrors(5,1)= 4

FeedErrors(5,2)= "PERSISTENCE FAILED" 

FeedErrors(6,1)= 5

FeedErrors(6,2)= "DOWNLOAD BLOCKED" 

FeedErrors(7,1)= 6

FeedErrors(7,2)= "CANCELED" 

FeedErrors(8,1)= 7

FeedErrors(8,2)= "UNSUPPORTED AUTHENTICATION" 

FeedErrors(9,1)= 8

FeedErrors(9,2)= "BACKGROUND DOWNLOAD DISABLED" 

FeedErrors(10,1)= 9

FeedErrors(10,2)= "Feed Does NOT EXIST" 

FeedErrors(11,1)= 10

FeedErrors(11,2)= "UNSUPPORTED MSXML" 

FeedErrors(12,1)= 11

FeedErrors(12,2)= "UNSUPPORTED DTD" 

FeedErrors(13,1)= 12

FeedErrors(13,2)= "DOWNLOAD SIZE LIMIT EXCEEDED" 

 

oFeedMgr = NEWOBJECT("Microsoft.FeedsManager")

oRootFolder = oFeedMgr.RootFolder

oFeeds=oRootFolder.Feeds

 

 

x=NEWOBJECT("myFolderEvents")

 

IF EVENTHANDLER(oRootFolder.GetWatcher(FES_SELF_AND_CHILDREN_ONLY ,FEM_FEEDEVENTS  ),x)

     Wait window nowait  "Feeds Interface Instantiated!"

ELSE

     Wait window nowait  "Feeds Interface Instantiation FAILED!"

ENDIF

 

RETURN

 

DEFINE CLASS myFolderEvents AS session OLEPUBLIC

 

     IMPLEMENTS IFeedFolderEvents IN "c:\windows\system32\msfeeds.dll"

 

     PROCEDURE IFeedFolderEvents_Error() AS VOID;

                    HELPSTRING "Occurs when a feed folder event error occurs."

     * add user code here

                    EventsLogger("Folder Event Error","")

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FolderAdded(Path AS STRING) AS VOID;

                    HELPSTRING "Occurs when a folder or subfolder is added."

     * add user code here

                    EventsLogger("Folder "+PATH+" Added",PATH)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FolderDeleted(Path AS STRING) AS VOID;

                    HELPSTRING "Occurs when a folder or subfolder is removed."

     * add user code here

                    EventsLogger("Folder/subfolder "+PATH+"removed.",PATH)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FolderRenamed(Path AS STRING, oldPath AS STRING) AS VOID;

                    HELPSTRING "Occurs when a folder or subfolder is renamed."

     * add user code here

                    EventsLogger("Folder/subfolder "+oldPath+ " RENAMED to "+PATH,PATH,oldPath)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FolderMovedFrom(Path AS STRING, oldPath AS STRING) AS VOID;

                    HELPSTRING "Occurs when a folder or subfolder is moved from this folder."

     * add user code here

                    EventsLogger("Folder/subfolder MOVED FROM "+oldPath+" to "+PATH,PATH,oldPAth)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FolderMovedTo(Path AS STRING, oldPath AS STRING) AS VOID;

                    HELPSTRING "Occurs when a folder or subfolder is moved to this folder."

     * add user code here

                    EventsLogger("Folder/subfolder "+oldPath+" MOVED TO "+PATH,PATH,oldPAth)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FolderItemCountChanged(Path AS STRING, itemCountType AS Number) AS VOID;

                    HELPSTRING "Occurs when the aggregated item count of a feed folder changes."

     * add user code here

                    EventsLogger("Folder ITEM COUNT for Folder "+PATH+" Changed to "+ALLTRIM(STR(itemCountType)),PATH,,itemCountType)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedAdded(Path AS STRING) AS VOID;

                    HELPSTRING "Occurs when a feed is added to the folder."

     * add user code here

                    EventsLogger("Feed "+PATH+" Added",PATH)

 

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedDeleted(Path AS STRING) AS VOID;

                    HELPSTRING "Occurs when a feed is deleted from the folder."

     * add user code here

                    EventsLogger("Feed "+PATH+" Deleted",PATH)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedRenamed(Path AS STRING, oldPath AS STRING) AS VOID;

                    HELPSTRING "Occurs when a feed is renamed."

     * add user code here

                    EventsLogger("Feed "+PATH+" Renamed",PATH)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedUrlChanged(Path AS STRING) AS VOID;

                    HELPSTRING "Occurs when the URL of a feed is changed."

     * add user code here

                    EventsLogger("Feed "+PATH+" URL Changed",PATH)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedMovedFrom(Path AS STRING, oldPath AS STRING) AS VOID;

                    HELPSTRING "Occurs when a feed is moved from this folder."

     * add user code here

          EventsLogger("Feed MOVED FROM "+oldPath+" TO "+PATH, PATH, oldpath )

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedMovedTo(Path AS STRING, oldPath AS STRING) AS VOID;

                    HELPSTRING "Occurs when a feed is moved to this folder."

     * add user code here

          EventsLogger("Feed MOVED TO "+oldPath+" FROM "+PATH, PATH, oldpath )

 

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedDownloading(Path AS STRING) AS VOID;

                    HELPSTRING "Occurs when a feed starts to download."

     * add user code here

          EventsLogger("Feed Download "+PATH+" STARTS",PATH)

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedDownloadCompleted(Path AS STRING, Error AS VARIANT) AS VOID;

                    HELPSTRING "Occurs when a feed has finished or failed downloading."

     * add user code here

 

          lcErrorMessage=FeedErrors(ASCAN(FeedErrors,Error)+1)

          EventsLogger("Feed "+PATH+" Download "+IIF(error=0,"FINISHED ","FAILED "+lcErrorMessage),PATH,,,Error)

         

     ENDPROC

 

     PROCEDURE IFeedFolderEvents_FeedItemCountChanged(Path AS STRING, itemCountType AS Number) AS VOID;

                    HELPSTRING "Occurs when the item count of a feed changed."

     * add user code here

          EventsLogger("Feed "+PATH+" ITEM COUNT Changed to "+ALLTRIM(STR(itemCountType)),PATH,,itemCountType)

         

     ENDPROC

 

ENDDEFINE

 

 

**********************

PROCEDURE eventslogger

**********************

LPARAMETERS tcEventMEssage, tcPAth,tcOldPath,tnItemCountType, tErr

 

lcLogMessage=TTOC(DATETIME())+[,]+;

                tcEventMEssage+[,]+;

                tcPath+[,]+;

                IIF(VARTYPE(tcOldPath)=[L],[],tcOldPath)+[,]+;

                IIF(VARTYPE(tnItemCountType)=[L],[],ALLTRIM(STR(tnItemCountType)))+[,]+;

                IIF(VARTYPE(tErr)=[L],[],ALLTRIM(STR(tErr)))

 

?lcLogMessage

STRTOFILE(lcLogMessage+CHR(13),"FeedEventsLog.CSV",1)

RETURN .t.

 

 [UPDATED 10-02-06] I've added 2 flash videos of about 3 mins each showing this code working on XP  SP2 and Vista RC1.

 

10/1/2006 5:20:57 AM (Eastern Daylight Time, UTC-04:00)
Hi Juan,

Does the event handling code above work for you with the latest version of MSFeeds? If so, I'd be interested in what version you are using. Instantiation fails every time at this end, even after modifying the IFeedFolderEvents_FeedItemCountChanged method so that the signature matches (wrong number of parameters). I'm curious about this, since using EventHandler would be preferred to the way it is being done now.

Also, my apologies for not posting the modified code from Calvin's blog. I'm not in the habit of holding back, but in this case the work that is being done was for Microsoft and I didn't receive written approval from Milind Lele or Alan Griver, so even with Calvin's prompting I chose not to disclose it.
10/2/2006 9:43:56 AM (Eastern Daylight Time, UTC-04:00)
Hi Craig,

Sorry but I can't disclose that information ;)

Jokes aside, the version of MSFeeds I am using is the latest available to general public, i.e., 7.0.5700.6.
I've added an update footnote on this original post with links to 2 videos of this code working on XP and Vista RC1.

No apologies needed on this end, knowing how generous you are with the code you post on you blog, I sort of had a clue of what was going on, but still I felt that I had to shake the tree a little bit, Alan Griver came to the rescue after all.

Juan
Juan Calcagno
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):