Silverlight session

A while ago, I went to a Silverlight session. For those who don’t know, Silverlight is a new product from Microsoft. You can compare it with Flash, difference is that the new version let’s you write your code in dotnet 🙂

As they explained it, they told us the Silverlight runtime actually downloads the managed dll (assembly) and runs it. My first impression that I also tried to explain was that in a corporate environment, many firewalls will block exe,dll,… files. So how where they gonna solve this. I got the feeling nobody actually found this important. Am i the only one who finds it strange that my browser will try to download an run dll files ??? If I were Microsoft I would at least rename the extension to sli or something. Maybe you can do this yourself, haven’t looked into detail in the software.

Alleloeja!!

Hey guys,

I have to admit it’s been a while. But here I am again 😀

Today I saw this post on the serverside. And I have only one word for it Alleloeja.

Just look at this piece of code


import com.jinvoke.JInvoke;
import com.jinvoke.NativeImport;

public class Example {
@NativeImport(library="User32")
public static native int MessageBox(int hwnd, String text, String caption, int type);

public static void main(String[] args) {
JInvoke.initialize();
MessageBox(0, "This MessageBox is a native Win32 MessageBox", "Caption", 0);
}
}

Why did it take this long to actually do this?

In C# you could do this right from the start. Well beter late than never probably?

Crystal Reports in VS.NET 2005

For a client I had created a couple of records. Problem was that they another company had developed stuff in Access and I had to integrate with that flat file. The Access file was located on a network share. When I developed it was on my local disk and when I deployed my Typed Dataset objects were updated automatically. The crystal reports however didn’t get updated. After a long time I finally found a solution for setting the database location @ runtime.


CrystalReport1 rep = new CrystalReport1();
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo =rep.Database.Tables[0].LogOnInfo;
ConnectionInfo connectionInfo = new ConnectionInfo ();
connectionInfo = logOnInfo.ConnectionInfo;
connectionInfo.DatabaseName = "Database";
connectionInfo.ServerName = "Server";
connectionInfo.Password = "pwd";
connectionInfo.UserID = "uid";
rep.Database.Tables [0].ApplyLogOnInfo(logOnInfo);

There’s one stupid thing here. I had made my application so that I gave my report as string param. The application that woud look in the application path for that report. This way I could update my reports without redeploying. Unfortunately if you do it like this I didn’t find a way to access the tables of my report. The reportview seems to not give you the actual CrystalReport object when you load it from a string???

Well in in the end it works, that’s all that matters!

Javapolis

I went to javapolis, I have to say, I’m glad I went. I saw a lot of old friends there. Nice to catch up what they had been doing the last couple of years. Someone even called me ‘The enemy’ because I also did dotnet. But hey I like programming and don’t want to be bound to 1 language, why constrain yourself. We as developers are so openminded, why not about the language we do it in then???

I saw some demos of flex2. Well, Adobe / Macromedia have built a nice tool, I really have to admit. I’ll be given it a test drive. I’ll also give openlaslo a go, but according to one of their ‘sales/consultants’. It is not as far yet as flex2. And I’m pro opensource, but I’m not anti closed source. There’s a big difference and if the product is worth it, I’ll pay for it. In the future I will pay for a copy of Visual Studio if I’m the express edition doesn’t furfill my needs. If you do dotnet development on windows I’ve tried sharpdevelop (on linux monodevelop) and for oss development its ok, but If I’m doing work for a client I calculate the hours it takes. Well If I can buy a product that makes me work faster why not?? For doing java development I use eclipse because thats somewhat the standard and I can work very fast in it! So there’s no problem! But for dotnet windows client development the situation is different!

Topreader Desktop Development (2)

This weekend and this evening I did some more TopReader development. I got stuck on the right mouse click popup (context menu) for creating folders,adding feeds, … I asked #gnome and Murray pointed me to the UIManager class. I have to say this is a nifty thing!!

For those out there who (like me) didn’t know about this Factory, it reads an xml file like the following

<ui>
  <popup name="channelpopupmenu" action="channelpopup">
    <menuitem name="MarkRead" action="MarkRead"/>
  </popup>
  <popup name="folderpopupmenu" action="folderpopupmenu">	
    <menuitem name="CreateFolder" action="CreateFolder"/>	
    <menuitem name="AddFeed" action="AddFeed"/>
  </popup>
</ui>

In your code you just do this for initializing it

