Nicholas Clarke

  • rss
  • Home
  • Articles
  • Downloads
  • Contact

FastSharp - Rapid C# Scripting

Nick Clarke | February 17, 2008

Today I had to update a regular expression that I have not touched in two years!

On first look I got the old hhmm where do I start :)

(?<Protocol>\w+):\/\/(?<Subdomain>\w+)\.(?<Domain>\w+)\.(?<tlDomain>[\w.]+)/(?<File>.*)

This matches:

http://subdomain.url.com/Default.aspx

And breaks it into:

Protocol: http
Subdomain: subdomain
Domain: url
tlDomain: com
File: Default.aspx

But the problem starts when you have a - (dash) in the subdomain:

http://a-subdomain.url.com/Default.aspx

This of course fails as I use \w to break up the subdomain string, which just matches alphanumeric characters. All I need to do is to allow - as well as a-zA-Z0-9 (\w).

The final expression was:

(?<Protocol>\w+):\/\/(?<Subdomain>[\w-]+)\.(?<Domain>\w+)\.(?<tlDomain>[\w.]+)/(?<File>.*)

- Change marked in red

Simple change but testing this takes some time as I either have to run my complete application or write a small test program.

Last week Matt Manela on the msdn blog shared a great application that allows you to test C# code without having to even write a class or create a project.

FastSharp is a great tool for testing out some code. It even goes as far as checking for compilation errors.

FastSharp Compile Error

This was caused by me not adding the correct library for the Regex class.

To fix this all I had to do was click settings and then add the using statement.

using System.Text.RegularExpressions;

FastSharp Success

My little code snippet then ran fine and I was able to test and adapt my change very fast.

Great tool be sure to check it out + for more in depth into why and how it was coded see Matt’s post.

Comments
2 Comments »
Categories
Development, Microsoft
Comments rss Comments rss
Trackback Trackback

Web Request from SQL Server via C#

Nick Clarke | January 16, 2008

Yesterday I was trying to think of a way to call a web page via a SQL Agent job and could not find a way to do it.

I could setup a scheduled job on the web server itself and use Windows scheduler to request the page on a set date and time, but all of my other scheduled jobs are within SQL Server, so I thought it would be best to keep them all in one place.

This stumped me until I remembered that its possible to create stored procedures and functions in C# or any other clr language.

In order to create a C# SQL Server function and allow it to connect to a URL I had to do quite a bit of research, so to save you the time I thought I would make a note of the steps I performed:

1 First create a database project in Visual Studio 2005 and then a C# SQL Server function:

using System;
using System.Data;
using System.Net;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
 
public partial class UserDefinedFunctions
{
 [Microsoft.SqlServer.Server.SqlFunction]
 public static SqlString WebRequest(string URL)
  {
 	// Create a request for the URL.
 	System.Net.WebRequest request = System.Net.WebRequest.Create(URL);
 
	// If required by the server, set the credentials.
 	request.Credentials = CredentialCache.DefaultCredentials;
 
	// Get the response.
 	HttpWebResponse response = (HttpWebResponse)request.GetResponse();
 
	// Close open connections
 	response.Close();
 
	// Return the status.
 	return new SqlString("Response: " +
					response.StatusCode +
	 				" - " +
					response.StatusDescription);
  }
};

If you deploy the code to the DB now you will get all kinds of security errors, which I had to work through.

2 These are the steps that I had to perform to allow my function to be successfully deployed to the DB and runnable via SQL:

2.1 Change the Permission level to external in the project properties.

Solution Properties

Note: To be able to deploy the dll to the database you will also have to set the connection string.

For more information on these settings please see the msdn documentation.

2.2 Using SQL Server Management Studio enable CLR within your database:

sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO

CLR integration is required to deploy and run the code above. It can also be enabled using the Surface Area Configuration Tool (SACT).

2.3 Set the database to be trustworthy:

ALTER DATABASE myDatabase
SET trustworthy ON

This tells SQL Server to trust the database. For more info see the msdn documentation.

2.4 Now deploy the CLR function into the database using Visual Studio’s deploy menu option

2.5 That should be everything and you should now be able to run the command below.

SELECT [myDatabase].[dbo].[WebRequest] ('http://--YourDomain--/runthis.aspx')

Hopefully you now get the response from the web request.

This approach works great and allowed me to schedule the running of some .Net code (within a aspx page) that couldn’t be placed in the database itself. As this is a generic web request you can use this approach to request any URL.

Source code for the CLR SQL function:
You will need to set the connection string to be able to deploy the dll.

