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

Working with Orchard from a Hard Programmers Prospective – Part II

Creating a Hello World Module the Orchard way

So here we are ready to do the next part in our series of Orchard Discovery… Let’s make their Hello World module in the default installation, and then let’s see about implementing the Hello World in Visual Studio 2010, using no helpers.  “Buckle Up Boys, it’s going to be a bumpy ride”

So to start with, Here is the link to the tutorial provided by Orchard website on how to do the “Hello World”.  The first thing they tell you is before you get started to download and install the Code Generation feature Command-line Code Generation . To be totally fair I’m going to use the OrchardWpi we got running in WebMatrix to do this part…  I start up WebMatrix, select Choose a Site option and Select my Orchard Site.

image

image

Now we click on the URL for the orchard website and open it up, get into Manage settings and from here on out we just follow the steps in the original article on installing the tools.

Tips for their instructions:

  • first up, there are way too many modules in the gallery if you use the Feed: Any optionimage Be sure to drop that down and select the image and click the Apply button.
  • Gee wouldn’t it be nice if there was a sort order? don’t look for it there isn’t one as of 1.0
  • Gee wouldn’t it be nice if there was a search function?  Again don’t look for it, there isn’t one as of 1.0
  • Quickest way to find your module is do a Ctrl+F (find function for your browser) and search for Code Generation
    image
  • Hey, if I install a module, how about we assume that I WANT to use it, other wise I probably wouldn’t have isntalled it. Can we make the default for installed modules as setting it to already being enabled? that would be helpful

With that done, we continue on our way with the Hello World Tutorial. And right off the bat we have our first question from their instructions: “Open the Orchard command-line”; so how do you open the command-line.  Intuitive it is not, here is a link to the instructions on using the command-line interface.  Basically you need to open a Command line in the bin directory of the Orchard website you want to work on… Hey, give them a break, this is version 1.0…  Don’t forget to make sure you start up the command line as an administrator, to save yourself some grief, and making it a Visual Studio 2010 command prompt would probably be best, although supposedly not required.

You can find the bin directory by going back to WebMatrix and clicking on the path link for the website, and navigate down from there to the bin directory.

image

Ok, now that we got the command prompt open we continue on with our exercise from the Hello World Tutorial. First you need to get the Orchard Commandline tool started.  I’ll save you the digging around in the documentation to find out how: from the command line in the bin directory run the Orchard.exe.  That will initialize the Orchard Command line tools and then we basically just run the command codegen module HelloWorld.

image

I decided to follow the editing instructions using the built in editor in WebMatrix

image

Editorial: A txt file?  you might as well have an INI file.  AND you have a warning that I should be careful to use spaces and not tabs to indent?  Come on Orchard developers, I know XML is verbose and over used, but in this case it seems a lot more intelligent, what we have now looks so VB 3 world type… (and for the record I started programming in VB3 so please don’t flame me too much).

Ok, I save my changes and move onto the next step, where they recommend that I put in a Routes.cs file in the HelloWorld Folder, let me show you how I did that in WebMatrix.  (make sure to click on the “Files” header in the Un-outlook bar), I click on the HelloWorld folder and then click on the Create a new file link on the page.

image

