Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog
- ===================================================================
- --- /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog (revision 120306)
- +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog (working copy)
- @@ -1,3 +1,13 @@
- +2008-12-01 Anton Kytmanov <carga@mail.ru>
- +
- + * Activity.cs: Class is marked with [Serializable] attribute;
- + initial extremely naive implementation of Save and Load methods
- + just to satisfy to unit-test; commented Save and Load declarions
- + were removed from code.
- + * DependencyObject.cs: Class is marked with [Serializable] attribute
- + * DependencyProperty.cs: Method GetObjectData was implemented;
- + some xml comments were added.
- +
- 2006-09-26 Jordi Mas i Hernandez <jordimash@gmail.com>
- * WorkflowParameterBindingCollection.cs: SetItem call base method
- Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs
- ===================================================================
- --- /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs (revision 120306)
- +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs (working copy)
- @@ -92,12 +92,24 @@
- }
- // Methods
- +
- + /// <summary>
- + /// Method searches for particular DependencyProperty among registered in repository
- + /// using its name and owner type
- + /// </summary>
- + /// <param name="propertyName">property name</param>
- + /// <param name="ownerType">owner type</param>
- + /// <returns>null, if nothing found; property otherwise</returns>
- public static DependencyProperty FromName (string propertyName, Type ownerType)
- {
- - DependencyProperty rslt;
- + DependencyProperty result = null;
- - rslt = properties [propertyName.GetHashCode() * ownerType.GetHashCode()];
- - return rslt;
- + int key = propertyName.GetHashCode () * ownerType.GetHashCode ();
- + if (properties.ContainsKey (key)) {
- + result = properties [key];
- + }
- +
- + return result;
- }
- public static IList <DependencyProperty> FromType (Type ownerType)
- @@ -166,11 +178,29 @@
- return property;
- }
- - [MonoTODO]
- - void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
- - {
- - throw new NotImplementedException ();
- - }
- + /// <summary>
- + /// Helper class to incapsulate property name and owner type in single box during serialization
- + /// </summary>
- + [Serializable]
- + private class SerializationStorageBox : IObjectReference {
- + private string property_name;
- + private Type owner_type;
- +
- + #region IObjectReference Members
- + public object GetRealObject (StreamingContext context) {
- + return DependencyProperty.FromName (property_name, owner_type);
- + }
- + #endregion
- + }
- +
- + /// <summary>
- + /// Method is used to put enough information about state of the object in SerializationInfo.
- + /// </summary>
- + void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) {
- + info.AddValue ("property_name", this.name);
- + info.AddValue ("owner_type", this.owner_type);
- + info.SetType (typeof(SerializationStorageBox));
- + }
- public override string ToString ()
- {
- Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs
- ===================================================================
- --- /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs (revision 120306)
- +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs (working copy)
- @@ -27,6 +27,8 @@
- using System.ComponentModel;
- using System.Collections.Generic;
- using System.Workflow.ComponentModel;
- +using System.Runtime.Serialization;
- +using System.Runtime.Serialization.Formatters.Binary;
- #if RUNTIME_DEP
- using System.Workflow.Runtime;
- @@ -34,6 +36,7 @@
- namespace System.Workflow.ComponentModel
- {
- + [Serializable]
- public class Activity : DependencyObject
- {
- private static DependencyProperty NameProperty;
- @@ -255,12 +258,7 @@
- return ActivityExecutionStatus.Closed;
- }
- - //public static Activity Load(Stream stream, Activity outerActivity)
- -
- - //public static Activity Load (Stream stream, Activity outerActivity, IFormatter formatter)
- //public void RegisterForStatusChange (DependencyProperty dependencyProp, IActivityEventListener<ActivityExecutionStatusChangedEventArgs> activityStatusChangeListener)
- - //public void Save (Stream stream)
- - //public void Save (Stream stream, IFormatter formatter)
- protected internal virtual void OnActivityExecutionContextLoad (IServiceProvider provider)
- {
- @@ -343,6 +341,51 @@
- return activity;
- }
- +
- + /// <summary>
- + /// Save activity to the given stream
- + /// </summary>
- + /// <param name="stream">stream to store data</param>
- + public void Save (Stream stream) {
- + BinaryFormatter formatter = new BinaryFormatter ();
- + Save (stream, formatter);
- + }
- +
- + /// <summary>
- + /// Save activity to the given stream using given formmatter
- + /// </summary>
- + /// <param name="stream">stream to store data</param>
- + /// <param name="formatter">formatter to be used during serialization</param>
- + public void Save (Stream stream, IFormatter formatter) {
- + if (stream == null)
- + throw new ArgumentNullException ("stream");
- + if (formatter == null)
- + throw new ArgumentNullException ("formatter");
- + formatter.Serialize (stream, this);
- + }
- +
- + /// <summary>
- + /// Load activity from the given stream
- + /// </summary>
- + /// <param name="stream">stream with serialized activity</param>
- + /// <returns>deserialized activity</returns>
- + public static Activity Load (Stream stream, Activity outerActivity) {
- + BinaryFormatter formatter = new BinaryFormatter ();
- + return Load (stream, outerActivity, formatter);
- + }
- +
- + /// <summary>
- + /// Load activity from the given stream
- + /// </summary>
- + /// <param name="stream">stream with serialized activity</param>
- + /// <param name="formatter">formatter to be used during deserialization</param>
- + /// <returns>deserialized activity</returns>
- + public static Activity Load (Stream stream, Activity outerActivity, IFormatter formatter) {
- + if (stream == null)
- + throw new ArgumentNullException ("stream");
- + if (formatter == null)
- + throw new ArgumentNullException ("formatter");
- + return (Activity)formatter.Deserialize (stream);
- + }
- }
- }
- -
- Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs
- ===================================================================
- --- /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs (revision 120306)
- +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs (working copy)
- @@ -28,6 +28,7 @@
- namespace System.Workflow.ComponentModel
- {
- + [Serializable]
- public abstract class DependencyObject : IComponent, IDisposable
- {
- private IDictionary <DependencyProperty, object> values;
- Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog
- ===================================================================
- --- /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog (revision 120306)
- +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog (working copy)
- @@ -1,3 +1,8 @@
- +2008-12-01 Anton Kytmanov <carga@mail.ru>
- +
- + * DependencyPropertyTest.cs: Test added for method DependencyProperty.FromName
- + and for method GetObjectData which is used during serialization
- +
- 2006-09-24 Jordi Mas i Hernandez <jordimash@gmail.com>
- * WorkflowParameterBindingCollectionTest.cs: added
- Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs
- ===================================================================
- --- /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs (revision 120306)
- +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs (working copy)
- @@ -30,6 +30,7 @@
- using System.Workflow.ComponentModel;
- using System.Collections;
- using System.Collections.Generic;
- +using System.Runtime.Serialization.Formatters.Binary;
- namespace MonoTests.System.Workflow.ComponentModel
- {
- @@ -71,6 +72,30 @@
- }
- }
- + [Serializable]
- + public class SerializationTestHelperClass : DependencyObject {
- + public const string propertyName = "Name";
- +
- + private static DependencyProperty NameProperty = DependencyProperty.Register (propertyName, typeof (string),
- + typeof (SerializationTestHelperClass), new PropertyMetadata ("some default value"));
- +
- + public SerializationTestHelperClass () {
- + }
- +
- + public SerializationTestHelperClass (string name) {
- + Name = name;
- + }
- +
- + public string Name {
- + get {
- + return (string)GetValue (SerializationTestHelperClass.NameProperty);
- + }
- + set {
- + SetValue (SerializationTestHelperClass.NameProperty, value);
- + }
- + }
- + }
- +
- [Test]
- public void RegisterEvent ()
- {
- @@ -130,6 +155,50 @@
- typeof (ClassProp3), new PropertyMetadata ("someone@example.com"));
- }
- + [Test]
- + public void TestFromNameMethod () {
- + string propertyName = "To";
- + Type ownerType = typeof (ClassProp3);
- + DependencyProperty expected = DependencyProperty.Register (propertyName, typeof (string),
- + ownerType, new PropertyMetadata ("someone@mail.ru"));
- +
- + DependencyProperty actual = DependencyProperty.FromName (propertyName, ownerType);
- +
- + Assert.IsNotNull (actual, "#K1#1");
- + Assert.AreEqual (expected.Name, actual.Name, "#K1#2");
- + Assert.AreEqual (expected.OwnerType, actual.OwnerType, "#K1#3");
- + Assert.AreEqual (expected.PropertyType, actual.PropertyType, "#K1#4");
- + Assert.AreSame (expected, actual, "#K1#5");
- +
- + actual = DependencyProperty.FromName ("garbage", ownerType);
- +
- + Assert.IsNull (actual, "#K1#11");
- + }
- +
- + [Test]
- + public void TestGetObjectDataMethod () {
- + string activityName = "TestSerialization";
- + string propertyName = SerializationTestHelperClass.propertyName;
- +
- + SerializationTestHelperClass expected = new SerializationTestHelperClass (activityName);
- + object actual = null;
- +
- + BinaryFormatter formatter = new BinaryFormatter ();
- + using (MemoryStream ms = new MemoryStream ()) {
- + formatter.Serialize (ms, expected);
- + ms.Position = 0;
- + actual = formatter.Deserialize (ms);
- + }
- +
- + Assert.IsNotNull (actual, "#K2#1");
- + Assert.IsTrue (actual is SerializationTestHelperClass, "#K2#2");
- +
- + DependencyProperty actualDepProp = DependencyProperty.FromName (propertyName, typeof (SerializationTestHelperClass));
- + Assert.IsNotNull (actualDepProp, "#K2#3");
- + Assert.AreEqual (propertyName, actualDepProp.Name, "#K2#4");
- + Assert.AreEqual (typeof (SerializationTestHelperClass), actualDepProp.OwnerType, "#K2#5");
- + Assert.AreEqual (typeof (string), actualDepProp.PropertyType, "#K2#6");
- + Assert.AreEqual (activityName, ((SerializationTestHelperClass)actual).Name, "#K2#7");
- + }
- }
- }
- -
Add Comment
Please, Sign In to add comment