Long Cloud Technologies
"... A Yankee in the Land of the Long White Cloud, Aotearoa ..."

Working with Orchard from a Hard Programmers Prospective – Part I

Moving Orchard from WebMatrix to a “real” programming environment.

For the record, that sub-title is meant in jest. WebMatrix is a a real programming environment, but you know us professional programmers, we are just a bit on the snobbish side, and so unless it is “our” development environment (OS, Language, Tool, Etc.) we do have a tendency to sneer at the alternatives.  The truth of the matter is, that there is so much to learn out there, that there is no way we can know it all.  We are forced by necessity of not truly being the geniuses we sometimes think we are, of specializing in some way in our choice of languages and tools.  We are a lazy bunch and we will often go out of our way to avoid having to “work”, and learning something new is “work”.  Since I have no illusions that I am lazy (I know I am lazy), I will take the “hit” of work of moving out of a dev environ that I am not used too (and having to learn it) to move into a dev environment where I already know how to swim like a duck.

Historical note: as I sit here typing up this post, twitter has just informed me that it is possible that an Official with Japan’s safety agency says that a Meltdown may be under way at Fukushima Nuclear Reactor.  I hope Twitter is wrong.

So let’s start with installing Orchard using the Microsoft Web Platform Installer(WPI) Rather then repeating what is already out there I refer you to the documentation post at the Orchard web site on Installing Orchard with the WPI for the complete list of steps and recommendations. Suffice it to say I installed the WebMatrix platform, then installed the Orchard CMS application, naming the site OrchardWebMatrix.  Finishing up the install and configure steps, this is what I got. …

Whoops, wrote the above paragraph in anticipation of it working correctly… it didn’t; seems that the instructions on the Orchard website aren’t exactly complete.  I followed their steps, and Orchard didn’t install in WebMatrix and it didn’t run! DOH.  Seems that if you have a professional .Net Development machine configured (meaning Server 2008 or Windows 7 with IIS installed and configured) the WPI, doesn’t install by default into WebMatrix, you have to do an extra step they left out of the instructions.

Once you have downloaded and installed Web Platform Installer to your machine, click the Add to include Orchard CMS as an item to install.

Image

This is from the Orchard website.  If you have IIS installed, BEFORE you click the Install button as they tell you to, make sure to click the “Options” hyperlink just to the left of the Install button.

image

Make sure to select the IIS Express (required for use with WebMatrix) the option, then click ok THEN click install. At that point you can return to the instructions on Orchard and go on your way.

Wait, they left something else out from the instructions,

When the installation is complete, click the Launch link.

Image

When you launch Orchard in your browser, you will be presented with the Orchard setup screen.

They make it seem like when you click Launch that you go right into Orchard, you actually don’t..  you go into WebMatrix like this.

image

In order to Launch Orchard you need to click on the URL There at the top.  So I did and configured it to use the Compact Framework SQL.

I’ve taken a quick spin around the WebMatrix, and it’s a pretty good starting point…  I think I even know web developers who would prefer it to my “professional” Visual Studio 2010 setup…  Maybe I will take the time to learn this thing… but not today.  If you click on the Files section of the Un-Outlook bar you get an interesting Tool Ribbon button if you have VS installed.

image

Clicking on that Visual Studio launch button and you get this.

image

Orchard loaded up in Visual Studio as a Web Application.  Not too shabby.

Now let’s see how we can get Orchard setup to run correctly in IIS.  From my earlier attempts I know we can do it using the WPI, let me walk thru that method first.

Ok, this time in the WPI after we click “Add” for Orchard, and before we click install, let’s go into that options dialog again and select the other option – IIS

image

Click OK and Click Install, Accept the License, and we get a new dialog

image

I’ll leave it to go into the Default Web Site, and name it OrchardWpi.

Now you may notice that above it says Step 1 of 2… They lie, there is no step 2 of 2, Orchard just starts installing.  Once it is done you get the following..

image

Click on the Launch Orchard CMS and let’s see what happens.

image

Wow what do you know, it works.  Click Finish Setup and we are good to go.

image

Let’s see where that ended up on the Harddrive, no great surprise c:\inetpub\wwwroot\orchardWpi

