RSS 2.0
# Monday, February 14, 2011

You know, I like simple little nice enhancements that make things easier.  Like the extension manager in Visual Studio restarting the project you were in after doing an update that requires a restart of Visual Studio.  Phil Haack just blogged about the version 1.1 of NuGet being released.  I’ve applied plenty of extension updates and of course Visual Studio handled restarting properly.  Just wanted to make note of how those little things make a big difference in the user experience.

Technorati Tags:
Monday, February 14, 2011 9:06:29 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Visual Studio
# Monday, February 7, 2011

In our previous post, we very quickly put together a site using asp.net mvc, Entity Framework code first and MvcScaffolding templates.  That got it up and running, but of course there’s still plenty to do.  But before we get going in more development, let’s take a step back and look over the files so we understand what is going on.

So, how does MVC work? MVC stands for Model View Controller.  The pattern lends itself very well to having a good separation of concerns. That of course creates a very testable architecture. One of the goals for asp.net mvc was to use convention over configuration. How many times have you created a webforms application and had a ton of configuration in web.config?  Webforms straight out of the box uses a good deal of configuration just to get going.  MVC is structured in a predictable way.  There is a controllers directory where all the controllers are to be housed and a views directory where all the views are to be housed.  Routing is used to define how a URL is parsed out to map to the controllers.  So, our default route for KimmysCookbook.com is:

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Recipe", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

What this is saying is that when a URL comes in, the first part should map to a controller, the second part to an action on that controller and the third part is a parameter that will be passed to that action.  The last part defines the defaults.  If no controller is is passed then the default is Recipe.  So in our case, when a user navigates to http://www.kimmyscookbook.com mvc will map that to http://www.kimmyscookbook.com/Recipe/Index .  Notice how easy that URL is to read.  That URL tells the MVC framework to look for a controller named RecipeController (the controller prefix is assumed by the framework) and it looks in the Controllers directory off the root of the site for it.  Once that type is loaded, it will look for the Index method within it and execute that resource.  Notice I said resource.  That’s an important distinction.  We are not serving up pages, rather we are serving resources.  So far the only resource we have returned are Views, however we could return just plain content (text), JSON, a file or even write our out ActionResult.  Just derive from ActionResult.

Our current Index method on the Recipe controller is this:

        public ViewResult Index()
        {
            return View(this.repository.GetAllRecipes());
        }

This is returning a View.  By default, the framework is going to seek out a view in the Views/Recipe directory.  Again, convention over configuration.  It will also search the Shared directory as well.

Our model in this case is an IEnumerable<Recipe>. So we are passing a list of Recipes to the view.  The view’s job is simply to display the model passed to it.  The view is intended to be very simple, therefore you don’t have a code behind file as you do in webforms. 

Monday, February 7, 2011 10:48:40 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
mvc
# Thursday, January 20, 2011

Ok, well, for whatever reason, I wasn’t able to get the old project working with MvcScaffolding after updating to the RTM of MVC 3.  I had even run the upgrade tool.  We are and were dealing with beta software, sometimes that’s what happens.  Thankfully we weren’t too far along.  So, what I’ve done is created a new project and simply added all our model classes to the new project.

I then reinstalled our packages from NuGet:

image

image

Now we will do some scaffolding.

image

Change the default route to point to our Recipe Controller:

image

And wa-la, we’ve got a running application.

image

Since we never defined a connection string for the application, it created a new database in our Sql Server Express instance with the fully qualified name of the context class.

image

So you can see that outside of create our model classes, everything else can be automated and done very quickly.  Understanding what is actually going on is important, so next we’ll look in more detail at the files that were created.

Technorati Tags: ,
Thursday, January 20, 2011 10:52:44 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Entity Framework | mvc | SQL Server | Visual Studio
# Monday, January 17, 2011

Ok, so MVC 3 just RTM’d, so we are going to take a step back and upgrade.  First off, go uninstall the RC – be sure to uninstall both mvc 3 and the vs tools.  Once that is done you can open Web PI and install mvc 3.  If you don’t have Web PI yet, you can get 3.0 from here. http://www.microsoft.com/web/downloads/platform.aspx 