uim = new UIManager ();
uim.AddUiFromResource("FeedMenu.xml");

And if you want to show a context menu, you intercept the right mouse click event on your widget and do this little piece of code

Menu w = (Menu)uim.GetWidget("ui/channelpopupmenu");
w.Popup();

The widget is retrieved by the tagname or its actual name
As easy as that!!!

Now we take it a step further. During initalisation we do this

uim = new UIManager ();
uim.InsertActionGroup (group, 0);
uim.AddUiFromResource("FeedMenu.xml");

Where the action group represents a group of Action objects (Duh)

ActionEntry[] entries = new ActionEntry[] {
    			new ActionEntry ("MarkRead", Stock.Cut, "MarkRead", null,
                     "MarkRead",
                     new EventHandler (OnMarkRead)),
                new ActionEntry ("CreateFolder", Stock.Cut, "CreateFolder", null,
                     "CreateFolder",
                     new EventHandler (OnCreateFolder)),
                new ActionEntry ("AddFeed", Stock.Cut, "AddFeed", null,
                     "AddFeed",
                     new EventHandler (OnAddFeed))
                   };

I haven’t configured them as you can see, all are the Cut Stock item.
So we linked the selection of the context menu item with the designed EventHandler.

One word: SWEET

What can I do so far with my app, well I can create folders, add feeds, read feeds, mark a whole feed as read. In the backend the feeds get updated automatically. As I mentioned everything is stored in a small sqlite3 database, for 318 items it’s 600 k, not tho much if you ask me. I wonder how much feeds I can archive before I reach the limit of sqlite (thought that was 2 gigs,but not sure)

I’ll keep you posted (offcourse it’s gonna be opensourced, LGPL probably as I like it more than the GPL)

Topreader Desktop Development

The last couple of days I’ve been doing some hacking in Mono/Gtk#. A year ago I created a small patch for liferea, I wanted to create some more patches but the damn thing wouldn’t build on my ubuntu box. I asked the mailinglist but the reaction was that they hadn’t gotten a clue what could be the issue. Now it is a default installed ubuntu box, no special thingies, just apt-get install gnome-devel, that’s it.

So I had 2 options, find out why the hell the autotools was crashing or start writting my own RSS aggregator. Well stupid me chose the second option.

You might ask Why?
Well actually very simple I wanted to do some heavy dutty development to get back into the gtk libraries. As I want to join in on the tinymail development somewhere in the future …
Secondly it had been more than a month that I did any c# development. So I created a simple project in monodevelop, took the 2 defacto standard rss and atom dotnet libraries and started hacking.

Where am I now?
Well I have a TreeView on the left with my rss feeds, I have a TreeView with all the unread items and I display the unread Items in a WebControl (firefox embedded). The feeds that are in my TreeView get checked for updates every 3000 seconds. If you click an unread item it doesn’t get displayed anymore. So basic viewing capabilities are getting there. 🙂
view the screenshot

How?
If I’m not mistakend liferea didn’t use a database, I instead decided to implement it using a sqlite3 database. All the folders,channels and items are stored in it. I have to say I really was amazed by the speed of it.

What’s next?
Well a lot has to be done but what will happen in a few days is the ability to add folders and feeds from the gui.

Long term goal?
Well very simple finally get the rss aggregator I want, all the aggregators I’ve tried all had some nice features but none of them combined the ones I want. The scratch your own itch thingy 🙂

The name?
TopReader
What? TopReader?Wtf? Well since a few weeks I’m self employed and the company name is TopCoders so … 😀

Mono/glade app did the job

A while ago a wrote about a mono app I was busy developing. Well this weekend the event took place where my app was used. And expect one little bug in the app (my fault) it worked very very good! Everyone was pleased with the result.Let me explain a bit about the event. It’s called 6 uren loop van zolder (dutch) in english this would translate to something like 6 hour run of zolder , as you prolly guessed its about a group of people running 6 hours 🙂

So these people run laps around the race track of zolder. One round was 3930 meters, I had designed an application that would let them insert new runners but more importantly it was made to keep track of how many laps a runner did. So we set us up in a little box at the start/finish line. Everytime someone came along they yelled the number of the runner and we had to insert it. Not so difficult you would image, right. Okay but imagin this, those runners sometimes stay in groups of 20 people. And all those 20 people come by you have to insert them, believe me the first couple of rounds it was really speed typing and mistakes were not so easy to fix then because the lack of time. At the end reports had to be generated for every category with the best results frist, bad results last. (if you can say that 50 km is bad 🙂 )