The model dialog that opens has Common Selected for “File Types” none of which will give you the ability to create a class, click on the Suggested Category scroll down and find the Class (C#) item, click on it and in the Name box below set it to Routes.cs and click OK

image

Copy and paste the text from the tutorial and repeat the process as instructed for the HomeController.cs, then do the same for the View file.

Then the instructions tell you to add some lines manually to the HelloWorld.csproj file ( and this tutorial is obviously not for the newbie or someone who wants to ask questions.  It tells you want to do, not so much on the how ).  Just follow thru the instructions. So I did and this is what I got…

image

OK, so I can make Orchard say hello, I have no idea how that all comes together so let’s see if I can take it apart.

First things first, I think we need to know what the CodeGen did before we know how to proceed manually.  Consequently I’m going to run CodeGen and create a new module called UMadeThis.  I’ll follow the same steps as above from the command line.

Note: if you create a module in Orchard using command line and it doesn’t show up in WebMatrix, be sure to Right Mouse on the Modules Folder and Click the Refresh, your module should now show up.

Going again in the Files group, find the UMadeThis folder and let’s “expand” every folder; Now let’s go see what got made…

image

Not a whole bunch.  The web.config for both the Scripts and the Styles is the following

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>
  <system.web>
    <httpHandlers>
      <!-- iis6 - for any request in this location, return via managed static file handler -->
      <add path="*" verb="*" type="System.Web.StaticFileHandler" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers accessPolicy="Script,Read">
      <!--
      iis7 - for any request to a file exists on disk, return it via native http module.
      accessPolicy 'Script' is to allow for a managed 404 page.
      -->
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
    </handlers>
  </system.webServer>
</configuration>

The web.config is in the View Directory is a little more interesting

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>
  <system.web>
    <httpHandlers>
    </httpHandlers>

    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <controls>
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

At first glance seems pretty standard for an MVC View Web.config, but taking a closer look I noticed something else: just below the first block of code is from the code generated by the CodeGen in Orchard, the second block is from a normally generated MVC project.

<pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

<pages 
        validateRequest="false" 
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

They look almost the same but I see a minor difference in the Orchard Stuff,  The type engines for the Orchard have all had the processorArchitcture specified processorArchitecture=MSIL. basically if not specified your module would be built to what ever processorArchitecture was specified in the build settings, but this extra flag overrides that, and makes sure that your module is built to the MSIL, Microsoft Intermediate Language.  MSIL can be viewed as the assembly code of the CLR.  It means of course that your module is not optimised for the target processor architecture, but on the plus side, this means it will run correctly in CLR at run time.

Finally I noticed one other thing, the View web.config DID NOT include the section for razor web pages…

Now that was interesting, so where is that information for Razor pages located? it is located in base Orchard website web.config file.  In a normal MVC generated project, the reverse is true.  Let me do a quick comparison between the razor entry in the Orchard Web site’s base web.config

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Linq" />
        <add namespace="System.Collections.Generic" />
        <add namespace="Orchard.Mvc.Html" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

And the razor entry in a standard MVC projects View Web.Config file

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="RecoveryAssist.Dal" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

And if you look at the pageBaseType you see the real difference.  In Orchard they want to make sure that the Page base type is based on the Orchard.Mvc.ViewEngines.Razor.WebViewPage, whereas a standard mvc project makes System.Web.Mvc.WebViewPage the page base type.  Again, I’m not sure what impact that has, but I’d be willing to bet it isn’t insignificant.

Next time, we will do this all over again, but inside of Visual Studio 2010…

Posted on 20 Mar 11 14:38 by matthew.hintzen |

Bookmark this post with:

E-mail | Comments(0) | Comment RSS


New Code Highlighter plugin for Windows Live Writer

Just download and installed a new Syntax Highlighter Plugin for Windows Live Writer, for usage with Alex Gorbatchev’s SyntaxHighlighter jscript stuff.  The new plug in was created by Tugberk Ugurlu, you can find it here: http://tugberkugurlu.com/archive/windows-live-writer-codehighlighting-plugin-for-alex-gorbatchev-s-syntaxhighlighter

It is greatly appreciated from me, as the one I was using was created back in 2007… and nothing since then was good enough.

Now all that is left for me it so provide a Razor Plugin to go with Gorbatchev’s library.

Posted on 20 Mar 11 14:33 by matthew.hintzen |

Bookmark this post with:

E-mail | Comments(0) | Comment RSS


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


Working with Orchard from a Hard Programmers Prospective – Prologue

So after much research and study, our intrepid group of programmers at Red Jungle decided we would attempt to settle on the Orchard CMS as our Platform of choice for clients looking for a CMS solution.  We did this for many reasons, but here are the highlights as far as I’m concerned

  • Completely open source http://orchardproject.net/
  • ASP.NET MVC 3 base (with Razor)
  • Originally built by Microsoft, but no longer owned by Microsoft
  • Funded by Microsoft (with no strings attached) for the next two years
  • Principle Developers of Oxite, Erik Porter and Nathan Heskew joined team (outside MS perspective)
  • Plug-in Architecture and extensibility built on a simplified model.

Before I go much further, I think a quick retrospective on last Microsoft Opensource CMS system is in order.  It was built in ASP.NET 1.0 using what was then considered best practices.  During internal development it was known as IBuySpy, and was meant to showcase those best recommended practices when creating a n-tiered web platform.  The Main developer they had brought in for the example site took the core of the IBuySpy example and extended it to a Full Featured CMS system that we all know better as DotNetNuke.

I’ve used DotNetNuke in the past, I’ve even wrote a tutorial about making modules for DNN and explaining what is really going on under the hood as you develop the module: Creating a DNN Module and Understanding DNN Architectural Approach.  While DNN continues to be used and does a great job, it, like so many old systems, has a bit of a legacy built in that it can’t just drop, that at times can make it feel creaky and old.

The world has moved on quite a bit since IBuySpy, and sometimes it is for the best to sell the old house and start from a fresh new foundation, we at Red Jungle feel that Orchard is just such a candidate.  If it becomes even half as successful as DNN was before it, I think we will have made a VERY good choice.

Now that doesn’t mean that I don’t have some issues with Orchard, life is beautiful, la la la.  First up, the install, extension and maintenance of Orchard was made to be easy for people with minimal technical background. By default if you use the install provided by the The Microsoft Web Platform it uses the new Microsoft WebMatrix which in itself is a free-ware and geared towards open source development (you didn’t really expect Microsoft to let AMP be the only free option out there did you)?  While I think the WebMatrix is a great tool, and the price is right (free for everything to run a website) for a hard code monkey like myself it just doesn’t have the horse power and the shade tree mechanic capabilities I want.

Also the out of the box tutorials and instructions of how to extend Orchard are VERY easy, but they “hide” too much under the covers for my taste.  I may yet end up using the shortcuts and tools, but I want to understand exactly how all those helpers fit together to make the magic work.

So I have three main goals with this set of blog posts and two sub-goals. 

  1. I want to move Orchard (and document how) to run in a more robust development environment then WebMatrix, get it to run in IIS with full customization from within Visual Studio 2010 Universal, as a Web Application.
  2. Create the Hello World module using the CodeGen capablities as explained on the Orchard website here, then recreate the Module doing everything manually.
  3. Finally Recreate my “ToDo Task List” from my original DotNetNuke tutorial on codeproject to be applicable to Orchard and deconstruct the Architecture of the system as it applies to Module Creation.
  4. Sub-goals
    1. Package the ToDo Task list as a redistributable, and document how to do so
    2. Publish the ToDo module on NuGet feed for Orchard.
Posted on 13 Mar 11 13:16 by matthew.hintzen |

Bookmark this post with:

E-mail | Comments(0) | Comment RSS