#DDD10 – My Ramblings

This post is a little late as DDD10 was on the 1st September, but I have been extremely busy #cough# attending Gaga concerts and working late. (Yes I’m a big Gaga fan, what of it! :0) )

For anyone that doesn’t know, “DDD” simply means DeveloperDeveloperDeveloper and are community events which are (at the moment) free to the community and sponsored by various partners. Now just because they are free this definitely does not dilute the content on offer. Before I ramble on about the Sessions on offer, I would like to say what a marvellous job the organisers and speakers of the events do, to make these events so successful. You really do feel the passion from these guys and gals. Humbling to say the least.

This is my 2nd year attending the event (again held at Microsoft). This year i wanted to choose Sessions which are applicable to what im trying to achieve now, instead of what interests me from the title. So as I’m learning ASP.NET and MVC at home at the moment, i decided to focus the majority of my efforts around web technologies (where possible), so i chose the following Sessions:



Keeping JS Sane

ASP.NET MVC gone wrong

WebSockets and SignalR – Building the Real Time Interactive web

Performance and Scalability, the Stack Exchange way

Windows 8 with XAML and C#

Developing a production immune system


My Experience….


As you can see a good mix of Sessions.  Overall, I had an really good day, enjoying myself immensely and learning some stuff along the way. Big thanks to all everyone involved. So how did i find the sessions……

  1. Keeping JS Sane – The first session of the day was run by an excitable Rob Ashton. The first thing I learnt was “Add Ponies”, which I presume is a reference to Rob’s fascination of My Little Pony“?Lets set the scene – It is 9.30AM on a Saturday morning, I have been up since 4am and travelled from Durrington-By-Sea to Reading with my laptop bag and overnight bag. I’m tired and ratty but I was looking forward to the day ahead, until I’m bombarded with references to a kiddies toy. I sighed…. alot…. It is a shame, because Rob’s work on line is astounding and in any normal circumstances I’m sure he is a great guy to be around and a good laugh. The problem was the early morning and a ratty Gareth, who didn’t appreciated the finer side to Rob’s hyperactive start.I did learn a few things (considering I’m a JS nOOb that should of been a must), which i will investigate. Specifically using JSLint and Zombie client-side testing framework.  I would like to point out though, that I met a (drunk) Rob at the after party and he is a very nice and witty chap and consumed at last count, 3 pizza’s at Pizza Express. Fair play to the chap!
  2. ASP.NET Gone Wrong – So after the first session, i was hoping for more, and i got it. This session was presented by Stuart Leeks and Simon Ince from Microsoft. The presentation was around the 11 rules of MVC where people slip up. It was a well thought out and well presented session, with some solid code samples, and Stuart and Simon really worked well together. I took a lot from this presentation, and i will be thinking over the coming weeks on how i can use them to improve my coding using MVC. The rules are:
    1. Controller Rule 1 – NO Business Logic in your Action Methods!
    2. Controller Rule 2 – A good Action Method should only be approximately 15 lines of code.
    3. Controller Rule 3 – Action Filters are your friend! Do not use a Base Controller to code generic functionality applicable to a Controller (Like Logging).
    4. Controller Rule 4 – Don’t use JavaScriptResult in your C#. Leave your Javascript on your Views.
    5. View Rule 5 – Always use strongly-typed Views. Don’t use the dynamic ViewBag or ViewData. Use ViewModels instead for this.
    6. View Rule 6 – Minimise logic within Views.
    7. View Rule 7 – I have written down “No Javascript in Views”. I will need to confirm this one i think. Unless Stuart meant putting your Javascript code within a separate Javascript source file and not directly in a View.
    8. View Rule 8 – Don’t use Base Vie. Create one per View.  This is for maintainability purposes.
    9. Model Rule 9 – Have a separate ViewModel for each View.
    10. Model Rule 10 – Don’t use base ViewModels. If needed use Child Actions to perform generic functionality.
    11. Model Rule 11 – Dont add any behavioural logic to the ViewModels.
  3. Websocket’s and SignalR – This was another solid session by Chris Alcock, and another I’m glad I attended. It was a tough choice as Gary Short’s Raspberry Pi was on at the same time, and my inner-Nerd really wanted to attend. Chris though did an excellent job describing Websocket’s and its implementation within SignalR. Nice session with the following points of interest:
    1. Websockets Protocol is currently on Version 13.
    2. Browser support is: Firefox 11+, Chrome 16+ and IE10.
    3. SignalR doesn’t just use Websockets, so can fall back to older protocols for browsers which doesn’t support Websockets.
    4. Tip: Never create a SignalR folder in the root of your Visual Studio Project as this will break stuff.
    5. Tip: Breakpoints can Timeout in SignalR Projects when debugging.
  4. Performance and Scalability, The Stack Exchange Way – Another one of my favourite sessions. Marc Garvell  presented some really interesting ideas using technologies he help build at Stack Exchange to locate performance issues that could be costly to them. It was a insightful presentation talking about Profiling using Miniprofiler  which can be used in MVC projects. Its a single assembly which can be included, and you pepper it around your code-base to use its functionality. It can also be used in a production environment which is a nice feature. Another example was their Micro-ORM, Dapper, as a light-weight alternative to EF  and LINQ-2-SQL.
  5. Windows 8 using XAML and C# – I chose this session because i attended Kris Athi DDD9 presentation on WIndows Phone 7 Development and thoroughly enjoyed it. I wasn’t disappointed this time either. A good session on Windows 8 and its feature set like Notifications, Charms and Contracts etc, but nothing i didnt already know. Kris though knows what he is talking about and i was thoroughly impressed again on his talk. This is a good thing, because if he doing future talks, i will probably choose his session based on his skills alone and not the subject matter, so well done Kris!
  6. Developing a Production Immune System – Out of all the sessions before DDD10 started, it was this one which i was looking forward to the most. I think i had a perception that this was going to be talking about creating systems to detect and fix issues automatically (as per the session brief), but it wasn’t. David Walker did warn us at the beginning of the presentation that he had picked a wide topic, and that he did. I didnt get anything from the presentation I’m afraid, which is testament to the fact with minus no notes to do with this talk! Sorry!


