CsharpGears is Free and Open Source Framework



I use this opportunity to emphasize the fact that the CsharpGears Framework is absolutely Free and Open source, meaning anyone who wants can download the framework and use it for free, or even make changes in the code, but he/she can't claim he/she invented it.
Recently a reader told me he wanted to use my framework but he was interested in making changes in the source code, and then I noticed that I havent put the full version available for download, so I did that immediately.
And anyone who has some kind of trouble using the CsharpGears framework, may feel free to contact me, I will be happy to help. If anyone has a constructive suggestion or wish for next releases, post it as a suggestion.

"There is nothing like a dream to create the future" - Victor Hugo

C# RSS Builder : How to Build Really Simple Syndications



RSS has become quite popular recently, and from developer's point of view, it's a quite common requirement to implement. So I have decided to make an object-oriented approach and write a few classes that might come in handy. You can see the source code below, it is quite simple and straightforward. One note to those who haven't read my previous posts: The retrieval from the database is made by another set of classes called DatabaseEntities. These classes allow me to directly bind C# classes with SQL table columns and return lists of business objects instead of DataTables.
Back to the RSS feed, there are a few things you need to do: first you need RSS items, as by the standard of the RSS XML tags. Then you need to create a logo of the RSS feed. This is optional, but it is a nice way to offer your readers visual connection to your brand. You will also need a Stream object where the feed should be output. It could be any type of stream. For the purposes of this example, I am using a FileStream, but for a real scenario (ASP.NET) you would need to use the Response's output stream. Take a look at the code, and please tell me if it is REALLY SIMPLE :)


C# Logger when Handling Exceptions

Having the Logger configured as in the previous post, it is very easy to use it to log exceptions directly. The ILogger interface provides a method called AppendException() which takes a reference of an Exception object, which will log the stack trace, the message and the targetted site of the exception that was thrown. If you are familiar with my previous post, you can use this class from the CsharpGears framework to log your exceptions out-of-the-box. For instance, in ASP.NET web applications, you could use this logger to trace all the exceptions in the global.asax file when handling the event OnApplicationError or anytime an exception occurs and then redirect the user to a custom error page.

Here is the minimum amount of code to set all that up:

/* Set up configuration for the logger */
            string DbProvider = "System.Data.SqlClient";
            string ConnectionString = "...";

            /* Create the logger */
            ILogger Logger = new DbLogger(DbProvider,ConnectionString);
            Configuration.LogLevel = LogLevel.ERROR;

            try
            {
                /* Generate an exception */
                int generates_exception = 1 / 0;
            }
            catch (Exception ex)
            {
                Logger.AppendException(ex);
            }
            /* Retrieve the messages from today */
            List<LogMessage> TodaysLogContent = Logger.ReadLogByDate(DateTime.Now);

            /* Print the log messages from today */
            foreach (LogMessage message in TodaysLogContent)
            {
                Console.WriteLine(message.Message + " " + message.UserName + " " + message.Date + "\n");
            }

Creating C# Logger with CsharpGears



The Need of Logger for C#
Loggers come in handy when one wishes to trace the execution of his program. These pieces of code make life much easier when it comes to maintaining the application code error free. That is because with logging capabilities, the developer is able to track every time an unusual event occurs. Then it will be easy to determine where the code needs more attention, whether it includes refactoring, bugs or something else.
There are loggers for C#, they are not something new. But what they often lack, is known as ease-of-use. Here could fall Log4Net and other classes that could be found accross the Web. Often, developer needs a simple logger, some code that will get the job done when an exception is thrown. 
Therefore I have decided to write flexible C# classes that will still be extremely simple to use, flexible by design, and will give the developer control of the log level.(Log levels are an important aspect of the loggers, as they give the power to control which events will enter the log, and which will be left out.
The Database Logger in C#
The Logger classes in the CsharpGears Framework are organized in the following way:

Writing Data Access Layer (DAL) and Business Access Layer (BAL) with CsharpGears Framework

Today I am going to show you how to write Data Access Layer (DAL) and Business Access Layer (BAL) using the CsharpGears Framework.
One of the most accepted approaches of the today's application architecture is the 3-tier architecture, or it's general version n-tier architecture. The idea is to separate the logic of the application in separate layers, each of which will be able to communicate in a standardized way with another layer. Most often, the tier that is responsible for displaying the data is called the presentation layer, which is capable of invoking the layer that holds all the business logic - namely the business layer. The business layer, however can either be invoked by the presentation layer and return the results of the execution to it. In certain situations, the business layer will need to access some amount of data in order to perform all the calculations. In that case, the business layer invokes the third layer - data layer. The data layer is responsible for retrieving the sets of data from some source - be it a database or xml file or web service - it can be literally anything.


CsharpGears Framework : Object-Relational Mapping

Reasons for Object-Relational Mapping
Since the rapid development of the relational databases and the acceptance of the Object-Oriented Programming model, a new need rose: to quickly and correctly map the persistance medium model (namely, the SQL tables) to the business objects in some high level programming language (C# for instance). Developers noticed that they invest significant amount of time writing the Data Access Layer (DAL) when starting off a new project, so they started looking for ways to decrease that time and effort. As time went by, several companies started producing software to efficiently map the SQL tables into business classes. Today, numerous of them are fairly famous, such as the NHibernate, SubSonic, Microsoft's Entity Framework, LINQ, etc. You can find more detailed list of ORM software on wikipedia.
Benefits of the ORM


CsharpGears Framework : Using Different SQL Providers

Hello, I am about to present you how easily can you connect different types of databases with the C# Gears Framework. First of all, note that the IDatabase interface implementators do not care to what type of database they are connected to, they only care about the SQL query they need to execute. For example, here is how would you use C# Gears Framework in order to connect MySQL Database with .NET:
Connecting MySQL with C#
Step 1:Download and install the MySQL provider for .NET. Simply go to MySQL's download site and create an account if you already don't have one. The installation is pretty straightforward - there is a MSI installer.
Step 2:Add the MySQL.data.dll to your project. Ordinarily create new project in Visual Studio, go to References, right click on it and choose Add Reference. Then navigate to the path where the installation of the MySQL provider resides, and choose the mentioned dll.
Step 3: Start using the MySQL data provider. Now I will paste the whole code from my Default.aspx.cs file: