Example 1 (Simple)

Integrate a simple static data type into the CMS Console

In this simple example, we create a simple type "Demo.IItem" with three fields: Id (GUID), Title (String), Released (DateTime) and make it available in the Data perspective for adding, editing and deleting data items.

Note: You should create a class library for your IData types (with the references to Composite.dll and any other required ones), build it and place the DLL in /Bin on your website.

Static Data Type

  1. Create a class library project (for example, "SimpleType")
  2. In the project, create an IItem interface that inherits from IData, add three properties - Id, Title, Released - and add required attributes to both the IItem interface and the properties.
    using System;
    
    using Composite.Data;
    using Composite.Data.Hierarchy;
    using Composite.Data.Hierarchy.DataAncestorProviders;
    
    namespace Demo
    {
        [AutoUpdateble]
        [DataAncestorProvider(typeof(NoAncestorDataAncestorProvider))]
        [KeyPropertyName("Id")]
        [LabelPropertyName("Title")]
        [DataScope(DataScopeIdentifier.PublicName)]
        [ImmutableTypeId("{87122C34-E622-4e97-BD36-CBC398B862F9}")]
        public interface IItem : IData
        {
            [StoreFieldType(PhysicalStoreFieldType.Guid)]
            [ImmutableFieldId("{172DD44C-426B-4812-834B-6B45366E78CB}")]
            Guid Id { get; set; }
    
            [StoreFieldType(PhysicalStoreFieldType.String, 32)]
            [ImmutableFieldId("{ADB24D3D-FA2A-496a-BBE9-91CFEB88336F}")]
            string Title { get; set; }
    
            [StoreFieldType(PhysicalStoreFieldType.DateTime)]
            [ImmutableFieldId("{73AD86A2-C91D-42FB-9FD4-C40899AF9558}")]
            DateTime Released { get; set; }
        }
        
    }
    
    Download IItem.cs
     
    For more information on creating IData types, please see: Data types using C#.
     
    (See example for static page folder data and static page meta data below.)
     
  3. Build the project.
  4. Copy the DLL ("SimpleType.dll") to /Bin of your website.

Dynamic Form

In /App_Data/Composite/DynamicTypeForms, create an XML-based form definition for items of this type.


<cms:formdefinition xmlns:cms="http://www.composite.net/ns/management/bindingforms/1.0" xmlns="http://www.composite.net/ns/management/bindingforms/std.ui.controls.lib/1.0" xmlns:f="http://www.composite.net/ns/management/bindingforms/std.function.lib/1.0">
  <cms:bindings>
    <cms:binding name="Id" type="System.Guid" optional="true" />
    <cms:binding name="Title" type="System.String" optional="true" />
    <cms:binding name="Released" type="System.DateTime" optional="true" />
  </cms:bindings>
  <cms:layout>
    <cms:layout.label>
      <cms:read source="Title" />
    </cms:layout.label>
    <FieldGroup>
      <TextBox Label="Title" Help="The title of the item">
        <TextBox.Text>
          <cms:bind source="Title" />
        </TextBox.Text>
      </TextBox>
      <DateSelector Label="Released" Help="The date the item has been released">
        <DateSelector.Date>
          <cms:bind source="Released" />
        </DateSelector.Date>
      </DateSelector>
    </FieldGroup>
  </cms:layout>
</cms:formdefinition>
Download ItemForm.xml
 
For more information on creating form definitions, please see: Editing Form Markup.

Tree Definition

In /App_Data/Composite/TreeDefinitions, create an XML-based tree definition for items.


<ElementStructure xmlns="http://www.composite.net/ns/management/trees/treemarkup/1.0" xmlns:f="http://www.composite.net/ns/function/1.0">

  <ElementStructure.AutoAttachments>
    <NamedParent Name="Data" Position="Top"/>
  </ElementStructure.AutoAttachments>

  <ElementRoot>
    <Children>
      <Element Label="Items" Id="ItemsRoot">
        <Children>
          <DataElements Type="Demo.IItem, SimpleType" Label="${C1:Data:Demo.IItem:Title}" >
            <Actions>
              <EditDataAction Label="Edit" CustomFormMarkupPath="~/App_Data/Composite/DynamicTypeForms/ItemForm.xml" />
              <DeleteDataAction Label="Delete"/>
            </Actions>
          </DataElements>
        </Children>
      </Element>      
    </Children>
    <Actions>
      <AddDataAction Label="Add" Type="Demo.IItem, SimpleType" CustomFormMarkupPath="~/App_Data/Composite/DynamicTypeForms/ItemForm.xml"/>
    </Actions>
  </ElementRoot>