Comments
No Comments »
Categories
Microsoft, SQL Server
Tags
Microsoft, SQL Server
Comments rss Comments rss
Trackback Trackback

Microsoft running at full steam

Nick Clarke | December 6, 2007

It seems that you can wait ages for something to finally be released by Microsoft. For example I started .Net with Visual Studio 2005 beta only to wish for the RTM version and then SP1. SP1 came along only for me to wish that I had 2008. All of this due to bugs and missing/cut features.

It seems that Microsoft is coming to the end of a massive development cycle as there are lots of projects starting to stick their heads above water (Microsoft Firewall).

These are some that I have noticed including some links:

Silverlight 2.0 - Beta Q1 of 2008
ASP.Net 3.5 Extensions - Public release due
IIS 7.0 – Coming early 2008 with the new version of Windows Server
ASP.Net MVC – Preview any time now with the supported release in the first half of 2008

  • ASP.Net MVC Framework Part 1 - Overview
  • ASP.Net MVC Framework Part 2 - URL Routing
  • ASP.Net MVC Framework Part 3 - Passing ViewData from Controllers to Views

Windows Vista SP1 – Just got RC so RTM will not be too far away
Parallel FX – Preview out now

  • Programming in the Age of Concurrency - Anders Hejlsberg and Joe Duffy: Concurrent Programming with PFX
  • Daniel Moth Parallel Extensions
  • Parallel FX Team Blog

Visual Studio 2008 – Out now for MSDN subscribers with the official release being February.
.Net 3.5 – Out now
.Net Source Code – Coming soon
LINQ – Out now

  • Architecting LINQ to SQL applications, part 1 - Architecture for LINQ to SQL
  • Architecting LINQ to SQL applications, part 2 - What is LINQ?
  • Architecting LINQ to SQL applications, part 3 - DAOs and Repositories
  • Architecting LINQ to SQL applications, part 4 - Dynamic Queries

Volta - Technology preview
Expression Service Packs – Out now
XNA Game development platform – RTM Coming Soon

I’m sure I have missed some, but even so this is quite an impressive list to release at the same time especially when some of these are linked.

All of this makes me wonder what Microsoft is working on that we have not yet heard about. Oh how great it would be if I could to be a fly on their wall. As this is not possible I guess the next best thing is Channel9 :)

So I guess the wait continues. I’m looking forward to the first half of next year.

Comments
No Comments »
Categories
ASP.Net, Development, Microsoft, Visual Studio
Tags
Microsoft, Roadmap
Comments rss Comments rss
Trackback Trackback

Web Comics from MSDN

Nick Clarke | November 8, 2007

While working my way through the MSDN blogs I keep seeing these cool little IT web comics.

This one hit home and made me feel a bit guilty!

David Salaguinto - Dismiss or Snooze

Be sure to keep your eye on the Office Offline blog for more installments.

Comments
1 Comment »
Categories
Microsoft, Personal
Tags
Comics, Microsoft
Comments rss Comments rss
Trackback Trackback

Microsoft hitting back with Google Gears style sync

Nick Clarke | November 5, 2007

Microsoft has been busy developing a Google Gears style offline tool for web sites. Called Microsoft Sync Framework I wonder how well it will perform. It is of course only available for the Windows OS, whereas Google Gears works on also Mac and Linux.

It certainly sounds like it will do a lot out of the box: “The framework provides built-in support for synchronizing relational databases, NTFS/FAT file systems and Simple Sharing Extensions for RSS/ATOM, according to Microsoft”.

It would be nice to think that the big companies could get together and develop one solution that is the best that they can do, making the end user/development experience amazing and not hit and miss. For me CSS sums up pleasure and pain, which could have been avoided by the big players just having a meeting together (I know that’s easier said than done), but this is another story altogether.

Maybe it is me being naive and coming from an Open Source development background.

I do like Google Gears and it is used well in their RSS reader site, so it will be nice to see what is achievable with the soon to be developed offline sites.

For more info on Microsoft’s Sync Framework see ZDNet’s article or you can just jump straight into the developer network.

Comments
No Comments »
Categories
Development, Microsoft
Tags
Google Gears, Microsoft Sync
Comments rss Comments rss
Trackback Trackback

Mix:UK session videos now available

Nick Clarke | October 23, 2007

I was lucky enough to be able to attend the event here in London. It makes a nice change for an event like this to be on my doorstep :)

The event was really good and it is was great to finally put some names to faces. Ian Moulster has posted that the sessions are now available to watch, which is great news as you normally can’t attend them all:

“We recorded most of the sessions at the recent Mix:UK event and have now made them available online for you to view / download.

They’re available at http://www.microsoft.com/uk/mix07/agenda.aspx, and worth a look.

The Scott Guthrie sessions are particularly good, and the Windows Live sessions are some of the best I’ve seen to get you up to speed with the developer capabilities of Windows Live.”

Mix:UK session videos now available

Comments
2 Comments »
Categories
Development, Microsoft
Tags
Mix:UK
Comments rss Comments rss
Trackback Trackback

Vista for only £135,000

Nick Clarke | October 22, 2007

No, Microsoft has not overnight bumped up the price of their OS, but its the price you could pay to show your allegiance to Redmond for a private number plate in the UK.

Vista Number Plate

I searched for MAC and MACOSOX but there was no equivalent :(

While attending some events at Microsoft’s Reading campus I have seen a couple of the Windows Mobile cars driving around covered in stickers, but I think they missed a trick with the number plate:

Microsoft Windows Mobile Mini
image from Jason Langridge

Comments
No Comments »
Categories
Microsoft
Tags
Microsoft, Mini, Number Plate, Vista, Windows Mobile
Comments rss Comments rss
Trackback Trackback

Windows Live Writer and WordPress

Nick Clarke | October 21, 2007

It wasn’t until I read Ryan Boren post about the new beta for WordPress that I realized I had misunderstood what Microsoft’s Live Writer can do. His first bullet point was “Tagging support for Windows Live Writer“!, this was odd as I thought Live writer was just for Microsoft’s Spaces blog site.

I now stand corrected after downloading it and giving it a try. Its quite a cool blogging desktop application that allows you to post to different blog engines. All I had to do was point it to my URL and then it came back after 1 minute with all of the settings/locations and enabled me to start posting.

I did however notice a couple of oddities, the installer looks like it is just waiting for input, it is however just taking a while to install and while it is doing that it offers the change to append additional services to the setup. Not very clear, I even canceled it a couple of times as I could not find the next or finish button.

The other was the fact that there seems to be about 3 visible buttons, menu items or sidebars for the same thing. Check out the screenshot below:

Microsoft Windows Live Writer

I can count:

  • 2 x View
    • Toolbar x 2
  • 2 x Tools
    • Toolbar x 2
  • 3 x Weblog
    • Menu
    • Toolbar
    • Sidebar
  • 4 x Insert
    • Menu
    • ToolBar x 2
    • Sidebar

Not too sure why all of these different links and buttons are needed as they all serve the same purpose.

Comments
No Comments »
Categories
Microsoft, WordPress
Tags
Blogging, Live Writer, Microsoft, WordPress
Comments rss Comments rss
Trackback Trackback

MSDN blogs on steroids

Nick Clarke | October 18, 2007

Not sure if Microsoft has started a new blogging drive but in the past week the msdn blogs have gone crazy. Normally when I check the feed there is approximately 200 to read, which using Google Readers keyboard shortcuts I can zip through quite quick. But not any more:

1000+ MSDN Posts

This is just over the last couple of days! Maybe I now need to rethink about subscribing to all public msdn blogs :( Shame as there is always a good mix of information in there.

Would be great if it was possible to strip out all non-English posts maybe in the feed or via Google Reader.

Comments
No Comments »
Categories
Microsoft, Personal
Tags
Google Reader, MSDN
Comments rss Comments rss
Trackback Trackback

JoeOn.NET : Great article for PHP on the Microsoft platform

Nick Clarke | October 12, 2007

Thinking about starting to develop PHP on windows!?

Well, fear not Joe has collated a great collection of information to get you on your way.

Hopefully the days of hacking PHP into IIS are long gone.

Comments
No Comments »
Categories
Development, Microsoft, PHP
Tags
FastCGI, IIS, PHP, Zend
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Pages

  • Articles
  • Contact
  • Downloads

Categories

  • Adverts (4)
  • Books (2)
  • Business (3)
  • Development (21)
  • Google (4)
  • Microsoft (15)
    • ASP.Net (1)
    • SQL Server (1)
    • Visual Studio (3)
  • Music (3)
  • Personal (16)
  • PHP (2)
  • Software (1)
  • WordPress (3)

Archives

  • February 2008 (3)
  • January 2008 (4)
  • December 2007 (2)
  • November 2007 (13)
  • October 2007 (25)
  • September 2007 (1)

Google Reader Shared Items

    Shared Items
    rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox