Ayende @ Rahien

Refunds available at head office

Node.cs

No, the title is not a typo. There is so much noise around Node.js, I thought it would be fun to make a sample of how it would work in C# using the TPL. Here is how the hello world sample would look like:

public class HelloHandler : AbstractAsyncHandler
{
    protected override Task ProcessRequestAsync(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        return context.Response.Output.WriteAsync("Hello World!");
    }
}

And the code to make this happen:

public abstract class AbstractAsyncHandler : IHttpAsyncHandler
{
    protected abstract Task ProcessRequestAsync(HttpContext context);

    private Task ProcessRequestAsync(HttpContext context, AsyncCallback cb)
    {
        return ProcessRequestAsync(context)
            .ContinueWith(task => cb(task));
    }

    public void ProcessRequest(HttpContext context)
    {
        ProcessRequestAsync(context).Wait();
    }

    public bool IsReusable
    {
        get { return true; }
    }

    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
    {
        return ProcessRequestAsync(context, cb);
    }

    public void EndProcessRequest(IAsyncResult result)
    {
        if (result == null)
            return;
        ((Task)result).Dispose();
    }
}

And you are pretty much done. I combined this with a HttpHandlerFactory which does the routing, and you get fully async, and quite beautiful code.

Tags:

Published at

Originally posted at

Comments (38)

Macto: And it goes on your permanent record, too!

According to the way the blog posts are currently scheduled, I just spent about a month doing nothing but talking about stuff that has very little to do with the implementation, code or even just rough architecture. I bet you thought that you were going to see some code, diagrams and something real that you can sink your teeth into…

Well, not so fast, this is supposed to be a DDD sample, as such, the first and foremost topic that discuss is the actual domain. I think that this is likely to be the last of the pure domain posts, and I’ll get started with the actual design stuff shortly. But before we do that, we need to learn about one last aspect of the domain, the Inmate’s Record.

So far, we have dealt mostly with the Dossier, the legal stuff that means that we can keep an Inmate in lawful incarceration, but in addition to that, we also have the Inmate’s Record. The Record is basically all the interesting things that the prison stuff needs to know about the Inmate. Those things range from cliff notes version that you need to look at before you interact with an Inmate to a detailed record of his stay in prison.

The cliff note version is usually used in briefing about the guy, “Look, we have to take him to his court date, you need to remember, the guy is on suicide watch, so never leave him alone…”. In the cliff note version, we highly important aspects of the Record. Suicidal, Flighty (tried / planning to escape), Avoid Putting With Inmate X, etc.

The Full Record is used for things like intelligence reviews, interviews, parole hearings, and in any case where there is a need to learn a lot about the Inmate.

What goes into the Record?

  • Guards’ reports
  • Intelligence gathered
  • Disciplinary actions

And probably a whole lot more that I am forgetting. It is important to note the difference between the Dossier, which is usually handled by Legal and the Record, which is usually handled by Staff. They both refer to the same Inmate, but they are usually handled, maintained and used completely separately.

Tags:

Published at

Originally posted at

Comments (6)

Macto: Once more from the top, I swear I had a few more over there

Counting is more than just a regular event in prison, it is more like the heart beat of the entire operation. Indeed, one of the more disruptive events in a prison is when Inmates refuse to be Counted. That is ranked up there will a full scale riot.

Macto is meant to be mostly about the legal aspects of an Inmate’s incarceration, but it can’t ignore the Counting. Indeed, we need to explicitly support those. Just to make our life complicated, when Inmates are Counted, they don’t actually have to be Counted (except at Opening Count and Closing Count, of course), they just have to be Accounted For.

For example, an Inmate may be at the Courthouse during Noon Counting, and that is just fine, as long as we know that he is there. Or there might be an Inmate that is present in another cell during the day, which is also pretty common.

Any changes for the counting for Closing Count are usually pretty extraordinary, something being hospitalized, just arriving from a very long day at Court, etc.