In reading the release notes, which you can download here, seems we shouldn’t have any issues moving this project forward since we are so new into it. The install takes quite a while because it does some updates to Visual Studio as well.

Monday, January 17, 2011 5:57:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
mvc
# Friday, January 14, 2011
Friday, January 14, 2011 9:14:58 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Uplifting
# Wednesday, January 12, 2011

Ok, so maybe that’s not correct … do Roman numerals even have decimals.  Hmmm… maybe I should have paid a bit more attention in that class. In Part I we set up our classes and data access “layer”.  Thanks to ErikEJ letting me know of a provider that he – uh – provided for SQL CE, we’ll integrate that in.  Since this wasn’t in the original plan, we’ll call this I.V or 1.5.  Smile

You can go get the files from here.  I’m just going to include the files rather than the binary.  I found an issue in the SqlCeMembershipUtils.cs file in the CreateDatabaseIfNeeded method.  It has to do with how the path shows up.  When checking for the file, the connection returns the following for the Database (path) property, which of course is not the path to the actual sdf file.  The connection works however.

image

So, I’ve modified that method like so:

        public static void CreateDatabaseIfRequired(string connection)
        {
            string dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory") as string;
            string physConnectionString = connection.Replace("|DataDirectory|", dataDirectory);
            string[] parts = connection.Split('|');
            string physFileString = Path.Combine(dataDirectory, parts[parts.Length - 1]);

            string sdfPath = string.Empty;
            lock (_lock)
            {
                using (var testConn = new SqlCeConnection(physConnectionString))
                {
                    sdfPath = testConn.Database;
                }
                if (string.IsNullOrWhiteSpace(sdfPath))
                    return;

                if (!System.IO.File.Exists(physFileString))
                {
                    //OK, try to create the database file
                    using (var engine = new SqlCeEngine(connection))
                    {
                        engine.CreateDatabase();
                    }
                }
                ValidateDatabase(connection);
            }
        }

You will of course need to modify the connections in web.config for the membership provider and add using System.IO; to the top.  The other option would be to skip the file check and just eat the exception if it’s because of the file already existing.

Technorati Tags: ,
Wednesday, January 12, 2011 7:42:48 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -
Entity Framework | mvc
# Saturday, January 8, 2011

If you haven’t already, go install mvc 3 RC.  This will also install NuGet which we will be using.  You can read more about mvc 3 and NuGet on ScottGu’s blog.

Create a new MVC 3 Web Application and use Razor for the view engine.  Probably a good idea to tick on the unit test box to create unit tests.

image

Next get the Package Manager Console open.  View | Other Windows | Package Manager Console

Now we want to install the Entity Framework Code First libraries.  NuGet makes this very easy:

image

The console window support auto-completion, so just type Ins [TAB] and a list of options will show. Choose Install-Package then type EFC [TAB] to choose through a list of packages.  Couldn’t be easier.  I’m not going to go into details about what that does, you can read all about it in ScottGu’s posts and the video of Scott Hanselman’s talk.

In our first post in the series, our first goal was to make a quick site.  Doing it quickly means we are going to let the Entity Framework create the database for us.  We will also be using SQL CE so there won’t be a full database dependency.  SQL CE 4.0 is now bin deployable, so we can just copy it up and it’ll work.

EF, much like MVC, uses convention over configuration.  So, since our context (code to follow) is going to be named Cookbook, if we create a connection string entry called Cookbook, EF will automatically use that.

  <connectionStrings>
    <
add name="Cookbook" connectionString="Data Source=|DataDirectory|KimmysCookbook.sdf" providerName="System.Data.SqlServerCe.4.0"
/>
  </
connectionStrings>

As an aside, if you don’t create a connectionstring at all, EF CTP5 will create a Sql Server CE 4.0 database under the App_Data directory for you using the fully qualified type name as the name of the database.