image

Oh and look there is a csproj file in there… opening it in VS gets us this.

image

Not too bad, though I am sorry to see that it doesn’t get set to run against the IIS directory where it is installed. That is easily fixed.

image

OK, enough with the WPI doing our work for us, let’s manually set this thing up.

Turns out the instruction for Manually installing Orchard on the Orchard web site can’t be beat.  I followed their directions and it worked like a charm.  But I think I want to be a little more adventurous and install the whole source project to see what I get. So download the Source Code from the codeplex website

Ok, that was easy and now we have the whole system set up to really allow us to dig into the guts.

I open the solution and in Visual Studio 2010. Rebuild the entire solution, no errors that’s good.

Open the project window for Orchard, and on the web tab, select Specific page (leaving the entry blank), check the Enable Edit and Continue (because this is 2011, and I Love Edit and Continue, naysayers be damned), and hit the run with debug button

image

Site started up, ready for configuration.

image

So I click Finish Setup and (It is all a lie, there is no Pie afterwards) I have a working Orchard site with all open source available and loaded up for me in Visual Studio. 

Note, next screen shot is a “Lie”

image

Next time we see about building a module.

 

It’s all really a Lie

Ok, folks to be totally fair, the last screen shot and “TA-DA” sentence is really not exactly true.  You see I started this blog entry at home on my home dev machine and I got some REALLY strange errors in trying to get that last step from “enter configuration” to completed site, all source running Visual Studio 2010.  What I actually got on my home machine was this:

image

I worked on it for a couple of hours trying to figure it out and as of this writing, I actually still don’t know what the problem is on my home machine.  Finally I threw up my hands, it being the weekend and all, and put it aside.  Came into work this morning, and tried the EXACT same steps on my work computer, and lo and behold it worked as I detailed above.  So I decided to finish off this post, but I’m not about to give up on figuring out why it didn’t work at home.  If you go to this Post Orchard Source Install Problems I will keep a running log of my efforts to figure it out at home.

Posted on 13 Mar 11 17:09 by matthew.hintzen |

Bookmark this post with:

E-mail | Comments(0) | Comment RSS


Linq odd behavior and the need for a .ToList() [where I suspect there shouldn’t be any need]

Give an Entity Frameworks model that has an EmployerUsers table, in which there are two columns, Guid and Name  Consider this code…

List<SelectListItem> employerUserSelectList = new List<SelectListItem>( );

var employerUsers = dal.EmployerUsers.Where( eu => eu.EmployerGuid == SecurityHelpers.EmployerGuid );

employerUserSelectList.Add( new SelectListItem( ) { Text = " [ Select TeamMember ] " , Value = Guid.Empty.ToString( ) } );

employerUserSelectList.AddRange(
   employerUsers.ToList( ).Select(
      eu => new SelectListItem( )
      {
         Text = eu.Name ,
         Value = eu.Guid.ToString( )
      }
   )
);

The important piece of code I want you to really look at is this:

 

employerUsers.ToList( ).Select(
   eu => new SelectListItem( )
   {
      Text = eu.Name ,
      Value = eu.Guid.ToString( )
   }
)

now compare that with this…

employerUsers.Select(
   eu => new SelectListItem( )
   {
      Text = eu.Name ,
      Value = eu.Guid.ToString( )
   }
)

Would you or would you not expect these to both work exactly the same?  Well I would but if you try to run the code with the second clause you get the following error

image

System.NotSupportedException was unhandled by user code
  Message=LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
  Source=System.Data.Entity
  StackTrace:
		...SNIP...
  InnerException: 

Yeah, pretty weird, you have to add the .ToList() to coalesce the IQueryable into an IEnumerable BEFORE you call the .Select.

I think this is a bug, either the .Select shouldn’t be allowed on the IQueryable if it can’t handle it, or it should be smart enough to do the .ToList() if necessary.

Your Thoughts?

You can reach me on Twitter at @matthewhintzen:  http://twitter.com/matthewhintzen

Posted on 26 Aug 10 22:58 by matthew.hintzen |

Bookmark this post with:

E-mail | Comments(0) | Comment RSS