Microsoft-Compatible APIs in Mono 2.4

Microsoft-Compatible APIs in Mono 2.4

Mono is an open source project led by Novell to create a .NET-compatible set of tools that include, among others, a C# compiler and a Common Language Runtime. Mono can be run on Linux, BSD, UNIX, Mac OS X, Solaris, and Windows operating systems.

Mono’s current version is 2.4 (as of March 30). This version provides the core API of the .NET Framework, as well as support for Visual Basic.NET and C# versions 2.0 and (partially) 3.0. LINQ to objects and XML is part of the distribution, but not LINQ to SQL. C# 3.0 is now the default mode of operation for the C# compiler. Windows Forms 2.0 is also now supported.

Implementation of .NET Framework 3.0 is under development under an experimental Mono subproject called “Olive”, but the availability of a Mono framework supporting .NET 3.0 is still not planned yet. In Mono 2.4 release few major milestones have been achieved, specially introducing advanced Microsoft Compatible API’s.

Mono 2.4 and Microsoft-Compatible APIs

In the following sections I will discuss and show you implementation of these APIs.

    * ADO.NET 2.0 API for accessing databases.

    * ASP.NET 2.0 API for developing Web-based applications.

    * Windows.Forms 2.0 API to create desktop applications.

    * System.XML 2.0: An API to manipulate XML documents.

    * System.Core: Provides support for the Language Integrated Query (LINQ).

    * System.Xml.Linq: Provides a LINQ provider for XML.

    * System.Drawing 2.0 API: A portable graphics rendering API.

ADO.NET 2.0 API for Accessing Databases

For accessing database the Mono Framework has Mono.Data.dll assembly. This assembly has all the classes and Data Tools for Mono ADO.NET database connectivity. This is the abstract data provider access within Mono. Mono.Data.dll provides ability for .net 1.0, .net 1.1, .net 2.0, mono 1.0, and mono 1.1. Like ASP.NET application Mono’s web application supports configuration files & following are the components of the configurable sections of a configuration file related with Database connection.

    * ProviderFactory Class is used to create new Connections, Commands, DataAdapters, or Commands. All objects are returned using the provider interfaces such as IDbConnection, IDbCommand, IDbDataAdapter, or IdataParamter.

    * DataTools contains Static methods for doing common tasks like filling a Dataset with the contents of a select statement.

    * ProviderCollection is the List of providers configured in the system. Initially loaded from app.config, but can be modified at run-time.

    * Provider represents a given provider (factory) and holds information needed to create the types.

    * ProviderSectionHandler is used for loading the list of providers from the app.config into a ProviderCollection.

To see an example of a configuration file with a different connection string and provider information, see Listing 1.Here’s an example of C# source code for creating a connection with SQL Server database using Mono:

  IDbConnection conn; String connectionString =	"Factory=System.Data.SqlClient;" +	"Server=speedy;database=pubs;uid=sa"; conn = ProviderFactory.CreateConnection(connectionString);

Here’s a C# sample for creating a dataAdapter and filling a dataset.

IDbConnection conn =ProviderFactory.CreateConnectionFromConfig("testConnectionString");IDbCommand cmd=conn.CreateCommand();cmd.Text="select * from author"; DataSet ds=new DataSet();IDbDataAdapter adapter=ProviderFactory.CreateDataAdapter(cmd);adapter.Fill(ds, "Table1");

Sample C# code for displaying a list of configured ADO.NET providers:

Console.WriteLine("Configured Providers:");foreach (Provider p in ProviderFactory.Providers)	Console.WriteLine(p.Description);

ASP.NET 2.0 API for Developing Web-based Apps

Mono Framework also provides API’s for developing Web Based application like ASP.NET.Mono supports ASP.NET 2.0, ASP.NET AJAX and a handful of 3.5 controls.ASP.NET applications can be executed using Mono, developed mono application supports 3 (three) types of application/web hosing options:

    * For Apache hosting Use mod_mono a module that allows Apache to serve ASP.NET applications.

    * For FastCGI hosting Use the FastCGI if you have a web server that supports the FastCGI protocol for extending the server.

    * XSP is a simple way to get started with Mono hosting, a lightweight and simple web server written in C#. XSP supports SSL and TLS Client Certificates.

Advanced users can also use the HttpListener and the ASP.NET hosting to create their own hosts for ASP.NET applications.

Mono Web Applications can be configured through the web.config file. Additionally, developers can configure Mono-specific ASP.NET settings using the ASP.NET_Settings_Mapping engine. While debugging to obtain line numbers in stack traces & debug the application you need to do two things:

1. Enable Debug code generation in your page. 2. Run Mono with the debug command line option.

