Over the last few days, I’ve done some work on .Net download library, the successor to my FileDownloader class. I started working on this project about half a year ago, and had quite some difficulties picking up the thread again after GSoC 2009, since I was in the middle of rewriting the code I was simultaneously translating from MyDownloader, mainly with the handling of the worker threads. The core work has been completed now, meaning that you can use the lib to download files, and track their progress. This is still in experimental stage though, and the pause and resume functionality has not yet been adapted to my new worker implementation.
In any case, the first release, which will be 0.1, is in sight now. This release will cover the basic functionality promised by the library; segmented downloads in the background that you can pause and resume, and can track the progress of (percentage, speed, downloaded bytes, remaining bytes, remaining time, elapsed time). After this, I’m planning to do some big rewrites of things that come from MyDownloader I’m not really happy with. This will mainly be making the whole library more OOP and event based. Only after that I’ll start on the other things I originally scheduled, such as prioritizing downloads and bandwidth limitations. By that time, .Net fw 4.0 will probably be released, and it’s a good possibility I’ll start using post .Net 2.0 technologies then, mainly things found in the Task Parallel Library.
While working on the Download class of the .Net Download Library yesterday, I came across the need to add and retrieve items from a HashTable of a fixed type. After asking at MSDN forums, someone suggested creating for example a StringHashTable, which then contains a number of Shadow methods that ctype a parameter of the type String to Object, and then pass it along to the corresponding native method of the base class. I extended a little on this by creating a general type defined HashTable extension class: TypeHashTable. This class is pretty identical to the String variant, but I added one variable type (see the code below), making it usable for whatever type you need it, without any manual converting. I’m probably not implementing this in the .Net Download library, since the conversion there only requires a one line function, and the philosophy is to keep it as simple and small as possible. Anyway, I’ve put this class on my forums so that anyone can use it. It’s also a neat example of the usage of variable type definitions IMHO
While working on .Net download library, I realized I still didn’t know how to fire events from the background threads onto the main thread (meaning the thread that started the download by calling Start). I posted query on how to do this in vb.net on several forums, and got some helpful responses at MSDN. Apparently, the thing I’ve been searching for is called the Event-based Asynchronous Pattern, which is a general pattern for asynchronous operation’s with events. I have done some familiarization with it by doing the entire walk-through, and I also started implementing it into the Download class. I’ll probably commit my current code this weekend, hopefully with working cross thread events
While translating some of the C# code of MyDownloader to VB.Net for the .Net download library, I’ve already come across quite some awkward code. IMHO, the underneath example could go into the code horrors section of The Code Project.
Why? It uses breaks and returns in the middle of the code, like if C# is some lame generic language without selection structures. The use of the try-catch bloks also seems odd. Also have a look at the condition for the do while loop – lol. The only thing missing are a few GoTo statements, which would have convinced me to print this out and torture fellow geeks with
I started off translating this literally, but got so annoyed by the bad coding practice I decided to attempt to rewrite it. I say ‘attempt’, cause code written like that is not easy to understand, esp for people who are used to ‘decent’ structured code. I splitted the code into 2 subs instead of one, removed all breaks, returns, the insane do while true and put only the required code in try catches.
Today I again did some work on my .Net download library project. I added some stuff to the main class, Download, and also created the base of the DownloadManager class. This class will allow you to work with multiple downloads at once, by putting them in a list, and providing a variety of methods and properties that enable you to gather info or work with all or selections of the downloads.
I’m getting close to actually be able to start debugging the code, something which can take up quite some time with so much untested code.
Today did quite some work on .Net download library, the successor to my current FileDownloader class.
I started off with finishing the protocol provider code (see revision 4), and then went on adding a lot of the still missing stuff to the Download class (see revision 5), which now counts almost 800 lines of code. Most changes I made are pretty much C# to VB.Net translation from MyDownloader, one of the projects I’m basing this library upon. Doing this translating also comes with the challenges of leaving out code that’s not needed (for example a hook system for protocol providers), holding into account all the name changes I’ve made, and at some points revising the logic layout of the code, since I don’t agree with the original design. I also had some great fun with working with SyncLock statements and interfaces.
Although the project is still far from a first release, the basic structure is taking form, and I’m beginning to see where and how future features will need to be added
Now the Google Summer of Code coding period has finished, I can divide my attention between multiple projects again. Since I’ve been doing PHP and JavaScript only for over 2 months now, I’m starting off with taking a PHP-break. This means I won’t do any development of mayor new features for Maps or Semantic Maps, and definitely won’t work on any other PHP project. Of course I’ll still ensure bugs get fixed for my mapping extensions, and help people out with code when needed, but that’s about it. So basically I’m closing my Zend Studio, which has become one of my most used applications in the last months, and starting my Visual Studio again. Now I think of it, this is really awkward. I used to start my VS practically every time I booted my computer for over a year, and then only opened it a handful of times in a 2 month period.
So, what am I going to work on now? One of my last projects before I started GSoC was a VB.Net background file downloader, of which I released an article on The Code Project, and later on created a C# version. I got quite some positive feedback on this project by people, although it was initially created with the sole purpose of helping that needed a simple downloader someone out, to improve my own skills, and to demonstrate how to create a simple to implement downloader. I’m now continuing this project, by rewriting it from scratch, to both add some mayor new features, and mess around with some multi-threading stuff I’ve been wanting to try out for months now.
The mayor new features that will be added are simultaneous downloads (the current classes only support one download at a time), segmented downloads (woot!), download priorities and bandwidth limitation options. This will require a nice OOP approach, with some more advanced multi-threading. I’m basing part of my code on MyDownloader, an extremely nice C# downloader, which has quite some more functionality then what I’m doing. It’s more extensive then required for most people though, and not all that easy to implement. I also don’t really agree with some naming choices, and it lacks both code docs for devs that want to modify it, and devs that want to implement it. So clearly, I’ll put a lot of effort in keeping the new project as small and to-the-point as possible, and pay attention to easy of implementation, and usability. Another obvious difference is that this project is in VB.Net and not C#.Net. This has more advantages then disadvantages IMHO. If the project is compiled to a .dll or is used in a multi-project solution, it simply doesn’t matter what language it uses. A lot of casual programmers don’t know how to handle either, and the majority of these uses VB.Net, and not C#. And the ones that do know C# are more likely to know VB.Net then the other way around.
I’ve created a project on SourceForge to host the code, and be able to commit to the project’s SVN. Since the project now contains multiple classes, I renamed it to .Net DownloadLib.
After that project I’m planing to put some real effort into my mapping extension for MediaWiki again, and possibly to have a look at Python and Ruby. When school starts again, somewhere half way through September, some new project opportunities will probably arise for me, but I guess I’ll see that then. I’m also looking forward to ‘learning to program’ at school, which is destined to give me some great laughs. Luckily for me I’ll have to learn C++ at university, so I won’t be totally bored with it. I hope they don’t drive the low-level aspects of the language to far, since that’s pretty useless in today’s world IMHO.

Categories
Tag Cloud
Blog RSS
Comments RSS

Void « Default
Life
Earth
Wind
Water
Fire
Light 