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

Store PersistenceManager to IsolatedStorage

2 Answers 280 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Jonx
Top achievements
Rank 2
Jonx asked on 01 Feb 2012, 09:28 PM
Hi,
I used the GridViewCustomPropertyProvider sample which is nice thanks.

The problem is to store those settings into IsolatedStorage...

Is there an easy way I have missed?

I had to create myself a function to copy the stream from one object to the other. I'm sure there is a way so obvious that you don't talk about anywhere ;)

For people wondering, I'm calling the load in UserControl_Loaded and I save in various events like ColumnReordered, ColumnWidthChanged, Grouped, Filtered and Sorted.

Thank you for your lights,
John.

private void Save()
        {
            // Obtain the isolated storage for an application.
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                //IsolatedStorageFileStream s = store.OpenFile(@"GridsCommand.txt", FileMode.Create, FileAccess.Write);
                using (Stream stream = new IsolatedStorageFileStream(@"GridsCommand.txt", FileMode.Create, FileAccess.Write, store))
                {
                    if (stream != null)
                    {
                        PersistenceManager manager = new PersistenceManager();
                        Stream str = manager.Save(this.grdBeneficiaire);
 
                        CopyStream(str, stream);
                    }
                }
            }
        }
 
        public static void CopyStream(Stream input, Stream output)
        {
            byte[] buffer = new byte[8 * 1024];
            int len;
            while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                output.Write(buffer, 0, len);
            }
        }
 
        private void Load()
        {
            // Obtain the isolated storage for an application.
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (store.FileExists("GridsCommand.txt"))
                {
                    using (Stream stream = new IsolatedStorageFileStream(@"GridsCommand.txt", FileMode.Open, FileAccess.Read, store))
                    {
                        if (stream != null)
                        {
                            PersistenceManager manager = new PersistenceManager();
                            manager.Load(this.grdBeneficiaire, stream);
                        }
                    }
                }
            }
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 06 Feb 2012, 02:35 PM
Hi John,

Indeed the PersistenceFramework allows you to persist the settings of the UIElements in an isolated storage out-of-the-box. As long as you set the telerik:PersistenceManager.StorageId attached property to the elements which settings you need to persist, you'll be able to use the PersistenceFramework IsolatedStorageProvider class to save and load the persisted data. You can find more info here.

I also attached a sample project to demonstrate how to persist a RadGridView in an isolated storage. Let me know if it helps or if you need more info.

All the best,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jonx
Top achievements
Rank 2
answered on 06 Feb 2012, 03:00 PM
Hi Tina,
Thank you for the explanation.

I saw the samples. It's just that they was a sample showinf isolatedstorage and a sample showing custom PersistenceManager, just no sample showing how to use both.

Its very simple once someone tells you ;)

Thanks you for the sample,
John.

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