Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs
- ===================================================================
- --- /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs (revision 120306)
- +++ /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs (working copy)
- @@ -31,6 +31,10 @@
- namespace System.Workflow.ComponentModel
- {
- + /// <summary>
- + /// Class is used to register value property in DependencyObject repository. Then it will notify subscribers about every change and
- + /// it will be able to participate in binding and automatic UI and/or workflow updates.
- + /// </summary>
- [Serializable]
- public sealed class DependencyProperty : ISerializable
- {
- @@ -91,13 +95,23 @@
- set { _event = value; }
- }
- - // 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;
- -
- - rslt = properties [propertyName.GetHashCode() * ownerType.GetHashCode()];
- - return rslt;
- + DependencyProperty result = null;
- +
- + int key = propertyName.GetHashCode () * ownerType.GetHashCode ();
- + if (properties.ContainsKey (key)) {
- + result = properties [key];
- + }
- +
- + return result;
- }
- public static IList <DependencyProperty> FromType (Type ownerType)
- @@ -164,12 +178,30 @@
- property.attached = true;
- property.validator_type = validatorType;
- return property;
- + }
- +
- + /// <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
- }
- - [MonoTODO]
- - void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
- - {
- - throw new NotImplementedException ();
- + /// <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 ()
- @@ -178,4 +210,3 @@
- }
- }
- }
- -
- Index: /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog
- ===================================================================
- --- /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog (revision 120306)
- +++ /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog (working copy)
- @@ -1,3 +1,17 @@
- +2008-11-25 Anton Kytmanov <carga@mail.ru>
- +
- + * Activity.cs: Class is marked with [Serializable] attribute;
- + commented method declarions removed for already implemented ones.
- + Recently added methods were reformatted (tabified).
- + * DependencyObject.cs: Class is marked with [Serializable] attribute
- + * DependencyProperty.cs: Method GetObjectData was implemented;
- + some xml comments were added.
- +
- +2008-11-17 Anton Kytmanov <carga@mail.ru>
- +
- + * Activity.cs: Initial extremely naive implementation of
- + Save and Load methods just to satisfy to unit-test.
- +
- 2006-09-26 Jordi Mas i Hernandez <jordimash@gmail.com>
- * WorkflowParameterBindingCollection.cs: SetItem call base method
- Index: /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs
- ===================================================================
- --- /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs (revision 120306)
- +++ /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs (working copy)
- @@ -26,7 +26,9 @@
- using System.IO;
- using System.ComponentModel;
- using System.Collections.Generic;
- -using System.Workflow.ComponentModel;
- +using System.Workflow.ComponentModel;
- +using System.Runtime.Serialization;
- +using System.Runtime.Serialization.Formatters.Binary;
- #if RUNTIME_DEP
- using System.Workflow.Runtime;
- @@ -34,12 +36,13 @@
- namespace System.Workflow.ComponentModel
- {
- - public class Activity : DependencyObject
- + [Serializable]
- + public class Activity : DependencyObject
- {
- private static DependencyProperty NameProperty;
- private static DependencyProperty DescriptionProperty;
- private static DependencyProperty EnabledProperty;
- - private static DependencyProperty ExecutionResultProperty;
- + private static DependencyProperty ExecutionResultProperty;
- private static DependencyProperty ExecutionStatusProperty;
- private Guid workflow_id;
- private Queue <Activity> exec_activities;
- @@ -70,14 +73,14 @@
- Console.WriteLine ("*** You should use a version built with the Runtime dependencies");
- #endif
- }
- -
- - // Constructors
- +
- + // Constructors
- public Activity ()
- {
- Init ();
- Name = GetType().Name;
- }
- -
- +
- public Activity (string name)
- {
- Init ();
- @@ -101,32 +104,32 @@
- return parent;
- }
- }
- -
- +
- public string Description {
- get {
- - return (string) GetValue (DescriptionProperty);
- + return (string) GetValue (DescriptionProperty);
- }
- set {
- SetValue (DescriptionProperty, value);
- }
- }
- -
- +
- public bool Enabled {
- get {
- - return (bool) GetValue (EnabledProperty);
- + return (bool) GetValue (EnabledProperty);
- }
- set {
- SetValue (EnabledProperty, value);
- }
- }
- -
- +
- public ActivityExecutionResult ExecutionResult {
- get {
- return (ActivityExecutionResult) GetValue (ExecutionResultProperty);
- }
- - }
- + }
- public ActivityExecutionStatus ExecutionStatus {
- get {
- return (ActivityExecutionStatus) GetValue (ExecutionStatusProperty);
- @@ -137,17 +140,17 @@
- public bool IsDynamicActivity {
- get {return false;}
- }
- -
- +
- public string Name {
- get {
- - return (string) GetValue (Activity.NameProperty);
- + return (string) GetValue (Activity.NameProperty);
- }
- set {
- SetValue (Activity.NameProperty, value);
- }
- - }
- -
- + }
- +
- public string QualifiedName {
- get {
- return Name;
- @@ -186,7 +189,7 @@
- set {
- parallel_parent = value;
- }
- - }
- + }
- // Methods
- [MonoTODO]
- @@ -195,7 +198,7 @@
- throw new NotImplementedException ();
- }
- - protected internal virtual ActivityExecutionStatus Cancel (ActivityExecutionContext executionContext)
- + protected internal virtual ActivityExecutionStatus Cancel (ActivityExecutionContext executionContext)
- {
- return ActivityExecutionStatus.Canceling;
- }
- @@ -210,7 +213,7 @@
- {
- }
- -
- +
- public Activity GetActivityByName (string activityQualifiedName)
- {
- return GetActivityByName (activityQualifiedName, true);
- @@ -252,26 +255,21 @@
- protected internal virtual ActivityExecutionStatus HandleFault (ActivityExecutionContext executionContext, Exception exception)
- {
- - return ActivityExecutionStatus.Closed;
- + 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)
- {
- }
- -
- +
- public override string ToString ()
- {
- return Name + " [" + base.ToString ()+ "]";
- }
- -
- +
- //public void UnregisterForStatusChange (DependencyProperty dependencyProp, IActivityEventListener<ActivityExecutionStatusChangedEventArgs> activityStatusChangeListener)
- // Private methods
- @@ -289,7 +287,7 @@
- te = new TimerEventSubscription (executionContext.ExecutionContextManager.Workflow.InstanceId,
- expiresAt);
- - WorkflowQueuingService qService = executionContext.GetService <WorkflowQueuingService> ();
- + WorkflowQueuingService qService = executionContext.GetService <WorkflowQueuingService> ();
- queue = qService.CreateWorkflowQueue (te.QueueName, true);
- queue.QueueItemArrived += OnQueueTimerItemArrived;
- executionContext.ExecutionContextManager.Workflow.TimerEventSubscriptionCollection.Add (te);
- @@ -341,8 +339,54 @@
- activity = activity.Parent;
- }
- - return activity;
- - }
- + 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/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs
- ===================================================================
- --- /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs (revision 120306)
- +++ /svn/olive/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/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog
- ===================================================================
- --- /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog (revision 120306)
- +++ /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog (working copy)
- @@ -1,3 +1,8 @@
- +2008-11-25 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/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs
- ===================================================================
- --- /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs (revision 120306)
- +++ /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs (working copy)
- @@ -29,7 +29,8 @@
- using System.Security.Permissions;
- using System.Workflow.ComponentModel;
- using System.Collections;
- -using System.Collections.Generic;
- +using System.Collections.Generic;
- +using System.Runtime.Serialization.Formatters.Binary;
- namespace MonoTests.System.Workflow.ComponentModel
- {
- @@ -69,8 +70,32 @@
- {
- }
- - }
- -
- + }
- +
- + [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 ()
- {
- @@ -128,8 +153,53 @@
- DependencyProperty dp2 = DependencyProperty.Register ("From", typeof(string),
- 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