How did I do this, well first off this application had to run for 6 hours and had to be pretty stable so linux was off course my prefered choice of OS 🙂

Now I had to choose what language to do it in. Okay for work I do java, but I like to use other languages as well. I have done some project in dotnet in the past, but not yet on linux using mono. This was the best use case I could imagine. I had already played around with monodevelop in the past, so my choice for IDE was easy too. (I also wanted to try out the new version with the plugin system).

Because I really hate writting DAO layers with their CRUD statements.
(CreateReadUpdateDelete)
I used Nhibernate for doing all the Data Access. I’ve used Hibernate frequently in my java projects and wanted to know how far the dotnet/mono version got. I must say they did a pretty good job, only thin that didn’t work for me was the mapping in custom sql statements. ie. You have an object Runner with a property StartNumber that maps to a column Runner_Id, if you want to use it in a custom sql query, you would have to do something like “from Runner order by Runner_id” and not “from Runner order by StartNumber” as is in the java version and what you expect it to be. But hey maybe I didn’t check it good enough, and I didn’t get the CVS version.

Okay a Little example of a hibernate setup:
the mapping file

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="6urenloop">
	<class name="Categorie" table="categorie">
		<id name="CategorieId" column="categorie_id" type="int">
			<generator class="assigned"/>
		</id>
		<property name="CategorieName" column="categorie_name" type="String"/>
	</class>
</hibernate-mapping>

The Mapped object

// created on 1/25/2006 at 11:53 PM
using System;

public class Categorie
{
	private int _categorieId;
	private String _categorieName;
	
	public int CategorieId
	{
		get{return this._categorieId;}
		set{this._categorieId=value;}
	}
	
	public String CategorieName
	{
		get{return this._categorieName;}
		set{this._categorieName=value;}
	}
}

The Dao

using NHibernate;
using NHibernate.Cfg;
using System;
using System.Collections;
using System.Reflection;

public class CategorieDao{
	private ISessionFactory factory;
	private static CategorieDao _instance;

	private CategorieDao(){
		this._Init();
	}
	
	public static CategorieDao Instance{
		get
		{
			if(_instance==null)
			{
				_instance = new CategorieDao();
			}
			return _instance;
		}
	}
	
	
	private void _Init() {
		factory = HibernateUtil.Instance.Factory;
	}
	
	public Categorie FindById(int id)
	{
		ISession session = factory.OpenSession();
		ITransaction transaction = session.BeginTransaction();
		IQuery query = session.CreateQuery("from Categorie where Categorie_Id = :id");
		query.SetParameter("id",id);
		IList list = query.List();
		Categorie cat = (Categorie)list[0];
		transaction.Commit();
		session.Close();
		return cat;
	}
	
	
	public IList LoadAll()
	{
		ISession session = factory.OpenSession();
		ITransaction transaction = session.BeginTransaction();
		IQuery query = session.CreateQuery("from Categorie order by categorie_name");
		IList list = query.List();
		Console.WriteLine("list size : "+list.Count);
		transaction.Commit();
		session.Close();
		return list;
	}
}

Pretty straight forward right? As backend database I used mysql. I know there are other people running windows who want the results, this way if they setup a mysql on their windows they can import my tables.

I used 4 tables:

  1. Runners
  2. Categories
  3. Laps
  4. Results

The first 2 are obvious, but the laps table is a table with 3 columns

  1. runner_id
  2. max_lap
  3. timestamp

Every time a runner passes our box we would insert his startnumber, in the end we can track every runner his laps. This way if there are any wrong entries you can quickly fix them withou

Another thing that was pretty strange in my eyes was getting the selected value from a TreeView the code goes like this:

TreeModel model;
TreeIter iter;
if(this.CategorieLst.Selection.GetSelected(out model,out iter))
{
	newLoper.Categorie = (int)model.GetValue(iter,0);
}

With my java background it’s not that obvious, even in my dotnet projects I haven’t seen a construct like this. However in the C language it looks normal 🙂 Guess this is result from binding a C object to C# object. But it works, that’s what matters!

I used glade-2 to create the GUI (as is the standard for creating Gtk applications). I used the glade bindings to connect my gui to my code with the simple lines of code:

