improve.dk
Just another mindless drone looking for the perfect stack
posts - 220, comments - 475

Development: .NET


LINQPad – The Perfect Playground for Amazon Web Services

Written on Friday, February 17, 2012 by Mark S. Rasmussen in Development: .NET, Development: Amazon Web Services

How to use LINQPad for easy prototyping of AWS SDK code.

No comments | Write first comment
 

Seemingly Random Exceptions Thrown From CachedPathData.ValidatePath

Written on Tuesday, January 31, 2012 by Mark S. Rasmussen in Development: .NET

How CachedPathData.ValidatePath will throw HttpExceptions when RelaxedUrlToFileSystemMapping is set to false.

No comments | Write first comment
 

Automated Testing of OrcaMDF Against Multiple SQL Server Versions

Written on Monday, November 28, 2011 by Mark S. Rasmussen in Development: .NET, SQL Server: OrcaMDF, Development: Testing

See how I test OrcaMDF automatically against multiple versions of SQL Server.

No comments | Write first comment
 

Optimizing Single Instance Amazon S3 Delete Performance

Written on Thursday, November 17, 2011 by Mark S. Rasmussen in Development: .NET, Development: Amazon Web Services

Here's how to achieve maximum delete performance for Amazon S3.

No comments | Write first comment
 

Pushing the Limits of Amazon S3 Upload Performance

Written on Monday, November 07, 2011 by Mark S. Rasmussen in Development: .NET, Development: Amazon Web Services

Here's how to achieve maximum upload performance for Amazon S3.

16 comments | Read comments
 

How to Set Up and Serve Private Content Using S3 and Amazon CloudFront

Written on Wednesday, October 26, 2011 by Mark S. Rasmussen in Development: .NET, Development: Amazon Web Services

Walkthrough of how to setup private CloudFront distributions that utilizes private S3 buckets as their origin.

2 comments | Read comments
 

Copying a SQL Server database file that’s in use using Volume Shadow Copy

Written on Tuesday, June 21, 2011 by Mark S. Rasmussen in Development: .NET, SQL Server: Tricks

Learn how to copy an online SQL Server data file that is in use, using the AlphaVSS Volume Shadow Copy (VSS) functionality in C#.

No comments | Write first comment
 

Avoiding regressions in OrcaMDF by system testing

Written on Tuesday, June 14, 2011 by Mark S. Rasmussen in Development: .NET, SQL Server: OrcaMDF, Development: Testing

Learn how OrcaMDF utilizes system testing to avoid regressions between commits.

No comments | Write first comment
 

Using Fiddler to automatically download streamed MP3s

Written on Wednesday, June 01, 2011 by Mark S. Rasmussen in Development: .NET

Eric Lawrence’s Fiddler has many uses. I use it every day for debugging our client/server interaction, caching behavior, etc. What many don’t realize is that Fiddler is also an excellent platform for scripting, enabling you to modify requests and responses as they go out and come back. I made a quick script to automatically download streamed MP3 files as they were played, naming them automatically from the ID3 information contained in them. Before we get started, head on over and download the FiddlerScript Editor. Parsing ID3 tags As I’m lazy, and most likely you are too, we’ll...

No comments | Write first comment
 

Reverse engineering SQL Server page headers

Written on Thursday, May 19, 2011 by Mark S. Rasmussen in Development: .NET, SQL Server: Internals

Learn the internal format of a SQL Server page header as presented by DBCC PAGE. Using reverse engineering I'll show how to parse the header data.

No comments | Write first comment
 

Checking which database is stored in a detached mdf file

Written on Thursday, May 19, 2011 by Mark S. Rasmussen in Development: .NET, SQL Server: OrcaMDF

Learn how, using OrcaMDF we can figure out which database is stored in a deattached MDF file.

No comments | Write first comment
 

Papercut vs smtp4dev - Testing mail sending locally

Written on Thursday, July 01, 2010 by Mark S. Rasmussen in Development: .NET, Sysadmin: Technology

