25+ Podcast sources for your ears

Posted October 28th, 2010 in Development, Resources by Sam Beauvois

A free and easy source for information.

Podcasts are easy to find, you can sometimes listen to them online or you simply download them and listen later.

Put them on your “walkman” when you go out for a walk or when you take the public transports, at work when you are in an environment with multiple noise sources (it reduce them to a single source), when you are in a meeting for which you have no interest , or even in a family meal while your stepmother is talking about her last haircut.

You can also take it in your car when driving work or to home. It’s the option I take because I spend 4 hours a day in the car. I simply copy them on an usb stick and plug it to the radio. (you can also burn it on a cd, depends of your car radio system).

Do it your way !

Podcasts are a great idea, they allow you to listen to a show you missed, to be informed of the latest buzz and so on.

Listening to posdcasts is a good thing because even if you aren’t really attentive to what is said, your subconscient is smart enough to make you listen at important parts, so you if you heard of a subject after listening to a relative podcast, you know a little of the subject and you seem less dumb that you are.

Plus, il like me you listen to podcasts in a foreign language, you can significantly improve your knowlege by simply semi-listening to conversations in that language.

Like I early said : Podcasts are cool, so listen to them !

Here is my list of podcasts’s sources for developers : share it and enjoy it !

Use DropBox as version control system for a single person project

Posted October 12th, 2010 in Development, Tools by Sam Beauvois

If you are a single person working on a personal project, you maybe have encountered some backup and versioning issues.

Let’s examine a few solutions…

Manual backups

So you can do manual backups, naming them by date or by functionality and saving them on different supports but this can quickly become a real hell to maintain.

manual_backups_zoom

SVN

You can also us a svn tool, which is really nice : backups are usually on a remote server but you have to remind to do a “sumbit” when you want your sources to be saved.

subversion

There are some really good and free svn hosting (such as xpdev.com) but usually with annoying advertisements and limitations. Furthermore, for a single person project, it’s maybe be taking the bazooka to kill the fly…

Other source control solutions

There are plenty other solutions like git, cvs, or Microsoft team server but once again it’s maybe unneccesary for a single person project.

My current solution

The solution I use for my personal projects is “DropBox”.

dropbox

What is DropBox ?

Here is the description on the website

Dropbox is software that syncs your files online and across your computers.

Put your files into your Dropbox on one computer, and they’ll be instantly available on any of your other computers that also have Dropbox installed (Windows, Mac, and Linux too!). Because copies of your files are stored on Dropbox’s secure servers, you can also access them from any computer or mobile device using the Dropbox website.

How to use it like I do ?

First register at DropBox then install it.

Create your project directory

Put your project files there.

That’s it !

Now you have an automatic backup and versioning system for your files.

Look at the versioning system : it’s great !


Now if you want to develop with other persons, DropBox is certainly not the solution.

You can use it but you will have to be sure that the different persons aren’t working on the same files !

There is no merge system !

If your are about to create a new account, please use this link : I will earn extra storage space.

Dropbox is software that syncs your files online and across your computers.

A few online books

Posted September 3rd, 2010 in Development by Sam Beauvois

There are terrific books you can find on the web for free :

If you have some links, please add them in the comments

Debugging ADO.NET Datatables

Posted May 14th, 2010 in .NET, ADO.NET, Debug, Development by Sam Beauvois

Do you ever had the famous error message :

“Failed to enable constraints. One or more rows  contain values violating non-null, unique, or foreign-key  constraints.”

when using ADO.NET Datasets ?

Tthis is an incredibly useful message isn’t it ?

So what can you do to spare you some headaches ? Retrieve a more useful message sure !

You have to know that a Datatable object have a “HasError” property, this property allows you to know if the datatable has one ore more rows in error.

When HasError is true, you can retrieve the rows havin an error with the DataTable’s “GetErrors()” method wich return an array with all datarow having an error.

The “in errror” rows can inform you about errors with the “RowError” property.

Here is a simple helper class which can be used to debug a single DataTable or an entire DataSet:

using System;
using System.Data;

public class DataSetErrorRevealer
{

   /// <summary>
   /// Get errors on rows of a DataTable
   /// </summary>
   /// <param name="errorDataTable">The DataTable to be checked</param>
   public static void RevealTableErrors(DataTable errorDataTable)
   {
      if (errorDataTable == null)
      {
         Console.WriteLine("The provided DataTable object is null");
         return;
      }

      if (errorDataTable.HasErrors)
      {
         DataRow[] rowsInError = errorDataTable.GetErrors();
         if (rowsInError.Length <= 0)
         {
            Console.WriteLine("There is no problem with table {0}", errorDataTable.TableName);
         }
         else
         {
            foreach (DataRow errorRow in rowsInError)
            {
               Console.WriteLine(errorRow.RowError);
            }
         }
      }
   }

