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

PersistenceManager save parameter problem

5 Answers 320 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 13 Oct 2011, 03:36 PM
Hi,

in my project I have a method who need parameters and one of them is an object that I want the persistence stream result.
When I call my method, the PersistenceError event handler was called when I try to use the SAVE method of the PersistenceManager and I get the following french error message: Nombre de paramètres incorrects.

Here is the way I call my method:

PersistenceStorage

 

.Persist(MainGrid, ref stream, PersistenceStorage.PersistenceAction.Save, out errMsg);

 



Here is my static object with my method:

static

 

public class PersistenceStorage

 

{


static public bool Persist(object pObject, ref Stream pStream, PersistenceAction pPersistenceAction, out string pErrorMessage)

 

{

mResult =

true;

 

pErrorMessage =

string.Empty;

 

 

PersistenceManager manager = new PersistenceManager();

 

manager.PersistenceError +=

new Telerik.Windows.Persistence.Events.PersistenceErrorEventHandler(manager_PersistenceError);

 

 

try

 

{

 

if (pPersistenceAction == PersistenceAction.Load)

 

{

 

if (pObject != null && pStream != null)

 

{

pStream.Position = 0L;

manager.Load(pObject, pStream);

}

 

else

 

{

mResult =

false;

 

}

}

 

else if (pPersistenceAction == PersistenceAction.Save)

 

{

 

if (pObject != null)

 

{

pStream = manager.Save(pObject);

}

 

else

 

{

mResult =

false;

 

}

}

}

 

catch

 

{

mResult =

false;

 

}

 

finally

 

{

manager.PersistenceError -=

new Telerik.Windows.Persistence.Events.PersistenceErrorEventHandler(manager_PersistenceError);

 

pErrorMessage = mErrorMessage;

}

 

return mResult;

 

}

 


static
void manager_PersistenceError(object sender, Telerik.Windows.Persistence.Events.PersistenceErrorEventArgs e)

 

{

mErrorMessage = e.Exception.Message;

mResult =

false;

 

}

 


public
enum PersistenceAction { Load, Save }

 

 


static
private string mErrorMessage;

 

 

static private bool mResult;

 

}

5 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 18 Oct 2011, 07:56 AM
Hello Oliver,

Could you please give us more information on your scenario? What object are you trying to persist? Could you provide steps to reproduce this issue?

All the best,
Alex Fidanov
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 18 Oct 2011, 02:51 PM
Hi.

I'm trying to persist a Window

Here is the whole project (just click on the "Save Stream" button) :

*************************************************************************************************
Window1.xaml
*************************************************************************************************

<

 

Window x:Class="WpfApplication_PersistenceFramework.Window1"

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"

 

 

Title="Window1" Height="467" Width="Auto" Margin="10"

 

 

telerik:PersistenceManager.StorageId="Window1">

 

 

 

<Grid Margin="10" Name="MainGrid">

 

 

 

<Grid.RowDefinitions>

 

 

 

<RowDefinition Height="Auto" MinHeight="29" />

 

 

 

<RowDefinition Height="*" />

 

 

 

</Grid.RowDefinitions>

 

 

 

<StackPanel Orientation="Horizontal">

 

 

 

<telerik:RadButton Margin="5" Content="Save Stream" Name="radButtonSave" Click="radButtonSaveStream_Click" />

 

 

 

<telerik:RadButton Margin="5" Content="Load Stream" Name="radButtonLoad" Click="radButtonLoadStream_Click" />

 

 

 

<telerik:RadButton Margin="5" Content="Save Isolated Storage" Name="radButtonSaveIS" Click="radButtonSaveIsolatedStorage_Click" />

 

 

 

<telerik:RadButton Margin="5" Content="Load Isolated Storage" Name="radButtonLoadIS" Click="radButtonLoadIsolatedStorage_Click" />

 

 

 

<telerik:RadButton Margin="5" Content="Save file" Name="radButtonSaveFile" Click="radButtonSaveFile_Click" />

 

 

 

<telerik:RadButton Margin="5" Content="Load file" Name="radButtonLoadFile" Click="radButtonLoadFile_Click" />

 

 

 

</StackPanel>

 

 

 

<telerik:RadTabControl Grid.Row="1" Background="Transparent" Height="Auto" Name="radTabControl1" Width="Auto" OverflowMode="Wrap" AllTabsEqualHeight="True">

 

 

 