In Macto, we need to record not only that the counting has been made, but also:

  • How many Inmates where present?
  • How many Inmates where supposed to be there?
  • If there are any discrepancies, are they accounted for?

Oh, and you can’t just not accept invalid data, because if an Inmate has Escaped, you still need to be Count all of the rest (in fact, you want to be able to Count them very quickly, nothing make sure that you’ll Count as a suspected or real Escape attempt).

Speaking of which, there is another aspect of Inmate management that we haven’t spoken about yet, the actual tracking of the inmate, but I’ll discuss that in my next post.

Tags:

Published at

Originally posted at

Macto: Day to day life

So the officer shows up in the morning, logs into Macto, and… what does he sees? What are the day to day operations that are required?

This is usually much harder to figure out, because there isn’t any particular action that initiate things, it is usually the routine stuff that trips you.

Since we are mostly interested in the Inmates legal statuses, every day, we need to start with an Action Plan:

  • Which Inmates go home today?
  • Which Inmates’ incarceration should be extended?
  • Which of the Inmates need to go to court?
  • Notify interested parties about Inmates who are scheduled to be released soon.
  • Are there any Inmates who should have been freed but are still hanging around?

Again, note how limited our scope is. We don’t deal with things like cell searches, scheduled drills, etc. Those are happening in any reasonable prison, and they probably need to be tracked, reported on, and scheduled. But those things are pretty much Routine Military Activity (same as the requirement that every soldier re-qualify on firearms once in some period), and there is probably software out there that already does it. We are focusing on the Dossiers, and that is a complex enough world on its own.

Did you notice the actual difference between the first two items of the action plan? What is the difference between them?

Inmates which gets to go home are usually those that were sentenced and served their time. Inmates whose incarceration should be extended are Inmates whose authority for incarceration is time limited, and would have to be released. However, there is usually a reason why they are incarcerated, and that usually means that instead of letting them go, we have to take them in front of a judge to extend the incarceration period until they are finally sentenced.

This part of the system is basically reports and alerts. It gives the user the information about what sort of actions should be taken to ensure that we don’t run into habeas the curpus scenarios without good answers.

Tags:

Published at

Originally posted at

Comments (4)

Raccoon Blog Performance

Update: See below for details about the server load.

I just run into this tweet:

image

That isn’t the first time that we heard this, and it is actually surprising, not only was there no attention to performance given throughout the lifecycle of the project so far, we actually discovered some issues that theoretically should hurt performance.

The secret is that RavenDB is really good in optimizing itself based on usage patterns. That came out of the realization that we had to drop people into the Pit of Success as much as possible. Raccoon Blog shows that we were able to do just that.

Please note that I am testing this with a RavenDB server over the internet, to emphasis the actual costs involved.

For example, let us look at the current state of this blog, using RavenDB MVC Profiler:

image

Just to be clear, in order to actually show the problem, I am running this locally, while the RavenDB server is actually the production RavenDB server for this blog, in other words, the vast majority of the time is actually network traffic, making queries to RavenDB over the Internet.

Remember that I said that we didn’t pay attention to performance? Notice how many remote queries we are making. We have 5 sessions and 7 queries. Why is that?

The reason for that is that we are using the Session per Action approach for scoping the session, and we make heavy use of Child Actions, each of which is going to get its own session. Give me a moment to fix that…

Well, that took three minutes, mostly because I wanted to do it right. There are advantages for Infrastructure Ignorance, and one of them is the ease in which we can make such changes.

image

The change isn’t drastic, we went from having 5 sessions and 7 requests to 1 session and 6 requests, in the post details view, however, it saved us two requests.

The actual cost of opening a session is essentially zero, so it is more the requests that we are making than anything else. We can improve performance even further by applying additional tactics, such as aggressive caching or batched calls, but we will save those for another post.

Update: I was asked about the load, and I hopped off to Google Analytics and got a few numbers:

image

