NullifyNetwork

The blog and home page of Simon Soanes
Skip to content
[ Log On ]

Archive - Historical Articles

You are viewing records from 06/14/2003 12:11:55 to 06/12/2004 15:00:08. I'll be adding support for selecting a date range in future.

All my code related articles, answers to questions, random bits and pieces that are of use are all listed here if you wish to ever revue them.  I'll add an entry to the menu as soon as I get a chance. Permalink 

Kudos to the guys (and gals) over at MS for making a serious contender in the server OS market - my Windows 2003 Server has been up for four months now after its teething troubles where it crashed once.

The question is, will it beat the 207 days uptime my Linux servers were on before they got replaced by newer hardware?

I now have Linux and Windows running side by side in two datacentres - both have only been down (the machines rather than than the connections) for security updates* in those four months - which I don't count as downtime since I choose when to reboot.

* - I do keep track of these:  The Debian based Linux server has been down three times for kernel updates and the Windows 2003 server has been down once for an update but I didn't note down what it was.

Permalink 

Another easy question!

Firstly, what type of screen size are you looking for?

There are two types you can look at - the current working area, basically the area a maximised application will fill if it is polite, and the physical screen which expands from the top row of pixels to the bottom of the start bar on a standard setup.

Thankfully the Screen class offers up both of these as properties, so you can easily:

int height = Screen.PrimaryScreen.Bounds.Height;

int width = Screen.PrimaryScreen.Bounds.Width;

To get the exact, complete screen size (it may be better to handle this as a Drawing.Rectactle as that is how Bounds is typed, however for ease of explanation this is how I will do it here).

And, just as easily you can do:

int height = Screen.PrimaryScreen.WorkingArea.Height;

int width = Screen.PrimaryScreen.WorkingArea.Width;

To get the total usable space for a friendly application.

Please don't use this to work out how big you need to make your always on top application so you can obscure the start menu - that is extremely annoying ;)

Permalink 

This is a quick and easy one for anyone else trying to send mail using ASP.NET.

First, add the using statement for the appropriate namespace:

using System.Web.Mail;

Then, create a MailMessage object:

MailMessage m = new MailMessage();
m.From = "
simon@nullifynetwork.com";
m.Subject = "A demo message";
m.Body = "This is the body\n\n-Simon";
m.To = "
you@yourplace.com";

And then, finally - send it using the static method off SmtpMail:

SmtpMail.Send(m);

Another example of why .NET rocks, what used to be an annoyingly complex task is now suddenly relegated to being easy as anything...

(This article is to make up for this monster article which discusses opening file handles on physical devices...)

Permalink 

Yes, the wisptis.exe file is legitimate - it is part of the Windows Journal Viewer and you probably installed it through Windows Update.

It's related to the tablet PC architecture.

Permalink 

So Robert made another "RSS is the ultimate solution" post and almost everyone jumped on it like rabid dogs.  Me included...

I have taken particular offense (not really the right word, as I greatly respect much of what Robert brings to the surface, and his opinions are usually fairly good - a healthy discussion is also nothing to get angry about!) at a reply to my comment there:

"It's also a way of getting the content itself delivered and stored on my computer."

This is a fairly annoying and completely false assumption regarding RSS.

The concept of the content being delivered to you is an excellent one, however this is NOT what RSS does.  RSS is a simple XML file (or webservice) sitting on the web waiting to be collected by your computer.

It does not tell you when it is updated.  It doesn't send itself down the line to you.  It isn't even distributed as far as your ISP's servers like E-Mail/Usenet is!

RSS is being used to solve a problem because it wasn't designed from the ground up as a syndication format - it was designed as a machine readable version of a site, hosted in the same way as the site itself.

A true solution to the problem would be to send the appropriate part of the RSS file down the line via some active means - even if it's just as far as the ISP's servers, this is a much more logical solution.

It has a plethora of benefits just a couple of which are instant or near instant updating of your readers with what they're interested in and far less bandwidth usage in all scenarios at all ends.

The technology already exists with MSN Alerts, MSN/AIM/Yahoo/ICQ/Jabber and dare I say it, E-Mail (shame this has been spoilt by the spammers and is useless for its purpose).  Why can't we use one of these instead of making a square solution fit a round problem?

RSS frustrates me for what it's being turned into, and for how that is being done.

Permalink  2 Comments 

Want to access a physical device (COM port, tape drive, LPT port, anything...) using C# .net?

You can't.  Not natively anyway:

FileStream fs = File.Open("\\\\.\\COM1", FileMode.Open, FileAccess.ReadWrite, FileShare.None);

Happily errors out saying you can't use the \\.\ format with a FileStream (\\.\ becomes \\\\.\\ when you escape the backspaces with more backspaces).

FileStream does however allow opening a handle, so all is not lost, you can simply use the format:

FileStream fs = new FileStream(handle, FileAccess.ReadWrite);

After opening the handle using a CreateFile API call.  To use this API call you need to platform invoke it, which is easily done once you look at the docs for it:

[DllImport("Kernel32.dll")]
static
extern IntPtr CreateFile(string filename, [MarshalAs(UnmanagedType.U4)]FileAccess fileaccess, [MarshalAs(UnmanagedType.U4)]FileShare fileshare, int securityattributes, [MarshalAs(UnmanagedType.U4)]FileMode creationdisposition, int flags, IntPtr template);

