.Net

Mindscape wants Beta Testers
1 May 2007 in .Net & Mindscape | Comments (0)

This is a bit of cross pollination but we are currently looking for beta testers for our first product. If you’re keen then head over to my post about becoming a beta tester on the Mindscape blog.

http://www.mindscape.co.nz/blog/?p=20

Thanks,

- JD

Trying the Castle Project?
27 April 2007 in .Net & Mindscape | Comments (0)

Mindscape

Recently it seems local .NET developers are picking up parts of the Castle Project (Monorail, ActiveRecord etc) and there has been a bit of discussion going on regarding how certain things should be done. It’s great to see this framework being picked up, it really does aid creating more robust and maintainable solutions. As with anything new that you’re learning it can sometimes be daunting and challenging though.

So where should you turn if you need guidance with using parts of the Castle Project? Mindscape.

We have really smart people here who not only know how to leverage it effectively but have also contributed code back to make the Castle Project better for everyone. If you’d like to talk to us about getting some guidance or help then contact us or contact me directly.

- JD

Reduce your .NET assembly size
12 April 2007 in .Net & Code | Comments (1)

I’ve always been interested in writing very small and efficient code. There isn’t much need for coding in C or Assembler these days (which I used to like playing with a few years back) so I really enjoy finding new ways of making .NET code smaller and faster. I thought I would share one inexpensive trick for making your assemblies just that bit smaller on disk.

  • Bring up the properties to your C# project file.
  • Click on the build tab.
  • Click on Advanced.
  • Set the File Alignment value to 512 (it will default to 4096 for C# projects)

File Alignment Property on C# Projects Dialog

For some reason Visual Basic solutions will default to 512 and C# projects seem to default to 4096. This affects how the MSIL code is written in the assembly and appropriately pads the file with zeros if required to fit code neatly into the file alignment size. Reducing this value has negligible or no affect on application start-up but can reduce your assembly size by a noticeable amount. Likely in the 10 – 20% range in terms of savings.

Always nice to get a free saving on assembly size!

- JD

Simple paging with LINQ for SQL
23 March 2007 in .Net | Comments (2)

One thing we’ve been playing with at Mindscape with the creation of Background Motion is LINQ for SQL (previously known as DLINQ). Over my time in software development I’ve found myself having to write paging code a few times. In itself it’s not hard but it is easy to do it in a dumb way if you don’t think beyond just restricting the dataset.

Every now and then I see code that pulls an entire dataset back from the database and then slices and dices it into a single page. This of course isn’t a very good idea but it does solve a basic issue when doing paging: knowing the total number of results which you need to know when displaying a paging control.

So you will need two queries, one to get the count, one to get the page. Still more efficient than transporting 10,000 or more rows of data to your application.

How does LINQ for SQL make this easier? Check out this code snippet:

private IList<Contribution> GetWithinDays(int days, int skip){

  return ModeratedContributions

    .Where(c => c.AddedOn >= DateTime.Now.AddDays(days))

    .OrderByDescending(c => c.AddedOn)

    .Skip(skip)

    .Take(PageSize)

    .ToList();

}

This is LINQ in action, this will return a collection of contributions which were added in the last 5 days, in descending order based on when the contribution was added. The key here is the Skip and Take methods. These allow to to chop of the start of the result set and Take will select the next number of rows from that point. Effectively this is doing your paging. Keep in mind that LINQ for SQL is converting this C# code into SQL so this paging functionality is being applied at the database, not in our application.

All you need to do is calculate the offset for the skip parameter and you’re done. In the code above, PageSize is defined within the scope of the class so is not passed in but this can be any integer for the number of results you want per page.

You really can’t get much easier than that. Now, just to get the count of the results, that’s easy enough with LINQ as well:

private int GetNumberWithinDays(int days)

{

  return ModeratedContributions

    .Where(c => c.AddedOn >= DateTime.Now.AddDays(days))

    .Count();

}

Now with those two pieces of data from our database, the results and total number of potential results we can go forward and implement some easy paging. Of course we control all the other information in this example such as the number of items on a page etc but overall you can see that LINQ enables these types of solutions easily.

For more information about LINQ for SQL check out this MSDN article.

- JD

Presentation: Extending Application Reach
22 March 2007 in .Net & Events & Microsoft & Mindscape | Comments (0)

Microsoft 2007 Technical Briefings

Thanks to everyone that came to our presentation on extending the reach of your applications. In a few weeks we will also be making available videos of the three presentations that Mindscape delivered for those wanting to see them again or who could not attend the sessions.

Here are the links from our presentation:

Presentation File:

Demonstration Files:

I hope everyone that attended this session found it useful, feel free to post feedback or questions.

- JD

BackgroundMotion
8 March 2007 in .Net & Code & Events & Microsoft & Mindscape | Comments (0)

BackgroundMotion Logo

BackgroundMotion is the website that Mindscape has developed and been showing off in the recent (and future) Microsoft 2007 Technical Briefings. Some people have been asking where they can see this site at the moment so I thought I would clarify that the site is not currently live. It will be available in the near future and I’ll announce that here when it does go live.

Further to this, we are looking to deliver the source code for the website so that everyone can learn about aspects of the system. Following from this there are plans to release video content showing why some design decisions were made and how we implemented them. Should be a great resource for learning from.

It’s been a great opportunity to be creating an awesome system that will be used by real people as well as creating surrounding documentation and content that enables people to learn more about how to do things.

- JD

Custom HttpHandlers and IIS7
23 February 2007 in .Net & Code & Microsoft & Tools & Windows | Comments (3)

I’ve been developing an ASP.NET solution and was starting to get some odd behavior on my development machine (Vista Ultimate). We’ve written a custom HttpHandler for managing user authorisation and when running the solution up against the ASP.NET Cassini web server (the “built in web server”) everything ran fine however when running against IIS7 authorisation wasn’t working correctly. Some debugging and it became evident that the handler wasn’t even executing when running within IIS7.

IIS7 provides a whole swag of great new functionality so after some hunting around I found that the module wasn’t registered with IIS7.

How do you register a custom module in IIS7?

Fire up IIS Manager

Select your website you want to add the module for (IIS will inspect the Web.config of the site to get the modules)

Open up “Modules”:

IIS7 Modules

You should find that your modules will be of Module Type “Managed” if you’re writing them in .NET, check it’s not already listed

Click “Add Managed Module…” on the Action pane

IIS7 Add Managed Module

Type in the name of your module and select it from the drop down list (IIS will populate this from what it finds in the web site, if the module isn’t listed then you’ve made a mistake somewhere :)

Add IIS7 HttpHandler Module

Click OK and you should now find that your custom HttpModule works :)