That isn’t super high, but it is respectable.

Tags:

Published at

Originally posted at

Comments (15)

RaccoonBlog new features

Working on RaccoonBlog is like therapy, it is simple, it is fun and there isn’t a lot of thinking involved. We recently did a bunch of new features that I just pushed. None of the feature is earth shattering, but each is improving the blog somewhat in fun ways.

RSS Feeds per categories:

image

Post and comments count:

image

The number shocked me, actually. And yes, there will be a post about this.

Per post comments feed

image

If you like keeping track on the comments of a particular post, you can now do so very easily.

Global comments feed

image

If you care to track all comments on all the posts, you can do that as well. And yes, I’ll post on that as well.

Social Login

image

One of the things that I hate is the need to login all the time. We remember those details by default, but it is still annoying. I hope that this would be useful to you too.

How far do you have to wait?

image

Tags:

Published at

Originally posted at

Comments (19)

Macto: Where is the Inmate anyway?

Accepting a new Inmate into prison is usually composed of the bureaucracy in the beginning, and ends with the Inmate arriving at his bunk. The last part is actually pretty complex.

Deciding where the Inmate would go is a decision that is composed of many factor:

  • What type of an Inmate is he? (Just arrested, sentenced, sentenced for a long period, etc)
  • Why is he in prison for?
  • What kind is he? (You want to avoid Inmate infighting, it creates paperwork, so you avoid putting them in conflict if possible)
  • Where there is room available?

I am skipping on other stuff, but I think that you get the picture.

The Inmate’s location is another thing that seems simple on the surface but gets complicated when you drill down. The Inmate’s location is actually compromised from several different aspects. First, and the most obvious one, is the actual physical location of the Inmate. For example:

  • Cell Block B, Section D, Cell 349
  • Redbrick Hospital, ER
  • Vacation
  • East Misphat Courthouse
  • “Loaned” to another prison

All of those are pretty obvious (loaning an Inmate is rarely done, but can happen if he has to do something like show up at a court near the other prison that is far from his current prison).

The next aspect is his location is who is signed for this prisoner. That is a problematic concept if you don’t understand how prisons work. You can think about it as a chain of responsibility. Since the Inmate is in Lawful Custody, if something happens to him, then someone is going to answer some questions. We used to have a joke, “you break, you replace”.  Who signed on for this Inmate is basically who has the legal responsibility for this Inmate. This can be:

  • Cpt. Yom Kashe, Commander Cell Block D
  • Lt. Halach Alley, Escorting to Courthouse
  • Sarge. Yashnoni, Guarding at Hospital

I think that you get the picture. And finally, we have who has overall responsibility for this Inmate? Put simply, while the Inmate is hospitalized for a week, it may be Sargent Yashnoni who is actually standing over the bed, but it is Captain Kashe that has the responsibility for the guy. He is the one who has to report him as “not present, location is known”.

Tags:

Published at

Originally posted at

Comments (5)

High memory usage with WCF Discovery

Yes, I know that this is basically saying that select is broken, but I am seeing some very strange stuff here. The code in question is this:

for (int i = 0; i < 15; i++)
{
    var discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
    var findCriteria = new FindCriteria(typeof(IDiscoverableService))
    {
        Duration = TimeSpan.FromSeconds(1)
    };
    discoveryClient.Find(findCriteria);
    discoveryClient.Close();
}

The full repro can be found here.

The problem is, put simply, that before this code, the working set is:  Working Set: 57,640 kb, after this have executed, it is 90,288 kb.

I went over the code with a fine tooth comb, but I don’t really see where all of this memory have gone.

The actual memory reported by GC.GetTotalMemory does go down after the cleanup, so I guess it could be that .NET isn’t releasing the memory back to the OS, but it still worries me somewhat.

I tried it with higher numbers for the loop, and it seems like eventually it settles down on some number and doesn’t grow from there. My main problem is what happens when you start doing async stuff. Let us take a look here:

