Tomorrow night (Tuesday, August 23rd), we are having another meetup to talk about using MVC inside of Sencha’s JavaScript products.  I (Peter Kellner) will be talking for the first 20 minutes about how we are integrating the MVC pattern in our Silicon Valley Code Camp web site, then Ed Spencer from Sencha will follow on talking a lot more about MVC and best practices as well as Q&A

Hope you can make it.  Details are here:

http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/events/28760211/

 

image

(About 100 People)

The Presentation was broken down into three parts. 

Part 1

Created a windows razor project that cached in image on a web site using best practices for threading and locking.  The code and project to do this are below:

var downloadByteArray = HttpContext.Current.Cache[cacheName] as byte[];
if (downloadByteArray == null)
{
// make sure multiple requestors are not filling up the cache
lock (LockVal)
{
downloadByteArray = HttpContext.Current.Cache[cacheName] as byte[];
if (downloadByteArray == null)
{
Thread.Sleep(sleep * 1000);

string imageLocation = HttpContext.Current.Server.MapPath("~") + imageUrl;

downloadByteArray = File.ReadAllBytes(imageLocation);
if (cacheExpiresSeconds > 0)
{
HttpContext.Current.Cache.Insert(cacheName, downloadByteArray,
null,
DateTime.Now.Add(new TimeSpan(0, 0, 0, cacheExpiresSeconds)),
TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
CacheInsertCounter = 9999; // any touch of this increments the global counter
}
}
}
}

 

 

Part 2

Tips from Steve Souders

 

Part 3

Sprite Library from Microsoft Example: 

 

imageIMAG0174IMAG0177

I’m trying to download a base64 encoded image that is about 4 Megabytes embedded inside a JSON object.  When I first tried this from my MVC3 Web application, I got the error:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

 

(more…)

So, here are the steps necessary to install NuGet on my windows laptop computer.  I’ve got vs2010 (not sp1) installed, I’ve disabled both Resharper and .net Reflector just to be safe.

First step, is to go to the NuGet.org web site and click on Install.

image

 

Accept the default:

 

image

 

Run Visual Studio 2010 again, then go into Tool/Extension Manager and select “Automatically check for updates to installed extensions” as follows:

 

image

 

Then, go to View / Other Windows / Package Manager and you will get the Nu-Get prompt.

image

 

Now, you’ have the NuGet prompt as follows.

 

image

At the PM prompt, to install scaffolding, start typing the following:

Install-Package mvc  {then press tab for auto expansion}

You’ll get a list of all packages that begin with mvc as follows:

image

I choose MvcScaffolding, press enter and.. you’ll get the error that you need to have a project open.  Of course, because it wants to add it to your project.

 

image

 

Now, let me add a real project with a simple class called MyTeam

public class MyTeam
{

[Key]
public int ID { get; set; }

[Required]
public string Name { get; set; }
public string City { get; set; }
public DateTime Founded { get; set; }
}

Now, when I re-run the last command, I get all my Controllers and Views.

image

Hope this helps, I have a lot more to learn now.

* I’m adding this comment after the post has been written to let anyone coming here know of another great post that goes further to explain no only what I’ve done here, but also two other ways including Mock and using Json Serialization.  The Post is written by Ashic Mahtab, aka “HeartattacK” on the forums.  His well written and informative article is here:  ASP.NET MVC – Unit Testing JsonResult Returning Anonymous Types.

This post will show how to return a simple Json result from an ASP.NET MVC 2.0 web project.  It will show how to test that result inside a unit test and essentially pick apart the Json, just like a JavaScript (or other client) would do.  It seems like it should be very simple (and indeed, once you see the answer it is), however there are lots of length discussions on the forums about this with all kinds of positives and negatives.  The one I based my solution on is from Stack Overflow and is here..  My personal length discussion that did not really yield a satisfactory answer is here.

If you follow my method, you’ll be able to unit test a JsonResult created by an MVC asp.net web application.

(more…)

Over the past couple years, the focus of the web development I’ve been doing involves building highly flexible, highly scalable and straight forward web sites to implement and maintain Line of Business (LOB) applications.  As you can probably tell from my posts, I’m very “practical” focused, and at the same time have a desire to build awesome web applications.

The technology pairing I’ve chosen is Microsoft’s .Net platform with MVC on the server, and ExtJS on the client.  Though it’s possible to still use ExtJS with standard html/aspx pages, I’ve found the best combination is to use 100% JavaScript on the client (ExtJS) and have all the server side technology be 100% service based.  I’ve used LINQ2SQL extensively as well as Entity Framework in the latest Visual Studio 2010 release.

The learning curve was quite steep to actually be able to efficiently build highly flexible, highly scalable applications using these technologies, but now that I know it, I wouldn’t have it any other way.

I’m considering putting together a series of 4 Day Classes around the country (or even world) that would basically teach people the methods and patterns I’ve learned and essentially leap frog a development team into being able to quickly do what it has taken me years to figure out.  I’ve been fortunate enough to know the top 1% instructors and I’m sure with the right incentive, can get them to join me in both putting together these classes as well as teaching them.

(more…)

Cutting to the chase, I choose Vladimir Bodurov’s Color Formatter!

For the past year or so, I’ve been working on a project that uses Microsoft’s ASP.NET MVC for providing data to our pure JavaScript application.  That is, there are no web forms, no dynamic HTML generation, just 100% JavaScript running on the client.  I’m using a library called ExtJS which gives us high quality “forms like” user interactions and MVC for getting the data.  That is, the Application looks like this:

image

The data retrieval URL used by the JavaScript look like:

(more…)

I’ve just started (within the past 2 days) learning and building a prototype with Microsoft’s new MVC platform.  It’s really just another project type in Visual Studio 2008, but it changes the way you write asp.net applications.  So far I like it, but I’m still on the honeymoon.  I have not really tried to do anything complex yet, and because it’s new to me, the simple things are still hard.  Scott Guthrie’s posts posts have been helpful, as well as reading a pre-release of Manning’s upcoming book ASP.NET MVC In Action by Jeffrey Palermo, Ben Scheirman and Jimmy Bogard.

(more…)

© 2012 PeterKellner.net. All Rights Reserved