Testing mail functionality in code using external mail servers has always been a hassle. If the mail manages to dodge antispam and various other mischievous services, it'll probably take several minutes to receive. On our Exchange servers it'll typically take 10-15 minutes before a locally sent mail actually arrives back in my inbox. We can do better! Papercut and smtp4dev are both applications that'll emulate a remote SMTP server on your local machine. Instead of actually sending the mail onwards like a normal SMTP server, they'll simply catch the mail and notify you. This means you'll receive the mail...

1 comments | Read comments
 

Bundling image requests for increased performance

Written on Monday, June 07, 2010 by Mark S. Rasmussen in Development: .NET, Development: AS/Flex/Flash

A common scenario in RIA's is to show a large amount of small pictures on a single page. Let's say we want to show 100 images in a grid. While the simplest approach is to just put in 100 image objects and load in the images one by one, I believe it can be done smarter... The cost of a request Each and every request will have a header overhead of about ~400 bytes outgoing and ~200 bytes ingoing - both varying depending on the host, cookies, headers etc. Multiply that by 100 requests and we've got about...

No comments | Write first comment
 

Speaking at Aarhus .NET User Group

Written on Friday, April 23, 2010 by Mark S. Rasmussen in Development: .NET, Presenting

On April 28th I'll be giving a presentation at Aarhus .NET User Group on SharedCache. The presentation will be part of a combined event where Morten Jokumsen will be presenting Velocity and Jakob Tikjøb Andersen will be presenting Cassandra. I'll give a quick run through of what SharedCache is and what it's not, how to use it and what you can expect from it. If all goes well, I'll have my EC2 SharedCache cluster up and running for demo purposes :) If you want to join, please sign up at Facebook.

No comments | Write first comment
 

Miracle OpenWorld 2010 Slides

Written on Saturday, April 17, 2010 by Mark S. Rasmussen in Development: .NET, Conferences, SQL Server: Miracle Open World, Presenting

These are my slides + materials from the sessions I presented at the Miracle OpenWorld 2010 conference.

No comments | Write first comment
 

Speaking at Odense .NET User Group

Written on Friday, February 19, 2010 by Mark S. Rasmussen in Development: .NET, Presenting

On March 10th I'll be giving a presentation at Odense .NET User Group on Scalability & Availability on the Microsoft platform. As the session will be in Danish, I'll be posting a danish abstract: I denne session kommer vi ind på hvordan man sørger for høj tilgængelighed og skalerbarhed af ASP.NET web applikationer ved brug af flere maskiner opsat som cluster. Hvordan sørger vi for konsistent deling af sessions på tværs af maskiner indenfor et cluster? NLB vil blive demonstreret som clustering teknologi med dets styrker og svagheder. Ligeledes vil den nye IIS7 Application Request Routing extension blive...

No comments | Write first comment
 

TechTalk on Scalability & Availability using NLB and IIS ARR

Written on Wednesday, December 16, 2009 by Mark S. Rasmussen in Development: .NET, Sysadmin: Availability, Sysadmin: Scalability, Presenting

As promised during my TechTalk today at Microsoft Denmark, here are the links to all slides and demo code. Unfortunately you'll not be able to download the VPC's as those total around 30GB. Download slides & code I sincerely hope you enjoyed the presentation as much as I did. Either way, I'd appreciate your comments on SpeakerRate - Thanks :)

No comments | Write first comment
 

Fixing Flash bugs and intercepting IIS Application Request Routing cookies

Written on Wednesday, December 09, 2009 by Mark S. Rasmussen in Development: .NET, Sysadmin: IIS, Sysadmin: Scalability, Development: AS/Flex/Flash

What does Flash, upload, cookies, IIS load balancing and cookies have to do with each others? More than I'd like :( When users need to upload files I often use the Flash based SWFUpload component. It allows for multiple file selection and progress display during upload. Handling the uploaded files on the .NET side is rather easy: for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFile hpf = Request.Files[i]; // ... Save / process the HttpPostedFile } One of the arguments for using Flash for web designs is that...