int count = 150;
var countdown = new CountdownEvent(count);

for (int i = 0; i < count; i++)
{
    var discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
    var findCriteria = new FindCriteria(typeof(IDiscoverableService))
    {
    };
    discoveryClient.FindProgressChanged += (sender, eventArgs) => {  }; // do nothing
    discoveryClient.FindCompleted += (sender, eventArgs) =>
    {
        countdown.AddCount();
        discoveryClient.Close();
        PrintMemory("Complete: ");
    };
    discoveryClient.FindAsync(findCriteria);
}

countdown.Wait();

At peek, I am seeing 600 MB (!) of memory used. Note that we are now using the default duration of 20 seconds, and it seems that DiscoveryClient is very heavy on memory.

If you know how, can you take a look at the code and tell me that I am crazy?

Tags:

Published at

Originally posted at

Comments (25)

Why I love Raccoon Blog

Why did you write your own blogging software? I can hear a lot of people asking. The answer, to tell you the truth, is actually quite simple.

I needed it. My blogging habits puts me quite outside any curve that you care to name, and the usual blogging software just don’t take some stuff into account.

Probably the most important aspect of that is the notion of scheduling. When I got the muse, I got the muse, and I post a lot. Just to give you some idea, the entire Microsoft N Layer App Sample was posted during one morning at the office. This would be my 6th post of the day, etc. That means that the process of sending a new post out has to be as automated as possible, including when to schedule it.

Raccoon Blog does this for me, finding out the latest blog post and scheduling the new post on the next work day. But it gets better, because blogging is basically writing over time, it is important to actually see it that way. Here is the main admin screen for Raccoon Blog:

image

As you can see, all of the posts are outlined nicely on a calendar, giving a real sense of when they are going to be posted. It is also showing a problem. When I do a series, I usually write all of them at once, and then dump it to the queue. But it is not necessarily the best case for reading. If you don’t care for the topic of the series, you might be bored for a long time. So it is good to mix up content a bit.

This is magic, but Raccoon Blog lets me drag & drop posts to new dates, meaning that in a few minutes, I can mix up the content so the blog wouldn’t be a one track topic for weeks on end. And the reason it is magic is that this is so much better than the alternatives that I have tried that it feels like heaven.

Here is how it looks like after the re-ordering:

image

Now that is more like it, mixed topics, a lot of stuff that would interest you (I hope) and no pain at all during the entire process.

Tags:

Published at

Originally posted at

Comments (21)

Review: Microsoft N Layer App Sample, part X–Architecture for the Space Age

imageContinuing my review of http://microsoftnlayerapp.codeplex.com/, an Official Guidance (shows up at: http://msdn.microsoft.com/es-es/architecture/en) which people are expected to read and follow.

Well, this is probably going to be the last post on the topic, because to be frank, I am getting a headache and I don’t really see the point anymore. I would strongly advise anyone looking at this sample application to consider it to be the epitome of worst practices and what not to do. I am frankly stunned to see something like that.

I didn’t spend a lot of time with the application, and I more or less just skimmed it here and there, and almost every single time, I found something that horrified me.

Yes, there are places for disagreements when you discuss software architecture, places where a decision can go both ways and while you might disagree with it, you can live with it.

This isn’t such a case, this is a case of a project that is literally choke full of traps and scary places. If you don’t look too deep, it says all the right things, but once you get a bit deeper, you can see how this is causing a black hole in your mind, eating away anywhere where good things can grow.

This is the ultimate architectural exercise, building an architecture without building an application.

Except that you can’t talk about an architecture in isolation, architecture is always driven by the actual needs of the application, not by whatever the architect read about last night and is dying to see how it works in the real world.

This isn’t how this it done, and attempting to follow the guidance in this manner would result in a lot of time and money going down the drain.

I can’t emphasize this enough, avoid this codebase, don’t look at it, and never try to follow anything shown there, it will end in tears, pain and suffering.