   /// <summary>
   /// Get errors on row for all tables of a DataSet
   /// </summary>
   /// <param name="errorDataSet">The Dataset to be checked</param>
   public static void RevealDataSetErrors(DataSet errorDataSet)
   {
         if (errorDataSet == null)
         {
            Console.WriteLine("The provided DataSet is null");
            return;
         }

         foreach (DataTable errorTable in errorDataSet.Tables)
         {
            RevealTableErrors(errorTable);
         }
      }
   }

Use it this way :


   TestDataSet dataset = new TestDataSet();
   try
   {
      using (SqlConnection sqlCon = new SqlConnection("MyConnectionString"))
      {
         SqlCommand sqlComm = sqlCon.CreateCommand();
         sqlComm.CommandType = CommandType.StoredProcedure;
         sqlComm.CommandText = "Select Stored procedure";
         SqlDataAdapter sqlDa = new SqlDataAdapter(sqlComm);
         sqlDa.Fill(dataset);
      }
   }
   catch (Exception ex)
   {
   // Will provide the error message :
   // "Failed to enable constraints. One or more rows
   // contain values violating non-null, unique,
   // or foreign-key  constraints."
   Console.WriteLine("Error : {0}", ex);

   // will provide a more helpful message
   DataSetErrorRevealer.RevealDataSetErrors(dataset);
   }

If you prefer, you can use an extension method :


using System.Data;
using System;

public static class DataSetExtensions
{
   public static void RevealErrors(this DataSet errorDataSet)
   {
      if (errorDataSet == null)
      {
         Console.WriteLine("The provided DataSet is null");
         return;
      }

      foreach (DataTable errorTable in errorDataSet.Tables)
      {
         errorTable.RevealErrors();
      }
   }

   public static void RevealErrors(this DataTable errorDataTable)
   {
      if (errorDataTable == null)
      {
         Console.WriteLine("The provided DataTable object is null");
         return;
      }

      if (errorDataTable.HasErrors)
      {
         DataRow[] rowsInError = errorDataTable.GetErrors();
         if (rowsInError.Length <= 0)
         {
            Console.WriteLine("There is no problem with table {0}", errorDataTable.TableName);
         }
         else
         {
            foreach (DataRow errorRow in rowsInError)
            {
               Console.WriteLine(errorRow.RowError);
            }
         }
      }
   }
}

use :


catch (Exception ex)
{
   // will provide an helpful message
   dataset.RevealErrors();
}

Hope this helps !

using System;
using System.Data;public class DataSetErrorRevealer
{

/// <summary>
/// Get errors on rows of a DataTable
/// </summary>
/// <param name=”errorDataTable”>The DataTable to be checked</param>
public static void RevealTableErrors(DataTable errorDataTable)
{
if (errorDataTable == null)
{
Console.WriteLine(“The provided DataTable object is null”);
return;
}

if (errorDataTable.HasErrors)
{
DataRow[] rowsInError = errorDataTable.GetErrors();
if (rowsInError.Length <= 0)
{
Console.WriteLine(“There is no problem with table {0}”, errorDataTable.TableName);
}
else
{
foreach (DataRow errorRow in rowsInError)
{
Console.WriteLine(errorRow.RowError);
}
}
}
}

/// <summary>
/// Get errors on row for all tables of a DataSet
/// </summary>
/// <param name=”errorDataSet”>The Dataset to be checked</param>
public static void RevealDataSetErrors(DataSet errorDataSet)
{
if (errorDataSet == null)
{
Console.WriteLine(“The provided DataSet is null”);
return;
}

foreach (DataTable errorTable in errorDataSet.Tables)
{
RevealTableErrors(errorTable);
}
}
}

Use ASP.NET Validators with the SharePoint:DateTimeControl

Posted March 15th, 2010 in ASP.NET, Development, Sharepoint by Sam Beauvois

If you want to use asp.net validation system with the SharePoint’s DateTimeControl, the first thing you need to know is that this control is “just” a wrapper around simple ASP.NET controls (textbox, dropdownlist).

If you want to set the ControlToValidate property of an ASP.NET validator to the DateTimeControl’s ID, it will throw an error!
As you can guess, you have to target the controls inside the DateTimeControl.

Since the DateTimeControl set the name of the controls programmatically, you can retrieve the id of the control:

  • Textbox date: DateTimeControl.ID +”Date”
  • Dropdownlist hours: DateTimeControl.ID +”DateHours”
  • Dropdownlist minutes: DateTimeControl.ID +”DateMinutes”

Example:

If you use the SharePoint:DateTimeControl with the TimeOnly property set to “true”


<SharePoint:DateTimeControl runat="server" ID="TheTime" TimeOnly="true"/>

You’ll have two dropdownlists, one for the hours and one for the minutes
The DateTimeControl set the name:

Dropdownlist hours: DateTimeControl.ID +”DateHours”

Html will be:

<select name="ctl00$PlaceHolderMain$ctl07$ctl02$TheTime$TheTimeDateHours" id="ctl00_PlaceHolderMain_ctl07_ctl02_TheTime_TheTimeDateHours" dir="ltr">
 <option value="00:">00:</option>
 <option value="01:">01:</option>
 <option value="02:">02:</option>
 <option value="03:">03:</option>
 <option value="04:">04:</option>
 <option value="05:">05:</option>
 <option value="06:">06:</option>
 <option value="07:">07:</option>
 <option value="08:">08:</option>
 <option value="09:">09:</option>
 <option value="10:">10:</option>
 <option value="11:">11:</option>
 <option value="12:">12:</option>
 <option value="13:">13:</option>
 <option value="14:">14:</option>
 <option value="15:">15:</option>
 <option value="16:">16:</option>
 <option value="17:">17:</option>
 <option value="18:">18:</option>
 <option value="19:">19:</option>
 <option value="20:">20:</option>
 <option value="21:">21:</option>
 <option value="22:">22:</option>
 <option value="23:">23:</option>
</select>

Dropdownlist minutes: DateTimeControl.ID +”DateMinutes”
Html will be:

<select name="ctl00$PlaceHolderMain$ctl07$ctl02$TheTime$TheTimeDateMinutes" id="ctl00_PlaceHolderMain_ctl07_ctl02_TheTime_TheTimeDateMinutes" dir="ltr">
 <option value="00">00</option>
 <option value="05">05</option>
 <option value="10">10</option>
 <option value="15">15</option>
 <option value="20">20</option>
 <option value="25">25</option>
 <option value="30">30</option>
 <option value="35">35</option>
 <option value="40">40</option>
 <option value="45">45</option>
 <option value="50">50</option>
 <option value="55">55</option>
</select>

So you can retrieve the ASP.NET controls by using :

  • For the date: TheTime$TheTimeDate
  • For the hours: TheTime$TheTimeDateHours
  • For the minutes: TheTime$TheTimeDateMinutes

Real case example:

I have two DateTimeControl, one named TheStartTime and one other named TheEndTime,

I want to validate that the end time is not before the start time.

So I’ll use the ASP.NET comparevalidator validator to compare the hours:

<asp:CompareValidator id="valDate" runat="server" ControlToValidate="TheEndTime$TheEndTimeDateHours" ControlToCompare="TheStartTime$TheStartTimeDateHours"
 Type="Integer"
 Operator="GreaterThanEqual"
 ErrorMessage="The end time must be greater than the start time">
 </asp:CompareValidator >

Now, if you want to validate both hours and minutes, one option is to add an “asp:CustomValidator” and check conditions server side :
Markup:

<asp:CustomValidator runat="server" ID="EndTimeMustBeLaterThanStartTimeCustomValidator"
EnableClientScript="false" ErrorMessage="Start time must be before end time"/>

Before the action, validate:

if (!IsEndTimeLaterThanStartTime())
{
 EndTimeMustBeLaterThanStartTimeCustomValidator.IsValid = false;
 return;
}

Validation method:


private bool IsEndTimeLaterThanStartTime()
{
 // retrieve the DropDownList
 DropDownList startHours = TheStartTime.FindControl("TheStartTimeDateHours") as DropDownList;
 DropDownList endHours = TheEndTime.FindControl("TheEndTimeDateHours") as DropDownList;

 // prevent from errors
 if (startHours == null ||
 endHours == null ||
 string.IsNullOrEmpty(startHours.SelectedValue) ||
 string.IsNullOrEmpty(endHours.SelectedValue))
 {
 return; // dont' do anything
 }

// the hour value is "00:"
 int startHour = Convert.ToInt32(startHours.SelectedValue.Replace(":",""));
 int endHour = Convert.ToInt32(endHours.SelectedValue.Replace(":", ""));
 if (endHour < startHour)
 {
 args.IsValid = false;
 }
 else
 {

 if (endHour == startHour)
 {
 // check the minutes
 DropDownList startMinutes = TheStartTime.FindControl("TheStartTimeDateMinutes") as DropDownList;
 DropDownList endMinutes = TheEndTime.FindControl("TheEndTimeDateMinutes") as DropDownList;
 // prevent from errors
 if (startMinutes == null ||
 endMinutes == null ||
 string.IsNullOrEmpty(startMinutes.SelectedValue) ||
 string.IsNullOrEmpty(endMinutes.SelectedValue))
 {
 return; // dont' do anything
 }

 int startMinute = Convert.ToInt32(startMinutes.SelectedValue);
 int endMinute = Convert.ToInt32(endMinutes.SelectedValue);

 if (endHour <= startMinute)
 args.IsValid = false;

 }
 }

 args.IsValid = true;

 }

You can also validate the Date himself if you choose to display it,
you can make a client side validation if you know javascript,
you can do everything like in “classic” ASP.NET.