viewpoint-particle

Author Topic: RSS Feed Reader Sample Code  (Read 10686 times)

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
RSS Feed Reader Sample Code
« on: June 13, 2013, 10:11:50 am »
Code: Winbatch
;***************************************************************************
;**   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

  • Sr. Member
  • ****
  • Posts: 511
Re: RSS Feed Reader Sample Code
« Reply #1 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
The mind is everything; What you think, you become.

stanl

  • Pundit
  • *****
  • Posts: 1816
Re: RSS Feed Reader Sample Code
« Reply #2 on: June 14, 2013, 06:37:19 am »
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

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: RSS Feed Reader Sample Code
« Reply #3 on: June 14, 2013, 08:26:27 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

  • Sr. Member
  • ****
  • Posts: 511
Re: RSS Feed Reader Sample Code
« Reply #4 on: June 14, 2013, 08:37:18 am »
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.
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

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: RSS Feed Reader Sample Code
« Reply #5 on: June 14, 2013, 08:46:55 am »
Try this instead:
Code: Winbatch
ObjectClrOption( 'use', 'System.ServiceModel.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
 
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

  • Sr. Member
  • ****
  • Posts: 511
Re: RSS Feed Reader Sample Code
« Reply #6 on: June 14, 2013, 09:05:45 am »
What version of dotNet do you have installed?

Ver 3, but on XP

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

  • Sr. Member
  • ****
  • Posts: 511
Re: RSS Feed Reader Sample Code
« Reply #7 on: June 14, 2013, 09:18:15 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

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: RSS Feed Reader Sample Code
« Reply #8 on: June 14, 2013, 09:32:02 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

  • Sr. Member
  • ****
  • Posts: 511
Re: RSS Feed Reader Sample Code
« Reply #9 on: June 14, 2013, 10:55:47 am »
Turns 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.