I have a headache now, and I think that I’ll stop before it goes over the top.

Tags:

Published at

Originally posted at

Comments (42)

Macto: Let’s CREATE an Inmate

After spending so much time talking about the application, I think that you can understand why this isn’t going to work:

image

For a start, we don’t create an Inmate. A prison just doesn’t have this concept.  Second, the process of accepting a new Inmate into the prison is a pretty complex one. An Inmate can come from one of several sources. It can be a guy just brought in from the streets or it can be an Inmate from another prison (and then it depends on where he came from), etc.

Each scenario requires different workflow for processing the new Inmate. And what about errors in the process? For example, let us say that your prison is rated for 14 years old and up, and suddenly you have at the gate an officer with three 13 years old that were just arrested with suicide belts. Legally, you aren’t allowed to hold them. Practically, you can’t really let them go. (For the record, that was a real scenario that happened, I had to get a judge to approve this.)

Here is another true story. I sent an Inmate to another prison, and along the way, the escort manage to forget the documents (those are the oh so important that the sky fall down and smacks you in the head if you don’t have them) in my prison. They got to the other prison around 2 AM, and only then discovered what happened. I was able to convince that prison’s commander to hold the guy until morning in his prison until I can send the documents.

Validation? You make me laugh. This is the real world, and if your system reject an Inmate that the prison commander has decided that he is going to accept… well, that Inmate still has to be tracked, but now it is offline and probably done on the back of some envelope somewhere. The system may alert and warn, but it cannot deny people.

Welcome to the real world.

Overall, the process for accepting a new inmate is quite simple, at its core. You need to be able to identify the Inmate, and you need to have a valid chain of lawful incarceration. The first might be a problem (the guy might have been just picked up, have no idea and refuse to identify himself). The second might also be a problem, as we have seen above.

But eventually, we have the Dossier for an Inmate, which contains name, id, picture and the chain of lawful incarceration. The next step is to place the Inmate in the prison, and that is a whole different key of gunpowder. I’ll discuss that in my next post.

Tags:

Published at

Originally posted at

Comments (12)

RavenDB MVC Profiler Support

I am not sure if you have noticed, but for the last few weeks, we have had a small tag on the top left side of the blog. Clicking on this would reveal the following information:

image

As you can see, generating the main page took 6 sessions and 8 calls to the RavenDB server. This reflect the fact that when building RaccoonBlog, we were far more focused on the architecture and paid very little attention to the actual performance of the system and mostly focus on being correct and architecturally sound.

I’ll point out that with no attention to performance, the new blog out performs the old blog quite handily.

We can dig a bit deeper into what is going on here:

image

As you can see, we have a list of requests made to the server, including all of the queries made. This make it quite easy to figure out what is actually going on. For bonus points, we can even dig deeper and look at an individual request:

image

From debugging stand point, it is incredibly helpful. From a performance optimization perspective, it is invaluable. This feature alone has been responsible for three different bug fixes (all of them very hard to figure out without it) and has guided us into several performance improvements for the blog.

We took the idea from the Mini MVC Profiler, I really liked the idea of that, but didn’t really like the code, so we set out to build Raven.Client.MvcIntegration.dll.

In your MVC application, you need to reference that assembly and:

  • In the Application_Start method, call Raven.Client.MvcIntegration.RavenProfiler.InitializeFor(documentStore).
  • In your main layout, include the following line: @Raven.Client.MvcIntegration.RavenProfiler.CurrentRequestSessions()

That would setup the RavenDB Profiler for MVC applications, giving you direct access to whatever is going on in that request. We even handle Ajax requests as well Smile

And a minor point as well, this feature is probably not something that you would use in production, but since I wanted to show it off for you, I made sure that it can be run in production. In order to facilitate this, there is a way to redact the information sent to the client, scrubbing it from any personal information. That has been done on this blog, but it is a fairly simple system, compromised mostly of the ability to black list specific fields by name. I would be careful when exposing this to the world, but especially if you are using this to see what is going on against a remote RavenDB instance, it can be invaluable tool.

