TL;DR:
Code is here: GitHub: RSS Aggregator
Video is embedded down below.
What are we doing?
We’re going to make an RSS Feed Aggregator, complete with parser library, Windows Forms GUI, and even an installer package. This was the first project I ever 100% completed that wasn’t a tutorial somewhere else. It’s not much, but I’m proud of it. And it gave me an excuse to learn how to write an installable application, which was something I had always wondered about. Anyway, this is going to be a 3 part project. The first part is going to be writing the XML parser library. It’s pretty easy really, if you’ve written any kind of code before. If not, that’s ok too. Watch the video, download the code, read this post, and you should be off to the races!
How this is gonna work:
The way I’m going to do these tutorials is a little different than a lot of the ones I’ve seen online. Maybe that will be a good thing? Time will tell I suppose. The blog posts are going to focus on the important parts of the videos and expand upon them. By the way, if you ever want to feel like you don’t have a clue what you’re doing, try making a video about something you think you’re decent at. That crap is hard!
So, to expand on a video, I guess you need the video huh?
And I guess I’ll be nice and give you some code too: GitHub: RSS Aggregator
No, LINQ is not a video game character…
Honestly, this part of the project doesn’t have a ton of code to explain, but there are some things I think need to be explained a little further. I’m much better at writing than I am speaking so let’s give it a written shot.
At roughly 24:00 in the video, I mention LINQ statements.
This is a quote from the above link:
After two decades, the industry has reached a stable point in the evolution of object-oriented (OO) programming technologies. Programmers now take for granted features like classes, objects, and methods. In looking at the current and next generation of technologies, it has become apparent that the next big challenge in programming technology is to reduce the complexity of accessing and integrating information that is not natively defined using OO technology. The two most common sources of non-OO information are relational databases and XML.
So what?
Essentially, what they’ve done is try to create SQL-like statements for your c# code. One of the things that used to hold me back from writing database applications was trying to figure out how to securely interact with a database. I remember having to piece together SQL statements into a string and then pass that string into another function, then that function would connect to the database, and finally run the string as a query on the database. It was a complicated mess really. LINQ is really nice because you can still use SQL-like logic to build your query, but the code is C# (in this case at least) and that feels much more natural.
string title = (from c in doc.Root.Descendants("channel") select c.Element("title").Value).FirstOrDefault();
Let’s break that down a little bit. Obviously, we’re storing data in a variable here. But how are we getting it? In English, that statement says: “From the data in the descendant tags that are called “channel” that exist in the root tag of a document, we want to select the tag that’s called “title” and store the value it holds in the variable.” Pretty nifty really. The c variable is basically just a holder variable that temporarily stores the data returned from the doc.Root.Descendants("channel")
statement. FirstOrDefault()
returns the first occurrence of a tag that might not be the only instance of it in a parent tag. RSS feeds aren’t supposed to have that happen, but you’re working with data that you can’t control so who knows what they might put in there, ya know?
What the heck is a property?
public string Title { get; set; }
Properties are something I had never heard of until I started learning C#. From my Java OOP class in school, I learned that almost everything should be private and the way you access your variables outside of a class should be with public getter and setter functions. Granted, this whole concept is a huge debate topic and my professor may have been a little (read extremely) overzealous about things, but I get where he was coming from. In this case, I have many variables that I’m ok with outside classes modifying, BUT I want to control HOW they can modify them. Rather than declaring separate methods to control how the variables can be modified, you would do this:
private int age; public int Age { get { return this.age; } set { this.age = (value > 0) ? value : 0; } } /// this.Age = 2; Console.WriteLine(this.Age) //returns 2; this.Age = -2; Console.WriteLine(this.Age) //returns 0;
Personally, that feels much better than traditional getters and setters. What do ya think?
Alright, that’s about all I’ve got to say about this one. Let me know what you guys think!
Wonderfullly explained every detail of the program (RSS Agregator) . Just a right place for C# beginner like me. Thank You very much for this Tutorial series.