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

The What and Where

Something that may not be obvious is if are creating an asp.net WebForms project and you put a datasource such as SqlDataSource or ObjectDataSource for example on the page, how can you prevent the SqlSelect associated with that datasource from being triggered.

The answer is to set the control’s visible property to false.  That’s it!

(more…)

(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 planning on launching some small consumer software products in the next couple months and to support this effort, I need to have a CMS, Forums Software, Store Front (Credit Card Processing) and Wiki solutions up and running.  Since I’m a .Net guy, my first choice is to use Microsoft .Net technology, but if I don’t find anything there that suits me, off to the LAMP stack I go.  It’s important to me that all of these are tied together with a single sign-on.  It always irritates me when you go to a site and they make you first log in to the site, the create a separate login for forums.  I will avoid that experience for my customers and users.

 

My Research

My research first started with Google/Bing type searches.  That really leads me to many choices.  Actually too many.  Next, I go to my friend network.  The first obvious person I turn to is Scott Cate because he seems to always have the best advice on this kind of thing. The guy is plugged into everything!

Scott give me a very strong recommendation to look at Umbraco.  He says he is personally involved in writing code for that CMS, it’s very extensible, has a great admin UI and bottom line, is just good stuff.  So, Off I go to http://umbraco.org.

 

(more…)

* 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…)

 

In this post, we’ll take a straight forward procedure based set of code and convert it to LINQ using a ReSharper from JetBrains suggestion.   I’ve found that in general, when I do things with foreach syntax, there is often a better way in Linq to do this.  The better does not jump out at me sometimes, however with ReSharper, it is often a button click away.

(more…)

 

This is probably something pretty simple, hardly worth blogging about, but it took me a little while (15 minutes)  to figure out how to open a file ReadOnly with StreamReader,  so hopefully, next person looking will hit my blog post right away and save themselves 14 minutes.  StreamReader can be very useful in C#.

Say you have a block of code like the following for simply reading all lines of a file:

(more…)

One of the fun parts of being an MVP is that occasionally we get asked to help at Microsoft events and answer questions around topics that are just fun to talk about regardless (and usually includes a free lunch).  Today, I was sitting at the ASP.NET Dynamic Data table.  We probably had about 10 people come and go.  turns out, the most interesting topic was Commerce server.  One of the guys at the table talked about a LINQ provider they developed that lets you make commerce server look just like any other LINQ data source.

Here are some pictures from my table.

CIMG0100 CIMG0102

(including, by twitter handles @Zannabanana and @EmilyF)

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…)

Microsoft’s big developer conference (PDC http://microsoftpdc.com/) happens about every other year when Microsoft has big announcements.  Turns out, there was one last year, and for the first time ever, they are having a second one in row this year.  Reason is because of large announcements from Microsoft including Windows 7.

The conference is Tuesday through Friday.  On Monday, there are special invents, usually full day in nature.  I’ve been asked to participate in the Windows 7 Bootcamp on Monday showing some of the new technology that is available from Microsoft.

image

(more…)

This is just going to be a short post, but I bet it’s something I do a large number of times so I thought I’d blog it.  Say you get back from something like a web service an array of objects.

(more…)

So, this is kind of embarrassing, that it took me a while to figure this out.  I have not been doing pure asp.net server control programming for a while, but I figure since it took me a while, maybe there is someone else in the same boat.

So, you have a GridView or DetailsView that has standard “Edit” “Update” “New” type command buttons on them.  The way they get there is by having the declaration something like this:

(more…)

Many of you know of ORCSWeb either by reputation, or by way of Scott Forsyth, one of my ASP.NET MVP brothers.  In case you don’t, they are a managed hosting solutions company specializing in Microsoft technologies.  I’ve used their basic services for quite a while and have always been very happy.  It has always seemed that anytime I’ve called them (and it always seems like the middle of the night) one of their tech support staff is always available to help me, and go the extra mile if necessary.

The company I’m now working at is small and we don’t have a lot of resources to maintain hardware and do operating system type support.  We do have a high load requirement so we need a very robust supported solution.  Before this, I’d always been in the under $50 per month type plan with ORCSWeb, but I decided I needed more servers and a higher level of support.  I really did not know what level of support to expect when signing up for the managed servers but decided to go for it anyway.

All  can say is WOW!!!  I am over the top impressed.

(more…)

So, you have an enum defined as follows:

public enum CompanyAddressType
    {
        Unknown = 0,
        Primary = 1,
        Warehouse = 2,
        Distribution_Center = 3,
        Cross_Dock = 4
    }

You want to iterate through the list and put the data into an asp.net dropdownlist.

(more…)

Today was my first time doing 2 presentations during the same day at a professional conference (VSLive, Las Vegas).  Both sessions were fun to present and hopefully the audience got as much out of it as I did.  Lots of great questions, several twitter posts and best of all, they both finished on time (that is, I finished the material at the time I meant to!).

Here is the material for the first presentation:

(more…)

Last night, I gave a 90 minute presentation on how to use ExtJS with ASP.NET serving up the data at the San Francisco Microsoft Office to what seemed to be between 50 and 100 people.  I started out with just a basic overview of ExtJS, starting with a hello world app, then, finally building it into a full blown paging, updating, inserting and deleting Membership Management editor.  The final application is actually here if you want to see how it runs:

PeterKellnerMSPodium

(more…)

Background

At my company, we have been running a workflow process that is taking 6 hours to complete.  This is a new project so we’ve had the good fortune to be able to use the latest Microsoft technologies.  We are a Microsoft shop, so that means Sql Server 2008, C#, ASP.NET, ExtJS, LINQ to SQL (hoping to move to Entity Framework someday) and others.  After spending all day running performance analysis tools and basically performing a full audit of the 6 hour process, we sadly concluded that our time was being eaten up by LINQ to SQL processing.  My experience has always been that anything you do on the compiled code side is usually overwhelmed by database access times, usually at least ten to one.  Well, I learned a lot yesterday.

(more…)

© 2012 PeterKellner.net. All Rights Reserved