I have had a lot of fun looking around in the inner workings of the new Dynamic Data Store. The concept is brilliant and can be used in a lot of different ways. My Itera.MultiProperty was one way of grouping and using properties in other places than the original was meant for, but that used text as storage for the sub properties.
I have made a project that can take a object and edit it with EPiServer properties.
If you have class like this:
public class Contact
{
public string Name { get; set; }
public string Note { get; set; }
public ContactInfo Work { get; set; }
public ContactInfo Home { get; set; }
}
public class ContactInfo
{
public string Street1 { get; set; }
public string Street2 { get; set; }
public int? ZipCode { get; set; }
public string City { get; set; }
}
The my code loops thou the items and use PropertyString to edit the string properties and PropertyNumber for the int’s. Other classes uses a new Property that can take any object and display it in edit mode
with this code you can set up the edit mode seen above and get the new values on the object
We can now add this object as a property to a episerver page
We add the prosject ObjectEdit and make a setting like this:
This settings are using the class ObjectAsEPiServerProperties to display the edit properties so no more need to make the UI part of the settings page.
or you can make a new property like this:
[Serializable]
[PageDefinitionTypePlugIn]
public class PropertyContact : PropertyObjectEdit
{
public PropertyContact() : base(typeof(Contact)) { }
}
And with some new attributes on the properties you can make the UI look almost as you want :), you can change what property that should be used to render each property.
public class Contact
{
[Tab(DisplayName="Name",ID="tab1")]
public string Name { get; set; }
[Display(typeof(PropertyLongString),DisplayName="My notes")]
public string Note { get; set; }
[Tab(DisplayName = "Contact info", ID = "tab2")]
[Display(DisplayName = "My work adress")]
public ContactInfo Work { get; set; }
[Display( DisplayName = "My home adress")]
public ContactInfo Home { get; set; }
}
Another fun function in this code is that you can add a list so you can easy edit and insert config and page settings.
if we add
public List<ContactInfo> OtherContactInfos { get; set; }
to the Contact class it will render like this:
To get hold of the values in a web page I’m overriding the standard Property getter to allow for dot notation. That can be used for instance in the standard episerver property handler
<EPiServer:Property PropertyName="Contact.Name" runat="server" />
<EPiServer:Property PropertyName="Contact.Work" runat="server" />
public static void Start()
{
PropertyDataCollection.GetHandler = OwnPropertyHandler;
}
public static PropertyData OwnPropertyHandler(string name, PropertyDataCollection properties)
{
PropertyData prop = PropertyGetHandler.DefaultPropertyHandler(name, properties);
string[] parts = name.Split(".".ToCharArray());
if (parts.Length > 1)
{
if (properties.Get("PageLink") != null && (properties.Get("PageLink") is PropertyPageReference))
{
PageData p = EPiServer.DataFactory.Instance.GetPage((properties.Get("PageLink") as PropertyPageReference).PageLink);
object start = p.PageObjects[parts[0]]; //Any other way?
prop = FindInObject(start, parts, 1, properties);
}
}
return prop;
}
Download
The code is a bit buggy, and there is not much error checking turned on :) but have committed it to epi code here
Is there any way of clearing the Dynamic data store? When I change/rename my classes the store complains about missing property?