This is a migrated thread and some comments may be shown as answers.

Need sample

9 Answers 165 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 11 Oct 2012, 08:43 PM
Hi,

we use VS2008 and telerik 2012.2.912.35 and we have a RadWindow and we're trying to use the êrsistenceFramework mechanism without any success :(

In our RadWindow, we have a RadRibbonView with RadDocking control and in the RadDocking control we have 3 panes. One pane contain a RadGridView, one pane contain a RadRichText and the last pane contain multiple TextBox.

In the application menu of the RadRibbonView, we implement an to to persist the layout of the RadWindow. Actually, when we click on the persist button, when in Loaded event we restore the layout, the application menu of the RadRibbonView appear open, the RadRichText contain the text of the moment when we persisted and it's the samething for all the TextBox.

After many hours of experimentation, we gave up :( Can you provide us a small demo on how to exclude the RadRibbonView and all the date of each controls from the persisting process.

Thank's

9 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 16 Oct 2012, 03:44 PM
Hi Oliver,

The PersistenceManager.SerializationOptions collection allows you to define which properties of a UIElement should or shouldn't be persisted. However, I am not really sure what you need to persist and what not, but if your goal is to persist the Window settings but not its Content, you can remove the Content property from the list of persisted settings as follows:
<Window ...
        telerik:PersistenceManager.StorageId="Window">
    <telerik:PersistenceManager.SerializationOptions>
        <telerik:SerializationMetadataCollection>
            <telerik:PropertyNameMetadata Condition="Except"
                              Expression="Content"
                              SearchType="PropertyName" />
        </telerik:SerializationMetadataCollection>
    </telerik:PersistenceManager.SerializationOptions>
    ...
</Window >

You can find more information about the SerializationOptions property in our documentation. Please have a look at it and try the suggested approach and let me know if I'm missing something.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Oliver
Top achievements
Rank 1
answered on 16 Oct 2012, 05:17 PM
Hi,

actually, when the application menu of the RadRibbonView is open, the user can click on our Persist button to persist the screen layout. When we start again our application, in the Loaded event, we reload our screen layout and the application menu appear open!!! In this situation, we don't want to persist the state of the application menu in our RadRibbonView.

Also, our application is a docking application and we have multiple RadPane and each RadPane have multiple controls inside of them: RadGridView, TextBox, RadRichText and we don't want to persist the content of each control, ie: We don't want to persist the TEXT property of the TextBox, the ItemsSource of the RadGridView, etc...

What is the better approach??? Not persisting the CONTENT of each RadPane?!?
If so, how I can acheive that???

Thank's
0
Tina Stancheva
Telerik team
answered on 19 Oct 2012, 10:59 AM
Hello Oliver,

In order not to persist the state of the application menu, you can use the PersistenceManager.SerializationOptions to exclude the IsApplicationMenuOpen property from the persisted settings of the RadRibbonView control:
<telerik:RadRibbonView >
    <telerik:PersistenceManager.SerializationOptions>
        <telerik:SerializationMetadataCollection>
            <telerik:PropertyNameMetadata Condition="Except" Expression="IsApplicationMenuOpen" SearchType="PropertyName" />
        </telerik:SerializationMetadataCollection>
    </telerik:PersistenceManager.SerializationOptions>
    <telerik:RadRibbonView.ApplicationMenu>
        <telerik:ApplicationMenu>
            ...
        </telerik:ApplicationMenu>
    </telerik:RadRibbonView.ApplicationMenu>
    ...
</telerik:RadRibbonView>

Regarding the RadPanes content, it might be best in your case to use the Docking Save/Load layout method as I've suggested in this forum thread. If you don't create a custom property provider for the RadDocking control, the PersistenceManager won't persist it and you can use instead its own Save/Load layout mechanism.

If the above suggestions don't help, it would be best to send us a sample solution demonstrating all issues so that we can take a closer look at your scenario, approach and implementation. Then we will be able to suggest more suited solutions for your case.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Oliver
Top achievements
Rank 1
answered on 29 Nov 2012, 10:26 PM
Hi Tina,

in my application, I have a class named PersistenceStorage (use by the developement team) and in my class I have 3 importants methods describe at the end of this message. One of the parameters of my "Persist" method receive it's a DependencyProperty, most of the time it's a RadWindow.

In my application, I have multiple RadWindow, for each RadWindow I would like to persist only their size and position, not their content. Each time I load and close a RadWindow, I call my method with my RadWindow as a parameter to load/save their infos. I would like to know if it's possible to define something in my method to skip the DependencyProperty content only when it's a RadWindow, this way, I will not have to take care of a "PersistenceManager.SerializationOptions" section in each of my RadWindow. 

Thank's

Method #1
--------------

static public bool Persist(PersistenceAction pPersistenceAction, System.Windows.DependencyObject pObjectToPersist, string pStorageId, out string pErrorMessage)
        {           
            bool result = false;
            pErrorMessage = string.Empty;

            if (pObjectToPersist != null)
            {
                mObjectToPersist = pObjectToPersist;

                try
                {
                    // Validate if we need to generate a custom StorageId.
                    if (string.IsNullOrEmpty(pStorageId))
                    {
                        pStorageId = GetCustomStorageId(pObjectToPersist);
                    }

                    try
                    {
                        PersistenceManager.SetStorageId(pObjectToPersist, pStorageId);
                        result = Persist(pPersistenceAction, out pErrorMessage);
                    }
                    finally
                    {
                        pObjectToPersist.ClearValue(PersistenceManager.StorageIdProperty);
                    }
                }
                catch (Exception ex)
                {
                    GclLogger tracingTool = GclLogger.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    tracingTool.Log(GclLogger.Level.Error, "PERST008", "Error occured during '{0}' file. Message: {1}", pPersistenceAction.ToString(), ex.ToString());
                    pErrorMessage = ex.Message;
                }
            }

            return result;
        }



Method #2:

        static public string GetCustomStorageId(System.Windows.DependencyObject pObjectToPersist)
        {
            string customStorageId = string.Empty;           

            if (pObjectToPersist != null)
            {
                Assembly assembly = pObjectToPersist.GetType().Assembly;
                customStorageId = assembly.GetName().Name + "." + pObjectToPersist.GetType().Name;               
            }

            return customStorageId;
        }

Method #3:

        static public bool Persist(PersistenceAction pPersistenceAction, out string pErrorMessage)
        {
   ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadGridView), new GridViewCustomPropertyProvider());
   ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadDocking), new DockingCustomPropertyProvider());
            ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadRichTextBox), new RichTextBoxCustomPropertyProvider());

            pErrorMessage = string.Empty;
            PersistenceManager manager = new PersistenceManager();
            manager.PropertyPersisting += new Telerik.Windows.Persistence.Events.PropertyPersistingEventHandler(manager_PropertyPersisting);
            IsolatedStorageProvider storage = new IsolatedStorageProvider(manager);

            try
            {
                try
                {
                    if (pPersistenceAction == PersistenceAction.Load)
                    {
                        if (ConfigUtils.GetBoolValue("UsePersistence", null, true))
                        {
                            storage.LoadFromStorage(); // TODO CHECK
                        }
                    }
                    else if (pPersistenceAction == PersistenceAction.Save)
                    {
                        if (ConfigUtils.GetBoolValue("UsePersistence", null, true))
                        {

                            //Telerik.Windows.Persistence.SerializationMetadata.PropertyNameMetadata propNameMetadata = new Telerik.Windows.Persistence.SerializationMetadata.PropertyNameMetadata();
                            //Telerik.Windows.Persistence.SerializationMetadata.SerializationMetadataCollection serializationMetadata = new Telerik.Windows.Persistence.SerializationMetadata.SerializationMetadataCollection();
                            //propNameMetadata.Condition = Telerik.Windows.Persistence.SerializationMetadata.SerializationMetadataCondition.Except;
                            //propNameMetadata.Expression = "Content";
                            //propNameMetadata.SearchType = Telerik.Windows.Persistence.SerializationMetadata.MetadataSearchCriteria.PropertyName;
                            //serializationMetadata.Add(propNameMetadata);                         
                            //PersistenceManager.SetSerializationOptions(mObjectToPersist, serializationMetadata);

                            storage.SaveToStorage(); // TODO CHECK
                        }
                    }

                    return true;
                }
                catch (Exception ex)
                {
                    GclLogger tracingTool = GclLogger.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    tracingTool.Log(GclLogger.Level.Error, "PERST001", "Error occured during '{0}' file. Message: {1}", pPersistenceAction.ToString(), ex.ToString());
                    pErrorMessage = ex.Message;
                    return false;
                }
            }
            finally
            {
                manager.PropertyPersisting -= new Telerik.Windows.Persistence.Events.PropertyPersistingEventHandler(manager_PropertyPersisting);
    ServiceProvider.UnregisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadGridView));
    ServiceProvider.UnregisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadDocking));
                ServiceProvider.UnregisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadRichTextBox));
            }
        }

