Click here to Skip to main content
15,880,796 members
Articles / Mobile Apps
Article

Building applications with Mono

Rate me:
Please Sign up or sign in to vote.
4.56/5 (20 votes)
6 Nov 20032 min read 94.2K   325   32   6
Developing .NET cross platform applications using mono and IBM DB2

Introduction

MONO is an open source project started in 2001 under the coordination of Ximian, with the purpose of developing an open source, cross platform implementation of the .NET Framework. In this article, I will show the basics of building a distributed application using Mono. The application was written in C# on a RedHat 9 based system. It uses IBM DB2 as a database backend, the SAMPLE database that ships with DB2 and my IBM DB2 open source managed provider (included in the zip attached).

Description

This sample application is divided in 2 conceptual components: a server component accessible using .NET Remoting and a GUI application written in C# with GTK#. I chose to use this GUI toolkit because it is much more flexible and in some points much more mature than Windows.Forms and it has the big advantage of being truly cross platform. It also has the big advantage of having a really easy to use interface designer - GLADE. The interface is saved in XML based files that can be easily imported in the C# code using the Glade.XML class. As a matter of fact, you can even define the events your application will handle and specify the functions handling each event, inside GLADE.

For running on a Windows machine, GTK will need the cygwin environment.

The server component is a data source for the client application. To keep the example simple, it only returns an ArrayList which contains employee related data from the SAMPLE database. The client application will receive this ArrayList and will insert the employee data in a GtkTreeView (a flexible equivalent of more Windows.Forms components, a DataGrid in this particular case).

Building the code

  1. The IBM DB2 Managed Provider

    On Linux with Mono:

     mcs -unsafe -target:library /d:OS_LINUX -r:System.Data.dll 
                            -out:System.Data.Db2Client.dll  *.cs

    On Windows with Mono:

    mcs -unsafe -target:library /d:OS_LINUX -r:System.Data.dll 
                           -out:System.Data.Db2Client.dll  *.cs

    The managed provider can also be used with Microsoft .NET Framework implementation:

    csc -unsafe -target:library /d:OS_LINUX -r:System.Data.dll 
                          -out:System.Data.Db2Client.dll  *.cs
  2. The EmployeeManager component
    mcs -r:System.Data.dll -r:System.Data.Db2Client.dll remotable.cs
  3. The server component:
    mcs -r:System.Runtime.Remoting.dll -r:remotable.dll server.cs
  4. The client component:
    C#
    mcs -target:exe -resource:db2test.glade -r:remotable.dll 
       -r:System.Runtime.Remoting.dll -r:gtk-sharp.dll 
       -r:glade-sharp.dll -out:sample.exe sample.cs

Running the code

  1. Launch the server:
    [db2inst1@linux db2test]$ mono server.exe

    The server must be launched by a user that has DB2 rights.

  2. Launch the client:
    mono sample.exe

    If you encounter any problems running this sample or if you have any questions related to using mono, please don't hesitate to contact me at victor.vatamanescu @ hqsoftware . ro (spaces are used for spam protection).

Happy hacking!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalwindows.forms Pin
codeJuice7-Nov-03 0:55
codeJuice7-Nov-03 0:55 
GeneralRe: windows.forms Pin
Giles7-Nov-03 1:39
Giles7-Nov-03 1:39 
GeneralRe: windows.forms Pin
Member 2611889-Nov-03 4:03
Member 2611889-Nov-03 4:03 
GeneralRe: windows.forms Pin
Dennis Hayes11-Nov-03 8:44
Dennis Hayes11-Nov-03 8:44 
GeneralRe: windows.forms Pin
Leonardo Pessoa5-Apr-05 2:30
Leonardo Pessoa5-Apr-05 2:30 
GeneralRe: windows.forms Pin
Member 6407236-Oct-04 4:48
Member 6407236-Oct-04 4:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.