RSS Feed Reader Sample Code

Started by Deana, June 13, 2013, 10:11:50 AM

Previous topic - Next topic

Deana

Code (winbatch) Select

;***************************************************************************
;**   RSS Feed Reader
;**
;** Purpose: Read an RSS feed using dotNet. Displays full summary of the selected Rss Feed in a message
;** Inputs:  URL of RSS feed
;** Outputs: Results in a Reportview / Message
;** Reference:
;**       REQUIRES WinBatch 2013A or newer and dotNet 2.0 or newer
;**
;** Developer: Deana Falk 2013.06.13
;***************************************************************************
If Version( )< '2013A'
   Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
   Exit
EndIf
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Prompt for input
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rssfeed = 'http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml'
maxfeed = 128 ; Maximum nuber of syndication items to display

; Create an array to store the results
arrRssFeed = ArrDimension(maxfeed,2) ;Columns: Title,Summary
arrRssFeed[0,0] = 'Title'
arrRssFeed[0,1] = 'Summary'
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Load assemblies into the WinBatch process.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ObjectClrOption( 'use', 'System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35');System.ServiceModel.Web v4.0_4.0.0.0__31bf3856ad364e35
ObjectClrOption( 'use', 'System.ServiceModel.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35') 
ObjectClrOption( 'use', 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Create a class implemented by a managed assembly.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;Create an instance of XmlReader class that reads XML data from a specified URL.
XmlReader = ObjectClrNew( 'System.Xml.XmlReader' )
XmlReader = XmlReader.Create( rssfeed )
; Create an instance of Rss20FeedFormatter class.
Rss20FeedFormatter = ObjectClrNew( 'System.ServiceModel.Syndication.Rss20FeedFormatter' )
; The ReadFrom() method of Rss20FeedFormatter class accepts an XmlReader and reads the XML data.
Rss20FeedFormatter.ReadFrom(XmlReader)
; The XmlReader is closed.
XmlReader.Close()
; The Feed property of Rss20FeedFormatter class is of type SyndicationFeed and represents the feed being read.
; The Title and Copyright properties of SyndicationFeed class return title and copyright mesage of the current feed respectively.
Title = Rss20FeedFormatter.Feed.Title.Text
Title = Title : ' [ ' : Rss20FeedFormatter.Feed.Copyright.Text : ' ]'
; The Items property of the SyndicationFeed class returns a collection of SyndicationItem objects representing feed items. 
SyndicationItems  = Rss20FeedFormatter.Feed.Items
row = 1
ForEach Item in SyndicationItems
   arrRssFeed[row,0] = Item.Title.Text   ; Title
   arrRssFeed[row,1] = StrSub( Item.Summary.Text, 1, 2048 )  ; Summary   
   row = row + 1
Next

MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`RSS Feed Reader Sample`
MyDialogX=002
MyDialogY=059
MyDialogWidth=766
MyDialogHeight=353
MyDialogNumControls=005
MyDialogProcedure=`DEFAULT`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`257,331,122,012,PUSHBUTTON,"PushButton_Display",DEFAULT,"Display Feed Summary",1,10,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`391,331,070,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`015,033,736,290,REPORTVIEW,"ReportView_1",arrRssFeed,DEFAULT,DEFAULT,30,11534336,DEFAULT,DEFAULT,"192|192|192"`
MyDialog004=`015,003,526,012,VARYTEXT,"FeedTitle_1",Title,DEFAULT,DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog005=`015,023,300,008,STATICTEXT,"StaticText_1",DEFAULT,"Select the feed item you would like to display.",DEFAULT,60,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

;Display Full Summary of the selected Rss Feed in a message
feedtitle  = arrRssFeed[0,0]
feedsummary  = arrRssFeed[0,1]
Pause( feedtitle, feedsummary )
Exit


Reference:  http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/dotNet/System_ServiceModel+Read~RSS~Feed.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

Deanna,
What do you suppose this error (attached photo) indicates?
Maybe bad dotnet version? if so, how to upgrade that?
-Kirby
The mind is everything; What you think, you become.

stanl

Kirby;
That key is for .NET 4.0/4.5 - I posted code on the old board to collect the base assemblies into a db table that exist on a PC. In fact these are placed in WB CLROption() code.  You probably have a version of the assembly that will work with Deana's code and just have to replace that line with the version you have.
[EDIT] here is what mine shows on my laptop

Deana

Quote from: kdmoyers on June 14, 2013, 05:01:24 AM
Deanna,
What do you suppose this error (attached photo) indicates?
Maybe bad dotnet version? if so, how to upgrade that?
-Kirby

Kirby,
What version of dotNet do you have installed?

Try going to your start menu and typing 'System.ServiceModel.Web' in the 'search programs and files' field. if you see a folder appear. Right-click and select 'open folder location'. Open that folder and you may see a sub folder that looks something like this: v4.0_4.0.0.0__31bf3856ad364e35 this is the version information need by the ObjectClrOption function.

That code was written on Windows 7 with .NET 4.0 installed. This version of the framework can be downloaded from Microsoft. See: http://www.microsoft.com/en-us/download/details.aspx?id=17851
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

Quote from: stanl on June 14, 2013, 06:37:19 AMYou probably have a version of the assembly that will work with Deana's code and just have to replace that line with the version you have.
Thanks Stan!
I'll try tinkering with that line to see if I can get it to work.
-Kirby
The mind is everything; What you think, you become.

Deana

Try this instead:
Code (winbatch) Select

ObjectClrOption( 'use', 'System.ServiceModel.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

Quote from: Deana on June 14, 2013, 08:26:27 AM
What version of dotNet do you have installed?

Ver 3, but on XP

Quote from: Deana on June 14, 2013, 08:26:27 AM
Try going to your start menu and typing 'System.ServiceModel.Web' in the 'search programs and files' field. if you see a folder appear. Right-click and select 'open folder location'. Open that folder and you may see a sub folder that looks something like this: v4.0_4.0.0.0__31bf3856ad364e35 this is the version information need by the ObjectClrOption function.

I found something similar, for 3.5.0.0 and 31bf3856ad364e35
I tried substituting the numbers in but that didn't work either.

I'll try downloading the 4.0 framework again.  Will report back.
-Kirby
The mind is everything; What you think, you become.

kdmoyers

Quote from: kdmoyers on June 14, 2013, 09:05:45 AM
I'll try downloading the 4.0 framework again.  Will report back.
That worked! Thanks for the help guys!
-Kirby
The mind is everything; What you think, you become.

Deana

Quote from: kdmoyers on June 14, 2013, 09:18:15 AM
Quote from: kdmoyers on June 14, 2013, 09:05:45 AM
I'll try downloading the 4.0 framework again.  Will report back.
That worked! Thanks for the help guys!
-Kirby

Turns out this functionality is supported back to dotNet 2.0. I modified the original code to use this minimum version. See code above.
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

Quote from: Deana on June 14, 2013, 09:32:02 AMTurns out this functionality is supported back to dotNet 2.0. I modified the original code to use this minimum version. See code above.
That worked too!
-Kirby
The mind is everything; What you think, you become.