NullifyNetwork

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

Archive - Historical Articles

You are viewing records from 02/19/2005 15:19:57 to 01/30/2006 13:54:29. I'll be adding support for selecting a date range in future.

The missing ones for Visual Studio 2005 (including some quite nice ones) are available from MSDN here.

Permalink 

As everyone here knows I'm a bit of a C# fanatic... And I just found Python which is a perfect complement to C#! It lacks the heavy duty features of C# but does have simplicity and speed of programming for 'getting an answer' making it an ideal scripting language.

Which leaves only one thing to do, mix them together! IronPython does just this - it is a version of Python written in C# and designed to run inside .NET programs. This video on MSDN TV is a good introduction to it!

I've even found a couple of pocket pc python interpreters out there which is nice.

Permalink 

I am SO happy I've found the solution to this annoyance - from http://msdn.microsoft.com/vstudio/support/knownIssues/default.aspx:

1.45 Using Windows Roaming Profiles may cause first time launch message to show on each startup.

When any one of the Visual Studio family of products is used with Windows Roaming Profiles, the first time launch message that says "Visual Studio 2005 is configuring the environment for first time use. This might take a few minutes." might appear on every session startup. This might cause unnecessary slowdowns in startup performance.

To resolve this issue

Click on the Tools > Options... Select "Import and Export Settings", and change the path under "Automatically save my settings to this file:" to a path that is NOT under the "My Documents" directory.

Permalink 

So I noticed an article mentioning you couldn't get clickonce working in Opera or Firefox. Well, I don't know about Firefox but I've had it working in Opera 8 for some time now.

The first problem you hit is that the framework isn't returned in the user agent. To solve this create a folder in your my documents called OperaJS and a new text document adddotnet2.js. Include the following:

// Adds the user .NET CLR user agent
navigator.userAgent = navigator.userAgent+'; .NET CLR 2.0.50727';

Now when looking at a clickonce install site you get the option to just install (make sure you actually have 2.0.50727).

The next step is to make Opera pass the url to the .application file format to EXPLORER. I would pass this to the appropriate file to run it, but then it won't be in the right context so we'll settle for a little dodgyness.

Click Tools, Preferences, Advanced, Downloads then add a new mime type of application/x-ms-application with an extension of application, then check "Open with other application", enter "explorer.exe" and check "Pass web address directly to application".

Now you should be able to navigate to clickonce applications and use them as if you were in IE!

Update 5th July 2008:

There is a firefox add-in here.

Permalink 

Well, I'm off to someplace with work, if anyone needs to contact me be prepared I'll be on roaming and not available like normal. Permalink 

Well, so far I'm unhappy with SQL 2005 and I've given it a full month so I'm going to rant a bit.

Microsoft did a good job of making visual studio 2005 pretty solid (although the visual designer is so very slow), but SQL 2005 is lacking in features that used to be there, and seems to consume far more resources than it ever used to.  Why can't I import/export objects (to move a database around) for one thing?!?