Tags:

Published at

Originally posted at

Comments (17)

Review: Microsoft N Layer App Sample, part IX–Not Invented Here is FUN

Continuing my review of http://microsoftnlayerapp.codeplex.com/, an Official Guidance (shows up at: http://msdn.microsoft.com/es-es/architecture/en) which people are expected to read and follow.

Is it not invented here if a Microsoft project chooses to re-invent something that Microsoft already did?

Take a look at how queries are being performed:

image

That looks strange, let us dig a bit deeper, shall we?

image

And it is not alone! It has a full family and some friends too:

image_thumb

 

So you create a specification, and then you call that specification to create an expression tree, and then you use that expression tree for the queries.  If only we had builtin specification support in the framework! Oh, wait! It is called Linq! And it is already being used here, so they obviously know about it.

And no, this isn’t the case of needing to serialize specification over the wire, they are used in the same process as the one where the queries execute on.

I mean, seriously! You didn’t consider just dropping all of those abstractions and getting the work done? Oh, I forgot, there isn’t any work to be done, the application isn’t actually doing anything, all the abstractions are the point.

Tags:

Published at

Originally posted at

Comments (26)

A visual look at RavenDB velocity

We recently added a very small feature to our build server, generating tags on the repository for every successful build. This has the surprising effect of giving us a really nice way of looking into something that I always wanted, the rate of change across pushes to production.

The way we work in Hibernating Rhinos, every single push to the remote repository is a viable product, and it becomes a a publicly available build. The problem is that in git there isn’t really a way to track pushes, so it was quite hard to figure out after the fact the scope of change of each build without looking at the individual commits.

With the new tags, we have a much easier time. I mean, just take a look:

image

You can see pretty rapid velocity here, with new goodies that come abroad.

Tags:

Published at

Originally posted at

Comments (6)

Review: Microsoft N Layer App Sample, part VIII–CRUD is so 90s

Continuing my review of http://microsoftnlayerapp.codeplex.com/, an Official Guidance (shows up at: http://msdn.microsoft.com/es-es/architecture/en) which people are expected to read and follow.

Take a look at the following:

image

I was curious about that, I didn’t really understand what is going on here, so I tracked it down a bit…

image

Skipping over the part where there is a cast of null, this seems to indicate that this is a call to modify the entity to simulate concurrency, digging deeper:

image

Seems like I was right, it is intended to force the save of this item to the database. That seemed very strange, so I checked upward, where this is used, and I found:

image

So, ChangeBankAccount is just another way of saying Save(), it seems, in a very round about way.

Tags:

Published at

Originally posted at

Comments (17)

Macto: Creating The Model

Actually, starting with the model is usually a bad idea, it ties you to a particular representation of the application, usually as codified in the database schema / UML diagrams. Instead, I rather like to talk about responsibilities.

In the case of Macto, we need to figure out what the system is actually doing. It is an incarceration system, and it seems pretty clear that the root of everything in a prison is in the Inmate, right?

Not so fast!

As a matter of fact, the prison care very much about the Inmate, but Macto? Not so much. That is because we need to make a distinction between what happens in the Real World and what actions are required by our system. In the case of Macto, we are actually managing the Inmate’s Dossier. I thought about calling this a File, but I thought it would be a confusing term, considering how often we use this term technically.

Why is the Dossier so interesting? Because from a IT system perspective, it is the only thing that actually happens in a prison that can be captured inside a computer. For example, does it make sense to make a system for managing garbage removal from the cells?

Sure, if we could RFID all of the inmates, that would give us great IT experience (and save a lot of time and effort), but I am going to assume a prison where this isn’t possible, where most of the actual interactions with the inmates is actually happening by real live people. That means that what we actually care about for Macto is a fairly narrow aspect of what it means to manage a prison, the Inmate’s Dossier.