You must enable debug code generation in your page using the Debug=”true” in the top of your page, or setting the compilation flag in Web.config (compilation option). Use the –debug command line option to Mono, this is done by setting the MONO_OPTIONS environment variable, For example:

$ MONO_OPTIONS=--debug xsp2Listening on port: 8080 (non-secure)Listening on address: 0.0.0.0Root directory: /tmp/usHit Return to stop the server.

Windows.Forms 2.0 API to Create Desktop Apps

For Graphical User Interface development, Mono has System.Windows.Forms namespace this supports Winforms 1.1 and 2.0. System.Windows.Forms in Mono is implemented using System. Drawing. Mono developers GUI has a designed where developers can design, execute windows form based applications.

Figure 1: Here’s the Mono Graphical User Interface for desktop-based application development.

To start development work the following package and library is required: Mono package and libgdiplus library. Not required for Windows XP.

The following is a C# example of a Form based application.

using System;using System.Drawing;using System.Windows.Forms; public class TestApplication : Form{	static public void Main ()	{		Application.Run (new TestApplication ?());	} 	public TestApplication ?()	{		Button b = new Button ();		b.Text = "Test Application!";		b.Click += new EventHandler (Button_Click);		Controls.Add (b);	} 	private void Button_Click (object sender, EventArgs e)	{		MessageBox.Show ("You have Clicked me!");	}}

LINQ to SQL

