Scanning Electron Microscope Image

This scanning electron microscope image, The Glass Forest by Mario De Stefano, won first place in photography in the International Science and Engineering Visualization Challenge. It shows a community of tiny diatoms – algae characterised by a peculiar glass-like cell wall.

B&B nationalisation is confirmed

I’m glad my mortgage is not with B&B:

Mortgage lender Bradford & Bingley (B&B) is to be nationalised, the government has confirmed.

Under the arrangement, the government will take control of the bank’s £50bn in mortgages and loans. Shares in the company have been suspended.

B&B’s £20bn savings business and branch network will be bought by rival Abbey, which is in turn owned by Spanish banking group Santander.

B&B is the latest bank to fall victim to the crisis in the financial sector.

“Following recent turbulence in global financial markets, Bradford & Bingley has found itself under increasing pressure as investors and lenders lost confidence in its ability to carry on as an independent institution,” said the Treasury.

more from the bbc website : http://news.bbc.co.uk/1/hi/business/7641193.stm

About the name Simon Steed

This is funny as hell, did a search on google for my name and blog and came across a site which promised to tell me all about myself, some of the stuff is pretty cool, things like

  1. Apparently i’m very well envoweled – 40% of the letters are vowels. Of one million first and last names they looked at, 29.7% have a higher vowel make-up.
  2. I like this one, my name spelt backwards is the pretty cool Nomis Deets
  3. Your ‘Numerology’ number is 6. If it wasn’t bulls**t, it would mean that you are responsible, careful, and compassionate. A giver, you are there to support and care for the most vulnerable.

Try it out for yourself – http://www.isthisyour.name

Dotnet Charting

I was looking for some suitable dotnet charting components/code and came across the following three articles.

http://www.c-sharpcorner.com/UploadFile/pseabury/2DCharting11152005052210AM/2DCharting.aspx

http://www.c-sharpcorner.com/UploadFile/steve_hall/drawinglinechart02072007053420AM/drawinglinechart.aspx

http://www.c-sharpcorner.com/UploadFile/jodonnell/ChartingInGDIplus11192005063716AM/ChartingInGDIplus.aspx

Heres a screenshot of the one i’m using:

Exception Handling the nice way

I’ve knocked up a simple project that demonstrates a few things, namely:

  1. Avoiding file locking issues when writing to a logfile using recursion
  2. Dealing with Unhandled Exceptions globally
  3. Writing this data to a local log file

The source code is below, feel free to download and use as you wish. If you make any improvements, please let me know. Credits to Mark bonafe for his original blog post Mark Bonafe’s Blog

ExceptionHandler.cs

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows;
using System;

namespace WindowsFormsApplication1
{

///
/// Handles displaying error messages
///
public class ExceptionHandler
{
///
/// Takes the exception message and displays a meaningful message to the user
///
public static string DisplayMessage(Exception ex)
{

return DisplayMessage(ex, “”);
}

///
/// Takes the exception message and displays a meaningful message to the user
///
/// The exception to display.
/// Current User
//[System.Diagnostics.DebuggerStepThrough()]
public static string DisplayMessage(Exception ex, string userName)
{

StringBuilder sb = new StringBuilder();

if (ex is DBConcurrencyException)
sb.Append(
“Concurrency Error: One or more people have updated this data since your last request.”);
else if (ex is SqlException)
{
sb.Append(
“Database Error: “);
switch (((SqlException)ex).Number)
{

case 547:
sb.Append(
“There is a constraint on the items you tried to modify. Please try again.”);
break;
case 2601:
// Unique Index
sb.Append(“Cannot insert duplicate values into the database.”);
break;
case 2627:
// Unique Constraint
sb.Append(“Cannot insert duplicate values into the database.”);
break;
default:
sb.Append(ex.Message);

break;
}
}

else
{
sb.Append(
“Exception Handler Unexpected Error: “ + ex.Message);
}

// Show Developers extra information about the error
// Line numbers, StackTrace, etc.
{
{

string nl = “nn”;

sb.Append(nl + “Exception Information:” + nl);
sb.Append(
“Message: “ + ex.Message + nl);
sb.Append(
“Source: “ + ex.Source + nl);
sb.Append(
“Stack Trace: “ + ex.StackTrace + nl);

if (ex.InnerException != null)
{
sb.Append(nl +
“Inner Exception Info:” + nl);
sb.Append(
“Message: “ + ex.InnerException.Message + nl);
sb.Append(
“Source: “ + ex.InnerException.Source + nl);
sb.Append(
“Stack Trace: “ + ex.InnerException.StackTrace + nl);
}
}
}

return sb.ToString();
}
}
}

