Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced LayoutSerializer with Async variant #265

Closed
wants to merge 11 commits into from
13 changes: 13 additions & 0 deletions source/.idea/.idea.AvalonDock/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions source/.idea/.idea.AvalonDock/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions source/.idea/.idea.AvalonDock/.idea/aws.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions source/.idea/.idea.AvalonDock/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions source/.idea/.idea.AvalonDock/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions source/.idea/.idea.AvalonDock/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions source/.idea/.idea.AvalonDock/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions source/AvalonDock.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=anchorable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Anchorables/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<RootNamespace>AvalonDock.Themes</RootNamespace>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net40</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net452</TargetFrameworks>
<UseWPF>true</UseWPF>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<RootNamespace>AvalonDock.Themes</RootNamespace>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net40</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net452</TargetFrameworks>
<UseWPF>true</UseWPF>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<RootNamespace>AvalonDock.Themes</RootNamespace>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net40</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net452</TargetFrameworks>
<UseWPF>true</UseWPF>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<RootNamespace>AvalonDock.Themes</RootNamespace>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net40</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net452</TargetFrameworks>
<UseWPF>true</UseWPF>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<RootNamespace>AvalonDock.Themes</RootNamespace>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net40</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net452</TargetFrameworks>
<UseWPF>true</UseWPF>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down
2 changes: 1 addition & 1 deletion source/Components/AvalonDock/AvalonDock.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<RootNamespace>AvalonDock</RootNamespace>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net40</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net5.0-windows;net452</TargetFrameworks>
<UseWPF>true</UseWPF>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
AvalonDock

Copyright (C) 2007-2013 Xceed Software Inc.
Expand All @@ -10,7 +10,7 @@ This program is provided to you under the terms of the Microsoft Public
namespace AvalonDock.Layout
{
/// <summary>Interface definition for a layout pane that can be identified by a unique id.</summary>
internal interface ILayoutPaneSerializable
public interface ILayoutPaneSerializable
{
/// <summary>Gets/sets the unique id for this layout pane.</summary>
string Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
AvalonDock

Copyright (C) 2007-2013 Xceed Software Inc.
Expand All @@ -12,7 +12,7 @@ This program is provided to you under the terms of the Microsoft Public
namespace AvalonDock.Layout
{
/// <summary>Defines a layout element that can be positioned in a Grid like environment.</summary>
internal interface ILayoutPositionableElement : ILayoutElement, ILayoutElementForFloatingWindow
public interface ILayoutPositionableElement : ILayoutElement, ILayoutElementForFloatingWindow
{
/// <summary>Gets/sets the <see cref="GridLength"/> of the dock width for this positionable layout element.</summary>
GridLength DockWidth { get; set; }
Expand Down Expand Up @@ -52,7 +52,7 @@ internal interface ILayoutPositionableElement : ILayoutElement, ILayoutElementFo
}

/// <summary>Defines a layout element that supports actual width and height properties.</summary>
internal interface ILayoutPositionableElementWithActualSize : ILayoutPositionableElement
public interface ILayoutPositionableElementWithActualSize : ILayoutPositionableElement
{
/// <summary>Gets/sets the actual width the positionable layout element.</summary>
double ActualWidth { get; set; }
Expand All @@ -62,7 +62,7 @@ internal interface ILayoutPositionableElementWithActualSize : ILayoutPositionabl
}

/// <summary>Defines a layout element that supports position properties for a floating window.</summary>
internal interface ILayoutElementForFloatingWindow
public interface ILayoutElementForFloatingWindow
{
/// <summary>Invoke this method to raise the FloatingPropertiesUpdated event to inform subscribers of the change.</summary>
void RaiseFloatingPropertiesUpdated();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
AvalonDock

Copyright (C) 2007-2013 Xceed Software Inc.
Expand All @@ -9,7 +9,7 @@ This program is provided to you under the terms of the Microsoft Public

namespace AvalonDock.Layout
{
internal interface ILayoutPreviousContainer
public interface ILayoutPreviousContainer
{
ILayoutContainer PreviousContainer { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/************************************************************************
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.Linq;
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>
/// <example>
/// <code>
/// private void Serialize()
/// {
/// // The serialization is not done async as the XmlSerializer used is not having async overloads
/// var serializer = new AvalonDock.Layout.Serialization.AsyncXmlLayoutSerializer(dockManager);
/// serializer.Serialize(@".\AvalonDock.config");
/// }
/// </code>
/// </example>
/// <example>
/// <code>
/// private async Task DeserializeAsync(AvalonDock.DockingManager dockManager)
/// {
/// using (var serializer = new AvalonDock.Layout.Serialization.AsyncXmlLayoutSerializer(dockManager))
/// {
/// serializer.LayoutRestore += async (s, args) =>
/// {
/// // Emulate an async operation for this
/// await Task.Delay(1000);
/// // Required for each interaction with actual AvalonDock, as these are STA components
/// await Dispatcher.InvokeAsync(() => args.Content = args.Content);
/// };
/// if (File.Exists(@".\AvalonDock.config"))
/// await serializer.DeserializeAsync(@".\AvalonDock.config");
/// }
/// }
/// </code>
/// </example>
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 Private Methods

/// <summary>Performs all required actions for deserialization.</summary>
/// <param name="function">
/// A function, receiving the <see cref="LayoutRoot"/> <see cref="XmlSerializer"/>,
/// that is supposed to call a deserialize method.
/// </param>
private Task DeserializeCommonAsync(Func<XmlSerializer, LayoutRoot> function)
=> base.DeserializeCommonAsync(() =>
{
var serializer = XmlSerializer.FromTypes(new[] {typeof(LayoutRoot)}).First();
return function(serializer);
});

#endregion

#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 Task DeserializeAsync(Stream stream)
=> DeserializeCommonAsync((xmlSerializer) => (LayoutRoot) xmlSerializer.Deserialize(stream));

/// <summary>Deserialize the layout a file from a <see cref="TextReader"/>.</summary>
/// <param name="reader"></param>
public Task DeserializeAsync(TextReader reader)
=> DeserializeCommonAsync((xmlSerializer) => (LayoutRoot) xmlSerializer.Deserialize(reader));

/// <summary>Deserialize the layout a file from a <see cref="XmlReader"/>.</summary>
/// <param name="reader"></param>
public Task DeserializeAsync(XmlReader reader)
=> DeserializeCommonAsync((xmlSerializer) => (LayoutRoot) xmlSerializer.Deserialize(reader));

/// <summary>Deserialize the layout from a file using a <see cref="StreamReader"/>.</summary>
/// <param name="filepath"></param>
public async Task DeserializeAsync(string filepath)
{
using (var stream = new StreamReader(filepath))
{
await DeserializeAsync(stream);
}
}

#endregion Public Methods
}
}
Loading