SlideShare a Scribd company logo
Orchard Dynamic Class Extensions
         (A Code Club Presentation)
               May 14, 2012
                       Presenters
                       Mark Dolar
                       Nesim Sisa

    Based on Article: Orchard Extensibility by Bertrand Le Roy

    http://msdn.microsoft.com/en-us/magazine/hh708754.aspx
Orchard Dynamic Class Extensions
                Key Questions -

 Why does Orchard have virtual methods?


 What does it mean to dynamically extend a class at
 runtime?


 Why dynamically extend a class at runtime?


 How do I dynamically extend a class at runtime?
Orchard Dynamic Class Extensions
        A Simple T/F Quiz about Orchard:
        Content Items are the central content entity in Orchard and
T   F   are entities users consider an end- product (like Blog
        Postings or a product page).
        In Orchard, Content Types are classes of Content
T   F   Items.

         In Orchard, Content Items are not instances of classes
T   F   such as BlogPost, Product or Widget.

        In Orchard, Content Items are composed of Content Parts
        where any two Content Items with common sets of
T   F   Content Parts are considered of the same Content Type
        class.
Orchard Dynamic Class Extensions
        A Simple T/F Quiz about Orchard:

T   F   Content Items in Orchard correspond to a URL.


        MPEG-2 Video Stream Closed Captioning Data is a
T   F   Content Part in Orchard.

        New Content Parts can by added to Orchard
T   F   without programming (ie. Visual Studio)
        Development.

T   F   In Orchard, Content Items are instances of Content Types.
Orchard Dynamic Class Extensions
          A Simple T/F Quiz about .NET:

T   F   C# is a statically typed language as opposed to
        a dynamically typed language.

        Static typing in C# means we can only describe
T   F   the fields, properties and methods inherent in all
        dynamic objects, not the objects themselves.
Orchard Dynamic Class Extensions
What important things do we know about Orchard's
dynamic content types?
   This is actually exactly how the blog post content type is defined

 1.ContentDefinitionManager.AlterTypeDefinition
 ("BlogPost",
 2. cfg => cfg
 3. .WithPart("BlogPostPart")
 4. .WithPart("CommonPart", p => p
 5. .WithSetting
 ("CommonTypePartSettings.ShowCreatedUtcEditor",
 "true"))
 6. .WithPart("PublishLaterPart")
 7. .WithPart("RoutePart")
 8. .WithPart("BodyPart")
 9. ); F
Orchard Dynamic Class Extensions
Extending the BlogPost content type dynamically

Two Approaches:
1. Adding an existing Content Part via a Yummy Recipe

       -Comments

        -Tags
2. Building a new Content Part via a Module

       -Brand X GPS

       -Metatag addition to page head example

       -Totally Unique Recording Device (T.U.R.D.)
Orchard Dynamic Class Extensions
Extending the BlogPost content type dynamically

Metatag addition to page head example:

         1.<meta content="Orchard is an open source Web
         CMS built on ASP.NET MVC."

         2. name="description" />

         3.<meta content="Orchard, CMS, Open source"
         name="keywords" />


    Module will add the above properties to the head section of
    the Blog Post Page

    Used to facilitate Search Engine Optimization

    A previously unavailable Content Part
Orchard Dynamic Class Extensions
Extending the BlogPost content type dynamically

Building a new Content Part via a Module

           -The Record

           -The Part Class

           -The Driver


These are basic components to a Content Type Module
Orchard Dynamic Class Extensions
Building a new Content Part via a Module

             -The Record
          0. public class MetaRecord :
          ContentPartRecord {

          0. public virtual string Keywords { get; set;
          }
          1. public virtual string Description { get;
          set; }
          2. }

Deriving from ContentPartRecord not absolutely necessary

A Record provides object persistence in the database

Virtual properties enables dynamic mix-in
Orchard Dynamic Class Extensions
 Building a new Content Part via a Module

                -The Record
            1.public class MetaHandler :
            ContentHandler {
            2. public MetaHandler(
            3. IRepository<MetaRecord> repository)
            {
            4. Filters.Add(
            5. StorageFilter.For(repository));
            6. }
            7.}
The record's only job is persistence.

Via a method, the Record table maps to the record class with calls to
the ContentPartRecord plus Keywords and Description String
Columns.
Orchard Dynamic Class Extensions
  Building a new Content Part via a Module

                 -The Part Class
   The representation of the part itself is another class that
   derives from ContentPart<TRecord>:

1.public class MetaPart : ContentPart<MetaRecord> {
2. public string Keywords {
3. get { return Record.Keywords; }
4. set { Record.Keywords = value; }
5. }
6. public string Description {
7. get { return Record.Description; }
8. set { Record.Description = value; }
9. }
10.}
Orchard Dynamic Class Extensions
Building a new Content Part via a Module

               -The Part Class
 -Part acts as proxy to Keywords and Description properties, but
 can be accessed through base ContentPart class.


 -Strong typing of of Keywords and Descriptions enabled by As
 method (analog to CLR cast operation):

 1.var metaKeywords = item.As<MetaPart>().Keywords;



 -Part class can be a composite; exposing subobject methods or
 composite properties.
Orchard Dynamic Class Extensions
Building a new Content Part via a Module

                 -The Driver

-Class derived from CotentPartDriver

-Scaled-Down Controller

-Methods handling well-defined events

       -Display

       -Editor
Orchard Dynamic Class Extensions
 Building a new Content Part via a Module
              -The Driver
Sample Driver for metadata display method -
       1.protected override DriverResult Display(
       2. MetaPart part, string displayType, dynamic shapeHelper) {
       3. var resourceManager = _wca.GetContext
       ().Resolve<IResourceManager>();
       4. if (!String.IsNullOrWhiteSpace(part.Description)) {
       5. resourceManager.SetMeta(new MetaEntry {
       6. Name = "description",
       7. Content = part.Description
       8. });
       9. }
       10. if (!String.IsNullOrWhiteSpace(part.Keywords)) {
       11. resourceManager.SetMeta(new MetaEntry {
       12. Name = "keywords",
       13. Content = part.Keywords
       14. });
       15. }
       16. return null;
       17.}
Orchard Dynamic Class Extensions
Building a new Content Part via a Module
             -The Driver


     -Most Drivers return a Dynamic Object called a shape

     -Shapes are assembled by Orchard into a composite and
     dynamic view model for the entire request.

     -Default rendering can be overriden by inserting a file into
     the current theme.
Orchard Dynamic Class Extensions
                Key Questions -
 Why does Orchard have virtual methods?


 What does it mean to dynamically extend a class at
 runtime?


 Why dynamically extend a class at runtime?


 How do I dynamically extend a class at runtime?
Orchard Dynamic Class Extensions
                   Thank You!

Mark Dolar Contact Info:

Linkedin:
http://www.linkedin.com/pub/mark-dolar/0/95/344

Follow Mark’s Little Media Blog via Twitter – More
Common Sense than one Blog should enjoy:

Twitter Name: Powerfinger

Current Topic: The Top Ten Reasons We Need Big Data
Orchard Dynamic Class Extensions
                  Thank You!

 Nesim Sisa Contact Info:

 Linkedin:
 http://www.linkedin.com/pub/nesim-sisa/41/911/540

Email:

Nesim.Sisa at gmail.com

More Related Content

PDF
OrchardCMS module development
PPTX
Pragmatic orchard
DOCX
Hibernate notes
PDF
Working with Servlets
PPT
Spring hibernate tutorial
DOCX
Struts notes
PDF
Hibernate complete notes_by_sekhar_sir_javabynatara_j
PPT
AspMVC4 start101
OrchardCMS module development
Pragmatic orchard
Hibernate notes
Working with Servlets
Spring hibernate tutorial
Struts notes
Hibernate complete notes_by_sekhar_sir_javabynatara_j
AspMVC4 start101

What's hot (20)

PDF
Rest web service
PPT
Tumbleweed intro
PPT
Struts N E W
PDF
Exploring Maven SVN GIT
PPTX
Spring & hibernate
PDF
Leverage Hibernate and Spring Features Together
PDF
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
PDF
Reactjs Basics
PPT
3) web development
PDF
Ee java lab assignment 4
PDF
JSP Technology II
PDF
Lec6 ecom fall16
PDF
Share point review qustions
PDF
Lab 5a) create a struts application
PDF
Spring boot jpa
PDF
Lab4 - android
PPTX
Rest and Sling Resolution
PDF
Struts notes
PPT
Java serverpages
PPTX
Basics of Spring - KNOWARTH
Rest web service
Tumbleweed intro
Struts N E W
Exploring Maven SVN GIT
Spring & hibernate
Leverage Hibernate and Spring Features Together
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Reactjs Basics
3) web development
Ee java lab assignment 4
JSP Technology II
Lec6 ecom fall16
Share point review qustions
Lab 5a) create a struts application
Spring boot jpa
Lab4 - android
Rest and Sling Resolution
Struts notes
Java serverpages
Basics of Spring - KNOWARTH
Ad