No comments | Write first comment
 

Reading width & height of Flash file

Written on Wednesday, November 11, 2009 by Mark S. Rasmussen in Development: .NET, Development: AS/Flex/Flash

Obtaining the movie height & weidth of a Flash file is an easy task using the swfdump tool that comes as part of the swftools package. Here's an example of how to invoke swfdump from C# and read out the height & width of a given Flash file. Start out by downloading on of the swftools releases. I'm using the latest development snapshot. I'll be using one of the Flash files I made in a previous blog post as a test file, but you can use any .swf file you want. The test Flash file is called test.swf. ...

No comments | Write first comment
 

Defending against the improbable

Written on Thursday, November 05, 2009 by Mark S. Rasmussen in Development: .NET

As little children we've all been taught that it's better to program defensively than relying on exceptions being thrown. However, sometimes it's preferably to just hope for the best and catch exceptions if they happen. Defending against the improbable Say we have a web application that receives and ID through the query string and serves a file accordingly, usually we'd write that like: if(File.Exists(path)) serveFile(path); else serve404(); This is what I've been doing in a large image serving website I run. However, it recently struck me that on average about 99.9% of all...

1 comments | Read comments
 

Solving access denied errors using Process Monitor

Written on Wednesday, October 21, 2009 by Mark S. Rasmussen in Development: .NET, Sysadmin: Technology, Sysadmin: Windows, Sysadmin: IIS, Sysadmin: Security

Access denied errors are not uncommon when deploying new websites / features that interact with the filesystem. While it might work in local testing, it suddenly doesn't anymore when deployed. Using Process Monitor I'll show how to easily debug these issues. I've made a very simple web application project with a Default.aspx file that has the following codebehind code: using System; using System.IO; using System.Web.UI; namespace FileWritingWebsite { public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { File.WriteAllText(@"C:\Test.txt", "Hello world!"); Response.Write("Done!"); } } } After deploying this to my webserver we receive the archetypical access denied error: In this case it's rather obvious where the error stems from,...

2 comments | Read comments
 

How to do URL rewriting on IIS 7 properly

Written on Wednesday, October 14, 2009 by Mark S. Rasmussen in Development: .NET, Sysadmin: IIS

One of my earlier blog posts, and the all time most popular one, was about how to make URL rewriting on IIS 7 work like IIS 6. While my method did provide a means to the goal, it's humiliatingly far from what I should've done. Since the old post is still the most visited post on my blog I feel obligated to write a followup on how to do proper url rewriting in IIS 7. The scenario I'll assume a completely vanilla IIS 7 setup, contrary to the old post, there's no IIS tampering required. I've setup...

11 comments | Read comments
 

Writing a calculator in C# using SableCC

Written on Wednesday, September 30, 2009 by Mark S. Rasmussen in Development: .NET

Writing a calculator is a simple task - just add nine buttons labeled 1-9 and add a plus and minus button and we're almost good to go. In this entry I'm going to write a calculator called SimpleCalc that does not have a GUI, instead it'll take in an arbitrary expression and calculate the results of it. The input I'll use as my immediate goal is the following: 25-37+2*(1.22+cos(5))*sin(5)*2+5%2*3*sqrt(5+2) According to Google the result is -9.83033875. Some of the tricky subjects we'll have to handle is operator precedence (multiplication before addition etc), nested expressions (2*1.22+cos(5) != 2*(1.22+cos(5))) and associativity (5+7...

5 comments | Read comments
 

Combining paths with multiple parts

Written on Wednesday, September 16, 2009 by Mark S. Rasmussen in Development: .NET

Whenever you concatenate multiple strings into a path, you really ought to be using the System.IO.Path class's Combine method. At times you may be concatenating a number of smaller parts of a path instead of just the two that the Path.Combine() method takes. Nested Path.Combine calls quickly become difficult to read and error prone: string partOne = @"C:\"; string partTwo = "Windows"; string partThree = @"System32\drivers"; string partFour = @"etc\hosts"; string combinedPath; combinedPath = Path.Combine(Path.Combine(Path.Combine(partOne, partTwo), partThree), partFour); Often we won't have all of our path parts in named variables, and even when we do, they'll rarely be named partOne, partTwo, partX etc. If we...

