XmlLayoutSerializer.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Xml.Serialization;
  15. using System.IO;
  16. namespace Xceed.Wpf.AvalonDock.Layout.Serialization
  17. {
  18. public class XmlLayoutSerializer : LayoutSerializer
  19. {
  20. public XmlLayoutSerializer(DockingManager manager)
  21. : base(manager)
  22. {
  23. }
  24. public void Serialize(System.Xml.XmlWriter writer)
  25. {
  26. var serializer = new XmlSerializer(typeof(LayoutRoot));
  27. serializer.Serialize(writer, Manager.Layout);
  28. }
  29. public void Serialize(System.IO.TextWriter writer)
  30. {
  31. var serializer = new XmlSerializer(typeof(LayoutRoot));
  32. serializer.Serialize(writer, Manager.Layout);
  33. }
  34. public void Serialize(System.IO.Stream stream)
  35. {
  36. var serializer = new XmlSerializer(typeof(LayoutRoot));
  37. serializer.Serialize(stream, Manager.Layout);
  38. }
  39. public void Serialize(string filepath)
  40. {
  41. using (var stream = new StreamWriter(filepath))
  42. Serialize(stream);
  43. }
  44. public void Deserialize(System.IO.Stream stream)
  45. {
  46. try
  47. {
  48. StartDeserialization();
  49. var serializer = new XmlSerializer(typeof(LayoutRoot));
  50. var layout = serializer.Deserialize(stream) as LayoutRoot;
  51. FixupLayout(layout);
  52. Manager.Layout = layout;
  53. }
  54. finally
  55. {
  56. EndDeserialization();
  57. }
  58. }
  59. public void Deserialize(System.IO.TextReader reader)
  60. {
  61. try
  62. {
  63. StartDeserialization();
  64. var serializer = new XmlSerializer(typeof(LayoutRoot));
  65. var layout = serializer.Deserialize(reader) as LayoutRoot;
  66. FixupLayout(layout);
  67. Manager.Layout = layout;
  68. }
  69. finally
  70. {
  71. EndDeserialization();
  72. }
  73. }
  74. public void Deserialize(System.Xml.XmlReader reader)
  75. {
  76. try
  77. {
  78. StartDeserialization();
  79. var serializer = new XmlSerializer(typeof(LayoutRoot));
  80. var layout = serializer.Deserialize(reader) as LayoutRoot;
  81. FixupLayout(layout);
  82. Manager.Layout = layout;
  83. }
  84. finally
  85. {
  86. EndDeserialization();
  87. }
  88. }
  89. public void Deserialize(string filepath)
  90. {
  91. using (var stream = new StreamReader(filepath))
  92. Deserialize(stream);
  93. }
  94. }
  95. }