Viewers also liked (17)

PDF
What will be YOUR Moonwalk?
PPT
2010 Alberta Chamber Agm pp
PPTX
02 блаженны плачущие
PPTX
PARIS COMO "LA CIUDAD DEL AMOR"
PPTX
НАГОРНАЯ ПРОПОВЕДЬ общее введение
PDF
What's your Moonwalk?
PPT
Earthquake ppt
PDF
Drømmeløftet Moonwalk + Innovation Norway: Norway beyond Oil & Gas
PPT
Disaster events p.p
PPTX
17-03 блаженны кроткие
PPTX
那個藏在你屁股後面的小玩意兒
PPT
Toll ppt
PPTX
ORGANISATION STRUCTURE
PPTX
India public expenditure recent
PPT
STAFFING
PPT
Earthquake ppt
PPTX
CHSurvey introduce
What will be YOUR Moonwalk?
2010 Alberta Chamber Agm pp
02 блаженны плачущие
PARIS COMO "LA CIUDAD DEL AMOR"
НАГОРНАЯ ПРОПОВЕДЬ общее введение
What's your Moonwalk?
Earthquake ppt
Drømmeløftet Moonwalk + Innovation Norway: Norway beyond Oil & Gas
Disaster events p.p
17-03 блаженны кроткие
那個藏在你屁股後面的小玩意兒
Toll ppt
ORGANISATION STRUCTURE
India public expenditure recent
STAFFING
Earthquake ppt
CHSurvey introduce
Ad

Similar to Orchard Dynamic Class Extensions (20)

PPTX
Copy is a 4 letter word
PPTX
Oleksandr Krakovetskyi - Orchard CMS
PPTX
Orchard
PDF
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
PDF
CUST-3 Document Management with Share
PPT
Objectifying drupal
PDF
People aggregator
PDF
Xv ocd2010-jsharp
PPTX
Getting started with WordPress development
PDF
Workshop: Creating your first WordPress plugin
DOCX
PRG 421 Education Specialist / snaptutorial.com
PDF
Django 1.10.3 Getting started
PPTX
In-Fisherman.com - Building an Enterprise Level Drupal Site
PPT
Word press interview question and answer tops technologies
PPT
PPT
20100707 e z_rmll_gig_v1
PPT
The smartpath information systems c plus plus
DOCX
Prg421
PPT
CustomizingStyleSheetsForHTMLOutputs
PPTX
Best Practices for Migrating a Legacy-Based CMS to Drupal
Copy is a 4 letter word
Oleksandr Krakovetskyi - Orchard CMS
Orchard
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
CUST-3 Document Management with Share
Objectifying drupal
People aggregator
Xv ocd2010-jsharp
Getting started with WordPress development
Workshop: Creating your first WordPress plugin
PRG 421 Education Specialist / snaptutorial.com
Django 1.10.3 Getting started
In-Fisherman.com - Building an Enterprise Level Drupal Site
Word press interview question and answer tops technologies
20100707 e z_rmll_gig_v1
The smartpath information systems c plus plus
Prg421
CustomizingStyleSheetsForHTMLOutputs
Best Practices for Migrating a Legacy-Based CMS to Drupal