2 comments | Read comments
 

The cost of latent logging code

Written on Saturday, September 12, 2009 by Mark S. Rasmussen in Development: .NET

Logging is an integral part of most applications, whether it's for logging performance metrics or causality data. Avoiding performance hits due to logging can be tricky though as we don't want to spend CPU cycles on the logging infrastructure when logging is disabled, while still keeping the full logging ability when required. Imagine the following scenario in which we want to log an exception in our application: Logger.Log("An error occured at " + DateTime.Now + " on computer " + Environment.MachineName + " in process" + Process.GetCurrentProcess().ProcessName + "."); Inside the Logger.Log method we may have a check for...

6 comments | Read comments
 

Making the ASP.NET State Service work across network

Written on Monday, August 24, 2009 by Mark S. Rasmussen in Development: .NET, Sysadmin: IIS, Sysadmin: Availability, Sysadmin: Scalability

Once you start distributing your ASP.NET website across multiple webservers, you're going to need a way to share session state. That is, unless your app is stateless, in which case scaling it should be a breeze! One of the easiest ways to provide common session state for a small cluster (very dependant on load and hardware specs, but ~10 servers max, per state server), is to use the built-in ASP.NET State Service. It's a free service that's installed alongside the .NET Framework on all Windows servers. While the InProc session storage is stored directly in the w3wp process,...

1 comments | Read comments
 

devLINK 2009 followup

Written on Monday, August 17, 2009 by Mark S. Rasmussen in Development: .NET, Conferences, Presenting

I'm finally sitting in the train on my way home from the Airport and an excellent week spent in Nashville, also known as Nash Vegas. First of all, major kudos go out to John Kellar (@johnkellar) and the rest of the devLINK team. I still can't believe the amazing quality of devLINK as a conference, the speaker lineup, food, party, etc, all for a price of just $75! From what I gathered, there were only three international participants at devLINK this year, including me and @KasperVesth - if devLINK continues its current path, I'm sure there'll be plenty more...

No comments | Write first comment
 

IIS7 - The object identifier does not represent a valid object

Written on Wednesday, July 08, 2009 by Mark S. Rasmussen in Development: .NET, Sysadmin: IIS

When adding sites to IIS7 either by script or by editing the config files directly, you may receive an error in the sites list that says: Unknown: The object identifier does not represent a valid object. (Exception from HRESULT: 0x800710D8) I'm running multiple servers in an NLB setup, using the shared configuration feature of IIS7 (config files are stored on a SAN exposed through a CIFS share). My first thoughts were that this was probably related to the shared configuration / network access, but I'm able to reproduce the problem even with...

7 comments | Read comments
 

Evolution of the simple genetic algorithm

Written on Saturday, May 02, 2009 by Mark S. Rasmussen in Development: .NET

Based on my previous post on how to implement a simple genetic algorithm, I got some great comments pointing out that the algorithm might not be the most pure form of a genetic algorithm. I won't disagree, though I will point out that evolution also does occur due to mutation alone, so genetic algorithms may come in different forms. Making it more "genetic" The basic point is that I was only mutating my chromosomes, I wasn't actually pairing them up and reproducing via a crossover function. I've changed my GeneticAlgorithm class slightly to give more control to...

3 comments | Read comments
 

Implementing a simple genetic algorithm

Written on Wednesday, April 29, 2009 by Mark S. Rasmussen in Development: .NET

In this blog post I'll give a quick introduction to what genetic algorithms are and what they can be used for. We'll implement a genetic algorithm that attempts to guess an RGB color by evolving upon a random set of initial guesses, until it at some point evolves into the correct RGB value. What are genetic algorithms? Contrary to other types of algorithms, genetic algorithms do not have a clear path of improvement for solution candidiates, and it's not an exhaustive search. A genetic algorithm requires a few base components: A representation of a...

