Possibility to known the STorageId

2 posts, 0 answers
  1. Oliver
    Oliver avatar
    263 posts
    Member since:
    Feb 2011

    Posted 15 Dec 2011 Link to this post

    Hi,

    I have a generic class to persist (load/save) RadControls from/to disk and I in my class I catch different exceptions. I would like to know if it's possible to know the StorageId my class trying to persist because when I'm catching an exception, I would like to log the StorageId in my log file?

    Thank's

    Here is my 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
        }
    }

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Dec 2011 Link to this post

    Hello Oliver,

    Currently, this scenario is not supported. The PersistenceError event args do not provide information about the root object which is being saved. If the property is on the root level (property of the control that you are serializing) then you could get its serialization id. However, if the property is nested, then you have only the proeprty's name and path.
    We logged a feature request in our PITS and now you are able to vote for, this way increasing its development priority.

    Greetings,

    Petar Mladenov
    the Telerik team

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

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top