Skip to main content

Posts

Sasa-v0.9.4-RC2 Released - A Sasa.Dynamics Overview

I've just uploaded the next release candidate for Sasa-v0.9.4 . This features a few changes due to problems I ran into while porting old code to the new codebase. Not bugs per se, but unfortunate limitations of certain Microsoft libraries. There are also a few new extensions written to showcase Sasa.Dynamics, which are detailed below. Sasa.Dynamics The experimental type safe reflection facilities of Sasa v0.9.3 were completely revamped since they weren't general enough to handle all of the CLR's and C#'s constructs. The main problem was that the ref-based callback interface wouldn't integrate well with readonly fields. The only time you can create a reference to a readonly field is in the constructor, so clients couldn't implement the old IReflected interface on any immutable objects. The new approach in Sasa.Dynamics separates two orthogonal concepts: 1. typecase, and 2. folding over an object's fields. Typecase is an operation from the research li...

Sasa v0.9.4-RC1

Over two years in coming, I've just uploaded the first release candidate for Sasa v0.9.4 . Quite a few changes in this release which I'll detail more fully once I'm closer to the final release. Suffice it to say that this release contains many small bug fixes, specifically to the MIME multipart parsing, more tests with a switch to xUnit unit-testing framework, and numerous enhancements and more powerful abstractions across the board. Some of these abstractions have appeared in blog posts here over the past two years, like the extensible Pratt parser , the purely functional hash-array mapped trie , and a simple software transactional memory in pure C# , to name but a few. The libraries are now also better organized into logical units. You can peruse the documentation online . Here is a mostly complete change log for the curious: added a function to convert integers into an English sentence representation. added custom equality and comparisons extensions for strings. ...

AspQ - A JavaScript Event Queue for ASP.NET

A nearly universal problem in ASP.NET is handling multiple postbacks. There are various server-side and client-side solutions to deal with this, but these solutions can only be understood once you already have the domain knowledge to solve the problem yourself. You then end up repeating the pattern in every project. Well, programming is about not repeating yourself and automating repetitive tasks. So I've released a reusable abstraction to handle multiple postbacks on the client-side. Because it's a client-side solution, it will only work for browsers with JavaScript enabled, but that's by far the most common case. AspQ AspQ is a small JavaScript object that hooks into the ASP.NET JS standard and AJAX runtimes. It basically queues all sync and async postback requests so they don't interfere with one another, and applies the updates in event order. I believe this option provides a superior user experience to simply preventing a submit until the previous postback ha...

Can't Catch Exceptions When Invoking Methods Via Reflection in .NET 4

I just tried updating the Sasa build to .NET 4, when I ran into a bizarre problem. Basically, the following code throws an exception when running under .NET 4 that isn't caught by a general exception handler: static int ThrowError() { throw new InvalidOperationException(); // debugger breaks here } public static void Main(string[] args) { var ethrow = new Func<int>(ThrowError).Method; try { ethrow.Invoke(null, null); } catch (Exception) { // general exception handler doesn't work } } Turns out this is a Visual Studio setting. Given the description there, whatever hooks VS has into the runtime when transitioning between the native and managed code have changed their behaviour from .NET 3.5. So VS isn't aware of the general exception handler further up the stack, and breaks immediately. I can see this being handy if you're writing reflection-heavy code, as it breaks at the actual source of an exception instead of ...

Managed Data for .NET

Ensō is an interesting new language being developed by Alex Loh, William R. Cook, and Tijs van der Storm. The overarching goal is to significantly raise the level of abstraction, partly via declarative data models. They recently published a paper on this subject for Onwards! 2012 titled Managed Data: Modular Strategies for Data Abstraction . Instead of programmers defining concrete classes, managed data requires the programmer to define a schema describing his data model, consisting of a description of the set of fields and field types. Actual implementations of this schema are provided by "data managers", which interpret the schema and add custom behaviour. This is conceptually similar to aspect-oriented programming, but with a safer, more principled foundation. A data manager can implement any sort of field-like behaviour. The paper describes a few basic variants: BasicRecord: implements a simple record with getters and setters. LockableRecord: implements locking on...

M3U.NET: Parsing and Output of .m3u files in .NET

I've been reorganizing my media library using the very cool MusicBrainz Picard , but of course all my m3u files broke. So I wrote the free M3U.NET library , and then wrote a utility called FixM3U that regenerates an M3U file by searching your music folder for the media files based on whatever extended M3U information is available: > FixM3u.exe /order:title,artist foo.m3u bar.m3u ... The M3U.NET library itself has a fairly simple interface: // Parsing M3U files. public static class M3u { // Write a media list to an extended M3U file. public static string Write(IEnumerable<MediaFile> media); // Parse an M3U file. public static IEnumerable<MediaFile> Parse( string input, DirectiveOrder order); // Parse an M3U file. public static IEnumerable<MediaFile> Parse( IEnumerable<string> lines, DirectiveOrder order); } The 3 exported types are straightforward. A MediaFile just has a full path to the file itself and ...

Delete Duplicate Files From the Command-line with .NET

Having run into a scenario where I had directories with many duplicate files, I just hacked up a simple command-line solution based on crypto signatures. It's the same idea used in source control systems like Git and Mercurial, basically the SHA-1 hash of a file's contents. Sample usage: DupDel.exe [target-directory] The utility will recursively analyze any sub-directories under the target directory and build an index of all files based on their content. Once complete, duplicates are processed in an interactive manner where the user is presented with a choice of which duplicate to keep Keep which of the following duplicates: 1. \Some foo.txt 2. \bar\some other foo.doc > The types of files under the target directory are not important, so you can pass in directories to documents, music files, pictures, etc. My computer churned through 30 GB of data in about 5 minutes, so it's reasonably fast.