6 comments | Read comments
 

TxF presentation materials

Written on Friday, April 24, 2009 by Mark S. Rasmussen in Development: .NET, Presenting

Yesterday I presented on how to use Transactional NTFS (TxF) in .NET, at the Copenhagen .NET User Group. Downloads Slides: TxF.pptxMaterials: TxFMaterials.zip

2 comments | Read comments
 

Solving deadlocks through locking hints

Written on Wednesday, April 01, 2009 by Mark S. Rasmussen in Development: .NET, SQL Server: Optimization

Learn what causes a SQL Server deadlock and how to solve it using locking hints and isolation modes. We'll be looking at the updlock hint as well as the serializable isolation mode.

1 comments | Read comments
 

ANUG Talk: Optimizing SQL Server 2005

Written on Thursday, March 12, 2009 by Mark S. Rasmussen in Development: .NET, SQL Server: Optimization, Presenting

These are the slides & materials for my "Optimizing SQL Server 2005" talk presented at the Aarhus .NET User Group.

2 comments | Read comments
 

Resource URLs and their effect on client side caching

Written on Sunday, March 08, 2009 by Mark S. Rasmussen in Development: .NET, Sysadmin: Scalability

One of the best way to improve performance of any website is to reduce the load from clients by allowing them to cache resources. There are various ways to ensure we utilize client side caching to the fullest extent, an often overlooked parameter however, is the actual URL for the resource we want to cache. The traditional methods Basically client side caching comes down to three different parameters, the cache policy, the expiration dates as well as the last-modified / etag of the resource. Through the no-cache policy we can completely disallow all caching of the resource,...

No comments | Write first comment
 

Utilizing transactional NTFS through .NET

Written on Sunday, February 15, 2009 by Mark S. Rasmussen in Development: .NET, Development: Win32

We're used to using transactions when dealing with the database layer. Transactions ensure we can perform multiple queries as one atomic event, either they all succed or they all fail, obeying the rules of ACIDity. Until Vista, performing transactional file operations haven't been possible. Transaction NTFS (or TxF) is available from Vista and onwards, which means Server 2008 is also capable. XP and Server 2003 do not support TxF and there are currently no plans of adding TxF support in systems previous to Vista. So what is the benefit of using TxF? The benefit is that we can...

1 comments | Read comments
 

TechTalk: Optimizing SQL Server 2005

Written on Thursday, January 22, 2009 by Mark S. Rasmussen in Development: .NET, Presenting

I held a TechTalk on optimizing SQL Server 2005 on the 21st of January. I think it went well so I'm looking forward to the evaluations - please fill them out :) I have put up the slides, code and test database backup for you to download. Slides + Code DB Backup Note that the slides are in Danish - sorry non-danes. As I mentioned at the end of the TechTalk, I barely made it through all of my slides, and that's even after I sacrificed a lot of the topics & depth I wanted...

No comments | Write first comment
 

Implementing imperative security declaratively using PostSharp

Written on Saturday, November 01, 2008 by Mark S. Rasmussen in Development: .NET, Sysadmin: Security

At a recent TechTalk I talked about code access security and how to perform declarative and imperative security demands & requests. There's no doubt declarative security checking is nicer than imperative checking, but not everything can be done declaratively. Say we have the following method: static void writeFile(string filePath) { File.WriteAllText("test", filePath); } We want to make sure we have permission to write to the filepath. Declaratively, we can request (SecurityAction.RequestMinimum) for an unrestricted FileIOPermission which would ensure that we had write access. But requesting unrestricted IO access is way overkill, since we only need access to select paths. I got the question,...

No comments | Write first comment
 

I don't like static methods

Written on Thursday, October 16, 2008 by Mark S. Rasmussen in Development: .NET