<telerik:RadTabItem Header="Test 1" />

 

 

 

<telerik:RadTabItem Header="Test 2" />

 

 

 

</telerik:RadTabControl>

 

 

 

<GridSplitter Grid.Row="1" Margin="0,48,32,22" Name="gridSplitter1" Width="36" />

 

 

 

<telerik:RadColorPaletteView Grid.Row="1" HorizontalAlignment="Left" Margin="14,43,0,0" Name="radColorPaletteView1" Width="124" SnapsToDevicePixels="False" Height="111" VerticalAlignment="Top" />

 

 

 

<telerik:RadColorPicker Grid.Row="1" HorizontalAlignment="Right" Margin="0,43,74,26" Name="radColorPicker1" Width="70" MainPaletteHeaderText="" />

 

 

 

<telerik:RadColorSelector Grid.Row="1" Margin="171,43,150,169" Name="radColorSelector1" MainPaletteHeaderText="" MainPaletteOrientation="Vertical" />

 

 

 

<telerik:RadPropertyGrid Grid.Row="1" Height="129" HorizontalAlignment="Left" Margin="54,0,0,25" Name="radPropertyGrid1" VerticalAlignment="Bottom" Width="153" />

 

 

 

</Grid>

 

</

 

Window>

 


*************************************************************************************************
Window1.xaml.cs
*************************************************************************************************

using

 

System;

 

using

 

System.Collections.Generic;

 

using

 

System.Linq;

 

using

 

System.Text;

 

using

 

System.Windows;

 

using

 

System.Windows.Controls;

 

using

 

System.Windows.Data;

 

using

 

System.Windows.Documents;

 

using

 

System.Windows.Input;

 

using

 

System.Windows.Media;

 

using

 

System.Windows.Media.Imaging;

 

using

 

System.Windows.Navigation;

 

using

 

System.Windows.Shapes;

 

using

 

System.IO;

 

using

 

System.IO.IsolatedStorage;

 

using

 

Telerik.Windows.Controls;

 

using

 

Telerik.Windows.Persistence;

 

using

 

Telerik.Windows.Persistence.Storage;

 

namespace

 

WpfApplication_PersistenceFramework

 

{

 

/// <summary>

 

 

/// Interaction logic for Window1.xaml

 

 

/// </summary>

 

 

public partial class Window1 : Window

 

{

 

Stream stream;

 

 

public Window1()

 

{

InitializeComponent();

}

 

private void radButtonSaveStream_Click(object sender, RoutedEventArgs e)

 

{

 

string errMsg;

 

 

PersistenceStorage.Persist(MainGrid, ref stream, PersistenceStorage.PersistenceAction.Save, out errMsg);

 

}

 

private void radButtonLoadStream_Click(object sender, RoutedEventArgs e)

 

{

 

string errMsg;

 

 

PersistenceStorage.Persist(MainGrid, ref stream, PersistenceStorage.PersistenceAction.Load, out errMsg);

 

}

 

private void radButtonSaveIsolatedStorage_Click(object sender, RoutedEventArgs e)

 

{

 

IsolatedStorageProvider isoStorageProvider = new IsolatedStorageProvider();

 

isoStorageProvider.SaveToStorage();

}

 

private void radButtonLoadIsolatedStorage_Click(object sender, RoutedEventArgs e)

 

{

 

IsolatedStorageProvider isoStorageProvider = new IsolatedStorageProvider();

 

isoStorageProvider.LoadFromStorage();

}

 

private void radButtonSaveFile_Click(object sender, RoutedEventArgs e)

 

{

}

 

private void radButtonLoadFile_Click(object sender, RoutedEventArgs e)

 

{

 

}

}

 

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;

 

 

IsolatedStorageProvider storage = new IsolatedStorageProvider();

 

 

try

 

{

 

if (pPersistenceAction == PersistenceAction.Load)

 

{

storage.LoadFromStorage();

}

 

else if (pPersistenceAction == PersistenceAction.Save)

 

{

storage.SaveToStorage();

}

 

return true;

 

}

 

catch (Exception ex)

 

{

pErrorMessage = ex.Message;

 

return false;

 

}

}

 

/// <summary>

 

 

