Posted by Brian on February 15, 2010
Previous posts in this series:
- An RSS Dashboard in F#, part four (speech agents)
- An RSS Dashboard in F#, part three (RSS feeds)
Let me quote myself from the introductory entry of this blog series:
That about sums it up. You can see from the colors in the screenshot from part one what I desired, but this requires knowing which links are ‘visited’ and which are not, so I can color each link appropriately. It turns out, this information can be had via unusual means…
Here’s all the code for today, followed by some commentary.
I can serve this document over HTTP GET on localhost with a tiny WCF web service. To describe what I want to serve, I created a tiny MyContract class, with a single Get() method that returns the document as a Stream. I mark up the class with the appropriate WCF attributes. That’s just 6 lines of code in addition to my giant string constant.
The ‘discoverer’ object implements IDisposable so we can be good citizens and clean up when we’re done. This includes releasing the COM objects we created and shutting down the WCF service. I’m ignoring any error code or exceptions that happen here (since I’m only going to Dispose() when the app finishes running).
Here’s some tiny client code that demonstrates how this can be used to find out which links are visited:
let Main() = use disc = new IEVisitedLinksDiscoverer() printfn "%A" (disc.IsUriVisited("http://stackoverflow.com/questions/tagged/f%23")) printfn "%A" (disc.IsUriVisited("http://www.google.com/")) [<System.STAThread>]
which, of course, prints “true” and “false”. I hereby pronounce this code “good enough”!
A great thing about F# is that the .Net platform integration makes it so easy to combine all these various technologies to knock up some code that gets the job done.
We’re almost done! At this point in the blog series, we’ve walked through all the ‘guts’ of the application. The only remaining thing to do is assemble all the pieces and slap a dazzling WPF UI on top of it. App ahoy!