And after talking so long about why we care only about it, lets talk about what it is. The Inmate’s Dossier is the folder in the registration desk where all of the relevant information about a particular inmate is kept. Here is how it looks like:

image

What is stored inside that dossier? Well, all the really important aspects of being an Inmate. First and foremost, we have the chain of lawful authority for incarceration. What is that?

Let us take a very simple case, of a guy caught vandalizing a car. The chain of lawful authority for incarceration would be something like:

  1. 27 June 2011 20:52 – Arrest by Sargent Azulay for car vandalizing.
  2. 28 June 2011 14:52 – Detention, 8 days by Judge Judy
  3. 5   July 2011 – Remanded in Custody by Judge Thachil Oti
  4. 14 Aug 2011 – Sentenced, 3 months by Judge Koev Li
  5. 27 Sep 2011 – Released at end of sentence

What does all of this mean? Well, a lot, actually. At #1, we had a guy that was arrested by the police, we then have 24 hours to bring him in front of a judge, to make a determination about the case (a small matter of Habeas Corpus). At #2, the judge gave us 8 days to complete the investigation while the guy is still incarcerated. At #3, we showed up in front of a judge and convinced him that we have a strong enough case to keep the guy in jail until sentencing. At #4, we got the final sentence, but calculating it takes some thinking, it is a sentence from the time of the incarceration, which means that the guy spent a total of 3 months in jail, not 3 months from sentencing.

The chain of lawful authority for incarceration is incredibly important, because without it, you are Unlawfully Incarcerating and that is a Bad Thing.

Please note that I am drawing off the experience of prisons that I was at, mostly high security military prisons for terrorists. In a civilian prison, you have to worry about additional things, like work release programs, rehabilitation efforts, etc. I am not going to touch those issues in Macto, though.

What other things are going to go into the Dossier, the ability to answer quo warranto inquiries is probably the most important one, but there are other things going on there as well. For example, we track where is the Inmate located (not a trivial matter, actually). We need to track Reports on the Inmate (aggressive, suicidal, etc).

There are probably more than that, but I think that this is enough for now. You may have noticed that so far, I haven’t shown you any UML nor have I started with the database schema. To be perfectly frank, it is not relevant at this stage at all. On the next post, I’ll start talking about the basics of CRUD operations.

Tags:

Published at

Originally posted at

Comments (22)

Review: Microsoft N Layer App Sample, part VII–Data Access Layer is GOOD for you

Continuing my review of http://microsoftnlayerapp.codeplex.com/, an Official Guidance (shows up at: http://msdn.microsoft.com/es-es/architecture/en) which people are expected to read and follow.

Reading up on the data access implementation is always fun, mostly because of all the contortions that people go through. In this case, you can see the attempt to abstract away data access:

image

Of course, we expose Entity Framework types in our abstraction, but that is good, we will just have to implement EF on top of NHibernate if we ever want to switch, it is not like we are exposing a concrete class, it is an interface, we can replace it.

Let us also look at how this is used, shall we?

image

You know what, I am not even going to critique this, I am actually getting tired by reading this code, I have developed a bit of a tick, and it is getting hard to see wh…

Tags:

Published at

Originally posted at

Comments (42)

Thinking about doing an NHibernate course in Poland

