Itera.DynamicDataEdit v0.1 - Edit your objects with EPiServer Properties

by: Anders Hattestad

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

image

with this code you can set up the edit mode seen above and get the new values on the object

image

We can now add this object as a property to a episerver page

image

We add the prosject ObjectEdit and make a setting like this:

image

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; }
    
}

image

image

 

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:

image

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?

06 February 2010

Tags:


Comments

  1. This is from the samplecode, maybe you can use it to clear your store. protected static void ResetDatabase() { DataStoreProvider provider = DataStoreProvider.CreateInstance(); if (!(provider is DbDataStoreProvider)) { throw new NotSupportedException("The samples required a database provider"); } ((DbDataStoreProvider)provider).ExecuteTransaction(() => { using (IDbCommand cmd = ((DbDataStoreProvider)provider).CreateCommand()) { cmd.CommandText = "delete from tblBigTableReference"; cmd.ExecuteNonQuery(); cmd.CommandText = "delete from tblBigTable"; cmd.ExecuteNonQuery(); cmd.CommandText = "delete from tblSystemBigTable"; cmd.ExecuteNonQuery(); cmd.CommandText = "delete from tblBigTableIdentity"; cmd.ExecuteNonQuery(); cmd.CommandText = "delete from tblBigTableStoreInfo"; cmd.ExecuteNonQuery(); } }); StoreDefinition.ClearCache(); }
  2. Thanks. That worked
Post a comment    
User verification Image for user verification  
EPiTrace logger