Nested TransactionScopes in .NET

Posted by admin on December 7th, 2009

In next example, the persistence to the database will not be executed.

C#:
  1. IBinaryAssetStructureRepository rep = new BinaryAssetStructureRepository();
  2. var userDto = new UserDto { id = 3345 };
  3. var dto = new BinaryAssetBranchNodeDto("name", userDto, userDto);
  4. using (var scope1 = new TransactionScope())
  5. {
  6.     using (var scope2 = new TransactionScope())
  7.     {
  8.         //Persist to database
  9.         rep.CreateRoot(dto, 1, false);
  10.         scope2.Complete();
  11.     }
  12.     scope1.Dispose();
  13. }
  14. dto = rep.GetByKey(dto.id, -1, false);

scope1.Dispose(); is not necessary in this example, but I added it for clearance.

<

Getting an embedded resource out of the assembly + convert to bytearray

Posted by admin on December 7th, 2009

My file is located under /images/donkey.jpg, so in that case, don't forget to add .images.

C#:
  1. var assemblyName =  typeof(BinaryAssetFileDataProviderTest).Assembly.GetName().Name;
  2. var str = typeof (BinaryAssetFileDataProviderTest).Assembly.GetManifestResourceStream(assemblyName + ".images." + "donkey.jpg");
  3. var blob = new byte[str.Length];
  4. str.Read(blob, 0, (int)str.Length);
  5. var size = (int)str.Length;
  6. str.Close();

<

Saving a connectionString at runtime to .NET app.config

Posted by admin on December 7th, 2009
C#:
  1. var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  2. var connectionStringSettings =
  3. new ConnectionStringSettings("ConnectionString", _arguments["connectionString"], "System.Data.SqlClient");
  4. config.ConnectionStrings.ConnectionStrings.Add(connectionStringSettings);
  5. config.Save(ConfigurationSaveMode.Modified);
  6. ConfigurationManager.RefreshSection("connectionStrings");

<

Educational software

Posted by admin on October 18th, 2009

I've been working almost 5 years now on educational software in two companies (first Indie Group, now Televic-Education). We mainly created CD-ROMS (that were enclosed with schoolbooks) and online solutions. All those applications were not built from scratch, instead we created a framework that could read in all exercises and hierarchy of the exercises. Those exercises were created in a back end were you could assemble them in folders and export them in a format for our framework (xml) or other formats like SCORM.

I haven't got any videos yet on those CD-ROMS, but you can see two of our online solutions in action. The first is Edumatic, the first application that was created and which has some 20 exercise types (multiple choice, fill in, cross word, dragndrop, translate, ...). It can be used online or exported to be used in CD-ROMS. On the site of edumatic, you can try out an online example of a multiple set of exercises (for each exercise type there are a lot of exercises). Our senior product manager (;-) Piet Santy) also shows an example each day created with Edumatic which you can follow on Twitter --> link. Please follow and try out his examples! Some of his past examples are shown here and here and here and here(demo). Edumatic back end is created in ASP.NET, the front end in Flash (AS2). Together with Christophe Herreman we created the framework for it, but a lot of other persons contributed to the framework, back end and exercise types like Kristof Neirynck(current technical lead), Bert Vandamme, Piet Santy, Sofie Deparcq and others.