Glade.XML gxml = new Glade.XML (null, "6urenloop.glade", "window1", null);
gxml.Autoconnect (this);

And giving my widgets the same name as in the glade file,adding the xml attribute [Glade.WidgetAttribute] is all that is needed. Easy isn’t it?

Here you can find some screenhosts
The screen for inserting new runners:

The screen for inserting laps and creating,exporting the results:

I’m going to make some small adjustments, refactor to use english variables and not dutch variables. Have a GUID for every lap to make updating the laps easier. Once that is done I’ll post it on sourceforge and everybody who does something like this can reuse the code base maybe even update it. You can even check it out for Nhibernate, the documentation of NHibernate isn’t quite as good as the java version.

Ps yes I know, the interface is very ugly and not following the Gnome Guidelines, but it works like a sharm.

I lied, sorry!!

Okay, in my last post I said I was going to use one of the discussed design patterns, but because of of the lack of time (short deadline) I didn’t do it, sorry 🙁

Well that said, let me shortly explain. I was asked to develop an application to keep track of some runners. These runners would run a fixed track for a duration of 6 hours. Well I thought this was the perfect occasion to get up to date with gtk(#) and mono. I also did a fresh install of dapper drake (more on that in the near future), and installed almost everything I could find on mono from the ubuntu repositories.

I most say, development went smooth, okay I have to admit, I do know some things about the Gtk Object Model and widgets, so I had a head start. Well its far from finished, but I thought, lets blog about it 😉 And because we all like screenshots, here are some from the development.
Here’s the monodevelop, okay I know its C# and a lot of you guys are gonna throw something at me, but I did 90% of my work in VM enabled programming languages, and I like it. I have to admit the monodevelop IDE is far and I mean far from where VS.NET is, but at least there’s something. I also mailed with one of the developers a year ago and he told me that he was refactoring the whole code base to use the plugin pattern (as almost all tools do these days). The version I installed was already the refactored one, and from the plugin manager I had the option to install some plugins. I wanted to give the Version Control plugin a go, but it just draw a blank panel, hmmm, maybe I’ll check it out later.

As you can see I don’t have much at this time, but the big picture is to have 1 form with 3 tabs. First tab is for doing the CRUD on our runners. The second tab will be tab where the users can enter the number of the runner when he passes and a new record will be inserted with the timestamp to keep track of how many laps the runner has done, and also what time it took him to do all his laps.

The third pannel will be an overview panel where the user can see all the runners with their laptimes, and there will be a print option. Now about the print option, I’m not quite sure yet. I think I’m going to use OpenOffice Calc, build a template and than call that template from my mono app. Then the user can choose whether he wants to print it, send it to an email adres,… Its up to him.

The backend will be implemented using NHibernate, the hibernate buddy but than in mono/dotnet. It should work the same, as hibernate what I’ve used in several java projects already. And no matter what some managers say, it does shorten the development cycle!! And no its not a miracle tool, some things are just better done in plain Sql code.

The db will off course be mysql, what else? (okay, maybe postgre or sqllite)

In the next screenshot you will see my dear old glade-2 tool builder. How else would you build a gnome app, right?!
I hope to have it finished by the end of the weekend, otherwise I’ll be in trouble. After its finished, I’ll put it under the GPL or LGPL license and see if I can get a hold of a sourceforge pass (or maybe even gnome pass), to store it on their CVS.

Mono in rawhide

Finally the day has come, but you already knew this, right?

I for one am 100% behind the mono project. Why, well in my opinion it will open the door to a lot of new developers on the market. Let’s face it, there are a lot of companies who have invested in custom developped applications, these applications are mostly written for the microsoft platform. But a lot of companies are migrating their solutions to newer technologies, be it dotnet or java or …

If the developers were smart enough to just just the default libraries and nog use any com wrappers, it shouldn’t be to difficult to port their new solutions to linux.

Okay, it isn’t as simple as that off course, but it makes it more simple than porting a c# app to ansi C or python. Let me rephrase that, you won’t have to rewrite all your code. Maybe this will persuade some more companies to invest in linux development (mono) because they can still use it on their windows system while they are migrating.

I’m really curious if this is going to make a shift somewhere. I hope so, can’t wait to turn this freaking ms workstation into a gnome desktop!! Be it FC, ubuntu, Novel desktop,… as long as its a linux and if its gnome, even beter!