Setup.EXE bootstrap for WiX and/or msi
MSIEXEC /i My.msi REINSTALL=ALL REINSTALLMODE=vomus
Not exactly user friendly. So it was time to create a nice setup.exe bootstrap to detect when an upgrade was needed and issue the horror statement. A quick tour around the Windows SDK brought up the their sample. Written in Win32/C++ it seemed to be over complicated especially since I know the product is only ever going onto machines with .net pre-installed. So I wrote the following little csharp console code that does the trick for my requirements.
static
void Main(string[] args){
Type componentType = Type.GetTypeFromProgID("WindowsInstaller.Installer"); if (componentType == null){
Console.WriteLine("Windows Installer is either not installed or could not be located"); return;}
object componentInstance; try{
componentInstance =
Activator.CreateInstance(componentType);}
catch (Exception e){
Console.WriteLine("Windows Installer is either not installed or could not be located: " + e.Message ); return;}
object returnType = componentType.InvokeMember("Products", BindingFlags.GetProperty, null, componentInstance, null); IEnumerable stringList = (IEnumerable)returnType; bool foundProduct = false; foreach (string product in stringList)
{
if (product == "{YOURPRODUCT_GUID}"){
foundProduct =
true; break;}
}
if (foundProduct){
System.Diagnostics.
Process.Start(@"msiexec", @"/i My.msi REINSTALL=ALL REINSTALLMODE=vomus");}
else{
System.Diagnostics.
Process.Start(@"msiexec", "My.msi");}
}
Optimizing Virtual PC
Fun with Enums
Consider the following Enum…
Medal.Bronze = 0
Medal.Silver = 1
Medal.Gold = 2
The majority of cases people leave it as an int (can be any non-char integral type). However, what happens when you want to store/persist the type? If I was to save this to a disk file I might choose to use XML and have a result like…
<Medal>2</Medal>
Then when I load the XML back I can easily convert it back…
Medal medal = (int)Convert.ToInt32("2");
However, I don’t actually like this, the value of 2 has no real meaning to the reader, I’d much prefer to see
<Medal>Gold</Medal>
Well it is possible. To save the name rather than the value you can use ToString and a format string…
medal.ToString("G");
Reading the name back into the enum uses the often overlooked Parse method…
Medal medal = (Medal)Enum.Parse(typeof(Medal), "Gold");
Admittedly this doesn’t solve localization problems of having XML, "human readable" but I prefer it.
Constellation of Features
1. Like a star field, here are so many stars that you have trouble singling out anything interesting
2. Like the ‘bigger dipper’, ‘the archer’, etc it is supposed to show or signify something to one person but to others it is impossible (or very hard) to recognise
3. A group of related features
In the talk the phrase was in the context of applications like Word where there are so many things to choose from that the user is simply bewildered and will find it difficult to focus on the task they wish to complete, i.e. (1). But I rather like the other definitions too, especially (3) which conveys the opposite message.
Query Analyser vs. SQL Management Studio
SQL Server Dynamic Help
Remote Desktop Clent 2.0 for the Mac
MyRemoteMachine /console
It hasn’t been without problems, currently I only get a blank screen after a tried to start in full screen mode. I’ll see what happens after a reboot.
[Edit] Setting the colour depth down and then back-again seemed to stop that problem.
Javascript, scope fun with the for loop
function A()
{
for (index = 0; index < 10; index++)
{
alert(index);
B();
alert(index);
}
alert(‘finish’);
}
function B()
{
for (index = 0; index < 10; index++)
{
// do nothing
}
}
I ran this on Firefox/Safari and got….
0,9, finish
I was surprised on two counts, 1. Why didn’t the for loop work? 2. Why the shared scope? Anyway assuming I had accidentally created a global I corrected it and it worked as expected…
for (var index = 0; index < 10; index++)
Xml and XPath on the client via JavaScript
client browser using JavaScript. Normally I wouldn’t entertain the
thought but with the recent push of AJAX and various cross-browser
script libraries I thought I’d take another look. NB. This doesn’t
consider JSON, I’ll post on that option later.
XmlDocument
The
core requirement to most XML processing (ignoring SAX style processing)
is the document. AJAX has helped here and it seems that the majority of
browsers implement some form of Dom but they do suffer from
inconsistencies.
HttpRequest
Probably the most
reliable object is HttpRequest, which is a necessity for AJAX. There
is a cross-browser issue but it’s fairly simple to solve…
if(window.XMLHttpRequest && !(window.ActiveXObject))…
httpRequest = new XMLHttpRequest();
…
if(window.ActiveXObject)
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
after
that the objects seem to use the same API. There does seem to be some
drawbacks with this approach, you need a web site (or service) to get
the XML from and the lack of XPath support.
XmlDocument revisited
"But
I don’t want to fetch my XML from a site, I created it on the client",
I hear you cry. Well most browsers support the following…
if (document.implementation && document.implementation.createDocument)…
xmlDoc = document.implementation.createDocument("", "", null);
…
if (window.ActiveXObject)
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
similar
in nature to the previous cross-browser test. These have good DOM
support and you can create/append elements as you’d expect. The load
method seemed a bit flaky. Now this maybe my code so I’ll hold off
saying it doesn’t work…but it didn’t seem to! But creating the DOM
manually seemed fine so it is still useful, especially for sending data
back. However, the biggest issue seems to be XPath
XPath
XPath is a very useful API for searching XML but its support in
browsers is very patchy. Mozilla based browsers offer a good implementation…
var paragraphCount = document.evaluate( ‘count(//p)’, xmlDocument, null, XPathResult.ANY_TYPE, null );
and it includes NodeIterator for a selectNodes style enumerating.
Microsoft has the more usual (I’m an MS developer) SelectNodes, again
very easy to abstract out the difference in API. However…Safari. The
Konqueror based browser simply doesn’t like XPath. So what to do? I
considered writing my own query engine but I don’t really want to waste
my time re-inventing the wheel. So I had a look for a script library,
but it seems like XPath libraries and are still in their infancy. Of
the ones out there XML for SCRIPT
looked promising but still not 100%. At this point I realised that for
my specific needs I could get away with a bit of DOM walking so I left
it there.
Conclusion
My conclusion is that XML support in the browser is ok if you base your
work around HttpRequest. But if you want to do XPath then look for an
alternative.