-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new serializer classes, supporting async serialization scheme
- Loading branch information
Showing
3 changed files
with
441 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
source/Components/AvalonDock/Layout/Serialization/AsyncXmlLayoutSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/************************************************************************ | ||
AvalonDock | ||
Copyright (C) 2007-2013 Xceed Software Inc. | ||
This program is provided to you under the terms of the Microsoft Public | ||
License (Ms-PL) as published at https://opensource.org/licenses/MS-PL | ||
************************************************************************/ | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
namespace AvalonDock.Layout.Serialization | ||
{ | ||
/// <summary>Implements a layout serialization/deserialization method of the docking framework.</summary> | ||
public class AsyncXmlLayoutSerializer : LayoutSerializerBase | ||
{ | ||
#region Constructors | ||
|
||
/// <summary> | ||
/// Class constructor from <see cref="DockingManager"/> instance. | ||
/// </summary> | ||
/// <param name="manager"></param> | ||
public AsyncXmlLayoutSerializer(DockingManager manager) | ||
: base(manager) | ||
{ | ||
} | ||
|
||
#endregion Constructors | ||
|
||
#region Public Methods | ||
|
||
/// <summary>Serialize the layout into a <see cref="XmlWriter"/>.</summary> | ||
/// <param name="writer"></param> | ||
public void Serialize(XmlWriter writer) | ||
{ | ||
var serializer = new XmlSerializer(typeof(LayoutRoot)); | ||
serializer.Serialize(writer, Manager.Layout); | ||
} | ||
|
||
/// <summary>Serialize the layout into a <see cref="TextWriter"/>.</summary> | ||
/// <param name="writer"></param> | ||
public void Serialize(TextWriter writer) | ||
{ | ||
var serializer = new XmlSerializer(typeof(LayoutRoot)); | ||
serializer.Serialize(writer, Manager.Layout); | ||
} | ||
|
||
/// <summary>Serialize the layout into a <see cref="Stream"/>.</summary> | ||
/// <param name="stream"></param> | ||
public void Serialize(Stream stream) | ||
{ | ||
var serializer = new XmlSerializer(typeof(LayoutRoot)); | ||
serializer.Serialize(stream, Manager.Layout); | ||
} | ||
|
||
/// <summary>Serialize the layout into a file using a <see cref="StreamWriter"/>.</summary> | ||
/// <param name="filepath"></param> | ||
public void Serialize(string filepath) | ||
{ | ||
using (var stream = new StreamWriter(filepath)) | ||
{ | ||
Serialize(stream); | ||
} | ||
} | ||
|
||
/// <summary>Deserialize the layout a file from a <see cref="Stream"/>.</summary> | ||
/// <param name="stream"></param> | ||
public async Task Deserialize(System.IO.Stream stream) | ||
{ | ||
var serializer = new XmlSerializer(typeof(LayoutRoot)); | ||
var layout = (LayoutRoot)serializer.Deserialize(stream); | ||
await FixupLayout(layout); | ||
Manager.Layout = layout; | ||
} | ||
|
||
/// <summary>Deserialize the layout a file from a <see cref="TextReader"/>.</summary> | ||
/// <param name="reader"></param> | ||
public async Task Deserialize(TextReader reader) | ||
{ | ||
var serializer = new XmlSerializer(typeof(LayoutRoot)); | ||
var layout = (LayoutRoot)serializer.Deserialize(reader); | ||
await FixupLayout(layout); | ||
Manager.Layout = layout; | ||
} | ||
|
||
/// <summary>Deserialize the layout a file from a <see cref="XmlReader"/>.</summary> | ||
/// <param name="reader"></param> | ||
public async Task Deserialize(XmlReader reader) | ||
{ | ||
var serializer = new XmlSerializer(typeof(LayoutRoot)); | ||
var layout = (LayoutRoot)serializer.Deserialize(reader); | ||
await FixupLayout(layout); | ||
Manager.Layout = layout; | ||
} | ||
|
||
/// <summary>Deserialize the layout from a file using a <see cref="StreamReader"/>.</summary> | ||
/// <param name="filepath"></param> | ||
public async Task Deserialize(string filepath) | ||
{ | ||
using (var stream = new StreamReader(filepath)) | ||
{ | ||
await Deserialize(stream); | ||
} | ||
} | ||
|
||
#endregion Public Methods | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
source/Components/AvalonDock/Layout/Serialization/LayoutRestoreEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/************************************************************************ | ||
AvalonDock | ||
Copyright (C) 2007-2013 Xceed Software Inc. | ||
This program is provided to you under the terms of the Microsoft Public | ||
License (Ms-PL) as published at https://opensource.org/licenses/MS-PL | ||
************************************************************************/ | ||
|
||
using System.ComponentModel; | ||
|
||
namespace AvalonDock.Layout.Serialization | ||
{ | ||
/// <summary> | ||
/// Implements an event that can be used to communicate between deserialization method | ||
/// and client application that a new item (LayoutAnchorable or Document) is about to | ||
/// be constructed and should be attached to a corresponding viewmodel. | ||
/// | ||
/// The client application can use this event to Cancel reloading the item or | ||
/// attach (a viewmodel) content to the view item that is about to be reloaded and presented in the UI. | ||
/// | ||
/// Use the Cancel property to indicate the case in which an item should not be deserialized. | ||
/// </summary> | ||
public class LayoutRestoreEventArgs | ||
{ | ||
#region constructors | ||
|
||
/// <summary> | ||
/// Class constructor from <see cref="LayoutContent"/> and <paramref name="previousContent"/> object. | ||
/// </summary> | ||
/// <param name="model">The model of the view that has been deserialized.</param> | ||
/// <param name="previousContent">The content if it was available in previous layout.</param> | ||
public LayoutRestoreEventArgs(LayoutContent model, object previousContent) | ||
{ | ||
Cancel = false; // reloading an item is not by cancelled by default | ||
Handled = false; // an item is not handled by default | ||
Model = model; | ||
Content = previousContent; | ||
} | ||
|
||
#endregion constructors | ||
|
||
#region Properties | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the event should be canceled. | ||
/// </summary> | ||
public bool Cancel | ||
{ | ||
get; private set; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the event should continue processing. | ||
/// </summary> | ||
public bool Handled | ||
{ | ||
get; private set; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the model of the view that is about to be deserialized. | ||
/// </summary> | ||
public LayoutContent Model | ||
{ | ||
get; private set; | ||
} | ||
|
||
/// <summary> | ||
/// Gets/sets the content for the <see cref="Model"/> that is about to be deserialized. | ||
/// </summary> | ||
public object Content { get; set; } | ||
|
||
#endregion Properties | ||
} | ||
} |
Oops, something went wrong.