Stephan Dekker

If you are out to describe the truth, leave elegance to the tailor. (Albert Einstein, 1879 - 1955)

 

Create your own VBA module in Excel:

Sub exportAllModules()
    
     '  reference to extensibility library
    
    Dim objMyProj As VBProject
    Dim objVBComp As VBComponent
    
    Set objMyProj = Application.VBE.ActiveVBProject
    
    For Each objVBComp In objMyProj.VBComponents
        If objVBComp.Type = vbext_ct_StdModule Then
            objVBComp.Export "C:\temp\" & objVBComp.Name & ".bas"
        End If
    Next
    
End Sub

Add reference to:

Microsoft Visual Basic for Applications Extensibility

Give trust to the macros:

1. Open Excel 2007.
2. Click the Office Button (top-left most button in the window)
3. Click the Excel Options button.
4. Click Trust Center in the menu on the left.
5. Click Trust Center Settings in the window on the right.
6. In the new window that opens click Macros in the menu on the left.
7. Check the box next to Trust Access to the VBA project object model.
8. Click OK.
9. Click OK.
10. Close all Office applications and try your project again.

 

Happy days!

Posted by Stephan Dekker
Filed under:

For one of my customers I needed to run a financial risk calculation on a Solaris box. The original app is written in C# .NET and targeted for Windows usage. Given my 2 previous posts, it shouldn’t come as a surprise that I choose to use Mono to run the app on Solaris. The whitepaper said I could, so sure it will work.

As said, I created a Ubuntu VM in about an hour(!), configured it in another hour and was ready to do the actual Mono work. Ubuntu has Mono installed by default, so all I had to do is compile the app (and run DotFuscator, just for good practice) , copy it to the linux box via a fileshare on my physical machine and copy it to a folder on the linux box. Happy days, it all works fine.

With that POC working, I ticked the box for managing risk around running the app with Mono and running Mono on Linux. The latter was actually only ticked half, as it was pre-installed, but being a poor dev and not sticking to proper Agile practices, I ticked the box anyway J

I got the login details of the SUN box, which I didn’t have to install and configure luckily. What I read and have heard, Solaris is a whole different installation experience as opposed to Ubuntu. I’m not sure if SUN has the ability to download a Solaris box as a VM, but I had the real thing and a powerfull one as well, so why bother with VMs.

Another happy moment, was when I got the choice of logging in with console or through the XWindows. XWindows please, thank you! J

First thing after logging in was to open a console and try “mono -?” Doohh!!!! No Mono!!!

Off to the Mono-project website to see what they are saying about this topic:

http://www.mono-project.com/Other_Downloads

Basically you need to install a tool to install other packages, so it’s sort of the open source “Windows installer” tool. The installer tool uses the underlying “pkg-get” (The “Windows installer service”) to actually install the packages (MSIs). The difference is that the unix tool uses a list of packages you can install. In our case you can invoke it like: “TheInstallTool –i mono” and it will install mono.

The tool is called “pkgutil” and can be found on: http://www.blastwave.org/. On the first page there is a little bit hidden link, called “READ THE HOWTO”. CLICK ON THAT!!! This will take you to a page of instructions.

Step 1: Be Patched Up To Date

I didn’t know: A) how to do this, B) wether I was or needed to do it in the first place. So I assumed I was up to date and soldiered on...

Step 2: Install pkgutil

That’s the tool we need to install. Make sure you’ve got the correct version of the script, but in my case I ran the following commands:

·         uname –a

·         cat /etc/release

·         pkgadd -d http://blastwave.network.com/csw/pkgutil_`/sbin/uname -p`.pkg

·         mkdir /etc/opt/csw

·         cp -p /opt/csw/etc/pkgutil.conf.CSW /etc/opt/csw/pkgutil.conf

You should end up with an exact copy of the log up on the blastwave website. I actually had one error/warning that the /etc/opt/csw already existed, but that did stop me from continuing.

Step 3: Fetch the Software catalog