Inspired by a recent question on StackOverflow, I felt like sharing my thoughts on static methods in general. I used to love utility classes filled up with static methods. They made a great consolidation of helper methods that would otherwise lie around causing redundancy and maintenance hell. They're very easy to use, no instantiation, no disposal, just fire'n'forget. I guess this was my first unwitting attempt at creating a service oriented architecture - lots of stateless services that just did their job and nothing else. As a system grows however, dragons be coming. Polymorphism Say we have...

4 comments | Read comments
 

Using Squid as a reverse proxy with a .NET url rewriter

Written on Sunday, October 05, 2008 by Mark S. Rasmussen in Development: .NET, Sysadmin: Windows, Sysadmin: Scalability

Once you start receiving visitors from all over the world, a new kind of scaling issue arise. It's not a matter of adding more servers to the cluster or optimizing code (we'll assume these factors are perfect), it's a simple matter of geography and mathematics. Serving code from one end of the world to the other will take time, no matter how quick your servers are handling the request. The speed of light suddenly seems quite slow. At one of my current projects we serve a lot of image data. Letting US based clients fetch all the data from...

1 comments | Read comments
 

TechTalk material part 2

Written on Wednesday, August 20, 2008 by Mark S. Rasmussen in Development: .NET, Sysadmin: Security, Presenting

I continued my TechTalk on security in the .NET framework today, taking off from where we left last time. As promised, here are the demos and slides (in Danish). Regarding the demos, the baseline folders contain the code as it was at the beginning of the presentation, the others contain the code as it ended up after the presentation. Slides Demos

No comments | Write first comment
 

Updating XmlOutput

Written on Sunday, August 10, 2008 by Mark S. Rasmussen in Development: .NET

Since I originally posted my XmlOutput class I've received lots of great feedback. I'm happy that many of you have found it useful. I have been using the class myself for most of my xml writing requirements lately (in appropriate scenarios) and I've ended up augmenting it a little bit. Nothing major, just a couple of helpful changes. Automatic xml declaration Instead of manually declaring our xml declaration each time: XmlOutput xo = new XmlOutput() .XmlDeclaration() .Node("root").Within() .Node("result").Attribute("type", "boolean").InnerText("true"); XmlOutput will instead add an XmlDeclaration with the default parameters: var xo = new XmlOutput() .Node("root").Within() .Node("result").Attribute("type", "boolean").InnerText("true"); Note that this is a breaking change,...

No comments | Write first comment
 

TechTalk material

Written on Wednesday, August 06, 2008 by Mark S. Rasmussen in Development: .NET, Sysadmin: Security, Presenting

I held my TechTalk on CAS security in the .NET framework today. As promised, here are the demos and slides (in Danish). If you're asked for a key password, it's "123456". Slides Demos

2 comments | Read comments
 

.NET Security TechTalk

Written on Friday, June 13, 2008 by Mark S. Rasmussen in Development: .NET, Sysadmin: Security, Presenting

I will be hosting two TechTalks on security in .NET, at Microsoft Denmark in August. The TechTalks will be held in DANISH. Jakob Andersen will be co-hosting the TechTalks, hopefully filling in on my weak points and vice versa. I urge participants to comment on this post regarding topics you would like us to talk about, problems you've had, suggestions and so forth. If you're not attending, please comment anyways - I'll be blogging a lot on security for the time being and I'm always seeking relevant topics to research further :)

3 comments | Read comments
 

Providing custom assembly evidence

Written on Friday, June 13, 2008 by Mark S. Rasmussen in Development: .NET, Sysadmin: Security