</ElementStructure>
Download ItemView.xml  

For more information on creating tree definitions, please read: Guide to Applications.

Note: Apart from the name of your data type, you should specify the name of the assembly in all the Type attributes in the tree definition file: Type=”Demo.IItem, SimpleType” (where “SimpleType” is the name of the assembly).

Now that you have everything in place, open the Data perspective. The “Items” node must appear at the top of the tree. You can add new items as well as edit and delete the existing ones.

The data of this type is stored in /App_Data/Composite/DataStores in the corresponding XML file - in this example, in "Demo.IItem_Published.xml".

Code sample: Static page data folder

For a static page folder, create an interface that inherits from IPageDataFolder. (For more information on creating IPageDataFolder types, please see: Data types using C#.)

using System;

using Composite.Data;
using Composite.Data.Hierarchy;
using Composite.Data.Hierarchy.DataAncestorProviders;

namespace Demo
{
    [AutoUpdateble]
    [DataAncestorProvider(typeof(NoAncestorDataAncestorProvider))]
    [KeyPropertyName("Id")]
    [LabelPropertyName("Title")]
    [DataScope(DataScopeIdentifier.PublicName)]
    [ImmutableTypeId("{93F95C27-B3EF-445B-B034-7844B6425176}")]
    public interface IFolderItem : IPageDataFolder
    {
        [StoreFieldType(PhysicalStoreFieldType.Guid)]
        [ImmutableFieldId("{0B70A463-CDB1-4302-A8C7-02D30CA8E6DE}")]
        Guid Id { get; set; }

        [StoreFieldType(PhysicalStoreFieldType.String, 32)]
        [ImmutableFieldId("{F45FB897-52F0-4C20-8DBF-1149358662EF}")]
        string Title { get; set; }

        [StoreFieldType(PhysicalStoreFieldType.DateTime)]
        [ImmutableFieldId("{89E1B884-AD01-4175-90B1-25C90C323529}")]
        DateTime Released { get; set; }
	}
}

Download IFolderItem.cs

To make the static page data folder available in the Console, ensure creating it on the application startup.

Code sample: static page meta type

For a static page meta type, create an interface that inherits from IPageMetaData. (For more information on creating IPageMetaData types, please see: Data types using C#.)

using System;

using Composite.Data;
using Composite.Data.Hierarchy;
using Composite.Data.Hierarchy.DataAncestorProviders;

namespace Demo
{
    [AutoUpdateble]
    [DataAncestorProvider(typeof(NoAncestorDataAncestorProvider))]
    [LabelPropertyName("Title")]
    [DataScope(DataScopeIdentifier.PublicName)]
    [ImmutableTypeId("{BD54274D-1218-43A4-B0C4-DC9B48E37D4F}")]
    public interface IMetaDataItem : IPageMetaData
    {
        [StoreFieldType(PhysicalStoreFieldType.String, 32)]
        [ImmutableFieldId("{A2E89174-E51E-4B20-9CC2-9C1A475077CB}")]
        string Title { get; set; }

        [StoreFieldType(PhysicalStoreFieldType.DateTime)]
        [ImmutableFieldId("{6A2CCFD2-0F79-40AF-9C9B-A8FEC0D015D5}")]
        DateTime Released { get; set; }
    }  
}

Download IMetaDataItem.cs

To make the static page data folder available in the Console, ensure creating it on the application startup.

Ensure creating static types on application startup

using Composite.Core.Application;
using Composite.Data.DynamicTypes;

namespace Demo
{
    [ApplicationStartup]
    public class Startup
    {
        public static void OnBeforeInitialize()
        {
            
        }

        public static void OnInitialized()
        {
            DynamicTypeManager.EnsureCreateStore(typeof(IFolderItem));
            DynamicTypeManager.EnsureCreateStore(typeof(IMetaDataItem));
        }
    }
}

Download Startup.cs

For information on using EnsureCreateStore, please see: Data types using C#. For information about the ApplicationStartup attribute, please see Application Startup.