Makes sense doesn’t it? When you have an app that can install from a catalog, to download it?

/opt/csw/bin/pkgutil --catalog

Step 4: Security First!

Yeah right, on to step 5...

Step 5: Before you proceed...

Don’t mess with the root account... yadda, yadda, yadda... Ok, I’m done.

Well, as it turned out. I wasn’t. The very important bit is in the second last paragraph, to set the path: PATH=/opt/csw/bin:/usr/sbin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/ccs/bin

That took me an hour to figure out where the bloody hell Solaris installs the files. Hiding details is great until stuff goes pear shaped. Also RTFM applied, very true. Let’s call it a draw.

At that stage my “mono –?” did return me something! Not sure anymore wether it showed me the Man page or complained about incorrect commands, but the mono command was found and that meant: On to the next stage!

I copied the DotFuscated, on windows compiled to the “All CPU” target,executable (the bin/debug/MyRiskConsoleApp.exe"/ to a filer in the cloud. Went back to the SUN box, opened Firefox and copied it from the filer to the machine.

I’m sure you can imagine that I was very excited when the command: “mono /users/sdekker/Desktop/MyRiskConsoleApp.exe 1000 2” didn’t came back with errors, but with the calculated results!

I explained the coolness to my wife, but I don’t think she really grasped my excitement of it all... J

Another job well done, Stef!!

Posted by Stephan Dekker
Filed under: , ,

I already figured it out from the website, but it's nice when the website is actaully correct: Ubuntu comes with Mono installed. Some apps, F-Spot for instance, need it, so it's installed out of the box.

I just compiled a hello world, console app, copied it to my virtual Linux box (Share on my Win box asVirtual PC doesn't allow higher resolutions than 800x600 for some reason and that makes the Ok button for the "Sharing permissions" window, drop out of reach) Browsing to my local box btw is a pretty awesomeexperience. Not as awesome as, let say, diving with whales, but still.... You open up the "Windows Network" folder, the machine then goes off and finds you all the domains on the network, which is, in my case, My own AD domain at home, My company AD domain as I'm using my work laptop, Workspace and another insignificant one. Probably my router come to think of it... So you'll double click on the domain you need and it go out and find all the machines on that domain. If you then double click on the machine it asks you to login, so I punched in the username, domain and password and Bang! I'm in!!

Sorry, focus....

So compiled my hello world console app, opened linux pulled it from a share on my windows host OS and copied it into a folder under my user account. Don't know if that matters, but just to be safe. Double clicked.....   Error.... Damn....   Double clicked again.....  Error again.... Bloody computers, allways so consistent....

What you need to do is run it with mono. (Mind the lower case btw.) So open a console window and use:

mono DotNetHelloWorldApp.exe

And capow!!! a nice hello world message is staring right in the face!

I haven't tried any fancy stuff, but I have seen windows and other trivial .NET features being used, so it shouldn't give me a lot of grief.

Take care!

 

Posted by Stephan Dekker | with no comments
Filed under: ,

I last worked with Linux ages ago and now need to run a couple of tests with Mono on a Linux box. I'm not counting a couple of Cygwin incidents during my working days at “Vrije Universiteit”, as that's not Linux, that's actually sort of cheating. :-)

So, to brush up my skills I took it upon myself to finally try Ubuntu Linux. I downloaded 9.10 and apparently they are now naming the versions. This version is labelled "Karmic Koala" which seems too much of a coincidence (I live Down Under for a couple of years)

Anyway: Downloaded the ISO, fired up a fresh Virtual PC, mounted the CD and choose Install from the boot menu. Waited for 30 min and Happy Days! The machine comes up with a nice brownish background and starts asking about time zones, keyboard layout, etc. I punch in all the details, give a username and password and all done!

It works fantastic. I must say that Linux has come a long way as an OS. It’s slick, no driver nonsense, all goodness.

I’m now setting up file sharing, which means installing and running Samba if I remember correctly and that did give me some grief. Apparently if you choose DHCP, that doesn’t include the default gateway settings, so you need to set that yourself through the console:

route add default gw 10.0.0.138

But if you try that, you’ll get an error stating that you do not have the permissions. You need to be Root to do that, which your not. Even though you are in the admin group by default, that is not the same as root. The root password btw is set to a Hash at installation and the idea is that the root account should not be used at all. You could, if you really wanted do that by setting the password to a known one, but as it’s against guidelines, let’s not.

Instead, we need to raise our own level of authority to the root level with the following command:

sudo -i

Ubuntu does that a lot btw. You’ll get a dialog, very familiar from Vista or Win7, asking you to punch in the password to raise the level. In this case, as we are running it in a console, we need to do it with a command.

Anyway: Now we have internet access, lets run the updates. Holy crap! 158 updates!! That will take me all night!!

Pfew, this is Linux land and not Bill domain. An update is in average 0.5 MB, so running the updater takes as long as for me to type this blog! J

Hopefully, I can now set up file sharing and do the POC with Mono. Exciting stuff!

Posted by Stephan Dekker | 2 comment(s)
Filed under: ,

Even though there are already a couple of blogposts about bookmarking pages from an asp.net environment using the AJAX scriptmanager, there are not a lot of people that have done deep linking with querystrings and silverlight apps hosted in HTML.

This feature is missing in the current version of silverlight (2.0) and needs to be implemented by hand, if you need to have it. A lot of business App need it, and so does ours.

The solution is an elegant one as well (If I may say so myself): Create a javascript method that gets called when the silverlight app starts, let the javascript method call a method on our silverlight app that's exposed to javascript and let that silverlight method parse the querystring into anything we want it to be!

So here we go:

  • Create an HTML host file to host the silverlight app. Make sure the object has an Id. In our case: SilverlightControlApp 

   66     <div id="silverlightControlHost">

   67         <object id="SilverlightControlApp" data="data:application/x-silverlight-2,"  <!-- Notice the ID -->

   68             type="application/x-silverlight-2" width="100%" height="100%">

   69             <param name="source" value="ClientBin/MyYetAgainVeryCoolDemoApp.xap"/>

   70             <param name="onerror" value="onSilverlightError" />

   71             <param name="onload" value="PassTheQueryStringToSilverlight" />    <!-- Notice the Event -->

   72             <param name="background" value="white" />

   73             <param name="minRuntimeVersion" value="2.0.31005.0" />

   74             <param name="autoUpgrade" value="true" />

   75             <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">

   76                  <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>

   77             </a>

   78         </object>

   79         <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>

   80     </div>

  • Create a javascript file to contain the QueryStringRetrieval. I named it "QueryStringHelper.js".
  • paste the following method in there:

    2 function PassTheQueryStringToSilverlight(sender, args) {

    3     try     {

    4         silverlightControl = document.getElementById("SilverlightControlApp");

    5         silverlightControl.Content.SilverlightApp.SetQueryString(location.search);

    6     }

    7     catch (e) {

    8         alert("An exception occurred in the script. Error name: " + e.name

    9               + ". Error message: " + e.message);

   10     }

   11 }

 

  • Add the javascript reference in the HTML page:

   20     <script type="text/javascript" src="Silverlight.js"></script>   <!-- Generated by VS -->

   21     <script type="text/javascript" src="QueryStringHelper.js" />    <!-- Add this yourself -->

  • Add an OnLoad event handler to the Silerlight host object to call the javascript method. Notice the event in the HTML code above.
  • Open the App.xaml.cs and create a method to receive the queryString. Use the ScriptableMember to expose the member to be called from Silverlight.

   65         [ScriptableMember]

   66         public void SetQueryString(string queryString)

   67         {

   68             // Get the panel from the querystring

   69             var parms = QueryStringHelper.ParseQueryString(queryString);

   70             if (parms.ContainsKey("panel")) SetPanel(parms["panel"]);

   71         }

   72 

   73         private void SetPanel(String panel)

   74         {

   75             // Navigate to the specified panel

   76             if (_availablePanels.Contains(panel)) page.PanelToShow = panel;

   77         }

  • Register the class as scriptable in the HTML pages by calling HtmlPage.RegisterScriptableObject(String, Object); I've done it from the constructor in the App class in the App.xaml.cs. 

   20         public App()

   21         {

   22             HtmlPage.RegisterScriptableObject("SilverlightApp", this);

   23 

   24             Startup += Application_Startup;

   25             Exit += Application_Exit;

   26             UnhandledException += Application_UnhandledException;

   27 

   28             InitializeComponent();

   29         }

  •  Implement the querystring parsing. I re-used a piece of code from the almighty internet. Just create a class called QueryStringHelper and copy paste the following section code:

    2 using System;

    3 using System.Collections.Generic;

    4 using System.Text.RegularExpressions;

    5 

    6 namespace MyYetAgainVeryCoolDemoApp.Silverlight

    7 {

    8     public class QueryStringHelper

    9     {

   10         public static Dictionary<String, String> ParseQueryString(String queryString)

   11         {

   12             var result = new Dictionary<String, String>();

   13 

   14             // Source = http://increment.cx/wordpress/?p=106

   15             var regexPattern = @"\?(?<nv>(?<n>[^=]*)=(?<v>[^&]*)[&]?)*";

   16             var regex = new Regex(regexPattern, RegexOptions.ExplicitCapture);

   17             var match = regex.Match(queryString);

   18 

   19             for (var currentCapture = 0; currentCapture < match.Groups["nv"].Captures.Count; currentCapture++)

   20             {

   21                 result.Add(match.Groups["n"].Captures[currentCapture].Value.ToLower(),

   22                 match.Groups["v"].Captures[currentCapture].Value.ToLower());

   23             }

   24 

   25             return result;

   26         }

   27     }

   28 }

 And now, you'r ready to use query strings in your app!

Cheers mates!

 

Posted by Stephan Dekker | 4 comment(s)
Filed under:

If you have not heard about this you should realy check it out!!!

It's the successor to CAB, Smart Client Software Factory and implements a lot of Paterns and practices!

Download it from here

Stephan

Posted by Stephan Dekker | with no comments

Back to index 

Martin fowler is one of the inventors of the Model View Presenter pattern which he let retire a couple of years back. I don't think the rest of the software community will let the pattern retire though!

Mr Fowler suggested to split the pattern up into two very similar flavors of the pattern as you can read here:

So, as it's phased out and there is enough to find about the pattern already (like here and here) I will not write about this pattern.

 

 

 

 

It seems like every self respecting blogger needs at least one multi-episode blogpost, so this is the start of mine and it's about good design patters and the latest state of it.

While updating and enriching my knowledge about unit testing and automating the daily builds even further, I ran into some exciting new stuff. This made me think about writing a set of blogs that will discuss the whole unit testing matter from the ground up.

In the basic stuff I will only give a brief explanation with links to more elaborate instructions as I don't intend to re-write how to install and setup a daily build. I will give some tips and tricks I know of and maybe you guys can extend these??

After I have covert the basics, I will move into more recent stuff, like the retirement of the MVP pattern, the very new Presenter First methodology Ron Jacobs will be talking about at the various sessions he is giving all over the world and others...

The scope will be WinForms and ASP.NET applications as these will cover most business scenario's. Initially it will be focused on .NET 2.0 and leave WPF, WCF, WWF and cardspaces out of the equation, Maybe in part 17 or something this will be addressed :-)

I will write a Conclusion page right from the start of this multi-episode blogpost, but his is bound to change while I write new posts about these matters. I will try very hard to keep that in sync.

Of course I need an indexing scheme, so here it is:

  1. Introduction (This page)
  2. Basics of unit testing
  3. Basics of setting up unit testing in TFS
  4. Basics of Code coverage
  5. Design for unit testing 
  6. Design for code coverage
  7. Have I unit tested enough?
  8. Overview of design patterns to assist unit testing
  9. Supervising Controller pattern
  10. Passive View pattern
  11. Design / development processes that assist unit testing
  12. Test Driven Development (TDD)
  13. Presenter First design process
  14. Hoe this all fits into pragmatic everyday programming
  15. Conclusion(s)

But, Lets start at the beginning.....  here

A couple of nifty tips-and-tricks for VS2005.

http://msdn2.microsoft.com/en-us/library/bb245788(vs.80).aspx

Some of them I use allready, some of them I knew could be done. Now I know how when I need them or have some time to spare and want to invest it in speeding up my VS2005 usability.

Cheers!

 

 

Posted by Stephan Dekker | with no comments
Filed under:

Download it here: http://msdn2.microsoft.com/en-us/windowsmobile/default.aspx

Factsheet: http://www.microsoft.com/presspass/press/2007/feb07/02-11WM6SoftwareFS.doc

Cheers! Stephan

 

Posted by Stephan Dekker | 3 comment(s)
Filed under:

SQL Server CE (previously called SQL Mobile and SQL Everywhere) is a very lightweight SQL server that can run everywhere hance the name "SQL Everywhere". It is targeted to replace the XML data files in a lot of smart client apps.

It's realy, realy, realy great, but the problem is that a lot of tools do not (yet) support the data provider, witch makes it harder to use it. Like active reports. Somehow the provider does not get registered in the GAC as supposed to the documentation states (RC1 documentation). So, it seems I now have to find out where the providers get registered to sort out the problem.

The problem is that the provider resides in the System.Data.SQLClientCE namspace in stead of the System.Data.SQLClient namespace and that namespace is not commonly supported yet by the tools. The namespace is quit old actually, but up until recently it was not interesting to implement (other than om mobile app tooling)

I am contacting DataDynamics about it. Maybe i am not the first and the questing did not make the FAQ or KB yet. (You never know right?)

Maybe i can find another way to connect the ActiveReport to the dataset from the SQL Server CE. There is an option to use unbound fields and at runtime assign values to it. But they are all called Field1, Field2, Field3, etc. I simply refuse to use it. I just won't!

Another option I will look into, is to look for an XSD Dataprovider or somethomg. A dataprovider witch can read the XML schema into a dataset and implements the DataProvider interface so i can consume it from third-party tools.

Posted by Stephan Dekker | 2 comment(s)
Filed under: ,

Some collaegues are going to edmond in januari and one of them proposed to stay at Bill's place. That brought us to the topic of his house and a big discussion followed. So we looked some specs of his house up with google. Here you can find a overview of his little mansion :-)

Realy cool house and a great website to check it out...

Posted by Stephan Dekker | with no comments

For the podcast listeners out there in the Netherlans who have not yet made up there minds about the elections, would like to read the election programs of the political parties and who do not have the time (Is there anyone left due to these exclusions?):

The podcast version of the election programs can be downloaded here. There are also a couple of summary versions of the biggest parties.

Good luck making up yuo're mind and at least go and vote! Be glad you have the right to, so use it!

(Sorry, no spell checking, because im using the website to quickly blog about this)

Posted by Stephan Dekker | with no comments
Filed under:

Patrick had more time, but I actually spoke myself at DotNetRocks. Listen to my stumbling (starts at 1:02:00) as Richard surprised me by handing me the microphone all of a sudden.

It is kind of old news, but did not hear it, so maybe you guys havn't heard it either:

http://www.iunknown.com/articles/2006/10/20/dynamic-languages-microsoft-and-me

(Great domainname b.t.w.)

I think he was on DotNetRocks some time ago, but I'm not going to check witch/wich/who episode. You go look for it if you want to hear more about the RubyCLR for .NET here

Posted by Stephan Dekker | with no comments
Filed under:
More Posts Next page »