0
Tina Stancheva
Telerik team
answered on 04 Dec 2012, 05:01 PM
Hello Oliver,

Even in this case, you'll have to define the SerializationOptions for the Window object as this is the mechanism for customizing the set of persisted properties on an object. However, you can move your logic in code behind in a new method. You can try something like this:
static private void SetSerializaitonOptions(System.Windows.DependencyObject pObjectToPersist)
{
    SerializationMetadataCollection smc = new SerializationMetadataCollection() { Operator = LogicalOperator.And };
    smc.Add(new PropertyNameMetadata()
    {
        Condition = SerializationMetadataCondition.Except,
        Expression = "^Content$",
        SearchType = MetadataSearchCriteria.PropertyName
    });
    SerializationMetadataCollection subSMC = new SerializationMetadataCollection { Operator = LogicalOperator.Or };
    subSMC.Add(new PropertyNameMetadata()
    {
        Condition = SerializationMetadataCondition.Only,
        Expression = "^Height$",
        SearchType = MetadataSearchCriteria.PropertyName
    });
    subSMC.Add(new PropertyNameMetadata()
    {
        Condition = SerializationMetadataCondition.Only,
        Expression = "^Width$",
        SearchType = MetadataSearchCriteria.PropertyName
    });
    subSMC.Add(new PropertyNameMetadata()
    {
        Condition = SerializationMetadataCondition.Only,
        Expression = "Top$",
        SearchType = MetadataSearchCriteria.PropertyName
    });
    subSMC.Add(new PropertyNameMetadata()
    {
        Condition = SerializationMetadataCondition.Only,
        Expression = "Left",
        SearchType = MetadataSearchCriteria.PropertyName
    });
    smc.Add(subSMC);
    PersistenceManager.SetSerializationOptions(pObjectToPersist, smc);
}
 