It seems enterprise manager and query analyser are much better than SQL management studio in almost every way (even usability, there's definitely more clicking needed to get things done in the new management studio and others have agreed with this).

I have a variety of hardware (from low spec with just 512MB ram and a 3Ghz cpu to a dual 64bit beast with gigs of RAM) running the new tools, and there is no solution to the unbelievable slowdown experienced when managing the system (I haven't been able to find any actual decrease in query performance against the server process although it now regularly consumes 15% on  machines whilst idle).

Taking copying a database between servers as an example of my frustration, on two machines I have:

TITLE: Copy Database Wizard
------------------------------

No such interface supported

Errors when trying to copy a database using SQLDMO.

On a working machine I found that it can't copy to or from SQL 2000.  Then I found it can't copy to SQL 2005 express.  What's going on up there, did nobody test these features and if so what cloud were they on when they shipped something incapable of moving databases around?

At present I have to generate scripts for everything, then run them against the other server, then run a set of hand built scripts to enter the data...

Resolution (29 Jan 2006): Run the following to register MS XML again:

regsvr32 msxml3.dll
regsvr32 msxml6.dll
I have no idea how this got broken and why nothing else was working, but I did have the old version on the system. Still, scripting and copying doesn't work properly but apparently its being investigated.

Permalink  1 Comments 

I've been playing with Microsoft Sharepoint and have to say I'm very impressed...  I might replace this site with a sharepoint site if I can make it do exactly what I want (which I should be able to do! I can program webparts for it...) Permalink 

Hot on the heels of its big brother SQL 2005, SQL Express now has a management studio that provides similar features to the tool I was originally writing for MSDE!

Available for download from Microsoft now, it offers a nice selection of features that the free version of SQL was always missing (it's annoying when you have an engineer on site and they are struggling to find a problem that could be located with a single query!). Permalink 

My MSDN subscription is a bit broken at the moment unfortunately but it appears that Visual Studio 2005, .NET 2.0 and SQL 2005 are now all out and available to download!

Permalink 

There is currently a threat of another large hurricane, this one is likely to make landfall and directly affect the area that my datacentre is located in (Houstan, Texas).

Although over 10,000 gallons of diesel are already on hand please ensure that queeg.nullify.net (located at Fortress ITX in New Jersey) is correctly set up to provide backup DNS and/or mail as needed.

Good luck to everyone staying behind in the datacentre in the face of the evacuation and the storm.

Permalink 

As many of you know, I am a great fan of Opera. It has proved to be a highly secure, fast and powerful browser... Basically sites work and work well, and I can limit what they can and cannot do.

Now thanks to google changing their contract with opera when it comes to ad revenue from searches they can afford to make it 100% free.

Totally written from scratch and not based on Mosaic, Mozilla, IE or any other existing browser, it supports the following operating systems:

  • Windows!
  • Linux (a large number of distros AND a tar.gz)
  • FreeBSD
  • Solaris
  • OS/2
  • QNX
  • And a large number of mobiles
  • Mac

I still urge you to pay for premium support or whatever they call their subscription service in support for this great browser; but hey, if you can only pay by using it that's still good.

Permalink  6 Comments 

Here's a static method that sets a printer as the default on a system, using the windows scripting host network stuff from C#.  It's here so I can look it up if anyone else asks in future since I couldn't easily find how to do this in C#...  (I know the exception handling is poor)

/// <summary>
/// Sets a default printer
/// </summary>
/// <param name="name"></param>
public static void SetDefaultPrinter(string name)
{
   try
   {
      //late bind to the wsh network com object
      //create an instance of a reflection type
      Type t = Type.GetTypeFromProgID("WScript.Network");
      //create an instance using the system activator, consuming the type
      Object o = Activator.CreateInstance(t);
      //invoke the method using the object we created
      t.InvokeMember("SetDefaultPrinter", System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] {name});
   } 
   catch (Exception)
   {
      throw new Exception("Unable to set a default printer. The printer may not exist or the WScript.Network com object may have a problem.");
   }
}

Permalink 

Hosted sites may start to experience routing issues, I've had several messages regarding them already. I suspect this is as the diesel runs out at telco sites in or around the Gulf Coast. Ev1 are doing a great job in Houston and there are no visible problems with connectivity over here in the UK/Europe. Permalink 

You can get a free license key for Opera (similar to firefox but commercial, faster, more secure, smaller and with a lot more features - like torrent support) at their 10th birthday party!. Permalink 

I've worked on this for a total of eight hours now inbetween everything else, but this is a sneak peak of a new product/freebie I am working on.  Take special note of the syntax editor...  I couldn't make richedit do what I wanted, so have been writing a syntax highlighting, intellisense supporting editor from scratch.

Eventually it will colour keywords and provide region support, but just showing text, the line numbers, a movable cursor and scroll bars was a milestone for me given it is done totally from scratch (even if the scrollbars are yet to be mouse enabled).

Zorg Sql Manager

Permalink  2 Comments 

I am still alive, and I must apologise for not posting anything to my blog but work has been eating most spare time whilst I've been getting some software out the door.

Hopefully work will no longer need so much of my time though, so I've started a few projects, one of which is a management studio for MSDE/SQL Express that allows profiling and various other features that I can't find anywhere else (some are in the toolset that Microsoft ship which isn't licensed for use with MSDE and isn't freely downloadable, but some aren't to be found anywhere afaik).  Just trying to add intellisense to my query execution part of the application now.  One bug to fix with stopping traces and I'll put a version up for download.

In unrelated news I've also enabled SPF on all the domains on xerxes using Mail Essentials from GFi, so those of you with e-mail on queeg are the last not to get it - hopefully debian has something to implement SPF with exim otherwise I'll need to write something to wrap it...

Permalink 

Apologies for the lack of posting, but crunch mode at work whilst approaching beta has stopped me having time.  I'll probably get some more posted when it's over. Permalink 

This is good fun :) - a DHTML lemmings remake!

http://193.151.73.87/games/lemmings/index.html

It works on IE and Opera, so I have no doubt it'll work on Firefox/Mozilla.

Permalink 

[ Taken from my post at the ms forums here: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1014 ]

This is a bit bodged but I just hashed it together to see how easy it would be.  I thought back and could have just iterated over chararray, but it works which is what counts :D

/// <summary>
///
Represents a paragraph in English
///
</summary>
public
abstract class Paragraph
{
///
<summary>
///
Convert a string in arbitrary case to English sentence capitalisation.
///
</summary>
/// <param name="text">The text to convert
</param>
/// <returns>The paragraph of text
</returns>
public
static string ToSentenceCase(string text)
{
string
temporary = text.ToLower();
string
result = "";
while
(temporary.Length>0)
{
string
[] splitTemporary = splitAtFirstSentence(temporary);
temporary = splitTemporary[1];
if
(splitTemporary[0].Length>0)
{
result += capitaliseSentence(splitTemporary[0]);
}
else
{
result += capitaliseSentence(splitTemporary[1]);
temporary =
""
;
}
}
return
result;
}

private static string capitaliseSentence(string sentence)
{
string
result = "";
while
(sentence[0]==' ')
{
sentence = sentence.Remove(0,1);
result+=
" "
;
}
if
(sentence.Length>0)
{
result += sentence.TrimStart().Substring(0, 1).ToUpper();
result += sentence.TrimStart().Substring(1, sentence.TrimStart().Length-1);
}
return
result;
}

private static string[] splitAtFirstSentence(string text)
{
//these are the characters to start a new sentence after
int
lastChar = text.IndexOfAny(new
char[] {'.', ':', '\n', '\r', '!', '?'})+1;
if
(lastChar==1)
{
lastChar = 0;
}
return
new string[] { text.Substring(0, lastChar), text.Substring(lastChar, text.Length-lastChar) };
}
}

Permalink 

[posted by me on the new Microsoft Forums at http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1266 ]

ProcessStartInfo pi = new ProcessStartInfo("cmd.exe", "/c dir");
pi.WindowStyle = ProcessWindowStyle.Hidden;
pi.RedirectStandardOutput =
true
;
pi.UseShellExecute =
false
;
Process p = Process.Start(pi);
p.WaitForExit();
p.Start();
TextReader t = p.StandardOutput;
MessageBox.Show(t.ReadToEnd());

Permalink 

A colleague of mine at work was having some trouble with multithreading this morning and I suggested using asynchronous delegates (a delegate - something you can make do something else, in .NET this can be used as a form of trigger for starting any number of other methods that take and return the same parameters as it uses - that runs its methods in another thread).  This got me thinking so I decided to do a quick tutorial for anyone else who hasn't yet encountered this way of doing multithreading!

This is a short sharp example, and can be created in a simple form.  Remember not to try to update the form from the method being run by the delegate - if you want to do this you need to run a method that checks if InvokeRequired is true, then runs Invoke(myMethodsOwnName, new object {myFirstParameter, mySecondParameter, andSoOn}) if it is true, or does whatever UI editing is needed if false - so it is calling itself in the context of the user interface.

Anyway, on with the example!

/// <summary>
///
A button on the form
///
</summary>
private
void button1_Click(object sender, System.EventArgs e)
{
   delegateInstance = new
ExampleDelegate(beginThink);
   d.BeginInvoke(5, new
AsyncCallback(finished), null);
}

This is where the program runs, a simple button that can be pressed.  We want to do something CPU intensive and blocking in here but instead we create an instance of a delegate and use the BeginInvoke method, the methods parameters come first (in this case 5) and then the callback method to run, and null for the object state.

/// <summary>
///
An instance of the delegate used to call a method asynchronously
///
</summary>
private
ExampleDelegate delegateInstance;

/// <summary>
///
The example delegate
///
</summary>
private
delegate string ExampleDelegate(int param);

/// <summary>
///
The example method that would block the user interface
///
</summary>
/// <param name="workOn">Number of seconds to block for
</param>
/// <returns>Some string
</returns>
private
string beginThink(int workOn)
{
   Thread.Sleep(workOn*1000);
   return
"Done";
}

This is our ficticious CPU intensive action, in this case we'll just block the thread by seeping for workOn seconds.

/// <summary>
///
The method that is called when work is done
///
</summary>
/// <param name="results">The results of the work
</param>
private
void finished(IAsyncResult results)
{
   MessageBox.Show(delegateInstance.EndInvoke(results));
}

And this is run when the asynchronous delegate is completed.  EndInvoke automatically return the same type as the delegate, (a string) which makes this nice and easy.

Permalink 

Two days ago I got my new P7010 laptop, although it's hardly large enough to be called a laptop with a tiny 10.6" screen and being light enough to use with one hand whilst holding it with the other.

This is a review, or maybe a quick pass over it.  I'm typing it on it, but I won't be doing any serious coding on it due to some oddities with the keyboard layout (cursor keys, home and end which I regularly use are all one thing and need to use the fn key, which is in the wrong place being between ctrl and windows rather than on the far left.  And the delete key is in the top right.  I'll upload some pitctures to my public photo album shortly.)

There are several things nobody says when they talk about this laptop, and I wondered whether I should buy it because of this.  I'm very glad I did.

Firstly, it runs 3D games very well - if you use lower end settings.  This is to be expected with an Intel extreme graphics chip in it, and it's a tradeoff you need to make for the small size and long battery life.  I've yet to try Half-Life 2, but will update this post if I get a chance - probably on the weekend.

The 1.1Ghz processor easily beats a P4 3Ghz processor in appearing to be fast, it may not when encoding an MP3, or some other maths intensive task but it seems highly responsive - infact it appears as responsive as my Opteron workstation when using applications (although the drive is slower, however this is to be expected 10,000 rpm is physically a lot faster than 4200 rpm!).

Next, the screen everyone says is too high res for the size IS too high res for the size - but I've noticed that after using it for a short while I have easily gotten used to it.  Maybe support for 1024x640 would have been better than 1280x768, but this is at least future proofed for when Windows is fully vector based and will scale.  The screen is extremely crisp, clear and bright, though reflective and needing cleaning to prevent dust accumulating.  The screen is perfect for DVD's and videos - anything that scales..

It also has a slew of standard and not so standard features: Wireless, cd/dvd drive (in such a small laptop!) sd/mmc/memory stick reader, compact flash and seperate PCMCIA slot, two USB ports, video out, LAN, international modem, svideo and firewire.  An impressive battery life (so far tested to 6 hours 50 minutes real world use, with wifi on, without the second battery and with the screen not on the lowest brightness) rounds it off.  An impressive selection of modular options from Fujitsu Siements also makes this a very versatile device.

Missing features: GPRS/GSM, Camera, Bluetooth, serial and parallel ports, rear connectors (everything is conveniently on the sides), a top catch (although it seems to be sprung with some kind of mechanism that holds it shut and closes it quickly, but allows the screen to move freely to any angle), and dedicated graphics memory and card.

Overall I'm very impressed.  Apart from bluetooth most of the features are either not neded or an acceptable tradeoff for a device this small, the absence of bluetooth however should have meant the necessity of GPRS/GSM in a portable device - yet I am fine with wifi for the places I go.  As a large (book sized) PDA it serves well, as something to take notes on it beats a pda hands down - as you can see from this having been typed on it (I have no trouble touch typing on it).  As something to code on, we shall see.  As an entertainment device - well, you can watch dvd's, listen to music and play games - what more do you want?

I don't recommend anyone try to make such a small device their primary laptop or even worse primary computer without an external screen and keyboard/mouse however if you want small and portable because you travel or just don't want to carry a full laptop then this is the machine for you.

Permalink 

I've been looking for a good .NET profiler and always been hit by large price tags, bloated software and general failure.

So, I was happy to discover the person that made NAnt also makes NProf!  http://nprof.sourceforge.net/Site/SiteHomeNews.html

I had to delete regasm.exe from his archive as it throws an exception for some reason, but when using the one on my system it registered fine and is now working - happily integrated into Visual Studio .NET :)

Permalink 

Mere minutes after posting about VSA I notice a post on developer fusion by Mark Belles that is MUCH better at describing Microsoft.VSA - I suggest if your interest is peaked by my sample code you go have a look at his article!

Permalink 

Have you ever wanted to be able to add scripting to your application?  So your users can write a script and you can have it run inside it, adding menus, etc. - like Microsoft Visual Basic for Applications allows in Office.

This is a preliminary article, I'll try to rewrite this but I just took a 20 minute break from work (need to have something done for tomorrow - so yes, still working at 10PM!  GRR) and finally managed to get scripting using Microsoft.VSA working from a C# application.  Apologies for the lack of tabs in the formatting and lack of explanation.

This is missing the ability to access anything in the running application - you need to register a global item (in the same way as code items and references are added) to do that - then it is exposed as an object inside the environment running the script.

Add references to Microsoft.VisualBasic.Vsa and Microsoft.Vsa (when I repost I'll be using JScript.NET - never fear!) and add the following using clauses:

using System.Reflection;

using Microsoft.Vsa;

using Microsoft.Win32;

And then add the following code to a button or similar (with a textbox to enter your script in) - this will create a scripting engine object, then run your script inside it.  The best test is to show a message using MessageBox.Show(""); (remember though, it's VB!)

ScriptEngine eng = new ScriptEngine();
eng.Start();
IVsaCodeItem c = eng.CreateCodeItem(
"ScriptItem");
c.SourceText = textBox1.Text; //Where this is a simple vb.net script with a class called Script and a Sub called Main
eng.Run();

And now, the main code chunk snippet that is the scripting engine:

public class ScriptEngine : IVsaSite
{
private IVsaEngine Engine;
public ScriptEngine()
{
Start();
}

public void Start()
{
try
{
Engine =
new Microsoft.VisualBasic.Vsa.VsaEngine();
Engine.RootMoniker =
"myapp://net.nullify.www/ScriptEngine";
Engine.Name =
"vsaEngine";
Engine.RootNamespace =
"VsaEngine";
Engine.Site =
this;
Engine.InitNew();
CreateReference(
"Mscorlib.dll");
CreateReference(
"System.dll");
CreateReference(
"System.Windows.Forms.dll");
CreateReference(
"System.Data.dll");
CreateReference(
"System.Drawing.dll");
CreateReference(
"System.XML.dll");
}
catch (VsaException ex)
{
MessageBox.Show(
"Scripting engine error: "+ex.Message);
}
}

public IVsaReferenceItem CreateReference(string assemblyName)
{
IVsaReferenceItem item = (IVsaReferenceItem)Engine.Items.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
item.AssemblyName = assemblyName;
return item;
}

public IVsaCodeItem CreateCodeItem(string itemName)
{
try
{
IVsaCodeItem item = (IVsaCodeItem)Engine.Items.CreateItem(itemName, VsaItemType.Code, VsaItemFlag.Class);
return item;
}
catch (VsaException ex)
{
MessageBox.Show(
"Problem creating the code item: "+ex.Message);
}
return null;
}

public void Run()
{
if (Engine.Compile())
{
Engine.Run();
Type type = Engine.Assembly.GetType(
"VsaEngine.Script");
MethodInfo method = type.GetMethod(
"Main");
method.Invoke(
null, null);
}
}

#region IVsaSite Members

public object GetEventSourceInstance(string itemName, string eventSourceName)
{
// TODO: Add ScriptEngine.GetEventSourceInstance implementation
return this;
}

public object GetGlobalInstance(string name)
{
// TODO: Add ScriptEngine.GetGlobalInstance implementation
return null;
}

public void Notify(string notify, object info)
{
// TODO: Add ScriptEngine.Notify implementation
}

public bool OnCompilerError(IVsaError error)
{
MessageBox.Show(
"["+error.Line+"] Compiler error: "+error.Description);
return true;
}

public void GetCompiledState(out byte[] pe, out byte[] debugInfo)
{
// TODO: Add ScriptEngine.GetCompiledState implementation
pe = null;
debugInfo =
null;
}

#endregion

}

And finally to test this you can use the following code:

imports System
imports System.Diagnostics

module Script
sub Main()
MessageBox.Show("Boo")
end sub
end module

Permalink  2 Comments 

Robert Scoble is once again on his high horse about how RSS is amazing, comparing it to GUI versus CLI without looking at how primitive RSS itself is.  I propose it is around the other way, and that there is a successor for RSS out there.

RSS and ATOM as they are today WILL become extinct - or at least as limited as CLI's are today, with a small following; syndication and a standard way of reading content from a site without visiting the URI in a browser are going to be around for ages - I have no doubt about this.

The key is that someone needs to define a standard (e.g. - based on SOAP since we already happen to have it!) to query a 'feed' (now, we can term it a web service) for:

  • New entries without content since a previous point in time
  • New entries with content since a previous point in time
  • All entries ever
  • A specific web log entry
  • Comments for an entry
  • All comments since a point in time
  • All comments ever
  • An entry with comments at the same time
  • Indicating you linked to a post or comment
  • Posting a comment
  • And to 'subscribe' where you are e-mailed or IM'd (or using msn alerts, or Jabber alerts or whatever) when there is an update.

It is inevitable, RSS uses too much bandwidth and gives duplicated content only when you request it which means you need to keep checking back (even if you get a HTTP message to say it hasn't changed).

A web service could make available only the necessary information in a smart way, it could track and push information in the background to notify when your aggregator needs to look at your RSS/ATOM data for new entries, and it could allow a full integration of the site with the aggregator for comments.

Robert needs to look forward, not back...

Permalink 

http://me.sphere.pl/indexen.htm

MoonEdit is a multi user text editor, it lets two (or more) people simultaneously edit a single file, with multiple cursors, entry points and near real time collaboration.

I've been waiting for something like this for a while, after posting about it first, then a year or two later seeing SubEthaEdit for the Mac.  Hopefully someone (http://docsynch.sourceforge.net/) will come up with a plugin for Visual Studio.

(Links curtesy of ntk.net)

Permalink