Now for our Context class.  We’ll create each of our supporting classes as we go.  Right click on the Models folder and add a class.  As you are typing, as you put in the classes for the generic collections, pressing Ctrl-. will present you with a context of options.  Since the classes won’t exist yet, you can have VS create the classes for you right then.  They will of course be empty, but the shell is there.  VS is also intelligent enough to put them in the same folder as the current class with the same namespace.  So, when you type public DbSet<Recipe, you’ll get a squiggly saying that Recipe doesn’t exist.  Ctrl-. and choose to have it create the class for you.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace KimmysCookbook.Models
{
    public class Cookbook : DbContext
    {
        public DbSet<Recipe> Recipes { get; set; }
        public DbSet<Ingredient> Ingredients { get; set; }
        public DbSet<Comment> Comments { get; set; }
        public DbSet<Favorite> Favorites { get; set; }
        public DbSet<Tag> Tags { get; set; }
        public DbSet<Rating> Ratings { get; set; }
    }
}

The above context class is all that is needed for data access.

Let’s fill in the rest of our classes.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace KimmysCookbook.Models
{
    public class Recipe
    {
        public int ID { get; set; }
        public Guid UserID { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public long PrepTime { get; set; }
        public long CookTime { get; set; }
        public int Serves { get; set; }
        public string Instructions { get; set; }
        public string IPAddress { get; set; }

        public virtual ICollection<Ingredient> Ingredients { get; set; }
        public virtual ICollection<Tag> Tags { get; set; }
        public virtual ICollection<Comment> Comments { get; set; }
        public virtual ICollection<Rating> Ratings { get; set; }
        public virtual ICollection<Favorite> Favorites { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KimmysCookbook.Models
{
    public class Ingredient
    {
        public int ID { get; set; }
        public int RecipeID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KimmysCookbook.Models
{
    /// <summary>
    /// This is for user based tagging
    /// </summary>
    public class Tag
    {
        public int ID { get; set; }
        public int RecipeID { get; set; }
        public Guid UserID { get; set; }
        public string Value { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KimmysCookbook.Models
{
    public class Comment
    {
        public int ID { get; set; }
        public int RecipeID { get; set; }
        public Guid UserID { get; set; }
        public string Text { get; set; }
        public string IPAddress { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KimmysCookbook.Models
{
    /// <summary>
    /// This is to tag a recipe as a favorite for a user
    /// </summary>
    public class Favorite
    {
        public int ID { get; set; }
        public int RecipeID { get; set; }
        public Guid UserID { get; set; }
        public DateTime DateFavorited { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KimmysCookbook.Models
{
    public class Rating
    {
        public int ID { get; set; }
        public int RecipeID { get; set; }
        public Guid UserID { get; set; }
        public int Value { get; set; }
        public DateTime RatingDate { get; set; }
        public string IPAddress { get; set; }
    }
}

You’ll notice in the classes that the UserID field is a Guid. In this iteration, we are going to use the Membership provider that is baked into asp.net. In a future release, we plan to use OpenID instead. That being said and to keep it simple, we want to have the membership baked into the database that EF is going to create.  Unfortunately, SQL CE 4 still doesn’t support stored procedures so the current implementation of membership won’t work with it.  According to ScottGu’s post, they are looking into create a set of providers that will work with it. 

Technorati Tags: ,
Saturday, January 8, 2011 8:22:55 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -
.NET | Entity Framework | mvc | SQL Server
# Monday, December 27, 2010

Years ago I purchased the domain KimmysCookbook.com as a joke.  A friend on facebook had posted a picture of her taking a turkey out of the oven and a bunch of us started commenting on it and eventually the domain came to be.  She is a good cook, the joke wasn’t about her cooking, just about making a cookbook.

Anyway, I never did anything with it really, just posted that picture and let it sit.  Got to thinking that it would be a cool recipe site and with all the new stuff coming out of Redmond recently, why not take the time to build it up piece by piece using these technologies. 

I’ve been toying with the idea for a while, so I’ve already created a database locally for storage, but since we are looking to use new technologies and also doing it on the cheap and fast, we’ll use EF4’s code first ability tied with SQL Server CE 4.

Here’s the path I’m looking to take.  Each of these will be a separate iteration and push to the server.

  1. Quick ASP.net MVC 3 with EF4 code first site
  2. Add Silverlight support for ingredient editing
  3. Add OData support
  4. Silverlight out of browser with touch support
  5. Windows Phone 7 application

As with any project, these items may change as we go along.  Next entry will outline step 1.

Monday, December 27, 2010 7:58:51 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
mvc | Silverlight | Windows Phone 7
# Monday, December 13, 2010

Registering your phone for development requires the use of Windows Phone Developer Registration tool.

image

In Windows 7, hit the Windows key (or start button) and type “reg”.  It should show up as one of the first items in the list.

You will want to have you phone tethered to your machine and unlocked if you use a PIN.  As it states, you must have an active account developer account for this to work.

Once the tool is up and your phone is tethered and unlocked, simply enter your Windows Live ID and password and hit the register button. Simple as that.  If you need to unregister a phone, just run the utility again with the phone you need to unregister and the button will change from “Register” to “Unregister”.

Technorati Tags:
Monday, December 13, 2010 4:54:23 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Windows Phone 7
# Saturday, December 11, 2010

Recently a friend of mine asked me about digital frames and specifically about the Toshiba DMF102XKU. I hadn’t heard of it, but have had my fair share of digital frames – none of which have really had all that I wanted in a frame.  I want one that can get online wirelessly via at least 802.11g with WPA for security. I read through the specs on Amazon and it sounded good, so I ordered three.  I wanted a couple for gifts as well.

Opening the box shows the remote and the instructions.  One thing to note, the instructions are just a quick start guide.  The little booklet says to get the full owners manual you have to download it.  The link unfortunately does not go to the owner’s manual and doing a search on the site doesn’t turn it up either.  That’s one strike against it.  I’ve emailed them about sending it out.  Will update this post with whatever response I get.  Along with the quick start guide an “important information” guide.  This is only in English, so if you don’t speak English you are out of luck.  Of course if you don’t read English, you probably aren’t reading this anyway.

Another issue is the stickers on the frame – they were a bit difficult to get off and left a bit of residue behind.

IMG_5163IMG_5166IMG_5167

The frame can either be mounted on a wall or use the stand.  The frame feels good, sturdy and well built.

IMG_5187

When you first turn it on, it runs through a demo slideshow which shows the capabilities of the frame and some sample pictures.  The resolution is 800x480 and it has a tilt sensor to detect if it’s in landscape or portrait mode.  That’s nice.

So, the device is powered up and going through the demo.  Grab the remote to start working with it.  Remote doesn’t work.  Hmmm.  Grab one from another unit. Still no go.  So perhaps the unit is bad.  Looks like I’ll need to get in touch with customer support.

Thankfully the unit has a control built into the frame that lights up when you touch it.

IMG_5188IMG_5189

So, let’s get this thing online.  That couldn’t be simpler if you have a modern router.  Just hit the WPS button on the router and the frame and it will do the rest for you.

Getting setup with online stuff is a little confusing.  In the image on the left above, there is an option for “Online Service Settings”.  It would make sense that this would be where you set up all your online stuff.  However, the only thing you can do there is setup 3 different Picasa accounts.  What you need to do is click Mode either on the remote (mine doesn’t work) or on the frame itself.  From there you click on FrameChannel and it will prompt you to activate your frame giving you an access code and a website to enter it into.  If you don’t already have a FrameChannel account, you can create one and the choose the services that will come down Here is a sampling of what can be done on FrameChannel.

image

I have set my facebook account up to feed into it, and within just a couple minutes the pictures started coming in from the facebook friends I selected to have feed it.  The “My Friends Photos” tab allows you to invite people to email or MMS photos to the frame.

There are a couple ads for FrameChannel that cycle through.  I need to figure out how to get rid of that.

You can also add things like Digg, Twitter, Facebook status messages and more to the frame.  I have added local events so when something is available in my area, it will show it to me.

Overall I’m pleased with the device. I hope I can get the couple issues I have worked out. Honestly, I’ll probably never use the remote, but I I want to have it available.

Saturday, December 11, 2010 5:18:42 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Review
Archive
<December 2014>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
George Handlin
Sign In
Statistics
Total Posts: 53
This Year: 0
This Month: 0
This Week: 0
Comments: 9
All Content © 2014, George Handlin
DasBlog theme 'Business' created by Christoph De Baene (delarou)