static public bool Persist(PersistenceAction pPersistenceAction, System.Windows.DependencyObject pObjectToPersist, string pStorageId, out string pErrorMessage)
{
    bool result = false;
    pErrorMessage = string.Empty;
 
    if (pObjectToPersist != null)
    {
        if (pObjectToPersist is Window)
        {
            SetSerializaitonOptions(pObjectToPersist);
        }
 
        // ...
    }
}

Please give this a try and let me know if it helps.

Kind Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Oliver
Top achievements
Rank 1
answered on 04 Dec 2012, 06:55 PM
Hi Tina,

thank's for you piece of code, I appreciate :)

Juste a thing, do I have to consider the special characters in the "Expression" member ??? ie: ^Content$

Thank's
0
Tina Stancheva
Telerik team
answered on 07 Dec 2012, 12:40 PM
Hello Oliver,

The SerializationMetadataCollection basically builds a regular expression to search through the names of all properties of the control to find a match and this is the reason why I'm using these symbols.

Specifically in this case, I'm making sure that the correct properties will be persisted - the Window properties which names match exactly Content, Height, Width, all properties that end with Top and all properties that contain Left in their names.

This way your logic is more precise.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Oliver
Top achievements
Rank 1
answered on 07 Dec 2012, 01:57 PM
Hi Tina,

I'm not sure that I understand the using of the "^" and the "$" characters ine the "Expression" member???

Thank's

0
Tina Stancheva
Telerik team
answered on 12 Dec 2012, 01:33 PM
Hello Oliver,

These characters are used to specify the PropertyName value in the regular expression. The entire PropertyNameMetadata class describes a single regular expression that is used to get the properties that have to be persisted or not.

You can take a look at this post describing the way the '^' and '$' symbols are used bu the regular expression. Hope that makes it a bit clearer.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
PersistenceFramework
Asked by
Oliver
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Oliver
Top achievements
Rank 1
Share this question
or