TestExceptionHandler.cs (form)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace WindowsFormsApplication1
{

public class Form1 : Form
{
private LinkLabel linkLabel1;
private Button button1;

public Form1()
{
InitializeComponent();
}
[
STAThread]
static void Main()
{

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(new Form1());
}

private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
WriteExceptionToLogFile(
ExceptionHandler.DisplayMessage(e.Exception));
MessageBox.Show(ExceptionHandler.DisplayMessage(e.Exception));
}

private void InitializeComponent()
{

this.button1 = new System.Windows.Forms.Button();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(100, 12);
this.button1.Name = “button1”;
this.button1.Size = new System.Drawing.Size(75, 40);
this.button1.TabIndex = 1;
this.button1.Text = “Throw Exception”;
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// linkLabel1
//
this.linkLabel1.AutoSize = true;
this.linkLabel1.Location = new System.Drawing.Point(60, 55);
this.linkLabel1.Name = “linkLabel1”;
this.linkLabel1.Size = new System.Drawing.Size(165, 13);
this.linkLabel1.TabIndex = 2;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = “http://simonsteed.wordpress.com”;
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(292, 75);
this.Controls.Add(this.linkLabel1);
this.Controls.Add(this.button1);
this.Name = “Form1”;
this.ResumeLayout(false);
this.PerformLayout();

}

///
/// Uses recursion to check if the passed in filename is already locked by another process
/// it will continue to check to see if lock is released so that the caller can access it
/// It will currently only ever return true if the file is unlocked but never return false.
/// it would be dead easy to add a timer to this to automatically time out after a set period
/// unless you are happy for your app to wait until the process is finished.
///
/// filename to check
/// true or false
private static bool IsFileUsedbyAnotherProcess(string filename)
{

FileStream fs = null;
try
{
fs =
File.Open(filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None);
}

catch (System.IO.IOException exp)
{

string msg = exp.Message;
fs.Close();
fs.Dispose();
IsFileUsedbyAnotherProcess(filename);
// recheck access
}
fs.Close();
fs.Dispose();

return false;
}

private static void WriteExceptionToLogFile(string msg)
{

string LogFile = “log.txt”;
TextWriter tw = null;
try
{
if (!IsFileUsedbyAnotherProcess(LogFile))
{

// create a writer and open the file
tw = new StreamWriter(LogFile, true);

// write a line of text to the file
tw.WriteLine(DateTime.Now + “: ‘” + Environment.MachineName + “‘ – “ + msg);
}
}

catch { }
finally
{
// close the stream
if (tw != null)
{
tw.Close();
tw.Dispose();
}
}
}

private void button1_Click(object sender, EventArgs e)
{

throw new Exception(“Test Exception”);
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.
Process.Start(“http://simonsteed.wordpress.com”);

}
}
}

Erect

Erect

Originally uploaded by SimonAntony.co.uk

I love the serenity of this, it’s so obscure this tower sat in the middle of nowhere – in fact when the tide comes in, it laps at the edge of the green grass, even more surreal

What type of drinker are you?

Apparently the british government have determined that there are nine types of drinker – excerpt from the BBC website:

Drinkers fall into ‘nine groups’
The government believes it has identified nine types of heavy drinker as it launches a new alcohol campaign.
Department of Health research with focus groups found heavy drinkers often fell into one of a number of categories.
These ranged from de-stress and depressed drinkers to people who boozed because of boredom or to bond.
Experts said helping people to understand the reasons for their drinking habits was “very useful”.

THE NINE TYPES OF DRINKER

  • Depressed drinker
  • De-stress drinker
  • Re-bonding drinker
  • Conformist drinker
  • Community drinker
  • Boredom drinker
  • Macho drinker
  • Hedonistic drinker
  • Border dependents

I don’t know about you but I need a drink after reading that lot!

See the full article here Drinkers fall into ‘nine groups’

Get your local machine/computer name in c#

Four ways to get your local network/machine name:

string name = Environment.MachineName;
string name = System.Net.Dns.GetHostName();
string name = System.Windows.Forms.SystemInformation.ComputerName;
string name = System.Environment.GetEnvironmentVariable(“COMPUTERNAME”);