Mono Provides System.Data.Linq.dll that supports collaboration of the DbLinq. Mono’s LINQ to SQL is not limited to SQL server. System.Data.Linq.dll can be used to many other database providers by specifying the database provider on the connection string. See the following examples. (This is not a C# sample code; you can treat this code snipped as pseudo code).

     variable db = new DataContext("DbLinqProvider=Sqlite;" +  ???"DbLinqConnectionType=Mono.Data.Sqlite.SqliteConnection, Mono.Data.Sqlite, " +  ???????"Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756; " + ???"Data Source=Northwind.db3");

DbLinqConnectionType can be skipped if you provide your own IDbConnection. See the pseudo code.

 variable conn = new SqliteConnection ( ???"DbLinqProvider=Sqlite;" +  ???"Data Source=Northwind.db3" // Name of the database);var db = new DataContext (conn);

System.XML 2.0: An API to Manipulate XML Documents

System.XML.dll assembly is provides the entire API’s and namespaces for creating, editing and manipulating XML files.XML had DOM (Document Object Model) parser for working with XML. Like ASP.NET Mono also provide following Classes for manipulating XML object.

    * Xml Writer is almost equivalent to XmlTextWriter of Microsoft .NET used for Creating XML documents.

    * The XmlSecureResolver, which is introduced in MS .NET Framework 1.1 is implemented in Mono as well.

    * XmlTextReader, XmlNodeReader and XmlValidatingReader are also implemented in mono.

This is an example of a Reading XML document.

XmlTextReader myreader = new XmlTextReader ("Test.xml"); // XML in my local M/cmyreader.Read ();Console.WriteLine (myreader.NodeType); // What's the type of the Nodemyreader.MoveToContent (); // Move NextConsole.WriteLine (myreader.NodeType); ?// What's the next node typeConsole.WriteLine (myreader.Name); Console.WriteLine (myreader.GetAttribute ("version")); ?// version is name of the attributewhile (!myreader.EOF && myreader.Name != "item") // looping through the XML file	myreader.Read ();myreader.Read while (myreader.NodeType == XmlNodeType.Whitespace) // 4 attributes are there Name,ID,  ???????????????????????????????????????????????????????????????????????????????????//Department & Description	myreader.Read ();Console.WriteLine ("Name : " + myreader.ReadString ());myreader.Read ();myreader.Read (); ?Console.WriteLine ("Id ?: " + reader.ReadString ());myreader.Read (); myreader.Read ();Console.WriteLine ("Department ?: " + myreader.ReadString ());myreader.Read ();myreader.Read (); Console.WriteLine ("Description : " + myreader.ReadString ());

In Monodevelop, developers can also draw graphs using 2 different namespace 1. System.Drawing namespace that is compatible with Microsoft API. For Windows-based Mono, the GDI+ library is included with the operating system, and there is a specific Dll named GDIPLUS.DLL, The C# code that implements System.Drawing is the same for Windows and UNIX platforms. 2. Mono Cairo library (Mono.Cairo.dll) for 2D vector drawing. This assembly exposes Cairo API to managed applications; this is also very close to the OpenGL model.

Conclusion

Mono is a cross platform, open source .NET development framework. It allows developers to build Linux and cross-platform applications with improved developer productivity. Mono’s .NET implementation is based on the ECMA standards for and the Common Language Infrastructure. This open source product is still under constant improvement phase and hopefully the open source and .NET development community will be benefited by this product.

devx-admin

devx-admin

Share the Post:
AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered

AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious repercussions for America’s future. A

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the root causes of service disruptions

Bebop Charging Stations

Check Out The New Bebob Battery Charging Stations

Bebob has introduced new 4- and 8-channel battery charging stations primarily aimed at rental companies, providing a convenient solution for clients with a large quantity of batteries. These wall-mountable and

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a more equitable incorporation of both

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to Russia’s rapid utilization of airborne

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered around improving user experience, streamlining

Price Wars

Inside Hyundai and Kia’s Price Wars

South Korean automakers Hyundai and Kia are cutting the prices on a number of their electric vehicles (EVs) in response to growing price competition within the South Korean market. Many

Solar Frenzy Surprises

Solar Subsidy in Germany Causes Frenzy

In a shocking turn of events, the German national KfW bank was forced to discontinue its home solar power subsidy program for charging electric vehicles (EVs) after just one day,

Electric Spare

Electric Cars Ditch Spare Tires for Efficiency

Ira Newlander from West Los Angeles is thinking about trading in his old Ford Explorer for a contemporary hybrid or electric vehicle. However, he has observed that the majority of

Solar Geoengineering Impacts

Unraveling Solar Geoengineering’s Hidden Impacts

As we continue to face the repercussions of climate change, scientists and experts seek innovative ways to mitigate its impacts. Solar geoengineering (SG), a technique involving the distribution of aerosols

Razer Discount

Unbelievable Razer Blade 17 Discount

On September 24, 2023, it was reported that Razer, a popular brand in the premium gaming laptop industry, is offering an exceptional deal on their Razer Blade 17 model. Typically

Innovation Ignition

New Fintech Innovation Ignites Change

The fintech sector continues to attract substantial interest, as demonstrated by a dedicated fintech stage at a recent event featuring panel discussions and informal conversations with industry professionals. The gathering,

Import Easing

Easing Import Rules for Big Tech

India has chosen to ease its proposed restrictions on imports of laptops, tablets, and other IT hardware, allowing manufacturers like Apple Inc., HP Inc., and Dell Technologies Inc. more time

Semiconductor Stock Plummet

Dramatic Downturn in Semiconductor Stocks Looms

Recent events show that the S&P Semiconductors Select Industry Index seems to be experiencing a downturn, which could result in a decline in semiconductor stocks. Known as a key indicator

Anthropic Investment

Amazon’s Bold Anthropic Investment

On Monday, Amazon announced its plan to invest up to $4 billion in the AI firm Anthropic, acquiring a minority stake in the process. This decision demonstrates Amazon’s commitment to

AI Experts Get Hired

Tech Industry Rehiring Wave: AI Experts Wanted

A few months ago, Big Tech companies were downsizing their workforce, but currently, many are considering rehiring some of these employees, especially in popular fields such as artificial intelligence. The

Lagos Migration

Middle-Class Migration: Undermining Democracy?

As the middle class in Lagos, Nigeria, increasingly migrates to private communities, a PhD scholar from a leading technology institute has been investigating the impact of this development on democratic

AI Software Development

ChatGPT is Now Making Video Games

Pietro Schirano’s foray into using ChatGPT, an AI tool for programming, has opened up new vistas in game and software development. As design lead at business finance firm Brex, Schirano

Llama Codebot

Developers! Here’s Your Chatbot

Meta Platforms has recently unveiled Code Llama, a free chatbot designed to aid developers in crafting coding scripts. This large language model (LLM), developed using Meta’s Llama 2 model, serves

Tech Layoffs

Unraveling the Tech Sector’s Historic Job Losses

Throughout 2023, the tech sector has experienced a record-breaking number of job losses, impacting tens of thousands of workers across various companies, including well-established corporations and emerging startups in areas

Chinese 5G Limitation

Germany Considers Limiting Chinese 5G Tech

A recent report has put forth the possibility that Germany’s Federal Ministry of the Interior and Community may consider limiting the use of Chinese 5G technology by local network providers

Modern Warfare

The Barak Tank is Transforming Modern Warfare

The Barak tank is a groundbreaking addition to the Israeli Defense Forces’ arsenal, significantly enhancing their combat capabilities. This AI-powered military vehicle is expected to transform the way modern warfare

AI Cheating Growth

AI Plagiarism Challenges Shake Academic Integrity

As generative AI technologies like ChatGPT become increasingly prevalent among students and raise concerns about widespread cheating, prominent universities have halted their use of AI detection software, such as Turnitin’s