Orchard Dynamic Class Extensions

  • 1. Orchard Dynamic Class Extensions (A Code Club Presentation) May 14, 2012 Presenters Mark Dolar Nesim Sisa Based on Article: Orchard Extensibility by Bertrand Le Roy http://msdn.microsoft.com/en-us/magazine/hh708754.aspx
  • 2. Orchard Dynamic Class Extensions Key Questions - Why does Orchard have virtual methods? What does it mean to dynamically extend a class at runtime? Why dynamically extend a class at runtime? How do I dynamically extend a class at runtime?
  • 3. Orchard Dynamic Class Extensions A Simple T/F Quiz about Orchard: Content Items are the central content entity in Orchard and T F are entities users consider an end- product (like Blog Postings or a product page). In Orchard, Content Types are classes of Content T F Items. In Orchard, Content Items are not instances of classes T F such as BlogPost, Product or Widget. In Orchard, Content Items are composed of Content Parts where any two Content Items with common sets of T F Content Parts are considered of the same Content Type class.
  • 4. Orchard Dynamic Class Extensions A Simple T/F Quiz about Orchard: T F Content Items in Orchard correspond to a URL. MPEG-2 Video Stream Closed Captioning Data is a T F Content Part in Orchard. New Content Parts can by added to Orchard T F without programming (ie. Visual Studio) Development. T F In Orchard, Content Items are instances of Content Types.
  • 5. Orchard Dynamic Class Extensions A Simple T/F Quiz about .NET: T F C# is a statically typed language as opposed to a dynamically typed language. Static typing in C# means we can only describe T F the fields, properties and methods inherent in all dynamic objects, not the objects themselves.
  • 6. Orchard Dynamic Class Extensions What important things do we know about Orchard's dynamic content types? This is actually exactly how the blog post content type is defined 1.ContentDefinitionManager.AlterTypeDefinition ("BlogPost", 2. cfg => cfg 3. .WithPart("BlogPostPart") 4. .WithPart("CommonPart", p => p 5. .WithSetting ("CommonTypePartSettings.ShowCreatedUtcEditor", "true")) 6. .WithPart("PublishLaterPart") 7. .WithPart("RoutePart") 8. .WithPart("BodyPart") 9. ); F
  • 7. Orchard Dynamic Class Extensions Extending the BlogPost content type dynamically Two Approaches: 1. Adding an existing Content Part via a Yummy Recipe -Comments -Tags 2. Building a new Content Part via a Module -Brand X GPS -Metatag addition to page head example -Totally Unique Recording Device (T.U.R.D.)
  • 8. Orchard Dynamic Class Extensions Extending the BlogPost content type dynamically Metatag addition to page head example: 1.<meta content="Orchard is an open source Web CMS built on ASP.NET MVC." 2. name="description" /> 3.<meta content="Orchard, CMS, Open source" name="keywords" /> Module will add the above properties to the head section of the Blog Post Page Used to facilitate Search Engine Optimization A previously unavailable Content Part
  • 9. Orchard Dynamic Class Extensions Extending the BlogPost content type dynamically Building a new Content Part via a Module -The Record -The Part Class -The Driver These are basic components to a Content Type Module
  • 10. Orchard Dynamic Class Extensions Building a new Content Part via a Module -The Record 0. public class MetaRecord : ContentPartRecord { 0. public virtual string Keywords { get; set; } 1. public virtual string Description { get; set; } 2. } Deriving from ContentPartRecord not absolutely necessary A Record provides object persistence in the database Virtual properties enables dynamic mix-in
  • 11. Orchard Dynamic Class Extensions Building a new Content Part via a Module -The Record 1.public class MetaHandler : ContentHandler { 2. public MetaHandler( 3. IRepository<MetaRecord> repository) { 4. Filters.Add( 5. StorageFilter.For(repository)); 6. } 7.} The record's only job is persistence. Via a method, the Record table maps to the record class with calls to the ContentPartRecord plus Keywords and Description String Columns.
  • 12. Orchard Dynamic Class Extensions Building a new Content Part via a Module -The Part Class The representation of the part itself is another class that derives from ContentPart<TRecord>: 1.public class MetaPart : ContentPart<MetaRecord> { 2. public string Keywords { 3. get { return Record.Keywords; } 4. set { Record.Keywords = value; } 5. } 6. public string Description { 7. get { return Record.Description; } 8. set { Record.Description = value; } 9. } 10.}
  • 13. Orchard Dynamic Class Extensions Building a new Content Part via a Module -The Part Class -Part acts as proxy to Keywords and Description properties, but can be accessed through base ContentPart class. -Strong typing of of Keywords and Descriptions enabled by As method (analog to CLR cast operation): 1.var metaKeywords = item.As<MetaPart>().Keywords; -Part class can be a composite; exposing subobject methods or composite properties.
  • 14. Orchard Dynamic Class Extensions Building a new Content Part via a Module -The Driver -Class derived from CotentPartDriver -Scaled-Down Controller -Methods handling well-defined events -Display -Editor
  • 15. Orchard Dynamic Class Extensions Building a new Content Part via a Module -The Driver Sample Driver for metadata display method - 1.protected override DriverResult Display( 2. MetaPart part, string displayType, dynamic shapeHelper) { 3. var resourceManager = _wca.GetContext ().Resolve<IResourceManager>(); 4. if (!String.IsNullOrWhiteSpace(part.Description)) { 5. resourceManager.SetMeta(new MetaEntry { 6. Name = "description", 7. Content = part.Description 8. }); 9. } 10. if (!String.IsNullOrWhiteSpace(part.Keywords)) { 11. resourceManager.SetMeta(new MetaEntry { 12. Name = "keywords", 13. Content = part.Keywords 14. }); 15. } 16. return null; 17.}
  • 16. Orchard Dynamic Class Extensions Building a new Content Part via a Module -The Driver -Most Drivers return a Dynamic Object called a shape -Shapes are assembled by Orchard into a composite and dynamic view model for the entire request. -Default rendering can be overriden by inserting a file into the current theme.
  • 17. Orchard Dynamic Class Extensions Key Questions - Why does Orchard have virtual methods? What does it mean to dynamically extend a class at runtime? Why dynamically extend a class at runtime? How do I dynamically extend a class at runtime?
  • 18. Orchard Dynamic Class Extensions Thank You! Mark Dolar Contact Info: Linkedin: http://www.linkedin.com/pub/mark-dolar/0/95/344 Follow Mark’s Little Media Blog via Twitter – More Common Sense than one Blog should enjoy: Twitter Name: Powerfinger Current Topic: The Top Ten Reasons We Need Big Data
  • 19. Orchard Dynamic Class Extensions Thank You! Nesim Sisa Contact Info: Linkedin: http://www.linkedin.com/pub/nesim-sisa/41/911/540 Email: Nesim.Sisa at gmail.com

