Friday, 30 October 2009

Remember classes used in a workflow must be marked as Serializable

Silly mistake but I got this error the other day:

Event A on interface type B for instance id C cannot be delivered

This post reminded me to mark classes as serializable.

Thursday, 29 October 2009

It's been a while

I've not used this blog for sometime now. Been busy working to hard. and I've just not had the time to add anything recently.

That's about to change!

Personally I'd like to keep this blog updated at least once a day. The info I'll publish will be about software development, using agile methods, and anything else that I think may be interesting.

Hopefully within a few months this blog may become a useful reference for myself and more importantly to others who find my posts interesting, so please feel free to leave comments.

Until next time...

Tuesday, 24 February 2009

Outlook inbox spamed to many messages

Left log4net smtpappender on when I went on leave for a week. Unfortunately the system went wrong and I now have a couple of GIG's of data being downloaded into my inbox, which through Outlook is incredibly slow.

I set-up a rule to move the problem messages into deleted items, and I've also changed the "Connected to Microsoft Exchange" to only download headers. This seems to have sped up the influx of messages into my inbox, so that I can eventually delete them.

Very frustrating. Not sure if there is any other way to stop Outlook from downloading to much data. Any comments would be appreciated.

Monday, 8 December 2008

Free subversion hosting

Found this cool website that allows you host up to 5 svn repositories, and supports xp agile project management.

The site is http://www.xp-dev.com

Thursday, 27 November 2008

Convert XML to a DataSet and visa versa in C#

Simple... but for my own reference:

/// 
/// Convert the xml string into a DataSet object
/// 
/// The xml string to convert
/// The DataSet instance
public DataSet ConvertXmlToDataSet(string xml)
{
using (StringReader reader = new StringReader(xml))
{
using (XmlTextReader xmlReader = new XmlTextReader(reader))
{
DataSet dataSet = new DataSet();
dataSet.ReadXml(xmlReader);
return dataSet;
}
}
}

/// 
/// Converts a DataSet into an xml string representation
/// 
/// The DataSet to convert
/// The xml string representation of the DataSet
public string ConvertDataSetToXml(DataSet dataSet)
{
using (StringWriter writer = new StringWriter())
{
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(writer))
{
dataSet.WriteXml(xmlTextWriter);
return writer.ToString();
}
}
}

Friday, 7 November 2008

JQuery and ASP.NET Ajax ready and pageLoad Solution

I had a problem the other day with the JQuery ready function not firing on an Aspc post back. I found this useful article

The problem seems to be that the jQuery ready function is not called on an async postback. The pageLoad() ASP.NET ajax method is called however.

It seems that ASP.NET ajax and jQuery don’t get along together when it comes to the DOM load event, and ASP.NET ajax takes preference to the jQuery ready function.

So in short replace all jQuery: $(document).ready() instances in your code with function pageLoad(). This I think is a more elegant solution then intercepting the end_request event and altering the master page.

Wednesday, 5 November 2008

Generic function to obtain data from a DataRow

Sometimes it may be useful to have one generic function that can parse data from a DataRow column into the type you require.

For example: Perhaps you have an Employee object with the properties Id, Name and Salary, of types int, string and decimal.

Here is an example of some code to populate a list of Employee objects using a generic function.

public void LoadData()
{
IList employees = new List();
DataTable result = // Get data from SP
foreach (DataRow row in result.Rows)
{
Employee employee = new Employee();
employee.Id = GetColumnData<int>("EMP_ID", row, null);
employee.Name = GetColumnData<string>("EMP_NAME", row, "Unknown");
employee.Salary = GetColumnData<decimal>("EMP_SALARY", row, null);
employees.Add(employee);
}
}

/// 
/// Gets data from a column checks it can convert it correctly if no data or invalid casting the default
/// value is returned
/// 
/// The type of data to convert too
/// The name of the column in the row
/// The row containing the data
/// The default value
/// The data or the default value
public static T GetColumnData<T>(string columnName, DataRow row, object defaultValue)
{
if (row.Table.Columns.Contains(columnName) && row[columnName] != DBNull.Value)
{
string value = row[columnName].ToString();
TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
object result = converter.ConvertFromString(value);
try
{
return (T)result;
}
catch (InvalidCastException)
{
return (T)defaultValue;
}
}
else
{
return (T)defaultValue;
}
}