Archive | Posts RSS feed for this section

C# development with Mono and MonoDevelop

7 May

In the past two years, I have been developing .NET from my MacBook by running Windows XP into VM Ware and more recently into Virtual Box from OS X. This way, I could install Visual Studio and be able to work seamlessly.

But, this way of working has a major down side: it kills the battery of my laptop… I can easiely last for 3 hours if I stay in OS X, but can only last 45 min when XP is running.

Recently, I gave MonoDevelop a try for developing Developer IT‘s tools and web site. While being way less complete then Visual Studio, it provides essentials tools when it comes to developping software. It works well with solutions and projects files created from Visual Studio, it has Intellisence (word completion), it can compile your code and can even target your .NET app to linux or unix. This tools can save me a lot of time and batteries!

Although I could not only work with MonoDevelop, I find it way better than a simple text editor like Smultron. Thanks to Novell, we can now bring Microsoft technology to OS X.

Official BETA release of Developer IT

17 Mar

We finally did it

It’s been a week since our first online publish and our indexer robot is going as well as the website. We already have reach more than 20,000 articles and it’s only the begining.

Stay tune on http://www.developerit.com/

How to get full query string parameters not UrlDecoded

17 Mar

Introduction

While developing Developer IT’s website, we came across a problem when the user search keywords containing special character like the plus ‘+’ char. We found it while looking for C++ in our search engine. The request parameter output in ASP.NET was “c “. I found it strange that it removed the ‘++’ and replaced it with a space…

Analysis

After a bit of Googling and Reflection, it turns out that ASP.NET calls UrlDecode on each parameters retreived by the Request(“item”) method. The Request.Params property is affected by this two since it mashes all QueryString, Forms and other collections into a single one.

Workaround

Finally, I solve the puzzle usign the Request.RawUrl property and parsing it with the same RegEx I use in my url re-writter. The RawUrl not affected by anything. As its name say it, it’s raw.

Published on http://www.developerit.com/

How to obtain a random sub-datatable from another data table

13 Mar

Introduction

In this article, I’ll show how to get a random subset of data from a DataTable. This is useful when you already have queries that are filtered correctly but returns all the rows.

Analysis

I came across this situation when I wanted to display a random tag cloud. I already had the query to get the keywords ordered by number of clicks and I wanted to created a tag cloud. Tags that are the most popular should have more chance to get picked and should be displayed larger than less popular ones.

Implementation

In this code snippet, there is everything you need.
See the full source code here at http://www.developerit.com/2010/03/16/how-to-obtain-a-random-sub-datatable-from-another-data-table

Pro’s

This method is good because it doesn’t require much work to get it work fast. It is a good concept when you are working with small tables, let says less than 100 records.

Con’s

If you have more than 100 records, out of memory exception may occur since we are coping and duplicating rows. I would consider using a stored procedure instead.

Published on http://www.developerit.com/

Remove accents from String .NET

12 Mar

Private Const ACCENT As String = “ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÿÑñÇç”
Private Const SANSACCENT As String = “AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuyNnCc”
Public Shared Function FormatForUrl(ByVal uriBase As String) As String
If String.IsNullOrEmpty(uriBase) Then
Return uriBase
End If

‘// Declaration de variables

Dim chaine As String = uriBase.Trim.Replace(” “, “-“)

chaine = chaine.Replace(” “c, “-“c)

chaine = chaine.Replace(“–“, “-“)

chaine = chaine.Replace(“‘”c, String.Empty)

chaine = chaine.Replace(“?”c, String.Empty)

chaine = chaine.Replace(“#”c, String.Empty)

chaine = chaine.Replace(“:”c, String.Empty)

chaine = chaine.Replace(“;”c, String.Empty)

‘// Conversion des chaines en tableaux de caractŠres

Dim tableauSansAccent As Char() = SANSACCENT.ToCharArray

Dim tableauAccent As Char() = ACCENT.ToCharArray

‘// Pour chaque accent

For i As Integer = 0 To ACCENT.Length – 1

‘ // Remplacement de l’accent par son ‚quivalent sans accent dans la chaŒne de caractŠres

chaine = chaine.Replace(tableauAccent(i).ToString(), tableauSansAccent(i).ToString())

Next

‘// Retour du resultat

Return chaine

End Function


Published at http://www.developerit.com/2010/03/16/remove-accents-from-string-net from http://www.developerit.com/

Good SQL error handling in Strored Procedure

11 Mar

When writing SQL procedures, it is really important to handle errors cautiously. Having that in mind will probably save your efforts, time and money. I have been working with MS-SQL 2000 and MS-SQL 2005 (I have not got the opportunity to work with MS-SQL 2008 yet) for many years now and I want to share with you how I handle errors in T-SQL Stored Procedure. This code has been working for many years now without a hitch.

N.B.: As antoher “best pratice”, I suggest using only ONE level of TRY … CATCH and only ONE level of TRANSACTION encapsulation, as doing otherwise may not be 100% sure.

See the full article and source code at http://www.developerit.com/2010/03/16/good-sql-error-handling-in-strored-procedure

In conclusion, I will just mention that I have been using this code with .NET 2.0 and .NET 3.5 and it works like a charm. The .NET TDS parser throws back a SQLException which is ideal to work with.
Published on http://www.developerit.com/

Fake ISAPI Handler to serve static files with extention that are rewritted by url rewriter

10 Mar

Introduction

I often map html extention to the asp.net dll in order to use url rewritter with .html extentions. Recently, in the new version of www.nouvelair.ca, we renamed all urls to end with .html. This works great, but failed when we used FCK Editor. Static html files would not get serve because we mapped the html extension to the .NET Framework. We can we do to to use .html extension with our rewritter but still want to use IIS behavior with static html files.

Analysis

I thought that this could be resolve with a simple HTTP handler. We would map urls of static files in our rewriter to this handler that would read the static file and serve it, just as IIS would do.

Implementation

This is how I coded the class. Note that this may not be bullet proof. I only tested it once and I am sure that the logic behind IIS is more complicated that this. If you find errors or think of possible improvements, let me know.

See the full source code and article at http://www.developerit.com/2010/03/16/fake-isapi-handler-to-serve-static-files-with-extention-that-are-rewritted-by-url-rewriter

Conclusion

As you see, with our static files map to this handler using query string (ex.: /ISAPIDotNetHandler.ashx?fileUri=index.html) you will have the same behavior as if you ask for the uri /index.html.

Finally, test this only in IIS with the html extension map to aspnet_isapi.dll. Url rewritting will work in Casini (Internal Web Server shipped with Visual Studio) but it’s not the same as with IIS since EVERY request is handle by .NET.

Versions

  1. First release

Published on http://www.developerit.com/