Editor's Notes

  • #4: No matter what CMS you use to build your site, there will be a central content entity that goes by different names. In Drupal, it’s called a node, and in Orchard, it’s a content item. Content items are atoms of content such as blog posts, pages, products, widgets or status updates. Some of them correspond to a URL, and some don’t. Their schemas vary greatly, but what they have in common is they’re the smallest content units on the site. Or are they?As developers, our first reaction is to identify content items as instances of classes (post, page, product or widget), which is correct to an extent
  • #5: Question 1 certainly falseSome of them correspond to a URL, and some don’t. Question 2 may be true or false, depending on whether the Closed Captioning is being processed by a video player run by a driver. If the Closed Captioning is processed independent of the video, it could be it’s own content part (ie. A search algorithm).Question 3 probably false (requires a module). Content Types can be added without developmentQuestion 4 I think is true
  • #6: Question 1 is obviousQuestion 2 is probably true, but should initiate discussion. In other words, I can’t describe a Blog Posting because the definition is not universal. It turns out there are only two fields: Keywords and Descriptions and two methods: Display and Editor.
  • #7: There&apos;s not much Here...by designNo Comments or Tags
  • #9: The objective is to extend the capabilities of the Blog Post Content Type – is a new Content Type created?Figure 2 The SEO Meta Data EditorThese properties will be rendered into the head section of the page as standard metatags that search engines understand:&lt;meta content=&quot;Orchard is an open source Web CMS built on ASP.NET MVC.&quot;name=&quot;description&quot; /&gt;&lt;meta content=&quot;Orchard, CMS, Open source&quot; name=&quot;keywords&quot; /&gt;
  • #10: If you want to build a module, you will likely need each one these. One of them is optional – which one?
  • #12: That is basics of the Record
  • #13: The Part Class basically contains two properties – Keywords and Description
  • #14: Now we get to some interesting stuff –The part acts as a proxy to the record’s Keywords and Description properties as a convenience, but if it didn’t, the record and its properties would still be available through the public Record property of the base ContentPart class.Any code that has a reference to a content item that has the MetaPart part will be able to gain strongly typed access to the Keywords and Description properties by calling the As method, which is the analog in the Orchard type system of a CLR cast operation:varmetaKeywords = item.As&lt;MetaPart&gt;().Keywords;The part class is also where you’d implement any specific behavior of the part’s data. For example, a composite product could expose methods or properties to access its subproducts or compute a total price.Behavior that pertains to user interaction (the orchestration code that would in a regular ASP.NET MVC application be found in the controller) is another matter. This is where drivers come in.
  • #15: Each part in a content item has to get an opportunity to participate in the request lifecycle and effectively do the work of an ASP.NET MVC controller, but it needs to do it at the scale of the part instead of doing it at the scale of the full request. A content part driver plays the role of a scaled-down controller. It doesn’t have the full richness of a controller in that there’s no mapping to its methods from routes. Instead, it’s made of methods handling well-defined events, such as Display or Editor. A driver is just a class that derives from ContentPartDriver.
  • #16: Prepares the Rendering of the Part (extra precaution due to shared header region)
  • #17: By calling in to all the drivers for all the parts, Orchard is able to build a tree of shapes—a large composite and dynamic view model for the whole request. Its next task is to figure out how to resolve each of the shapes into templates that will be able to render them. It does so by looking at the name of each shape (Parts_Meta_Edit in the case of the Editor method) and attempting to map that to files in well-defined places of the system, such as the current theme’s and the module’s Views folders. This is an important extensibility point because it enables you to override the default rendering of anything in the system by just dropping a file with the right name into your local theme.