/// Load/Save from/to stream an object.

 

 

/// </summary>

 

 

/// <param name="pObject">Object to load/save.</param>

 

 

/// <param name="pStream">Stream that contain the serialized object.</param>

 

 

/// <param name="pPersistenceAction">Load/Save</param>

 

 

/// <param name="pErrorMessage">Error received during the persistence.</param>

 

 

/// <returns></returns>

 

 

static public bool Persist(object pObject, ref Stream pStream, PersistenceAction pPersistenceAction, out string pErrorMessage)

 

{

mResult =

true;

 

pErrorMessage =

string.Empty;

 

 

PersistenceManager manager = new PersistenceManager();

 

manager.PersistenceError +=

new Telerik.Windows.Persistence.Events.PersistenceErrorEventHandler(manager_PersistenceError);

 

 

try

 

{

 

if (pPersistenceAction == PersistenceAction.Load)

 

{

 

if (pObject != null && pStream != null)

 

{

pStream.Position = 0L;

manager.Load(pObject, pStream);

}

 

else

 

{

mResult =

false;

 

}

}

 

else if (pPersistenceAction == PersistenceAction.Save)

 

{

 

if (pObject != null)

 

{

pStream = manager.Save(pObject);

}

 

else

 

{

mResult =

false;

 

}

}

}

 

catch

 

{

mResult =

false;

 

}

 

finally

 

{

manager.PersistenceError -=

new Telerik.Windows.Persistence.Events.PersistenceErrorEventHandler(manager_PersistenceError);

 

pErrorMessage = mErrorMessage;

}

 

return mResult;

 

}

 

/// <summary>

 

 

/// Error message 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();

 

}

#endregion

#region

 

Enumerators.

 

 

public enum PersistenceAction { Load, Save }

 

#endregion

#region

 

Private declarations.

 

 

static private string mErrorMessage;

 

 

static private bool mResult;

 

#endregion

}

}


*************************************************************************************************
0
Tina Stancheva
Telerik team
answered on 21 Oct 2011, 11:18 AM
Hello Oliver,

Thank you for sending your code. I managed to reproduce a "Parameter count mismatch" error. However, this issue is caused by the indexer of the RadTabControl - the PersistenceManager cannot persist it but this error doesn't affect the persisting of the controls in the Grid and it is internally handled in the PersistenceManager. Basically there are controls that implement indexers and even though the persistence manager cannot persist them and an error is raised, the manager will still persist the properties of your UI elements.

This is why if you don't throw the NotImplementedException() the persistence will continue persisting the UI properties as expected.

Also, please keep in mind that in order to save the layout of the UIElements in an isolated storage, you need to set the telerik:PersistenceManager.StorageId attached property to the UIElements that will be persisted.

Greetings,
Tina Stancheva
the Telerik team

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

0
Michal
Top achievements
Rank 1
answered on 29 Jan 2013, 03:44 PM

Hello,

I am using the radGridView on wpf. Trying to save the grid layout I use the PersistenceManager.
I manage to operate the save, and see it get into

public object ProvideValue(CustomPropertyInfo customPropertyInfo, object context)

Function but when I use the load, it doesn't get into the

public void RestoreValue(CustomPropertyInfo customPropertyInfo, object context, object value).
I made a small code using the same scenario, and in it everything works fine.
Any suggestions???

0
Tina Stancheva
Telerik team
answered on 01 Feb 2013, 08:40 AM
Hello Michal,

I am not sure what might be causing the issue in your real-life application. But if you're using the PersistenceFramework to save the GridView settings in an IsolatedStorage, you can check to see if the storage contains the persisted data before loading it. The PersistenceManager class exposes a GetStorage() method that gets the current storage with the serialization objects. You can use that method while debugging your application to see if the PersistenceFramework can really find the RadGridView object and load its persisted settings.

If you're saving the settings in a stream, you'll need to make sure that the stream isn't empty and that its Position is at the beginning.

I hope this information can help you get to the cause for the issue in your application. If it doesn't you can send us your solution so that we can also take a look at it or you can try to isolate the issue by removing parts of the code until you get to the point where the issue is no longer reproducible.

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
Alex Fidanov
Telerik team
Oliver
Top achievements
Rank 1
Tina Stancheva
Telerik team
Michal
Top achievements
Rank 1
Share this question
or