Our other product, which is newer than Edumatic, is called Edumatic Exam. It is now used by three customers and has a lot of potential. It's more an assessment application than an exercise application and has currently some 15 exercise types. We are striving to support all exercise types from Edumatic, but that'll take some more time (we're nearly there). Client side is created in Flex, back end with .NET. This application is used by our government to test the knowledge of applicants. Daily there are multiple sessions with hundreds of candidates. We haven't got a demo online yet, but if you subscribe yourself at Selor, you can practice some of the language assessments with our application (you need to go to Mijn Selor, subscribe and then choose Taaloefenpakket... all in Dutch or French...) Try it out! The product is also online, but currently you can not register for it. That'll be something for the future. Currently working most on Edumatic Exam are Bert Vandamme, Sem Dendoncker, Wouter Vanden Berghe and me.

Cheers and practice!

<

SQL Server DateTime v’s .Net DateTime – Battle of Accuracy!

Posted by admin on June 10th, 2009

Link

<

Rounding up last month – Pex, Mocks, NSK, CHESS, Linq, Silverlight, TechDays

Posted by admin on April 4th, 2009

It has been a while since I wrote anything, but that's mainly because we have a new family member... Romée, a beautifull daughter, six weeks old!

dsc_0220

Back to the usual stuff. What have I been doing the last month. Well, there were Techdays, on which I wrote a few things but I still need to round that up. I also went looking for best practises to build a .NET layered application. The Northwind Starters Kit was most usefull for this. And there were also the Mocking frameworks, which seemed very complex at first (like everything in it it appears to be very simple afterwards...).

Pex & Chess

Very inspiring talk on Techdays about automated White box Testing and finding and reproducing Heisenbugs in concurrent programs. There was an example of a team that got a report of a bug that had to do with concurrency they just couldn't reproduce. They let CHESS do its thing and in less than a minute they found the bug. Very impressive.

Mocking frameworks

In my Flex projects I had already used mocks, but they weren't exactly mocks... Now that I began exploring .NET architecture, I really found out what these mocking frameworks are about. And they impressed me. Certainly the fact that if you want to use mocking frameworks you need good design, is interesting. To me it seems that a mocking framework is very good to test your base design (framework), if it's done using principles described in books like Patterns of Enterprise Application Architecture or Domain driven Design (or others).

Northwind Starters Kit

This Kit has helped me a lot in having a good example of how you could implement a good .NET layered architecture. I also checked out DinnerNow, but things went wrong when installing (and I just hate that -- if you're limited in time, you don't want to go looking why this or that doesn't install properly. If I have to make installers for cd-roms, they need to work...). I'm now implementing a very small part of a product of ours with this NSK example. I will also try to check out a few mocking frameworks and a few IoC frameworks and integrate them in this small part. The best way to check out this NSK is to checkout the svn repo.

SilverLight

A few good presentations on SilverLight at TechDays. I certainly think they got a lot of advantages over Flex, but it will still take a lot of time. What really annoys me a lot is the arrogance by which some presentators present SilverLight. Anyway, their CLR seems a lot more robust that the Flash Player, but so far I haven't seen business solutions being created with SilverLight. So I'm actually waiting a little bit on such examples. Now it's always very simple examples or interactive sites that really don't have to deal with a lot of data. There was a neat example of a Chess Game where they let a Javascript engine play against an .NET engine (SilverLight). SilverLight always won and could precess a lot more paths/second. A colleague of mine ported the engine to Flash, and could then compare Flash against .NET. The original game can be found here. The blog post from my colleague here. After the presentation on this, I asked a Microsoft guy how Flash would compare to this. He told me you couldn't do this in Flash. Mmmm.

Linq

Very good presentation on Linq! Now I now what Monads are (look them up in Wikipedia). I haven't used Linq all that much, but loving maths I'm interested in how this is implemented. The presentator quickly went deep into the subject which was fantastic (but also sometimes a labyrinth). Also the possibility to extend Linq to any other sort of data is great.

Oslo

Seemed very interesting, but I'll have to check more examples to know how this could be used in every day development. The custom parser seemed very powerfull if you would need to convert data to another format.

Cheers, Lieven Cardoen

<

TechDays Day I: Software + Services: The convergence of Saas, SOA and Web 2.0

Posted by admin on March 14th, 2009

Very motivational and interesting presentation, especially because of the different existing examples around on the net.

First of all, everything is about data and how to bring it to clients (whether they are users or other applications) and bringing software above the level of a single device.

An interesting book that was talked about is "Place to Space" by Peter Weill & Michael R. Vitale. "Place to Space" deals with the business models an e-business can adopt. The central idea of the book is that there are 8 atomic business models that exist. It's a very interesting way to model for example cash flow, product delivery, ...

Cool examples:

Eve Online : Very impressive game.
Photosynth I had seen this before and I really will try to make one myself.
British Library Well, this is less fantastic to me in terms of GUI, but it is a enormous access to data.
WorldWide Telescope Very impressive!
Yosemite Extreme Panoramic Imaging Project Also very impressive. Click on result by the way.

The Cloud was off course a topic in this presentation with the .NET Services and SQL Services. Will look into these in the coming weeks.

Lieven Cardoen

<

TechDays Day I: Identity & Cloud Services

Posted by admin on March 14th, 2009

In this presentation I kinda got lost a couple of times. I hoped to see some examples of Azure in practice, but this wasn't really the case (except one example that I hope to see soon on the blog of Vittorio Bertocci).

My interest was more in Azure for Web Developers. Azure Service Platform is designed to help developers create, deploy, manage and distribute web applications and services. Also, if you have a lot of traffic and load, you'll pay more, otherwise you'll pay less. Hosting is provided for you.

I'll just need to try it out. I know WebORB has managed to run their applications in the Cloud, so it shouldn't be a problem.

Quote:

Next time you'll want to build something in house, ask yourself:
Do I really need a generator here, or could I just connect a plug?

Link to Azure Services Platform

thx, Lieven Cardoen

<

TechDays Day I – Architecture: The good, the bad and the ugly

Posted by admin on March 10th, 2009

I was a little bit too late for this session, but I did manage to grab the most important things. The presentation began with a lot of antipatterns and then followed with good patterns. Most of the things were rather obvious. A really funny thing was an example of the MSSQL database behind one of the first versions of SharePoint. There were like hundreds of tables with absolutely no relationships between them. Instead they created some 500 stored procedures that needed to take care of the integrity of the database... Guess there are also 'disaster developers' working for Microsoft.

Anti patterns

McKinsey Syndrome

  • We know it all, we don't nee to listen...
  • They don't know what they really want...
  • Just a cookie-cutting re-delivery...

Opposite Anti-pattern: Obedient Butler

Napkin Doodle

  • It was so straight-forward requirement...
  • We agreed on all req's during lunch...
  • Light projects don't need heavy process...

Opposite Anti-pattern: Documentation Overkill

Measure abuse

  • Each req must have success metrics...
  • If you can't measure it, it is not there...
  • We need binary criteria of achievement...

Opposite Anti-pattern: Softie-softie

Start small, grow fast

  • Just for couple of users first...
  • Prototype, patch-up, deploy...
  • We'll add scalability later...

Opposite Anti-pattern: Let's Go Global NOW!

Best-of-breed

  • All the best tools (best database, best webserver, ...) but no communications beween them...

Opposite Anti-pattern: Vendor Lock-in

YAGNI (You Ain't Gonna Need It)

  • I'm sure nobody needs this requirement...
  • I bet this one is totally irelevant...
  • Too low on priority list...

Opposite Anti-pattern: Analysis Paralysis

Reinventing the wheel

  • We can do it better. Much better...
  • It would be boring to re-use the old stuff!
  • I trust my code and my code only.

Opposite Anti-pattern: Golden Hammer (One thing that solves everything... everything must be a nail...)

Sales-driven Design

  • We sold it, you just implement it...
  • Trust me, I'm technical too...
  • Does it work? Shut-up then...

Opposite Anti-pattern: Technological Purity

YAFL (Yet Another Fine Layer)

  • Architecture is simplicity, not intellectual violence

Good patterns

  • Modularity (degrees of freedom)
  • Open-ended systems (specific vs generic). Move from Application-Specific (solution) to General-Purpose (Infrastructure)
  • Build to grow (Wu Wei)
  • Identifier, Format and Protocol (back to the roots)
  • Middle-out Architecture (Wide range of implementations, Minimal Spec and Wide range of uses)
  • Poor-man Application Model
  • Web-Oriented Architecture
  • Lines matter more than boxes (Protocals are inherently stable, applications are not)
  • Dependency Inversion (Fold knowledge into data so program logic can be stupid and robust, What needs to be easy to understand and change goes into data, What will be stable goes into code). Data should depend on code, Code should not depend on data.
  • New-age development with MetaData and Model-Driven Design
  • Virtual worlds, virtual rules
<

Allow Port on Windows Server to enable WebORB Messaging

Posted by admin on March 6th, 2009

Had a problem starting the WebORB RTMPServer (in global.asax) today which was solved after adding the port as an exception in the Windows FireWall.

Log from WebORB:

[Thread-11] WEBORB INFO:6/03/2009 11:26:37:shutting down WebORB Message Server
[Thread-11] WEBORB EXCEPTION:6/03/2009 11:26:37:System.Net.Sockets.SocketException: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
at Weborb.Messaging.RTMPServer.shutdown()
[Thread-15] WEBORB EXCEPTION:6/03/2009 11:26:37:System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall
at System.Net.Sockets.Socket.Accept()
at Weborb.Messaging.RTMPServer.run()
[Thread-11] WEBORB EXCEPTION:6/03/2009 11:26:37:System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
at System.Net.Sockets.Socket.Disconnect(Boolean reuseSocket)
at Weborb.Messaging.RTMPServer.shutdown()

Adding an exception in windows firewall is done in the "Windows FireWall Settings". Choose tab Exceptions and Add port... There you enter the port that you use for the RTMPServer (default 2037), give a name and choose TCP.

thx, Lieven Cardoen

<

Copyright © 2007 Johlero – Cardoen Lieven. All rights reserved.