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

Persistonly current form

3 Answers 75 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 15 Dec 2011, 07:16 PM
Hi,

I have 2 forms, FormA & FormB, both was created but only one at a time can be visible. Each form have an existing StoradId property. When I click on my button "Save persistence" in my FormB, both forms persistence are save at the same time on disk???

If it's normal, can you tell me if it's possible to only save the persistence of the form from where the code is called?

Here is my persistence class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.Windows.Persistence;
using Telerik.Windows.Persistence.Storage;

namespace WpfApplication_Docking
{
    static public class PersistenceStorage
    {
        #region Public methods.
        /// <summary>
        /// Load/Save all controls that contain "telerik:PersistenceManager.StorageId="..."
        /// The file location is "$APPDATA\IsolatedStorage\..."
        /// </summary>
        /// <param name="pPersistenceAction">Load/Save</param>
        /// <param name="pErrorMessage">Error received during the persistence.</param>
        /// <returns>true if successfull otherwise false</returns>
        static public bool Persist(PersistenceAction pPersistenceAction, out string pErrorMessage)
        {
   

            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)
                    {
                        storage.LoadFromStorage();
                    }
                    else if (pPersistenceAction == PersistenceAction.Save)
                    {
                        storage.SaveToStorage();
                    }

                    return true;
                }
                catch (Exception ex)
                {
                    pErrorMessage = ex.Message;
                    return false;
                }
            }
            finally
            {
                //manager.PropertyPersisting += new Telerik.Windows.Persistence.Events.PropertyPersistingEventHandler(manager_PropertyPersisting);
            }
        }

        /// <summary>
        /// Event triggered when the stream persistence didn't worked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void manager_PersistenceError(object sender, Telerik.Windows.Persistence.Events.PersistenceErrorEventArgs e)
        {
            mErrorMessage = e.Exception.Message;
            mResult = false;
            throw new NotImplementedException();
        }

        /// <summary>
        /// This event is used to prevent any BroderBrush to have a transparent color when we persist an object.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void manager_PropertyPersisting(object sender, Telerik.Windows.Persistence.Events.PersistingPropertyEventArgs e)
        {
            //Not needed since version 2011.3.1116.35 of Telerik
            //if (e.Name == "BorderBrush")
            //    e.Cancel = true;
        }
        #endregion

        #region Enumerators.
        public enum PersistenceAction { Load, Save }
        #endregion

        #region Private declarations.
        static private string mErrorMessage;
        static private bool mResult;
        #endregion
    }
}



Thank's

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 20 Dec 2011, 04:47 PM
Hello Oliver,

 Could you please elaborate more on your scenario, your forms ? Do they share common parent container and do you persist this container ? If so, the behavior you have come up with is expected and your best option is to persist the two forms separately.

Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Oliver
Top achievements
Rank 1
answered on 21 Mar 2012, 06:05 PM
Hi,

that's exactly what I want, persist all the forms separately but how ?!?

In my working solution, sometime I have mutliple level RadWindow, I mean, form A display a form B, form B display a form C. On each form, on the closing event, I persist the form. When I close form C, my application persist all my forms!!!

Thank's
0
Accepted
Alex Fidanov
Telerik team
answered on 26 Mar 2012, 09:06 AM
Hi,

What you can do is to set the StorageId to all the forms that you want to persist (as you have already done) and remove the ones that you do not want to save, when persisting. You can do this through the PersistenceManager.GetStorage static method. The object store contains all of the keys and items that will be serialized. The other approach is to set the storage id on demand (when you are saving).

Kind regards,
Alex Fidanov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
PersistenceFramework
Asked by
Oliver
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Oliver
Top achievements
Rank 1
Alex Fidanov
Telerik team
Share this question
or