The Winner is….



So after 6 sessions, my top presentation goes too… well its a tie between ASP.NET MVC Gone Wrong and Performance and Scalability, The Stack Exchange Way. Both were really good solid presentations which I thoroughly enjoyed.

Overall though the day itself was marvellous and i think well received by all present. I will end by saying again a massive thank you to the organisers, sponsors and of course the speakers. DDD10 is what it is not because its free, but because of the community and the guys who take the time to organize it. Thank you 🙂

P.S. Pizza Express was brilliant as well and I met some lovely chaps as well.

Stephen Roberts

Aaron Rhodes

Max Edwards

Simon P Stevens

Dan Kendall

[MVC 3] MvcImage Alpha Released – Thumbnail

Ive now just uploaded the 2nd release for MvcImage, that now inlcudes Thumbnail support (Previewing and storage using Entity Framework).

This can be found here:

Codeplex: http://mvcimage.codeplex.com/releases/view/83859

Github: http://garfbradaz.github.com/MvcImage/

I will write a blog post tomorrow about how to support Thumbnails to go with this release. Please download and let me know what you think!

ADO.NET Entity Framework stack
Image via Wikipedia
Enhanced by Zemanta

[MVC 3] MvcImage Project……Its Alive!…..

Over the last few months i have done the following blog posts to explain how to handle images using MVC and various technologies like JQuery and Entity Framework. Now the majority of hits i receive are concerning these blogs posts, so obviously Image Handling is a common Achilles heel. The posts are also being referenced in forums to answer Image related questions. So i have decided to create a Open Source project which combines all of these blog posts into one solution for people to use. This project can be found here for anyone who wants to use it:

Codeplex: http://mvcimage.codeplex.com/

Github: http://garfbradaz.github.com/MvcImage/

At the moment it includes everything i have blogged about and shows you how to extend the RegisterModel to include adding Images when registering a new user. I will be adding the following to the project moving forward as i want this to an organic project that grows:

  1. Adding Thumbnails to the database and displaying these
  2. A details page of users so you can view their details and the images – A User Dashboard for the Admin
  3. A Image FileResult.
  4. A PDF document explaining what the Project does and where.

MY ORIGINAL BLOG POSTS – Image Handlers – JQuery/ASP.NET/SQL DB & Entity Framework (MVC3)

Tutorial 1 – Image Preview – JQuery

Tutorial 2 – Image Preview – HTML Helpers

Tutorial3 – Upload Image – SQL Server & Entity Framework

Tutorial 4 – Images – Downloading Images

Tutorial 5 – Thumbnail Support

Enhanced by Zemanta

[MVC 3] Upload Image –SQL Server & Entity Framework

UPDATE: I have now combined all my MVC Image Handling  blog posts into a Open Source Project. Feel free to check this out once you have read the post.


Original Blog Post:

The last post i described how to create a HTML Helper for Image Previewing. This time around we will be uploading an image to a Database, which is handled little differently than normal CRUD operations.

The following block of code shows my Create action method within my UserProfile controller:

 1:         public ActionResult Create(UserProfile userprofile,
 2:          HttpPostedFileBase imageLoad2)
 3:         {
 4:             var profileimage = new Medium();
 6:             if (imageLoad2 != null)
 7:             {
 8:                 using (Image img =
 9:                 {
 11:                     //--Initialise the size of the array
 12:                     byte[] file = new byte[imageLoad2.InputStream.Length];
 14:                     //--Create a new BinaryReader and set the InputStream
 //-- for the Images InputStream to the
 16:                     //--beginning, as we create the img using a stream.
 17:                     BinaryReader reader =
                              new BinaryReader(imageLoad2.InputStream);
 18:                     imageLoad2.InputStream.Seek(0, SeekOrigin.Begin);
 20:                     //--Load the image binary.
 21:                     file = reader.ReadBytes((int)imageLoad2.
 23:                     //--Create a new image to be added to the database
 25:                     profileimage.Created_Date = DateTime.Now;
 26:                     profileimage.Source = file;
 27:                     profileimage.File_Size = imageLoad2.ContentLength;
 28:                     profileimage.File_Name = imageLoad2.FileName;
 29:                     profileimage.Content_Type = imageLoad2.ContentType;
 30:                     profileimage.Height = img.Height;
 31:                     profileimage.Width = img.Width;
 32: #if DEBUG
 33:                     profileimage.Record_Status = "T";   //--Testing.
 34: #else
 35:                         profileimage.Record_Status = " ";/--Live.
 36: #endif
 40:                 }
 41:             }
 43:             if (ModelState.IsValid)
 44:             {
 46:                 db.Media.AddObject(profileimage);
 47:                 db.SaveChanges();
 49:                 return RedirectToAction("Index", "Home");
 51:             }
 53:             var viewModel = new UserProfileViewModel
 54:             {
 55:                 UserProfile = userprofile,
 56:                 UserTypes = userTypes
 57:             };
 59:             return View(userprofile);
 60:         }

This method creates has two parameters, the model UserProfile, and the imageLoad2 is the file posted. Have a look at the previous post about building the HTML.

NB: the parameter name imageLoad2 needs to be the name of the input file from the view so that is is bound (using the MVC Model Binding). If you used a different name the parameter would be null.

The method creates a Entity Framework model Medium, which is my class to describe the SQL Table which holds the Images. The images are saved within SQL as (MAX). Quite easy really, create a   to convert the image stream to binary,  then using the EF to the entity set, then save it to the table.

There we have it. Join me next time for downloading the image, using another custom HTML Helper.


Enhanced by Zemanta