- dataobjectbase_2.1.0.zip
- doc
- lib
- CatenaLogic.BlogArticles.dll
- output
- Release
- CatenaLogic.BlogArticles.dll
- CatenaLogic.Examples.exe
- Data
- Example 01 - Simple object
- Example 02 - Error validation
- Example 03 - Serialization
- Example 04 - Nested objects
- Example 05 - Backward compatibility
- Example 06 - Revert and apply
- screenshots
- Example 02 - Error validation.png
- snippets
- dataobject.snippet
- propdata.snippet
- src
- CatenaLogic.Examples
- App.xaml
- App.xaml.cs
- CatenaLogic.Examples.csproj
- Data
- Example 01 - Simple object
- Example 02 - Error validation
- Example 03 - Serialization
- Example 04 - Nested objects
- Example 05 - Backward compatibility
- Example 06 - Revert and apply
- Properties
- UI
- Input
- Windows
- Example 02 - Error validation
- Example 03 - Serialization
- Example 05 - Backward compatibility
- Example 06 - Revert and apply
- CatenaLogic.Test
- CatenaLogic
- DataObjectBase.sln
- DataObjectBase.vsmdi
- LocalTestRun.testrunconfig
- dataobjectbase.zip
|
using System.Windows;
using System.Windows.Input;
using CatenaLogic.Data;
using CatenaLogic.Windows;
using Microsoft.Win32;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace CatenaLogic.Examples.UI.Windows
{
/// <summary>
/// Interaction logic for BackwardCompatibilityWindow.xaml
/// </summary>
public partial class BackwardCompatibilityWindow : DataWindow
{
#region Constants
/// <summary>
/// Default file dialog filter.
/// </summary>
public const string FileDialogFilter = "DataObjectBase files|*.dob|All files|*.*";
#endregion
#region Variables
#endregion
#region Constructor & destructor
/// <summary>
/// Initializes a new instance of the <see cref="BackwardCompatibilityWindow"/> class.
/// </summary>
public BackwardCompatibilityWindow()
: base(DataWindowMode.Close)
{
// Initialize component
InitializeComponent();
// Add command bindings
CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, Save_Executed, Save_CanExecute));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, Open_Executed, Open_CanExecute));
}
#endregion
#region Properties
/// <summary>
/// Gets or sets OldPerson.
/// </summary>
/// <remarks>
/// Wrapper for the OldPerson dependency property.
/// </remarks>
public Data.OldNamespace.Person OldPerson
{
get { return (Data.OldNamespace.Person)GetValue(OldPersonProperty); }
set { SetValue(OldPersonProperty, value); }
}
/// <summary>
/// DependencyProperty definition as the backing store for OldPerson.
/// </summary>
public static readonly DependencyProperty OldPersonProperty =
DependencyProperty.Register("OldPerson", typeof(Data.OldNamespace.Person), typeof(BackwardCompatibilityWindow), new UIPropertyMetadata(new Data.OldNamespace.Person()));
/// <summary>
/// Gets or sets NewPerson.
/// </summary>
/// <remarks>
/// Wrapper for the NewPerson dependency property.
/// </remarks>
public Data.NewNamespace.Person NewPerson
{
get { return (Data.NewNamespace.Person)GetValue(NewPersonProperty); }
set { SetValue(NewPersonProperty, value); }
}
/// <summary>
/// DependencyProperty definition as the backing store for NewPerson.
/// </summary>
public static readonly DependencyProperty NewPersonProperty =
DependencyProperty.Register("NewPerson", typeof(Data.NewNamespace.Person), typeof(BackwardCompatibilityWindow), new UIPropertyMetadata(new Data.NewNamespace.Person()));
#endregion
#region Command bindings
/// <summary>
/// Determines whether the user can execute the Save command.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">The event data.</param>
private void Save_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
// Allow by default
e.CanExecute = true;
}
/// <summary>
/// Handled when the user invokes the Save command.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">Event Arguments.</param>
private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
{
// Let the user pick a filename
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.Filter = FileDialogFilter;
if (fileDialog.ShowDialog() ?? false)
{
// Save (and notice the great amount of code required to save the old object)
using (FileStream fileStream = new FileStream(fileDialog.FileName, FileMode.Create, FileAccess.ReadWrite))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fileStream, OldPerson);
}
}
}
/// <summary>
/// Determines whether the user can execute the Open command.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">The event data.</param>
private void Open_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
// Allow by default
e.CanExecute = true;
}
/// <summary>
/// Handled when the user invokes the Open command.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">Event Arguments.</param>
private void Open_Executed(object sender, ExecutedRoutedEventArgs e)
{
// Let the user pick a filename
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = FileDialogFilter;
if (fileDialog.ShowDialog() ?? false)
{
// Load (and enable redirects)
NewPerson = Data.NewNamespace.Person.Load(fileDialog.FileName, SerializationMode.Binary, true);
if (NewPerson == null)
{
// Restore new value
NewPerson = new Data.NewNamespace.Person();
// Show error
MessageBox.Show(Properties.Resources.LoadDataFailed, Properties.Resources.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
#endregion
#region Methods
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.