I recently mentioned the possibility of having an assembly provide custom evidence alongside the CLR provided evidence. Let's see how to do it. Creating the evidence The first step is to actually create the evidence itself. The evidence can be in any form, as long as it's serializable. That means you can use strings, complex types (provided they're serializable), or plain old'n'good XML. In lack of a better example, I'll create a piece of evidence that tells the birthdate and name of the developer behind the assembly. Really useful, I know. <?xml version="1.0" encoding="utf-8" ?> <myEvidence> <birthDay>1985-07-25</birthDay> <name>Mark S. Rasmussen</name> </myEvidence> Saving...

No comments | Write first comment
 

Analyzing assembly evidence

Written on Wednesday, June 11, 2008 by Mark S. Rasmussen in Development: .NET, Sysadmin: Security

When the CLR loads an assembly and needs to determine the appropriate permission set to apply, it's based on various evidence. Assembly evidence tells the CLR about the origins of the assembly, the zone it's loaded from and the file hash of the actual assembly file - these are just some of the more common evidence types the CLR uses, there are a lot more that are rarely used. Any object can be a piece of evidence, the CLR will only react on well known evidence types though. There are two different overall origins of evidence, assembly provided and...

1 comments | Read comments
 

Using IDisposable to write indented text

Written on Monday, June 02, 2008 by Mark S. Rasmussen in Development: .NET

I often need to output indented text in one way of the other, it could be HTML, XML, source code etc (please look beyond the actual problem domain - I'd enver write XML this way, it's just an example). Usually that involved me writing tab characters manually (or by calling a function that returned the current indentation string), cluttering the actual output. An example might look like this: StringBuilder sb = new StringBuilder(); sb.AppendLine("public static void Hello()"); sb.AppendLine("{"); sb.AppendLine("\tif(true)"); sb.AppendLine("\t\tConsole.WriteLine(\"World!\");"); sb.AppendLine("}"); Console.Write(sb.ToString()); Console.Read(); This ought to result in the following snippet: public static void Hello() { if(true) Console.WriteLine("World!"); } Pretty simple code, but it's a bit hard for the eyes, especially if there's...

2 comments | Read comments
 

Generic Dijkstra's Algorithm

Written on Tuesday, May 13, 2008 by Mark S. Rasmussen in Development: .NET

Through various projects, I've had to do some shortest-path finding in a connected graph. An efficient and straight-forward way to do this is using Dijkstra's Algorithm. Notice that it'll only work for graphs with non negative path weights, like 2D maps for instance. While I've used the algorithm on several occasions, it's only now that I've rewritten it in generic form The code is pretty much self explanatory if you keep the pseudo code implementation next to it. using System; using System.Collections.Generic; using System.Linq; namespace Improve.Framework.Algorithms { public class Dijkstra<TNode> { /// <summary> /// Calculates the shortest route from a source node to a target node...

No comments | Write first comment
 

Mapping datareader to objects using Reflection.Emit

Written on Friday, May 02, 2008 by Mark S. Rasmussen in Development: .NET

I've previously written of how to automatically map a DataTable into a strongly typed collection of objects. There's a problem though, it's not fast... I wanted to improve on it, and this is what I ended up with. The original method relied heavily on reflection to set the values directly. Reflection's bad in regards of speed, mkay? But reflection is not necessarily evil, you can do great good with it. Now, the problem with the original method is that each field is set using reflection for each row, that's [number of fields] * [number of rows] fields being set...

9 comments | Read comments
 

Performance comparison - reading data from the database strongly typed

Written on Wednesday, April 30, 2008 by Mark S. Rasmussen in Development: .NET

I'm a big fan of strongly typed database querying as well as returning strong typed results. Due to the nature of static languages, you'll get compile time checking of all our tables and columns. You can easily rename columns as you can be sure all your (internal) references are accounted for. Returning strongly typed lists of objects instead of DataReaders/DataTables / any other object based containers will also make it easier to transfer through data layers as you're always certain of what's available for you to read and what's not. But it comes at a cost. Performance. ...

6 comments | Read comments
 

Securing .NET Code

Written on Wednesday, April 16, 2008 by Mark S. Rasmussen in Development: .NET, Presenting

Time flies fast. Back in 2006, during my time as an MSP, I made a series of presentations on securing intellectual property in .NET code, resulting in my Securing .NET Code article. Although it's about two years old, most points are still valid today, unfortunately. I recorded a screencast of this article sometime in 2007, but I never really got it published, except for a link on the Microsoft Denmark site. It was my first screencast and unfortunately I made some mistakes, the biggest one being the click sounds from the mouse. An even bigger mistake was me deleting...

No comments | Write first comment