Another way

Some of you will already know that IIS7 configuration is now XML and you can configure IIS7 from the web.config. This was recently demonstrated at a local .NET User Group in Wellington by Jeremy. It’s a pretty kick ass change from how things work in IIS6 and earlier and makes explaining some of these things easier. After adding the Module reference I noticed Visual Studio warned me that the Web.config file had changed so I took a look at what it had changed and, sure enough:

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="CustomAuthModule"
type="Mindscape.ResearchProject.Website.Infrastructure.CustomAuthModule" />
</modules>
</system.webServer>

So you could just drop this block into your Web.config and get the same module registration that I detailed earlier. Fantastic.

- JD

Get Windows Vista Ultimate for $199
16 February 2007 in .Net & Events & Microsoft & Windows | Comments (7)

Many of you will be starting to see more and more people talking about Windows Vista now it’s come out in the retail market. I’ve been using it for quite some time and it has really grown on me, I strongly suggest you grab a copy and start using it today :)

Anyway, that aside, you may be questioning which version you need? Given the audience of my blog, I’d suggest Ultimate. It has some kick ass features that make doing development work a lot more enjoyable as well as things such as Windows Ultimate Extras. However, ultimate also comes with the biggest price tag so how can you get it a bit cheaper? You can come along to the Microsoft 2007 Technical Briefing event in Auckland/Wellington/Christchurch.

The cost is $199 to attend and you get to select either a copy of Windows Vista Ultimate or Office 2007 for yourself. Great sessions and software, what more could you want? :)

One of the coolest Ultimate Extras is DreamScene which allows a video to play as your desktop “image”. It’s really cool, Jeremy and Andrew have been loving it too.

- JD

P.S. Disclaimer, I’m speaking at this event so I’m taking the opportunity to pimp it as well as show it’s a great offer to get software :)