Guest User

Untitled

a guest
May 8th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.51 KB | None | 0 0
  1. Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog
  2. ===================================================================
  3. --- /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog (revision 120306)
  4. +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog (working copy)
  5. @@ -1,3 +1,13 @@
  6. +2008-12-01 Anton Kytmanov <carga@mail.ru>
  7. +
  8. + * Activity.cs: Class is marked with [Serializable] attribute;
  9. + initial extremely naive implementation of Save and Load methods
  10. + just to satisfy to unit-test; commented Save and Load declarions
  11. + were removed from code.
  12. + * DependencyObject.cs: Class is marked with [Serializable] attribute
  13. + * DependencyProperty.cs: Method GetObjectData was implemented;
  14. + some xml comments were added.
  15. +
  16. 2006-09-26 Jordi Mas i Hernandez <jordimash@gmail.com>
  17.  
  18. * WorkflowParameterBindingCollection.cs: SetItem call base method
  19. Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs
  20. ===================================================================
  21. --- /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs (revision 120306)
  22. +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs (working copy)
  23. @@ -92,12 +92,24 @@
  24. }
  25.  
  26. // Methods
  27. +
  28. + /// <summary>
  29. + /// Method searches for particular DependencyProperty among registered in repository
  30. + /// using its name and owner type
  31. + /// </summary>
  32. + /// <param name="propertyName">property name</param>
  33. + /// <param name="ownerType">owner type</param>
  34. + /// <returns>null, if nothing found; property otherwise</returns>
  35. public static DependencyProperty FromName (string propertyName, Type ownerType)
  36. {
  37. - DependencyProperty rslt;
  38. + DependencyProperty result = null;
  39.  
  40. - rslt = properties [propertyName.GetHashCode() * ownerType.GetHashCode()];
  41. - return rslt;
  42. + int key = propertyName.GetHashCode () * ownerType.GetHashCode ();
  43. + if (properties.ContainsKey (key)) {
  44. + result = properties [key];
  45. + }
  46. +
  47. + return result;
  48. }
  49.  
  50. public static IList <DependencyProperty> FromType (Type ownerType)
  51. @@ -166,11 +178,29 @@
  52. return property;
  53. }
  54.  
  55. - [MonoTODO]
  56. - void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
  57. - {
  58. - throw new NotImplementedException ();
  59. - }
  60. + /// <summary>
  61. + /// Helper class to incapsulate property name and owner type in single box during serialization
  62. + /// </summary>
  63. + [Serializable]
  64. + private class SerializationStorageBox : IObjectReference {
  65. + private string property_name;
  66. + private Type owner_type;
  67. +
  68. + #region IObjectReference Members
  69. + public object GetRealObject (StreamingContext context) {
  70. + return DependencyProperty.FromName (property_name, owner_type);
  71. + }
  72. + #endregion
  73. + }
  74. +
  75. + /// <summary>
  76. + /// Method is used to put enough information about state of the object in SerializationInfo.
  77. + /// </summary>
  78. + void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) {
  79. + info.AddValue ("property_name", this.name);
  80. + info.AddValue ("owner_type", this.owner_type);
  81. + info.SetType (typeof(SerializationStorageBox));
  82. + }
  83.  
  84. public override string ToString ()
  85. {
  86. Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs
  87. ===================================================================
  88. --- /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs (revision 120306)
  89. +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs (working copy)
  90. @@ -27,6 +27,8 @@
  91. using System.ComponentModel;
  92. using System.Collections.Generic;
  93. using System.Workflow.ComponentModel;
  94. +using System.Runtime.Serialization;
  95. +using System.Runtime.Serialization.Formatters.Binary;
  96.  
  97. #if RUNTIME_DEP
  98. using System.Workflow.Runtime;
  99. @@ -34,6 +36,7 @@
  100.  
  101. namespace System.Workflow.ComponentModel
  102. {
  103. + [Serializable]
  104. public class Activity : DependencyObject
  105. {
  106. private static DependencyProperty NameProperty;
  107. @@ -255,12 +258,7 @@
  108. return ActivityExecutionStatus.Closed;
  109. }
  110.  
  111. - //public static Activity Load(Stream stream, Activity outerActivity)
  112. -
  113. - //public static Activity Load (Stream stream, Activity outerActivity, IFormatter formatter)
  114. //public void RegisterForStatusChange (DependencyProperty dependencyProp, IActivityEventListener<ActivityExecutionStatusChangedEventArgs> activityStatusChangeListener)
  115. - //public void Save (Stream stream)
  116. - //public void Save (Stream stream, IFormatter formatter)
  117.  
  118. protected internal virtual void OnActivityExecutionContextLoad (IServiceProvider provider)
  119. {
  120. @@ -343,6 +341,51 @@
  121.  
  122. return activity;
  123. }
  124. +
  125. + /// <summary>
  126. + /// Save activity to the given stream
  127. + /// </summary>
  128. + /// <param name="stream">stream to store data</param>
  129. + public void Save (Stream stream) {
  130. + BinaryFormatter formatter = new BinaryFormatter ();
  131. + Save (stream, formatter);
  132. + }
  133. +
  134. + /// <summary>
  135. + /// Save activity to the given stream using given formmatter
  136. + /// </summary>
  137. + /// <param name="stream">stream to store data</param>
  138. + /// <param name="formatter">formatter to be used during serialization</param>
  139. + public void Save (Stream stream, IFormatter formatter) {
  140. + if (stream == null)
  141. + throw new ArgumentNullException ("stream");
  142. + if (formatter == null)
  143. + throw new ArgumentNullException ("formatter");
  144. + formatter.Serialize (stream, this);
  145. + }
  146. +
  147. + /// <summary>
  148. + /// Load activity from the given stream
  149. + /// </summary>
  150. + /// <param name="stream">stream with serialized activity</param>
  151. + /// <returns>deserialized activity</returns>
  152. + public static Activity Load (Stream stream, Activity outerActivity) {
  153. + BinaryFormatter formatter = new BinaryFormatter ();
  154. + return Load (stream, outerActivity, formatter);
  155. + }
  156. +
  157. + /// <summary>
  158. + /// Load activity from the given stream
  159. + /// </summary>
  160. + /// <param name="stream">stream with serialized activity</param>
  161. + /// <param name="formatter">formatter to be used during deserialization</param>
  162. + /// <returns>deserialized activity</returns>
  163. + public static Activity Load (Stream stream, Activity outerActivity, IFormatter formatter) {
  164. + if (stream == null)
  165. + throw new ArgumentNullException ("stream");
  166. + if (formatter == null)
  167. + throw new ArgumentNullException ("formatter");
  168. + return (Activity)formatter.Deserialize (stream);
  169. + }
  170. }
  171. }
  172. -
  173. Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs
  174. ===================================================================
  175. --- /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs (revision 120306)
  176. +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs (working copy)
  177. @@ -28,6 +28,7 @@
  178.  
  179. namespace System.Workflow.ComponentModel
  180. {
  181. + [Serializable]
  182. public abstract class DependencyObject : IComponent, IDisposable
  183. {
  184. private IDictionary <DependencyProperty, object> values;
  185. Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog
  186. ===================================================================
  187. --- /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog (revision 120306)
  188. +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog (working copy)
  189. @@ -1,3 +1,8 @@
  190. +2008-12-01 Anton Kytmanov <carga@mail.ru>
  191. +
  192. + * DependencyPropertyTest.cs: Test added for method DependencyProperty.FromName
  193. + and for method GetObjectData which is used during serialization
  194. +
  195. 2006-09-24 Jordi Mas i Hernandez <jordimash@gmail.com>
  196.  
  197. * WorkflowParameterBindingCollectionTest.cs: added
  198. Index: /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs
  199. ===================================================================
  200. --- /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs (revision 120306)
  201. +++ /svn/mono-olive2/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs (working copy)
  202. @@ -30,6 +30,7 @@
  203. using System.Workflow.ComponentModel;
  204. using System.Collections;
  205. using System.Collections.Generic;
  206. +using System.Runtime.Serialization.Formatters.Binary;
  207.  
  208. namespace MonoTests.System.Workflow.ComponentModel
  209. {
  210. @@ -71,6 +72,30 @@
  211. }
  212. }
  213.  
  214. + [Serializable]
  215. + public class SerializationTestHelperClass : DependencyObject {
  216. + public const string propertyName = "Name";
  217. +
  218. + private static DependencyProperty NameProperty = DependencyProperty.Register (propertyName, typeof (string),
  219. + typeof (SerializationTestHelperClass), new PropertyMetadata ("some default value"));
  220. +
  221. + public SerializationTestHelperClass () {
  222. + }
  223. +
  224. + public SerializationTestHelperClass (string name) {
  225. + Name = name;
  226. + }
  227. +
  228. + public string Name {
  229. + get {
  230. + return (string)GetValue (SerializationTestHelperClass.NameProperty);
  231. + }
  232. + set {
  233. + SetValue (SerializationTestHelperClass.NameProperty, value);
  234. + }
  235. + }
  236. + }
  237. +
  238. [Test]
  239. public void RegisterEvent ()
  240. {
  241. @@ -130,6 +155,50 @@
  242. typeof (ClassProp3), new PropertyMetadata ("someone@example.com"));
  243. }
  244.  
  245. + [Test]
  246. + public void TestFromNameMethod () {
  247. + string propertyName = "To";
  248. + Type ownerType = typeof (ClassProp3);
  249. + DependencyProperty expected = DependencyProperty.Register (propertyName, typeof (string),
  250. + ownerType, new PropertyMetadata ("someone@mail.ru"));
  251. +
  252. + DependencyProperty actual = DependencyProperty.FromName (propertyName, ownerType);
  253. +
  254. + Assert.IsNotNull (actual, "#K1#1");
  255. + Assert.AreEqual (expected.Name, actual.Name, "#K1#2");
  256. + Assert.AreEqual (expected.OwnerType, actual.OwnerType, "#K1#3");
  257. + Assert.AreEqual (expected.PropertyType, actual.PropertyType, "#K1#4");
  258. + Assert.AreSame (expected, actual, "#K1#5");
  259. +
  260. + actual = DependencyProperty.FromName ("garbage", ownerType);
  261. +
  262. + Assert.IsNull (actual, "#K1#11");
  263. + }
  264. +
  265. + [Test]
  266. + public void TestGetObjectDataMethod () {
  267. + string activityName = "TestSerialization";
  268. + string propertyName = SerializationTestHelperClass.propertyName;
  269. +
  270. + SerializationTestHelperClass expected = new SerializationTestHelperClass (activityName);
  271. + object actual = null;
  272. +
  273. + BinaryFormatter formatter = new BinaryFormatter ();
  274. + using (MemoryStream ms = new MemoryStream ()) {
  275. + formatter.Serialize (ms, expected);
  276. + ms.Position = 0;
  277. + actual = formatter.Deserialize (ms);
  278. + }
  279. +
  280. + Assert.IsNotNull (actual, "#K2#1");
  281. + Assert.IsTrue (actual is SerializationTestHelperClass, "#K2#2");
  282. +
  283. + DependencyProperty actualDepProp = DependencyProperty.FromName (propertyName, typeof (SerializationTestHelperClass));
  284. + Assert.IsNotNull (actualDepProp, "#K2#3");
  285. + Assert.AreEqual (propertyName, actualDepProp.Name, "#K2#4");
  286. + Assert.AreEqual (typeof (SerializationTestHelperClass), actualDepProp.OwnerType, "#K2#5");
  287. + Assert.AreEqual (typeof (string), actualDepProp.PropertyType, "#K2#6");
  288. + Assert.AreEqual (activityName, ((SerializationTestHelperClass)actual).Name, "#K2#7");
  289. + }
  290. }
  291. }
  292. -
Add Comment
Please, Sign In to add comment