Implement serialization of Settings and SettingsRepository.

- FIX: Stile werden jetzt gespeichert.
This commit is contained in:
Daniel Kraus
2015-08-11 16:12:39 +02:00
parent 53d13b394e
commit c9fc4a5fae
21 changed files with 593 additions and 44 deletions

View File

@ -1,4 +1,5 @@
/* ControlElementBase.cs
using System;
/* ControlElementBase.cs
* part of zaaReloaded2
*
* Copyright 2015 Daniel Kraus
@ -17,6 +18,7 @@
*/
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
namespace zaaReloaded2.Controller.Elements
{
@ -24,9 +26,10 @@ namespace zaaReloaded2.Controller.Elements
/// Base class for control elements that control e.g. the working
/// set of time points in a Formatter object.
/// </summary>
public abstract class ControlElementBase : ElementBase
[Serializable]
public abstract class ControlElementBase : ElementBase, ISerializable
{
#region Propertis
#region Properties
/// <summary>
/// Gets a list of child elements, all of which must be derived
@ -58,6 +61,43 @@ namespace zaaReloaded2.Controller.Elements
#endregion
#region Serialization
/// <summary>
/// Deserialization constructor.
/// </summary>
protected ControlElementBase(SerializationInfo info, StreamingContext context)
{
int version = info.GetInt32("Version");
int childrenCount = info.GetInt32("ChildrenCount");
Children = new List<FormatElementBase>();
for (int i = 0; i < childrenCount; i++)
{
Type typeOfChild = info.GetValue(SerializedChildName(i, "Type"), typeof(Type)) as Type;
Children.Add(info.GetValue(SerializedChildName(i, "Object"), typeOfChild) as FormatElementBase);
}
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Version", Properties.Settings.Default.SerializationVersion);
info.AddValue("ChildrenCount", Children.Count);
int i = 0;
foreach (FormatElementBase child in Children)
{
info.AddValue(SerializedChildName(i, "Type"), child.GetType());
info.AddValue(SerializedChildName(i, "Object"), child);
i++;
}
}
private string SerializedChildName(int index, string info)
{
return String.Format("Child{0}{1}", index, info);
}
#endregion
#region Protected methods
/// <summary>

View File

@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace zaaReloaded2.Controller.Elements
@ -25,7 +26,8 @@ namespace zaaReloaded2.Controller.Elements
/// <summary>
/// Controller element that writes arbitrary text to the document.
/// </summary>
class CustomText : FormatElementBase
[Serializable]
public class CustomText : FormatElementBase, ISerializable
{
public override string Label
{
@ -43,5 +45,20 @@ namespace zaaReloaded2.Controller.Elements
clone.Content = Content;
return clone;
}
#region Constructors
public CustomText () { }
/// <summary>
/// Deserialization constructor.
/// </summary>
protected CustomText(SerializationInfo info, StreamingContext context)
{
int version = info.GetInt32("Version");
Content = info.GetString("Content");
}
#endregion
}
}

View File

@ -21,13 +21,13 @@ using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using zaaReloaded2.LabModel;
using System.Runtime.Serialization;
namespace zaaReloaded2.Controller.Elements
{
/// <summary>
/// Base class for formatting elements.
/// </summary>
[Serializable]
public abstract class ElementBase : ICloneable
{
/// <summary>

View File

@ -16,12 +16,14 @@
* limitations under the License.
*/
using System;
using System.Runtime.Serialization;
namespace zaaReloaded2.Controller.Elements
{
/// <summary>
/// Base class for elements that perform actual formatting.
/// </summary>
public abstract class FormatElementBase : ElementBase
public abstract class FormatElementBase : ElementBase, ISerializable
{
/// <summary>
/// Gets or sets the content of this format element.
@ -41,5 +43,15 @@ namespace zaaReloaded2.Controller.Elements
protected virtual void OnContentChanged() {}
private string _content;
#region Serialization
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Version", Properties.Settings.Default.SerializationVersion);
info.AddValue("Content", Content);
}
#endregion
}
}

View File

@ -23,6 +23,7 @@ using System.Diagnostics;
using Microsoft.Office.Interop.Word;
using zaaReloaded2.LabModel;
using zaaReloaded2.Formatter;
using System.Runtime.Serialization;
namespace zaaReloaded2.Controller.Elements
{
@ -31,7 +32,7 @@ namespace zaaReloaded2.Controller.Elements
/// to a Word document.
/// </summary>
[Serializable]
class Items : CustomText
public class Items : CustomText
{
#region ElementBase implementation
@ -93,6 +94,13 @@ namespace zaaReloaded2.Controller.Elements
Content = content;
}
/// <summary>
/// Deserialization constructor.
/// </summary>
protected Items(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endregion
#region Private methods

View File

@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace zaaReloaded2.Controller.Elements
@ -26,7 +27,8 @@ namespace zaaReloaded2.Controller.Elements
/// Format element that causes a Formatter object to move the
/// insertion point to the next colum in a layout table.
/// </summary>
class NextColumn : ControlElementBase
[Serializable]
public class NextColumn : ControlElementBase, ISerializable
{
public override string Label
{
@ -50,5 +52,18 @@ namespace zaaReloaded2.Controller.Elements
{
return new NextColumn();
}
#region Constructors
public NextColumn() : base() { }
/// <summary>
/// Deserialization constructor.
/// </summary>
protected NextColumn(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endregion
}
}

View File

@ -18,11 +18,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace zaaReloaded2.Controller.Elements
{
class SelectEachDay : ControlElementBase
[Serializable]
public class SelectEachDay : ControlElementBase
{
public override string Label
{
@ -34,6 +36,13 @@ namespace zaaReloaded2.Controller.Elements
formatter.ProcessEachDay(this);
}
protected override ElementBase CreateInstance()
{
return new SelectEachDay(CloneChildren());
}
#region Constructors
public SelectEachDay() : base() { }
public SelectEachDay(FormatElementBase formatElement)
@ -44,9 +53,13 @@ namespace zaaReloaded2.Controller.Elements
: base(formatElements)
{ }
protected override ElementBase CreateInstance()
{
return new SelectEachDay(CloneChildren());
}
/// <summary>
/// Deserialization constructor.
/// </summary>
protected SelectEachDay(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endregion
}
}

View File

@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace zaaReloaded2.Controller.Elements
@ -26,7 +27,8 @@ namespace zaaReloaded2.Controller.Elements
/// Selects the time points of the first day in a given Formatter
/// object.
/// </summary>
class SelectFirstDay : ControlElementBase
[Serializable]
public class SelectFirstDay : ControlElementBase, ISerializable
{
public override string Label
{
@ -38,6 +40,13 @@ namespace zaaReloaded2.Controller.Elements
formatter.ProcessFirstDay(this);
}
protected override ElementBase CreateInstance()
{
return new SelectFirstDay(CloneChildren());
}
#region Constructors
public SelectFirstDay() : base() { }
public SelectFirstDay(FormatElementBase formatElement)
@ -48,9 +57,13 @@ namespace zaaReloaded2.Controller.Elements
: base(formatElements)
{ }
protected override ElementBase CreateInstance()
{
return new SelectFirstDay(CloneChildren());
}
/// <summary>
/// Deserialization constructor.
/// </summary>
protected SelectFirstDay(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endregion
}
}

View File

@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace zaaReloaded2.Controller.Elements
@ -27,7 +28,8 @@ namespace zaaReloaded2.Controller.Elements
/// Selects the time points of the last day in a given Formatter
/// object.
/// </summary>
class SelectLastDay : ControlElementBase
[Serializable]
public class SelectLastDay : ControlElementBase, ISerializable
{
public override string Label
{
@ -39,6 +41,13 @@ namespace zaaReloaded2.Controller.Elements
formatter.ProcessLastDay(this);
}
protected override ElementBase CreateInstance()
{
return new SelectLastDay(CloneChildren());
}
#region Constructors
public SelectLastDay() : base() { }
public SelectLastDay(FormatElementBase formatElement)
@ -49,9 +58,13 @@ namespace zaaReloaded2.Controller.Elements
: base(formatElements)
{ }
protected override ElementBase CreateInstance()
{
return new SelectLastDay(CloneChildren());
}
/// <summary>
/// Deserialization constructor.
/// </summary>
protected SelectLastDay(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endregion
}
}

View File

@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace zaaReloaded2.Controller.Elements
@ -26,7 +27,8 @@ namespace zaaReloaded2.Controller.Elements
/// Format element that causes a Formatter object to insert a table with
/// two columns and one row into the documents.
/// </summary>
class TwoColumns : ControlElementBase
[Serializable]
public class TwoColumns : ControlElementBase, ISerializable
{
public override string Label
{
@ -50,5 +52,18 @@ namespace zaaReloaded2.Controller.Elements
{
return new TwoColumns();
}
}
#region Constructors
public TwoColumns() : base() { }
/// <summary>
/// Deserialization constructor.
/// </summary>
protected TwoColumns(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endregion
}
}