May 2004 Entries
Now there's a post title I never expected to write, anyway, got this in my mail from B3TA - theres lots of wierd stuff on that site, but this movie just rocks! Basically it's squirrels (or tree-rats as the movie calls them)..umm...busking. You can downloads this from here
Sorry, had to add this one too, just a simple story about this guy's flying grandad..oh....and him being savaged by lions...odd that we british lost the empire isn't it :-)
Well, the last episode of Friends is about to start...and just been doing my blog trawl before I shut my laptop for the weekend - for which I just bought a new power adaptor; if you need a laptop adaptor, live in the UK and want the best deal, check out http://www.battery.co.uk/.
Most interesting bits I came across tonight are the Intelligent Message Filter archive manager and a tip to expose the Spam Confidence Level (SCL) - which are pretty invaluable if you're using the Exchange 2003 Intelligent Message filter.
Also read a bit more of the book Paper Prototyping (US) which is really pretty cool - essentially it covers how to define and protoype user interfaces on paper (hence the name :-)) anyway, more useful than it sounds!
So that's it - Friends has started (they're just talking about Ross 'doing it' with Rachael at the moment...)
Really just a wrapper around the really nice native C library, but could be handy when you need to compress stuff in the quickest way possible...here's the
SourceForge homepage
Bit concerned that an old post is being linked from this URL http://msdnprod/library/en-us/dnaspp/html/viewstate.asp?frame=true - especially as
1. The URL of the person doing the linking is a Microsoft one
2. That post REALLY needs updating (and is just such a simple solution)
3. The post isn't even accurate, in it I state that you lose encryption (even if it is the stinky 3DES) using this method - umm...wrong actually you don't just that if you use compression the technique becomes rather ineffectual (since compression and encryption are kind of exclusive - you can't really compress random data...)
Anyway, I may just update that article with a rather more flexible solution - it is an oddly popular post!
Oh, incidentally that post presents a technique to compress ViewState - specifically it uses BZip2 to compress a DataSet Viewstate - BZip2 uses something called the Burrows-Wheeler Transform which makes it one of the most efficient general purpose compression algorithms for XML (as in compactness, it is a bit slow) . Intertesting algorithm actually, it was written by a guy called Julian Seward about 8 years ago and is one of the least encumbered by patents etc...
UPDATE: Should mention, I figured out what this was - probably someone in Microsoft reviewing and checking links on this article - this is just a stunningly good piece on ASP.NET ViewState.
Just noticed this
link in
a post on
Kent Sharkeys blog. The
article by
Scott Mitchell covers various methods of making ASP.NET 1.1 based sites conform to WAI accessibility guidelines (or US Section 508 if you prefer :-)).
It is still stunningly annoying (and frankly unbelievable) that the
ASP.NET Hotfix Rollup is still not easily downloadable - almost a year since it was released, neither have I seen it on the MSDN subscribers download site (although apparently a few CMS 2002 updates actually include it!).
Umm..title says it all,
Larkware link is here,
download link here
Should mention I suppose the I lied in yesterdays post on threading using .NET...mea cupla :-). In that post I mentioned using delegates for multi-threading and said that you always had to use EndInvoke to avoid a memory leak...well not quite, what i actually do is use the excellent AsyncHelper class by Mike Woodring, this supports this syntax:
CalcAndDisplaySumDelegate d = new CalcAndDisplaySumDelegate(someCalc.Add);
AsyncHelper.FireAndForget(d, 2, 3);
No EndInvoke required as it takes care of this using a DynamicInvoke internally. Well, saves a few lines of code!
This is a common puzzler for people new to .NET (who aren't in the US!), just how do you parse a DateTime to be correct for your culture?
Answer, pretty easily...the DateTime.Parse has an overload which accepts an IFormatProvider, so this will let you parse a DateTime in a named culture:
DateTime.Parse("08/02/1973",new CultureInfo("en-GB"));
The above code being the code for GB - you can get a good list by looking at Internet Explorer -> Tools -> Internet Options -> Languages -> Add .
Using the code below will let you use the culture defined in the Globalization settings in web.config
(e.g., <globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB" uiCulture="en-GB"/>):
DateTime.Parse("08/02/1973", System.Globalization.CultureInfo.CurrentCulture);
Told you it was easy!
I found some really interesting articles on the new ASPNETResources.com site, including stuff on Doctypes which was pretty good and tips on getting CSS2 Intellisense support in VS.NET - worth keeping an eye on how this site develops methinks! Also a particularly interesting blog on the site covering similar subjects...
UPDATE: Poking around some more, just noticed they have a really great article on XHTML support using Response Filters in ASP.NET - excellent coverage!
I have a tendency to forget that people don't necessarily know everything (in counselling we called it "contextual framing" - basically aligning your mindset with that of the person you're counselling). With this in mind, here's a simple one which I forgot many prople don't know - how do you call a method asynchronously, e.g., how do you send an email whilst not blocking the thread of an ASP.NET page? Well, .NET makes this REALLY easy to do.
So, you probably know that sending email in ASP.NET is dead easy:
using System;
using System.Web.Mail;
namespace ExtraControls
{
///
/// Summary description for MailSender.
///
public class MailSender
{
public void SendMail(string fromAddress,string toAddress, string subjectLine,string messageText)
{
SmtpMail.Send(fromAddress,toAddress,subjectLine,messageText);
}
}
}
Right, so this sends to localhost, simple email, how do you make this Asynchronous?
using System;
using System.Web.Mail;
namespace ExtraControls
{
///
/// Summary description for MailSender.
///
public class MailSender
{
public void Main(string fromAddress,string toAddress, string subjectLine,string messageText)
{
SendMailDelegate del = new SendMailDelegate(SendMail);
AsyncCallback callback = new AsyncCallback(EndSendMail);
IAsyncResult ar = del.BeginInvoke(fromAddress,toAddress,subjectLine,messageText,callback,null);
}
public void EndSendMail(IAsyncResult ar)
{
SendMailDelegate del = (SendMailDelegate)ar.AsyncState;
try
{
del.EndInvoke(ar);
}
catch
{
//Or handle the exception in here...
throw;
}
}
public delegate void SendMailDelegate(string fromAddress,string toAddress, string subjectLine,string messageText);
public void SendMail(string fromAddress,string toAddress, string subjectLine,string messageText)
{
SmtpMail.Send(fromAddress,toAddress,subjectLine,messageText);
}
}
}
Right, so quite a few things added here - you'll see that there's a delegate called SendMailDelegate - which essentially acts as a method pointer letting you fire the SendMail method on a new thread. The actual 'firing' takes place using the del.BeginInvoke(...) line. The AsyncCallback specified before that line gives us a hook into a method which fires after the SendMail method completes - this is where you can handle errors as I've indicated, it's also where you can call the EndInvoke for the delegate.
Now it strictly isn't necessary to use the EndSendMail method to call the 'EndInvoke' - but it is best practice to avoif potential memory leaks. So that's it, whenever you want to do something asynchronously that's the essential pattern you'll want to use (there are others such as starting new threads etc...but this is the most common).
OK, terribly documented, but it works...this is just the source for a little HttpModule which tracks hits to a .TEXT blog - pretty simple but should give anyone who wants to do it a start. I'll post a more complete version at some point (mainly just want to test how this skin behaves with posted code ;-))
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Dottext.Framework;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using System.Threading;
using System.Net;
using Microsoft.ApplicationBlocks.Data;
namespace ExtraControls
{
///
/// Summary description for ViewTrackModule.
///
public class ViewTrackModule : IHttpModule
{
#region IHttpModule Members
public void Init(HttpApplication context)
{
context.EndRequest += new EventHandler(context_EndRequest);
}
public void Dispose()
{
// TODO: Add ViewTrackModule.Dispose implementation
}
#endregion
///
/// Ok, bit unusual...but I need the BlogConfig object to be available for the DB access...
///
///
///
private void context_EndRequest(object sender, EventArgs e)
{
HttpApplication httpApp = sender as HttpApplication;
System.Uri ur = httpApp.Request.UrlReferrer;
string testHost = string.Empty;
string thisHost = httpApp.Request.ServerVariables["SERVER_NAME"];
if(ur != null)
{
testHost = ur.Host;
}
if(testHost != thisHost)
{
HttpRequest re = httpApp.Request;
LogToDBDel del = new LogToDBDel(LogToDB);
IAsyncResult ar = del.BeginInvoke(re,null,null);
}
}
private delegate void LogToDBDel(HttpRequest re);
private void LogToDB(HttpRequest re)
{
string m_connectionString = Dottext.Framework.Configuration.BlogConfigurationSettings.Instance().BlogProviders.DbProvider.ConnectionString;
string clientIP = re.UserHostAddress;
if(!clientIP.StartsWith("192.") && !clientIP.StartsWith("10."))
{
string clientUserAgent = re.UserAgent;
string clientReferer = re.ServerVariables["HTTP_REFERER"];
string clientHostName = string.Empty;
try
{
clientHostName = Dns.GetHostByAddress(clientIP).HostName;
}
catch(Exception)
{
clientHostName = re.UserHostName;
}
string clientQueryString = re.RawUrl;
SqlParameter[] sqlParams = SqlHelperParameterCache.GetSpParameterSet(m_connectionString, "pr_Blog_SaveEntryStats");
sqlParams[0].Value = clientIP;
sqlParams[1].Value = clientUserAgent;
sqlParams[2].Value = clientHostName;
sqlParams[3].Value = clientQueryString;
sqlParams[4].Value = DateTime.Now;
sqlParams[5].Value = clientReferer;
try
{
SqlHelper.ExecuteNonQuery(m_connectionString, CommandType.StoredProcedure, "pr_Blog_SaveEntryStats", sqlParams) ;
}
catch(Exception)
{
}
}
}
}
}
As usual, this needs an entry in the web.config to hook in the module:
<httpModules>
<add name="RequestLogger" type="ExtraControls.ViewTrackModule, ExtraControls"/>
</httpModules>
Via Alex Barnett's post, with the earning potential of these things I can think of nothing better than for some of the cash to go to charity! You can get more details on the Big Noise Music site, where I notice they have a 1p streaming thing as well as a 75p dowload service. They seem to have support from some big UK artists including Coldplay (predictably), Ash, Badly Drawn Boy and Melanie C (unfortunately) ;-).
I used to work with Michael at a previous company, one of the most creative coders around any certainly worth keeping an eye on...He also has a really interesting post on Web Accessibility which links to a report pointing out some of the problems with current accessiblity testing tools...which is a bit of a pain, especially if you need sites to be truly accessible (of course ASP.NET 1.1 is not compliant at the moment - ASP.NET 2.0 fixes many of these issues though).
Thought I'd mention, while I was making the new skin for the site (which you'll miss if you're using a Reader of course!), I wanted to use a PNG for my little logo since I'd used a gradient and the logo has a drop-shadow which looked wierd under the wrong circumstances. Well, problem is IE doesn't natively show PNGs properly - there is a fix using the 'alphaimageloader' filter but that can break stuff in other borwsers. What I discovered was this really useful behaviour from WebFX - this just lets you use PNG as any other image then applies the filter dynamically - very handy!.Oh, whilst you're there check out some of the other stuff.
Well, this is the first of a few updates to this site over the next couple of days (prefer to take these things in steps - starting with the biggest). The update was fairly straightforward - one thing I haven't seen mentioned is the removal of the IIS *.* mapping which I needed in 0.94 - that had me confused for a while. The skin is also updated - has Mozilla 'issues' right now, but I'll get these fixed at the next update (which also adds a couple of other server controls to the page).
Please let me know any issues - send your gripes to blogcomments@mostlylucid.co.uk - ta.
Really useful service, chances are when you design a website you don't have access to the dozens of browser / platform combinations that your users do.
Browsercam (though commercial) offers the only truly viable way I've ever seen to do this, put simply you enter a URL and this service displays your site (or just a single page) in Six different browsers, three different operating systems, with and without flash. Very nice!
Wow,
this thing is promising. I usually use BlogJet for posting but SauceReader has a good RSS Reader and posting interface - and it has a functional SpellChecker!
Simple idea but really useful! An add-in which lets you past content as various different things in VS.NET.
Download it here. For more information, visit
Alex's Post
Thought I'd make a quick list of stuff I want to do but never have in .NET - yet....
- Reflection - haven't yet had ANY call to use reflection for anything, lucky me!
- Direct X 9.0 - I probably am going to play with this pretty soon, especially with this just around the corner (for the conspiracy theorists, the picture is eerily close to a Longhorny UI isn't it ;-))
- Remoting - again probably the fact that I'm primarily a web coder, but never had the need for this...
- Attribute Based Stuff - now, again, seems really useful, I've read tons on it, just never really found the need...
So what's yours - what stuff haven't you had the chance to play with yet in .NET?
Look here...the evil pooch will go away!
Mike Schinkel, president of Xtras.Net, made
an offer on his personal blog of a free XDN Professional membership (http://www.xtras.net/xdn) during the month of May 2004 for anyone that blogs about .NET frequently. If you are a .NET blogger, see
Mike's post for how to get your free XDN membership.
It's always a thing I've been fairly weak at - partly because in the past it was of limited use due to stupid browser incompatabilities - but now there's really no excuse for not being a CSS devotee, particularly when trying to design lightweight yet accessible sites. The best turorial I've ever found is at
this site - they have 5 main tutorials which go through many steps and impart knowledge with an almost scary subtelty. Anways,
go there, learn!
I'm planning (fingers crossed) to update this whole thing with the latest version (heavily modified by me) of .TEXT this weekend coming - I currently have a new snazzy skin (for the blog, my skin currently sports a nasty burn) and some other 'interesting' features ready for 'live'...
Recently been working on a site with this stuff, until now this has been really poorly documented (you may have seen a page with a .mspx extension - that's an MNP page). Anyway, Tim Sneath mentioned an article which was recently pulbished which covers in far more detail than I'd seen before, the structure and implementation of this system...worth a read!
UPDATE: Just in case..here's the reason I can mention MNP - otherwise it'd have been covered by my NDA and I'd have had a pinky removed (that's Microsoft right, I keep confusing Micrsoft and the Yakuza)
I'm trying to simulate the .NET 2.0 Database Cache Dependency stuff (well kind of, WAY simpler obviously). What I'm doing is running a little timer class as a static property of my global.asax.cs file...like so:
public static TimerClass timr = new TimerClass();
My actual timer class thing is really simple, it just adds items to a queue on each tick; in the actual app this will fire a simple stored procedure and only add certain items if the item has been updated. This is all really to get round requiring a context to update some stuff in the cache...this way I can do it 'offline'
using System;
using System.Timers;>
namespace CacheTimerTest
{
///
/// Summary description for TimerClass.
///
public class TimerClass
{
public TimerClass()
{
Timer timer = new Timer();
timer.Enabled=true;
timer.Interval=5000;
timer.Start();
timer.Elapsed +=new ElapsedEventHandler(timer_Elapsed);
}
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
if(!Global.qu.Contains("update1"))
Global.qu.Enqueue("update1");
}
}
}
So here's my question, can anyone think of a reason why this won't work reliably, as I say, I have a nagging feeling it won't but for the life of me I can't think why...
A couple of hours after
posting my gripe about the Mappoint.NET trial stuff, I got a mail from Michael Lightfoot at Microsoft UK...looks like I was signed up at some point so I now have these details. Now..do I have timew to write an example app before my meeting tomorrow...hmm...anyway, thanks Michael!
Well, here's the story...I am currently preparing a pitch for a job we're hoping to do for a large client who wants to use Geodistancing, Address Verification, mapping etc for their website; being a .NET devotee (all hail the CLR) I wanted of course to use Mappoint.NET to do all of this - strangely we didn't fancy paying $10000 (minimum) for a product which we don't know if the client wants to use of not (we have lots of options for this stuff...). I noticed that Mappoint.NET had started doing a trial version for MSDN subscribers cool - so I requested a license (through the horrible interface which has about 10 steps and loses the MS stylesheet half way through...). This was the day after the trial offer came through, but it said I'd get a response in 3 business days so that was fine (the presentation thing is tomorrow)...so after a week, nothing, I tried again, still nothing...just tried again...I'm not hopeful. So long story short we won't be recommending Mappoint.NET for this or any project in the near future (strangely every other company I contacted for their products - which are much cheaper than Mappoint.NET - responded with trial keys, free versions etc within the hour!
UPDATE: So I thought I'd try to ring MSDN UK to ask for help with this...they've never heard of the offer and have 'escalated to management'...not holding my breath!
Wish I had this the other week when I was doing my HTML image grabber thing...took me ages to find this stuff. Anyway, nice tool found
here which lets you easily use some of the cool Win32 PIIVOKE stuff a bit less painfully...
I realise this is probably very old news but I've been having a bit of fun tonight playing with the new shiny
Reflector - all I can say is WOW! Playing around in the source of .NET 2.0 is just too useful for a learning tool. I use this along with the
File Disassembler addin from
Denis Bauer - now I can dump whole assemblies to source files and poke around them (still not figured how to debug inside them which would be really handy!).
Sorry, had a bit of an unplanned hiatus over the past couple of weeks...a cold and a week away from computers being the main culprits. So, well, I'm back now feeling mentally reinvigorated and ready to play with some new stuff. Had an exellent break - one of the 'doing nothing' weeks I seem to require every six months or so to keep sane. I really recommend it fo all coders, just a week away from coding altogether.