(http://www.pinvoke.net/ is a great place to cheat)

You can then get handle (note that rather than defining the actual handle variable I'm going to put the CreateFile call inside the FileStream constructor - you could instead do InPtr handle = CreateFile() etc) by using CreateFile:

FileStream fs = new FileStream(CreateFile("\\\\.\\COM1", FileAccess.ReadWrite, FileShare.ReadWrite, 0, FileMode.Create, 0, IntPtr.Zero), FileAccess.ReadWrite);

First timers should remember to update their using statements, one for the FileStream, and one for the [DllImport]:

using System.IO;
using
System.Runtime.InteropServices;

Permalink  1 Comments 

This one's an old one.  It has been floating around in the blogging community for ages, and I figured I would just plain ignore it because the arguments both ways are fairly petty from my perspective.  I don't like that method of syndication at all - and would much prefer a push medium for it, like msn alerts or icq/jabber can be made to do.

But someone has finally asked me if I can add an Atom feed.

This is a little annoying, since I already have an RSS feed, but I like to satisfy people so I busily go to look at the atom specification.  It was far better though out than RSS for the job it's doing and it supports many more features.  If I was implementing the syndication features of my site again I'd choose atom.

But I have no intention of doing it for the moment, there's simply no practical benefit to it over rss - they are simple xml versions of content that is available through other means - I'm really tempted to make my own spec for a syndication format and see if a similar contest occurs...

Lets call it Stupidly Simple Syndication

<Feed>
   <Name>Feed name</Name>
   <Home>URL</Home>
   <Pinger>Address of XML webservice that allows you to define a url, ip and port, icq number, jabber address, passport or email address to call back when this feed is updated</Pinger>
   <Article>
      <Date>UTC date and time</Date>
      <Link>Link back to the article</Link>
      <Author>Author contact details or name</Author>
      <Subject>Subject</Subject>
      <Category>Optional category of article</Category>
      <Extensions>Somewhere people can put anything extra about articles</Extensions>
      <Content>The article</Content>
         <Comments>
            <Comment>
            <Date>UTC date and time</Date>
            <Author>Author contact details or name</Author>
            <Subject>Subject</Subject>
            <Extensions>Again, optional stuff</Extensions>
            <Content>The comment</Content>
            </Comment>
         </Comments>
   </Article>
</Feed>

We will rely on the existing HTTP headers to define when it was updated, when to fetch another one, etc. since we don't want to waste bandwidth.

We will also not worry about implementing shedloads of features most people won't care about in the base implementation, instead we will allow the use of extensions.  Setting up a webservice at a reliable url on the net allowing people/aggregators to pull out a description of the extensions used in a feed (ie - what format data is in there, why, what's a human name for it, is it for a machine or a reader, etc.) and anyone to register one.

This will permit it to have more features than either RSS or ATOM, whilst also being small, perfectly logical, and stupidly simple to begin with.

Permalink 

So, I had come up with a way to do double buffering before using a backbuffer and flipping it to the front for a simple game I wrote as a test.

I have just noticed there's a Control.SetStyle method:

this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();

Executing this in the forms constructor will turn on double buffering the correct way.

Permalink 

Three years to the day yesterday, at 12pm I started full time work at unnamedWorkplace when I should have gone on study leave for my exams.  12:00pm today I am 24 hours free with a stack of work, list of projects, bunch of supportive friends and no worries for the moment.

My departure from unnamedWorkplace was swifter than I expected after giving in my notice, but overall this is probably for the best...  I have lots of ideas for the short term, but in the long term I'm open to suggestions, or whatever turns my way.

Now to build my own future...

Permalink  1 Comments 

Well, I finally resigned. Permalink 

This is a rant, one of those almighty work related rants that result in Bad Things usually.  But it needs to be said.

So I go to unnamedWorkplace every day, in and out and support the 2500 ish users there.  I do more than my hours and make sure of it after I was complained about leaving early one day (after coming in early) even though I take none of the legally required breaks and just take the time at lunchbreak I need to eat.

I put in as much effort as I can.  I am overworked, yet I feel like I haven't exerted myself mentally.  The problems are always small, simple issues; relating to configuration, data extraction, hardware problems, accidents or downright stupidity on the part of the users.

The points on my appraisel completed, are ones I had to complete - all training was paid for by me, all self improvement driven by me.  The unnamedWorkplace has failed to complete all of its points, including taking another appraisel, I believe it was due December 2003.

On the whole, the only reasons I have not resigned are the sallary and lack of a replacement for the moment; and my other colleagues across all departments.  My friends are steadily leaving too - another four people I work with and have known well for many years have announced they are leaving, and the beaurocracy and inefficiency is steadily increasing.

So go on, make my day.  Eliminate one of the reasons for me to stay:  If you have an interesting programming or complicated support job let me know, if I can't do it now I will adapt.  Fast.  I'd even work for free for a bit as a trial (subject to contract of guaranteed employment or payment for time spent!).

Permalink  7 Comments 

A friend of mine has made a post to his blog (http://www.illegalexception.com/content.php?id=102) about web services been bad for security.  I don't see it that way - I see them as exactly the same as any other web based application or script that's exposed to the Internet and no more insecure.

That's not to say they aren't all insecure in some way, but he's concerned about the security of the client when a web service runs on the server and provides only an XML interface for data exchange.

I can't understand why a virus, trojan, or idiot user would install a webserver, configure a scripting language (Java servlets, PHP, ASP.NET, what have you...) then advertise a web service that will run with fairly limited rights (ie - the rights of the scripting language, which can't be root on *nix and is commonly INET_yourcomputer on Windows).

It would be far easier for a virus to simply down the local firewall then open a port - and it would have more power once it was done.

Web services simply take the human interface out of web applications, allowing an application to directly access one as if it were a local module of code - IE - the amazon web services allow you to search for products on the amazon site, and get back a list of objects in your application.

Permalink 

So someone e-mailed to ask me why I used as to cast my object:

IHiThere asm = o as IHiThere;
if (asm != null)
{
   MessageBox.Show(asm.Hi());
}
else
{
   MessageBox.Show("Failed to make asm = o");
}

Rather than:

IHiThere asm = (IHiThere)o;

When it is neater.

Well, there is a simple reason: This is because the as operator doesn't throw an exception when it fails but instead fills the variable with null. The check if the value was null checked if the code worked or not.

Note that in the real world you will want exception handling around the whole block, incase the user selects the wrong type of dll, or access to it is denied, or... well, you get the picture.  This means you can freely use brackets to cast it - but this is in my opinion a more elegant method of doing something where you want to know if it succeeded or failed.

Update in 2009:

I would just like to clarify that I was trying to make the point that you should use the as keyword when it's something you expect not to work but don't want to use the is keyword!

Permalink 

So, I'm playing with reflection with the intention of making a plugin system for future use and looking at the obscenely complex articles on the net that don't cover anything even remotely like what I want to do.  Which is have an object I didn't write, and be able to .DoSomething with it rather than have four lines of garbage to just run a static method.  I wanted to be able to use classes I hadn't referenced at design time, just as if I had.  Obviously they need to follow my interface definition, but that's a small price to pay.

So I eventually give up and go back to the docs and play around for a bit, eventually getting this ludicrously simple method working:

OpenFileDialog openasm = new OpenFileDialog();
if (openasm.ShowDialog() == DialogResult.OK)
{
   Assembly testasm = Assembly.LoadFrom(openasm.FileName);
   Type[] asmtypes = testasm.GetTypes();
   foreach (Type t in asmtypes)
   {
      if (t.IsClass & t.GetInterface("IHiThere")!=null)
      {
         object o = testasm.CreateInstance(t.FullName);
         IHiThere asm = o as IHiThere;
         if (asm != null)
         {
            MessageBox.Show(asm.Hi());
         }
         else
         {
            MessageBox.Show("Failed to make asm = o");
         }
      }
   }
}

A quick rundown, that's:

Load the assembly you want to look at:
Assembly testasm = Assembly.LoadFrom("filename.dll");

Get a list of the types of objects in it:
Type[] asmtypes = testasm.GetTypes();

Loop through it, and for each class that implements your chosen shared interface* create it as an object:
object o = testasm.CreateInstance(t.FullName);

Then cast it to your interface:
IHiThere asm
= o as IHiThere;

Creating it as a local object you can use just like normal:
MessageBox.Show(asm.Hi());

* - Note that the interface in question here looked like:

public interface IHiThere
{
   string
Hi();
}

And was referenced by both the 'plugin' and the 'host' application.

The plugin side was a simple class that implemented the IHiThere interface, and returned "Hellow world from the plugin" as a string in the Hi method:

public class Class1 : IHiThere
{
   public
Class1()
   {
   }
   public
string Hi()
   {
      return
"Hello World - from the plugin";
   }
}

Permalink  1 Comments 

This is a bit of a rant, but still - might help someone also plagued with the same problem.

I'm doing several projects at the moment, and finding that templating in ASP.NET is non-existant.  I know it's going to be fixed with the new version in 2005 - but still, I don't want to wait.

So when making a page with a consistent layout you have three choices:

  • Generate all content for the page and feed it to the client, ignore all the object based capabilities of asp.net and use it like PHP or Java server pages.
  • Use copious literals to import your header, footer and menu from someplace or auto-generate them at run time.  Again loose any nifty advantages asp.net had over the others in the process - but keep them for the main content
  • Output the page as XML then format it using an XSLT.

At the moment I've gone with the literals - it's easiest whilst still being asp.net rather than c# generating html and sending it to a client.

But what did Microsoft expect us to do?  This is just downright silly...

Permalink 

Update: If you work for Maindec, go away and research this yourself.  My previous manager was certain that you already knew how and didn't want my help before I resigned yet I'm getting repeated hits from your domain, so obviously what was meant was 'you know how to use a search engine'.

Someone hit this site with a referrer searching for how to convert from MDaemon to Exchange - something I'm casually thinking about every time I have to change something user related on our MDaemon server at work.  MDaemon is technically fine at handling lots of users (although a bit slow without referential storage).  But the user interface isn't suited to more than 500 users.

It's either Exchange or Exim and Courier-IMAP - which is a nice quick migration if you use Maildir's.  (HINT: To convert from MDaemon's mail format to Maildir you simply need to copy the messages into the new folder of each maildir, then convert them to have unix carriage returns - you can do this easily with a three line shell script in bash on Linux)

With converting to Exchange, I think you would have to use the exchange migration tool that comes with Exchange 2003.  This will allow you to connect over IMAP and fetch the messages.  This will take a CONSIDERABLE time, but I haven't looked into exchanges API - it is likely fairly easy to bulk import the mail much quicker than via IMAP.  I'll investigate this when I get a chance!

The easiest path to take is this:

  • Set up the Exchange server, with all users, etc.
  • Configure the Exchange server to recieve all mail
  • Rename the MDaemon servers domain to be something else
  • Notify all users to use the Exchange server and configure the machines/accounts/profiles of all users to use the new exchange server
  • Tell the users they can access their old mail and send fine from the MDaemon system - but will only recieve mail on exchange.
  • Migrate anyone that complains, and if you have lots of time free (cpu wise) try to migrate everything.

This will get your Exchange system up and running as quickly as possible - and fielding the queries from people will take less time than migrating the data in cases where there's considerable data in place.  You'll be surprised that only a few people will want all their old mail in the same place as their new mail - mail is time dependant and eventually it will cycle over.

This does require that you leave the MDaemon system running for a year or so - but use of the system will decrease as time passes by, and when it reaches zero in a month you can back up the data and reuse the physical hardware.

Permalink  1 Comments 

This makes me very happy - it loads quicker than visual studio and has a few of the features I like from visual studio in it.  It also allows you to highlight the current line - very handy in a wordwrapped document!

Omar Shahine at Microsoft mentioned it, and also covers how to replace notepad the correct way.

Permalink 

Has anyone seen an online real-time code collaboration application out there yet?

I'm looking for something suited to pair programming but online and with simultaneous data entry capabilities.  So both people have Visual Studio, both see the same code.  One types in one place another types in another and they can each see (assuming they're working on the same file, and the same place in that file) each others typing in real time.  This would allow for you to help another programmer.  They say two heads are better than one...

That or if anyone has any idea how you can easily do the user interface to such a thing so I can build one myself.  I was tempted to use accessibility to read the contents of a window then remoting to send it but this fails on the actual display of the entered data aspect.  It adds a major disconnect to have it in a seperate window.

And I don't want to reinvent the wheel and completely write a multiline, multiuser edit box by hand.  Not yet anyway... Permalink  6 Comments 

I've been thinking, how do you get around telco lockin?

You can't - well, not easily.  At least, not till there's a wireless mesh covering the whole world.

This is what the people at consume are aiming to get.  I think the ham radio operators got it right when they tackled the problem, which puts consume on the right track - but we need a longer range wireless medium to solve the problem.

Now, 3g, gsm, and others can solve the problem of range - but they're also all relatively slow in performance.  Ideal for keeping a continuous link, for chatting, for mail if you don't mind waiting - for voice services even.

So, what service covers the middle ground?  I don't particularly want a multi-billion dollar license just to provide wireless service to my peers.  I don't need a range in the kilometres (although that'd be handy!).

Permalink 

Okay so I need to know a bit of Java and be able to build something if needed to help a friend so figured I should install the stuff to get it going.

Now, here's the first of not many plusses over .NET.  I installed Eclipse by unzipping the archive and running it with an appropriate SDK installed.

It ran.  I was impressed.  Mostly by:

  1. The fact it wasn't as slow as treacle like all over Java IDE's I've had the dubious pleasure of trying out. 
  2. The fact that it was obviously Visual Studio .NET with a few minor improvements like a most excellent colouring of the current line slightly different so you knew where you were even with wordwrap and/or a long line.  Refactoring and code templates like what is coming out in Whidbey/Visual Studio .NET 2005 was also already in it and working well.
  3. My java app compiled and ran - the only difference between it and the equivalent C# app?  For some stupid reason Java's ArrayList is in the java.utils namespace rather than a collections namespace.
  4. Eclipse looks correct on Windows XP.  WHAT I hear you yell...  Well, it's true.  Visual Studio looks like it's on 2000 even if you change the theme, it's just poorer integration.

Now for the negatives I've noticed so far just playing around:

  1. No foreach on objects.  This one is really getting to me.  For just does not cut it!!!
  2. Threading doesn't use callbacks - you have to build a new thread class based on the parent class of Thread.  Seems somewhat of a disconnect from keeping the code nice and modular.
  3. The string type is capitalised.  Yes, I know this is petty.
  4. C# code looks nicer: Getters and setters are more neat and tidy.
  5. Where is delegation in Java?  It just seems to be... missing. 
  6. Interfaces seem to have been thought out more in C# - how do you prevent one being run if the object is addressed as its native type?
  7. Where are enums in Java?  Also... absent without leave.
  8. I can't seem to find struct's either - how to you make a high speed primitive type?
  9. Where are the overloading features again?  I can't find mention of most...  Operator overloading for example.
  10. No versioned GAC.
  11. No attributes for methods.

All this is ignoring the multi-language capability of .NET, and the 'interesting' model of page generation of ASP.NET where objects exist between calls and

Permalink  3 Comments 

Hmm, lots of people out there are searching for Jen Frickell on Google and mysteriously getting to my site because I mentioned her a while back.

The site you're looking for is over there, not here, although she doesn't update as much as she used to, bar special occasions - like April fools day...

Permalink 

Here's a little something that took a couple of hours to write, feedback is as always appreciated!  As I've already been asked: this is all GDI based, no DirectX...  Graphics for it would be appreciated!

Anyway, click here to run GravCave from my server, you need the dot net framework - available from windows update, or I expect it will run okay under mono.  If you wish you can right click and save target as to your local machine - it's 40kb and will run from anywhere.

Another .NET game in the same vein is Chris Sells' Wahoo.  This came about as I was curious why dot net based games weren't slowly appearing yet, so thought I'd see how difficult it was to code a game in: turns out with C# it's much easier than many other languages.

I assume when people realise that they CAN use DirectX with an app that is loaded directly from the net, they'll start using it.

UPDATE: Source code is available on this page on my site

Permalink 

Ever wondered how to double buffer with a Graphics object so your GDI+ based game/control doesn't flicker annoyingly?

Me too.  There's probably a built in method that's easier, but this is how I managed to get it to work smoothly, it's nice and simple and allows you to draw anywhere that offers up the normal CreateGraphics method.

First, set up a bitmap to act as your backbuffer:

Bitmap BackBuffer = new Bitmap(this.ClientSize.Width,this.ClientSize.Height);

Graphics DrawingArea = Graphics.FromImage(BackBuffer);

Next, you want to draw to your graphics object as normal, so DrawingArea.Clear(Color.Black); and such.

Once you've completed drawing the object that you want to smoothly move, simply draw the pre-rendered bitmap over the top of the Graphics object you want to update:

Graphics Viewable = this.CreateGraphics();

Viewable.DrawImageUnscaled(BackBuffer, 0, 0);

You can also use other techniques to increase the performance, such as reusing the backbuffer by defining it in the class you're using it in - this means .NET won't need to recreate it repeatedly.

Permalink 

Okay so I was just wondering why Kunal Das' OutlookMT looked very much like the idea I had for solving the problem, until I find this post whilst searching for a way around the annoying security dialog you get when accessing Outlook from C#:

http://blogs.officezealot.com/Kunal/archives/000503.html

It looks like a suggestion I made on Scoble's site about how I would access Outlook to enable blog integration was the initial inspiration for OutlookMT's solution to Scoble's problem.

I guess this blogging thing really does work...

Permalink 

If your validation isn't working in Asp.net after deploying to a webserver with multiple virtual hosts you might find you need to copy the aspnet_client directory from the default site to the affected site to get the client-side validation working.

A good reason to always do server side validation!

Permalink 

This is my first attempt at an instructional article, so opinions on quality would be great!  Let me know if I made any mistakes too...

It's mainly for all those like Robert Scoble who would like to be able to drag and drop an item to a folder in their Outlook and post it instantly to their Blog, but it also covers web services and talking to Outlook.

Accessing Outlook

The first requirement is to be able to access Outlook.  For those with Outlook 2003 and XP this is relatively easy, thanks to .Net and Microsoft shipping an appropriate assembly with Office.  To install the Office 2003 assembly, you should run the office install and choose .NET Programmability Support.

You might need to use the command prompt to copy Microsoft.Office.Interop.Outlook.dll out of the GAC after installing it so you can add a reference to it, if you can add it as a reference otherwise do so and let me know how!  The Visual Studio add reference dialog doesn't seem to list items in the GAC...

Add an appropriate using clause:

 

Then you should be able to instantiate an Outlook object and make requests of it:

Outlook.Application app = new Outlook.ApplicationClass();

Outlook.NameSpace NS = app.GetNamespace("MAPI");

Outlook.MAPIFolder inboxFld = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

This will give you access to inboxFld, which will allow you to iterate through the contents of the inbox!  You can also change this to iterate through notes, or through calendar entries, tasks, etc. as you want.

For example, to iterate through your mail you can do:

 

Console.WriteLine(t.Subject);

}

To write out all the subjects on the console.  The only annoying thing will be you need to say yes to a security dialog when you access mail items - I'm working on getting around this, it doesn't happen for tasks or notes, etc.

Once you are able to access Outlook, your next objective is to post data to your weblog.  You can avoid duplicates through one of two ways:

  • Keep track of what has been posted by maintaining an ArrayList of articles on your blog and checking before trying to post one.
  • Keep track of what has been posted by changing something in the MailItem's - e.g. - set or clear a flag.

The first method requires keeping a list synchronised with the blog, the second is quickest and easiest, but wouldn't be suited with multiple people possibly posting things.

Posting to your blog

Obviously everyone is using different software to manage their blog.  I can't give an example of every single method, however the simplest from a programmers perspective is if you can access the database of your blog via a webservice.

Building a webservice

Google can supply many examples and tutorials, however an example of doing this is fairly simple.

Choose to add a new webservice to your site, or create an entirely independant project and call it something suitable - ours will be blog because it's an example.

Firstly, you will need to add a few more items to your using list, so you can do XML serialisation of structures and objects.  I will assume your database is MS SQL Server too, so ensure the following are listed in addition to the defaults for a webservice (I forget what they are):

 

 

 

 

 

using System.Web.Services.Protocols;

 

 

You want to be as object oriented as possible when building your webservice, so you should define a NewsItem structure to pass back and forth, you can adjust this to include whatever you need to store in an article:

 

{

public int id;

public string topic;

public string subject;

public string postedby;

public DateTime postedat;

public string content;

 

}

This will allow you to reference rows in your database as objects, a simple organisational benefit that crosses over and permits easy use of methods of the webservice without passing a lot of parameters.  It also allows you to add groups of entries to an ArrayList, which is a big benefit (although there is a problem converting from an object transferred by a webservice and an ArrayList, if you ever do this you will need to iterate through the object and add the entries back to an ArrayList - .net does not support converting from an object[] to an ArrayList).

You can then build your method for adding the article to the database.  I have used the database on my blog as an example, you will obviously need to change the insert statement and connection string to fit your situation.  There is also no exception handling, ideally you should enclose the opening of the connection and the executing of the query in Try Catch blocks.

Note that the XmlInclude for the NewsItem struct is listed, this allows the webservice to accept a newsitem given as a parameter - otherwise if would not know to serialise the structure.

[WebMethod]

[XmlInclude(typeof(NewsItem))]

public void AddArticle(NewsItem newarticle)

{

SqlConnection sqlcn = new SqlConnection("Data Source=(local);" +

"Initial Catalog=NullifyDB;" +

"Integrated Security=SSPI");

sqlcn.Open();

SqlCommand sqlcmd = new SqlCommand("INSERT INTO newsarticle (subject, topic, content, uid) VALUES (@subject, @topic, @content, @postedby);", sqlcn);

sqlcmd.Parameters.Add("@subject", newarticle.subject);

sqlcmd.Parameters.Add("@topic", newarticle.topic);

sqlcmd.Parameters.Add("@content", newarticle.content);

sqlcmd.Parameters.Add("@postedby", 253);

sqlcmd.ExecuteNonQuery();

sqlcn.Close();

}

You should then provide additional methods for anything else you would want to do, such as listing articles, deleting articles, and editing.  For Outlook integration you really only need this method.

Accessing the webservice

Once the web service is up and working, you need to create a web reference to the webservice, this is done in visual studio by right clicking the references box and choosing add web reference.  Lets say there's one at http://webservices.nullify.net/blog.asmx

When you add a web reference Visual Studio will automatically produce a wrapping class that will allow you to easily instantiate the web service as a local object, without worrying about any of the underlying technology.  (I'll only cover synchronous calls here, otherwise this will turn into a full fledged book...)

To access the above web service, you would simply define it as a new object:

net.nullify.webservices.Blog blog = new net.nullify.webservices.Blog();

And you would define our NewsItem scructure that we defined in the webservice:

net.nullify.webservices.NewsItem article = new net.nullify.webservices.NewsItem();

This will allow you to now call methods of the blog object, which will execute directly on your web server, with all the rights of a normal asp.net page - including the ability to insert articles into your database!

Using our imaginary webservice, rather than writing the subject for each MailItem to the console, you can post them to your blog:

article.subject = t.Subject;

article.content = t.Body;

article.topic = "OutlookPost";

 

blog.AddArticle(article);

(Note, this is assuming your webservice has no security, or is protected by asp.net/IIS' own security!)

I hope this post helps someone!

 

public struct NewsItem

 

using System.Xml.Serialization;

 

using System.Web.Services.Description;

 

using System.Web.Services;

 

using System.Data.Common;

 

using System.Data.SqlTypes;

 

using System.Data.SqlClient;

 

foreach (Outlook.MailItem t in inboxFld.Items)
{

 

using Outlook = Microsoft.Office.Interop.Outlook;

(This article has been truncated due to migration to a new database, apologies!  I hope what is here helps and if you have questions there are copies around on the web of this article.)

Permalink 

*********************************** I, CRINGELY - April 1, 2004 Column *********************************** This message is being sent to inform you that Robert X. Cringely's latest column is now available online at: http://www.pbs.org/cringely/ The title and topic of this week's column are as follows: "Timing is Everything" No matter what happens in Microsoft's current slew of court cases, the end will be the same, says Bob: Redmond will win. ******************************** SUBSCRIBE/UNSUBSCRIBE To sign up to receive notification of new "I, Cringely" columns, please visit http://www.pbs.org/cringely/when/, or send an e-mail to listserv@pbs.org, and in the body of the message type "subscribe tellmewhen-l * " (without quotes). (You can substitute your name in place of the *). If you would like to have your name removed from this list, please send an e-mail to listserv@pbs.org, and in the body of the message type "signoff tellmewhen-l" (without quotes). To avoid conflict, be sure to send the message using the same account that you used to sign up. An e-mail confirmation will be sent when you are officially removed from the Cringely list. If you experience difficulty unsubscribing or you're interested in changing e-mail addresses, please send your request to www@pbs.org. ******************************** Copyright 2004 PBS Online. Permalink 

This is being posted from a winforms application using a webservice interfacing with my weblog. Next up, posting from outlook by dropping items into a folder! Permalink 

I finally understand.

The reason I've been unable to write good documentation all this time is who has been reading it.  I write code that describes how to do something to a computer.  That documentation must be excellent syntactically, all encompassing and as flawless as possible.  It must also be complicated as the compiler/interpreter is generally fairly stupid and needs intructions for every step.

I have a tendancy to take that over when documenting the code, what I really need to do is say "This does x" rather than "This does y to z in order to get x to be the desired value, but has to take into account a, b, and c factors".

I finally understand - document simply and briefly to document well...

Permalink 

Do you have an idea for a piece of software that you personally would like?

A tool that would help you in your day to day use of a computer?  Something that would be neat on your smartphone?  An application to store/retrieve a particular type of information on a pocket pc?

Something that solves a problem in your classroom/computer lab/school/university/office/shop floor?

A web site that needs to do something really special?

If you want it more than you want to sell it, let me know your idea. I am willing to solve interesting problems free of charge so long as I keep full rights to resell them! FREE development. You/your company/your school/your university get full rights to keep it and if you so desire distribute a marked copy so long as you don't charge for it I'm open to other relationships too such as sponsored open source, and complete development under contract - ideal if you need something like a website that can answer industry specific questions from your users, or that needs to solve a problem that won't sell to others. Or if you just want to keep your hands on it!

What do I get out of this? There is a chance I could get to build the next winzip.

What do you get out of this? Your problem is solved.  Period.

What can you get out of a really good idea? A split of any profits!

Hopefully this business model will suit anyone, with any amount of money so long as there is a need or an idea, let me know your opinions.

I'm already working on one solution using this idea, and it seems to be working quite well for everyone involved.

Permalink 

Sometime in the next two days I will be turning on the new version of SiteBuilder - the software that runs this site (need to come up with a better name...).

The new version is written in C#, and although I've built it so the urls of everything are the same certain things have changed.

Therefore expect things to break a little... (RSS GUID's for one thing, the admin system, no more workdrive file storage for the moment, no comic management)

Workdrive will be reappearing completely rewritten in .NET in a short while, along with full PIM and Outlook integration.

Update: All done and live!
Another update: And the RSS feed now validates too... Permalink  4 Comments 

I unplugged my headphones, and my whole system crashed! Amazing how these things happen, but to be honest it's the first crash where it hasn't been directly related to hardware failure.

I got sent to https://oca.microsoft.com/EN/Response.asp?SID=77 ("Error Caused by a Device Driver") which is completely useless.

During seperate testing on another machine, I found that this can also result in an immediate crash on login as the system attempts to play a sound.

Lets see how many people get sent here from google...

To workaround for this problem to prevent the system crashing is you need to go into the Sounds and Audio Devices control panel, then change the default devices for playback and sound recording to a present soundcard either in safe mode if you don't have access to the USB audio device, or before removing the device.

Now to find out how to actually submit more details for a microsoft bug report... A simple "What were you doing when this happened?" text box would probably help a ton on the oca.microsoft.com site. Permalink 

I'm just starting looking into the possibility of rebuilding the software this site runs on in C#. It looks like it'll be fairly easy to make a seamless transition from a visitors perspective, but I'll probably need to completely rebuild the admin system. Which isn't a bad thing... Question is, how secure is code written in C#? Will I need to have extensive checks on user input like I do in PHP... Or will I need to have more checks? My guess is less as it's not a scripting language, but it'll be interesting to see how easy it is to break it. Permalink 

I'm sitting here, waiting, wondering about Visual Studio .NET. It works well for any one task, yet I have a fairly small project I'm building to solve a friends problem at their work and it seems too big for Visual Studio. Let me explain: The solution has five projects - the web client, a smart client for one type of user, a smart client for the admin user, an assembly with shared classes, an installer add-on to install the database - and a couple of installers. In total there are barely fifty forms/source files. That isn't too much stuff, I've seen projects with twenty assemblies, resulting in thousands of files. Visual Studio, on opening my small solution opens every file. Slowly. The end result is a single line of tabs for each file so you can't find anything in it and end up ignoring and instead use the solution explorer. You can compile everything in the solution quicker than you can open it initially on my machine. And I have no animations or anything on, it simply takes AGES to load and show everything. I can close it all before I save, but I shouldn't need to - and even then it still insists on doing SOMETHING with every file when you load it. I pity anyone that doesn't start to split their solution into multiple smaller solutions when they get to 100 files... Question is... Will Whidbey really speed things up a bit... Permalink 

It appears that the expensive car (Windows 2003) crashes more often. It looks like the last crash was to do with an ISAPI module and IIS. Windows itself remained up. It bought down the whole of IIS too, not just the web services, and not just the ability to run one type of dynamic page (I don't know which isapi module as of yet, but my guess is asp.net or the gzip compression module as they are the only ones loaded). On the other hand, the tiny debian server with jvds.com has only been down because of a reboot for a kernel vulnerability. The ability to auto-restart after a short delay is built into the OS, but what about IIS - why can't you set an IIS service to auto restart, then if it fails x times wait 20 secs and try again?? Permalink 

7 Days uptime and we're on a roll. The TCO for Windows may be higher, but it is for getting a more expensive car too. Now we get to see if the more expensive car is better than the economy model. Permalink  3 Comments 

Lets hope there's no more patches released. I've finished moving everything across, it's just a case of checking that nothing is using the other server for a few hours before I shut it down. Permalink 

I got my test web service to run on the new server! Since my network provider has blocked ports 135 etc. I have to use frontpage extensions if I wish to access it with visual studio - which was really slow as I only have cable. Would be nice if you could use the tried and trusted ftp to publish projects! (I know I can manually do this, it's just not the same building it locally then ftping it up every time I build something - I'm going to go try script it myself, should be fairly easy...) Permalink  1 Comments 

Firstly, now I'm into the swing of posting stuff, I appear to have become addicted... Someone tell me when it gets rediculous and I need to stop. Some background: Today till friday are days off from my day job as a network admin at a College in the UK. I intended to read up a bit more on my MCSD, relax, go shopping, do some coding, etc. I'm actually spending most of it still doing a migration from cobalt server appliances onto a Windows 2003 Standard box (the Linux VDS' are already up and running, and have been now for 11 days). This is for my hobbyish hosting business. Why I'm writing this however is that I'm actually seriously concerned that I have today off, as part of my responsibilities at work include ensuring everything is secure - and that includes running patches of which it appears the one that showed up for the Windows 2003 Server earlier (I didn't recognise what it was for) appears to actually be a very serious one indeed. I expect to see a vulnerability for this flying around the net within the next few days causing appropriate devastation, and all the other things that ensue. I just have to hope that the firewalls, antivirus, and 'overkill' filtering at work actually holds out against whatever nasty bug gets invented. *sigh* Permalink 

My first almost server wide crash. I opened IE (configuring frontpage extensions) on terminal services and somehow it crashed the whole GUI. The last thing I got to do was send an error report. Not a real crash, as the server was actually okay and still serving pages - but still, a real inconvenience and I couldn't reboot it through the admin interface (it said it was rebooting, then did nothing. Same with trying to use shutdown.exe in a telnet session - I intend to install pskill on it ASAP) so was a right annoyance as I had to ticket a hard reboot. There is no way a Windows server is even remotely close to as stable, or as reliable as a Linux server at the moment, the kernel might be - but the user interface and patching is letting the whole system down. UPDATE: I'm really glad I personally know the customers I've already moved onto this server, if I didn't I'd feel really bad about this - instead I know I can make it up elsewhere, but if I had just moved a business critical website over I would be fuming. Permalink 

I got the new server on the 1/2/2004. I applied security fixes and rebooted it. Today, I found another security update to apply. I apply it and it wants a reboot. With the cobalt box, it would run literally for 200+ days without needing a reboot for a patch. I know I moved away from it for security reasons as the patches weren't coming anymore, but Microsoft really need to fix the rebooting of the machine. You don't need to restart ASP.net whenever you replace a web application, so why do you need to reboot the machine when it's a simple service or process that could be restarted on its own? The ability to replace a binary whilst running has been in Linux for a long time (no idea how long) - Microsoft recently added it to Windows in that it provides volume shadow copy services to permit the same kind of thing. So why does it still need a reboot?????? Anyway, enough of my frustrations. At least Microsoft are releasing patches unlike Sun do for Cobalt raq's. Advantage: It reboots fast. Permalink 

My customers like Windows 2003, well so far every one who's tested their site on it. Everyone (so far) who's tested the ftp thinks it's much faster. The ftp speed difference may be related to the hardware difference and current lack of users, 2ghz is considerable. On to a breakdown with more detail, please feel free to ignore this if you're stopping by for progress updates on the migration - it's more just for those who are interested.
  • The DNS server... Well, works. The configuration is again GUI based, which places restrictions on the speed of doing it, where I'd paste another four lines (or use a for loop!) and change the domain I now have to go through a wizard each and every time. Then go back in to turn on notify!
  • I like the look of the ATRN option on the smtp server. It makes what would have been a very painful thing to set up on Linux fairly easy. I dislike the lack of a basic IMAP4 server to go with the POP3 server though.
  • Permissions are massively better on Windows than on Linux, although the defaults always seem a little lax. The ability to fine grain restrictions can only be considered a benefit. cacls (command line tool) is a nice touch too. I miss the tickbox that Windows 2000 had where you could stop the rights being inherited. I know it's one click deeper, but that's annoying when you have to use it fifty times.
  • I want to script changes to the DNS Server, anyone have any ideas? Preferrably without stopping it, editing the registry, then starting the service again.
  • Why do I have to go through the process of manually doing a million things for each user I create. I want to be able to trigger a batch file to run every user that's created, and to create users based on a template!
Well, that's enough stressed babble from me for the moment, I'm off to try to find an alternative to .htaccess files that works on Windows so my users can configure their own restrictions and settings. Permalink 

To those experiencing strange problems with their hosting, this is as per the e-mail. All databases are now coming off xerxes.nullify.net, mysql.nullify.net redirects to it to continue to provide service without interruption if configured correctly in the first place. The databases on shodan are now in read-only mode, and all users are denied access. You MUST e-mail me with details of what accounts you need created on the new server setup. Your sites are already moved onto the new server unless you are paying, if you're paying they're going to be updated on the new server when I have confirmation of the final DNS change that will be coming sometime soon. Several people I own the domains for and host because they're friends have already been moved over, if they are experiencing problems then they need to contact me for their username and password - I'd mail it but without it you can't download your mail! (I'm trying to set them the same as initially - but if you changed your password I won't know.) Permalink 

I've started the test migration of data to the new windows 2003 server, this could be interesting. First points of note:
  • I prefer editing a config file to wiggling the mouse and using a gui.
  • Terminal services is laggy compared to SSH.
  • Microsoft's telnet server is very laggy compared to SSH, easily worse than a full graphics session over terminal services. Not sure how they managed that.
  • IIS 6 is almost the exact same speed on a 2.4Ghz machine as Apache on a 400Mhz machine.
  • PHP doesn't work so well under Windows, but fastcgi almost fixes this. Might just be the way Windows deals with starting new processes.
All in all, I am not impressed. But there is still time for things to change before I change my mind and get a debian server. Permalink 

Okay, I'm looking for comments primarily from users of the hosting regarding a hosting network rework. At the moment the setup is both overkill, and soon to be underpowered. I'm also concerned about the supportability of Cobalt units. I'm proposing to change the setup to one of the following options: Option 1, most outlay, best performance:
  • One UK Server, from dedipower with copious bandwidth and Windows 2003 Standard (expensive licensing is the biggest outlay) - acting as the main web server, main database server, backup mail relay and primary DNS
  • One US Virtual Dedicated Server, with very little disk space and memory but a decent chunk of bandwidth, running Linux - acting as secondary DNS and the primary mail server, but backed up onto the UK server.
Option 2, low(er) outlay, US only and less reliable:
  • One US Server, with Windows 2003 Web Edition - acting as the primary web server and DB server
  • Two US Virtual Dedicated Servers, running Linux - DNS, MAIL, etc.
There are other options, but those are the main two. Any suggestions, comments, ideas? I'll be getting the VDS as soon as possible as it's a part in every single setup and I wanted a backup mail server in a different datacentre anyway. Update: Just bought the VDS Update: Just bought the Win2k3 server, I'll see how it is for a few days before moving anything. Permalink  2 Comments 

The spammers are at it again, please do not mail me complaining about stuff with stupid addresses @nullify.net. The addresses do not exist, and were sent from the spammers directly, I had no involvement. Less than 25 addresses exist at nullify.net itself, of which only three send mail. Please check the message headers and report the issue to the appropriate abuse@ISP address. Permalink 

For 2004! And it appears that the big spam problem I've been having has been resolved, I do hope permanently. I think Microsoft are likely on the right track with 'charging' people cpu cycles to send spam, but fear that it's not going to affect spammers who use distributed trojans to send it. At least until that's not a possibility. Permalink 

This domain does not send spam. Infact, I go out of my way to prevent spam from entering it, and there are preventative measures should anyone attempt to send it. Recently a spammer sent a batch of messages with a return address at nullify.net that didn't exist, and have never existed. Please understand that a from address is easily faked to look like it came from anywhere, and that you should check the message headers for the true origin. If you have more details to enable me to trace this please IM me over ICQ or MSN. Permalink 

So, I think I've stopped updating subconsciously. I do still exist, I'm just thoroughly learning c# and the .net framework and being impressed that I can run stuff anywhere from linux to windows to my pocket pc without recompiling... Very handy. Permalink 

How do you notify a computer user, in a unobtrusive way that they'll still notice and have the opportunity to look at what you want to tell them? It's easy when it's important, you just show a dialog. But what about when it's not important? A system tray icon is sometimes missed, even flashing. The best I've seen so far are those little transparent popups in the bottom right. Any other ideas? Permalink 

I just rolled up a little application called [winunrar] that allows for extracting rar archives. Rar archives have better compression than zip, and this is a free app. Hopefully it'll be of use to someone, and it should mean that those without winrar, who don't like shareware, or generally want something small should still be able to benefit from rar compression! Permalink  2 Comments 

Looks like Microsoft are listening... Voice Command basically fullfills a half of what I was talking about a little while ago. Permalink 

I think I'm going to give C# a try after seeing Don Box and Chris Anderson do a MSDN TV program on Longhorn, programming in C# as easily as I program a page in PHP, yet writing a tile for the sidebar, and doing tcp/ip comms over http in just a couple of simple lines to make a Windows App post to Don's blog. Impressively simple. It might also be a solution to my long standing problem of decent RAD tools that develop for Pocket PC... .Net framework for Pocket PC should be usable from it. Combined with Mono on Linux, C# may well be the future of software development. I'm annoyed I discarded it as another Visual Basic when I heard about it initially... Permalink 

[Sitebuilder] now supports XML and particularly RSS formatting of pages. By including support in the site creation engine I've inherantly got syndication support for any page I feel like, including the main page. Check out the archive and the headlines in RSS - you can now blogroll my musings and silly observations! I've also started removing posts that when converted to XML don't conform to the standard or do but are unusable. It's easier than editing them and I think I want to start afresh. They'll always be in the iarchive if needed. If you're interested in using [sitebuilder] I can probably wrap you up a version under the GPL, so just [contact] me. Permalink 

Dylan Greene has found some pics of vs.net (and aero). Urls are at his site. Interesting... It looks like phpedit but with bits of dreamweaver. Permalink 

You could probably use a bayesian scheme to categorise music by mood based on the similarities of the compressability over time. It'd take training the system in the first place, but then it would probably be fairly accurate as the compressability is directly related to the music content. Then you could always listen to the right music for the moment... Permalink 

Tablet PC's are impractical. Looking at my PDA I find that hard enough to use with a pen - something bigger must be worse. We need a more natural means of control, the keyboard certainly cuts it for speed so maybe separate the tablet pc's screen into a keyboard (not like normal, but more like a pda's onscreen keyboard where applications don't hide behind it.). Voice recognition would be the most natural, but then you might as well scrap the screen and just have a bluetooth headset with a small flip out screen. Then you could see stuff, and hear stuff - whilst being able to dictate things to it too. Clearly we're not there yet... Permalink  1 Comments 

It's possibly the most twisted and inefficient language in existance, taking up an inordinate amount of storage space. It's not even easy to programmatically work with. Then again it's also almost human readable and you can fix almost all problems using notepad/vi. Grrr. Why can't there be a better portable storage medium... Permalink 

Bluetooth should auto-connect to a particular service when it was within range... So a pocket pc will just connect/sync as you walk in the house... Permalink 

There's loads of adverts on the net, but never for what you actually want... That and it's usually intrusive. I mean, I wouldn't mind being able to pull up on demand (a non-intrusive system, not something that comes up constantly) a selection of adverts for a particular thing, in a particular area, possibly with the ability to search by if they accept mastercard/switch/cheque/cash if they can fix your boiler on a sunday, if they have someone you can talk to about a product available at the moment, etc. A single like ebay but for adverts for anything would be handy. Permalink 

Why do people rely on the clock of the computer that the document is being accessed on? Why not rely on the senders clock... To enforce this it'd need for a small part of the encrypted document to exist only on the senders/intermediaries computer. When the document was requested this part could be requested, and sent without fear since the rest of the document is also required. After the time the part can be destroyed on the senders/intermediaries machine. This leaves a giant loophole - once you open the message, you can always read it, it relies on the software to destroy the part it has recieved after using it to successfully show the document. But I fear THAT loophole is unavoidable if the document is ever to be readable. (The document sent is encrypted so that only the correct reader can open it, and only when it's in its entirety.) Permalink  2 Comments 

I want a copy of a couple of days TV schedule on my PDA, preferrably in a searchable format as a simple listbox. That would be fairly useful... How on earth do you write a today screen plugin? Permalink 

My PDA isn't useful enough sitting on the desk whilst I'm at my machine. It should interact with the computer when I dock it and automagically: - Log into my chat mediums - Notify me of new e-mail rather than my computer, keeping the computer for work - not as a place to press F5 lots on a mail window - Notify me of new events, happenings and other things that would normally have me visiting sites - Be an information source that's not on screen, and therefore not a distraction Perhaps I can virtualise this by loading a page in IE that pulls data off my servers and shows the info? I don't have the first clue about programming on a pocket pc device... Shame you can't compile things in Delphi for it. Permalink 

Folders that show the contents of the inbox filtered would be handy. Permalink 

http://www.theregister.co.uk/content/31/30699.html Join The Registers cancer busters team, download a bit of software, and your computer will be scanning molecules for cancer fighting abilities while your computer is idling. Permalink 

I'm at work at the moment, but I just this morning tried Trillian 2 beta and have to share the good news that it has [jabber] support! I mean, yes - you have to pay for it, but it's well worth it and at only £15 approx it's not that expensive. Check out their website at www.trillian.cc and see if you like the free version. If you do you'll love the pay for version. (Hey, at least they're not paying me for the ad) Permalink 

I'm now the highest possible battle rank in Planetside (A MMOFPS - or massively multiplayer online first person shooter. Bet you didn't know that eh? Game with lots of people is more descriptive...). I still have another three command ranks to go, but what happens when you complete a MMOFPS? *breathes* Do you stop paying the monthly fee and never return, or do you continue paying, but not play except occasionally? A question for the ages... Permalink  2 Comments 

I've built an installer to download and install PuTTY - a free SSH client. It's available from the [putty] page. Permalink