I am thinking doing a course in Warsaw around the end of October. Before setting out to figure all the details, and with the caveat that this is still very early in the game, etc. I would like to solicit some input from you guys (well, if you are in Poland or nearby.

  • Would you come?
  • What level do you think the course should be?
Tags:

Published at

Originally posted at

Comments (65)

Review: Microsoft N Layer App Sample, part VI–Single responsibility principle is for idiots and morons

Continuing my review of http://microsoftnlayerapp.codeplex.com/, an Official Guidance (shows up at: http://msdn.microsoft.com/es-es/architecture/en) which people are expected to read and follow.

Take a look at the following:

image

It is obvious that someone recognized that there are distinct responsibilities in here.

It is just sad that C# doesn’t give us better way to split responsibilities other than regions and partial classes.

I mean, if we could have defined multiple interfaces and multiple classes… but that is crazy talk, no one needs to have multiple classes in their applications, what are we, Java?

Tags:

Published at

Originally posted at

Comments (43)

Streamlined RavenDB, Part I

One of the things that we worked very hard on (and are still working very hard) is making RavenDB as streamlined as possible, in the sense of making it very easy to do things that you commonly have to do.

Case in point, the Future Posts feature of this blog. Yesterday I went a bit overboard and posted about 10 posts in the space of two hours. (No, this isn’t my usual rate). That led to something that I didn’t quite foreseen:

image

We did have a limit on the number of future posts that we will show, but that limit was set to 15, and as you can see, it is actually pretty hard to look at things when we have so many, so instead I decided that we should have the following:

image

Just a minor UI change, but we now need to also change the data that we gather, or do we? Let us look at the code:

image

The only change that I actually had to do was modify the Take() from 15 to 5, and also ask the query to give me the query statistics. Because such as operation (pages + full count) is so common, RavenDB make it super cheap to do so. You don’ t need to issue a separate query, and you don’t need to do anything nor are you incurring any additional costs.

The information is already there.

Tags:

Published at

Originally posted at

Comments (26)

Review: Microsoft N Layer App Sample, Part V–Cross Cutting is a fine line

Continuing my review of http://microsoftnlayerapp.codeplex.com/, an Official Guidance (shows up at: http://msdn.microsoft.com/es-es/architecture/en) which people are expected to read and follow.

From the evidence, it seems that there has been some (lacking, insufficient and usually causing damage, but some) attention given to cross cutting concerns:

image

That is why I was shocked to read method after method that read like this:

image

And this:

image

And this:

image

I mean, did at no point someone stand up and said: “My Ctrl+C / Ctrl+V keys just fell off, we might need to think about a better way of doing this"?

I mean, cross cutting concerns didn’t raise the question of error handling?

I mean, seriously, you want to tell me that this type of code is an Official Guidance from Microsoft?

Tags:

Published at

Originally posted at

Comments (40)

Macto: The boundaries of a prison

Macto is a prison management system. To be rather more exact, it is an incarceration management system. Managing a prison is a very complex process (did you ever think about who takes the trash out? Or how to handle things like watch rotations?).

I am getting ahead of myself, however. The first thing that we have to do when we start designing a system is check:

  • What is the scope of the system?
  • What is the intended usage?
  • Who are the users?
  • What other systems are we going to interface with?

Those are the basics, because in a lot of projects, they don’t get asked.

Running a prison is a complex task, I already said. If we wanted a single piece of software to do it all, we would have to do a lot of stuff that we don’t really need. For example, are we going to write our own payroll system for the prison’s stuff? Our own medical software to manage the infirmary? What about managing the inventories in the prison (how many prison uniforms and tear gas canisters we have)? What about the maintenance software for the fleet of vehicles required to run even a small prison?  Or how about… but I think that you get my drift.

There are a lot of aspects where it would be significantly better to get an of the shelve solution rather than try to write our own version of that. We need to be focused where we would provide actual utility to our customer.

That is what I said that we are going to build incarceration system, not a prison management system. Macto is all about managing the aspects of a prison that are different than those of any other business.

You can read about Macto in my initial post about it, here, since it put the context of the system in a nice perspective.

I am not sure if there will be code available, but I am going to outline my thinking here, and I think that this would be valuable in itself.

Macto is going to be about managing the aspects of a prison that you can’t get off the shelve. In order to do that in a way that would make sense to you, I need to first explain what we are going to be doing.

Like any good architect, I’ll be doing that by starting with the model, which is also the cue for the next post.

Tags:

Published at

Originally posted at

Comments (5)