Guest User

Untitled

a guest
May 28th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.08 KB | None | 0 0
  1. Index: /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs
  2. ===================================================================
  3. --- /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs (revision 120306)
  4. +++ /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyProperty.cs (working copy)
  5. @@ -31,6 +31,10 @@
  6.  
  7. namespace System.Workflow.ComponentModel
  8. {
  9. + /// <summary>
  10. + /// Class is used to register value property in DependencyObject repository. Then it will notify subscribers about every change and
  11. + /// it will be able to participate in binding and automatic UI and/or workflow updates.
  12. + /// </summary>
  13. [Serializable]
  14. public sealed class DependencyProperty : ISerializable
  15. {
  16. @@ -91,13 +95,23 @@
  17. set { _event = value; }
  18. }
  19.  
  20. - // Methods
  21. + /// <summary>
  22. + /// Method searches for particular DependencyProperty among registered in repository
  23. + /// using its name and owner type
  24. + /// </summary>
  25. + /// <param name="propertyName">property name</param>
  26. + /// <param name="ownerType">owner type</param>
  27. + /// <returns>null, if nothing found; property otherwise</returns>
  28. public static DependencyProperty FromName (string propertyName, Type ownerType)
  29. {
  30. - DependencyProperty rslt;
  31. -
  32. - rslt = properties [propertyName.GetHashCode() * ownerType.GetHashCode()];
  33. - return rslt;
  34. + DependencyProperty result = null;
  35. +
  36. + int key = propertyName.GetHashCode () * ownerType.GetHashCode ();
  37. + if (properties.ContainsKey (key)) {
  38. + result = properties [key];
  39. + }
  40. +
  41. + return result;
  42. }
  43.  
  44. public static IList <DependencyProperty> FromType (Type ownerType)
  45. @@ -164,12 +178,30 @@
  46. property.attached = true;
  47. property.validator_type = validatorType;
  48. return property;
  49. + }
  50. +
  51. + /// <summary>
  52. + /// Helper class to incapsulate property name and owner type in single box during serialization
  53. + /// </summary>
  54. + [Serializable]
  55. + private class SerializationStorageBox : IObjectReference {
  56. + private string property_name;
  57. + private Type owner_type;
  58. +
  59. + #region IObjectReference Members
  60. + public object GetRealObject (StreamingContext context) {
  61. + return DependencyProperty.FromName (property_name, owner_type);
  62. + }
  63. + #endregion
  64. }
  65.  
  66. - [MonoTODO]
  67. - void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
  68. - {
  69. - throw new NotImplementedException ();
  70. + /// <summary>
  71. + /// Method is used to put enough information about state of the object in SerializationInfo.
  72. + /// </summary>
  73. + void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) {
  74. + info.AddValue ("property_name", this.name);
  75. + info.AddValue ("owner_type", this.owner_type);
  76. + info.SetType (typeof(SerializationStorageBox));
  77. }
  78.  
  79. public override string ToString ()
  80. @@ -178,4 +210,3 @@
  81. }
  82. }
  83. }
  84. -
  85. Index: /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog
  86. ===================================================================
  87. --- /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog (revision 120306)
  88. +++ /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/ChangeLog (working copy)
  89. @@ -1,3 +1,17 @@
  90. +2008-11-25 Anton Kytmanov <carga@mail.ru>
  91. +
  92. + * Activity.cs: Class is marked with [Serializable] attribute;
  93. + commented method declarions removed for already implemented ones.
  94. + Recently added methods were reformatted (tabified).
  95. + * DependencyObject.cs: Class is marked with [Serializable] attribute
  96. + * DependencyProperty.cs: Method GetObjectData was implemented;
  97. + some xml comments were added.
  98. +
  99. +2008-11-17 Anton Kytmanov <carga@mail.ru>
  100. +
  101. + * Activity.cs: Initial extremely naive implementation of
  102. + Save and Load methods just to satisfy to unit-test.
  103. +
  104. 2006-09-26 Jordi Mas i Hernandez <jordimash@gmail.com>
  105.  
  106. * WorkflowParameterBindingCollection.cs: SetItem call base method
  107. Index: /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs
  108. ===================================================================
  109. --- /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs (revision 120306)
  110. +++ /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/Activity.cs (working copy)
  111. @@ -26,7 +26,9 @@
  112. using System.IO;
  113. using System.ComponentModel;
  114. using System.Collections.Generic;
  115. -using System.Workflow.ComponentModel;
  116. +using System.Workflow.ComponentModel;
  117. +using System.Runtime.Serialization;
  118. +using System.Runtime.Serialization.Formatters.Binary;
  119.  
  120. #if RUNTIME_DEP
  121. using System.Workflow.Runtime;
  122. @@ -34,12 +36,13 @@
  123.  
  124. namespace System.Workflow.ComponentModel
  125. {
  126. - public class Activity : DependencyObject
  127. + [Serializable]
  128. + public class Activity : DependencyObject
  129. {
  130. private static DependencyProperty NameProperty;
  131. private static DependencyProperty DescriptionProperty;
  132. private static DependencyProperty EnabledProperty;
  133. - private static DependencyProperty ExecutionResultProperty;
  134. + private static DependencyProperty ExecutionResultProperty;
  135. private static DependencyProperty ExecutionStatusProperty;
  136. private Guid workflow_id;
  137. private Queue <Activity> exec_activities;
  138. @@ -70,14 +73,14 @@
  139. Console.WriteLine ("*** You should use a version built with the Runtime dependencies");
  140. #endif
  141. }
  142. -
  143. - // Constructors
  144. +
  145. + // Constructors
  146. public Activity ()
  147. {
  148. Init ();
  149. Name = GetType().Name;
  150. }
  151. -
  152. +
  153. public Activity (string name)
  154. {
  155. Init ();
  156. @@ -101,32 +104,32 @@
  157. return parent;
  158. }
  159. }
  160. -
  161. +
  162. public string Description {
  163. get {
  164. - return (string) GetValue (DescriptionProperty);
  165. + return (string) GetValue (DescriptionProperty);
  166.  
  167. }
  168. set {
  169. SetValue (DescriptionProperty, value);
  170. }
  171. }
  172. -
  173. +
  174. public bool Enabled {
  175. get {
  176. - return (bool) GetValue (EnabledProperty);
  177. + return (bool) GetValue (EnabledProperty);
  178.  
  179. }
  180. set {
  181. SetValue (EnabledProperty, value);
  182. }
  183. }
  184. -
  185. +
  186. public ActivityExecutionResult ExecutionResult {
  187. get {
  188. return (ActivityExecutionResult) GetValue (ExecutionResultProperty);
  189. }
  190. - }
  191. + }
  192. public ActivityExecutionStatus ExecutionStatus {
  193. get {
  194. return (ActivityExecutionStatus) GetValue (ExecutionStatusProperty);
  195. @@ -137,17 +140,17 @@
  196. public bool IsDynamicActivity {
  197. get {return false;}
  198. }
  199. -
  200. +
  201. public string Name {
  202. get {
  203. - return (string) GetValue (Activity.NameProperty);
  204. + return (string) GetValue (Activity.NameProperty);
  205.  
  206. }
  207. set {
  208. SetValue (Activity.NameProperty, value);
  209. }
  210. - }
  211. -
  212. + }
  213. +
  214. public string QualifiedName {
  215. get {
  216. return Name;
  217. @@ -186,7 +189,7 @@
  218. set {
  219. parallel_parent = value;
  220. }
  221. - }
  222. + }
  223.  
  224. // Methods
  225. [MonoTODO]
  226. @@ -195,7 +198,7 @@
  227. throw new NotImplementedException ();
  228. }
  229.  
  230. - protected internal virtual ActivityExecutionStatus Cancel (ActivityExecutionContext executionContext)
  231. + protected internal virtual ActivityExecutionStatus Cancel (ActivityExecutionContext executionContext)
  232. {
  233. return ActivityExecutionStatus.Canceling;
  234. }
  235. @@ -210,7 +213,7 @@
  236. {
  237.  
  238. }
  239. -
  240. +
  241. public Activity GetActivityByName (string activityQualifiedName)
  242. {
  243. return GetActivityByName (activityQualifiedName, true);
  244. @@ -252,26 +255,21 @@
  245.  
  246. protected internal virtual ActivityExecutionStatus HandleFault (ActivityExecutionContext executionContext, Exception exception)
  247. {
  248. - return ActivityExecutionStatus.Closed;
  249. + return ActivityExecutionStatus.Closed;
  250. }
  251. -
  252. - //public static Activity Load(Stream stream, Activity outerActivity)
  253. -
  254. - //public static Activity Load (Stream stream, Activity outerActivity, IFormatter formatter)
  255. +
  256. //public void RegisterForStatusChange (DependencyProperty dependencyProp, IActivityEventListener<ActivityExecutionStatusChangedEventArgs> activityStatusChangeListener)
  257. - //public void Save (Stream stream)
  258. - //public void Save (Stream stream, IFormatter formatter)
  259.  
  260. protected internal virtual void OnActivityExecutionContextLoad (IServiceProvider provider)
  261. {
  262.  
  263. }
  264. -
  265. +
  266. public override string ToString ()
  267. {
  268. return Name + " [" + base.ToString ()+ "]";
  269. }
  270. -
  271. +
  272. //public void UnregisterForStatusChange (DependencyProperty dependencyProp, IActivityEventListener<ActivityExecutionStatusChangedEventArgs> activityStatusChangeListener)
  273.  
  274. // Private methods
  275. @@ -289,7 +287,7 @@
  276. te = new TimerEventSubscription (executionContext.ExecutionContextManager.Workflow.InstanceId,
  277. expiresAt);
  278.  
  279. - WorkflowQueuingService qService = executionContext.GetService <WorkflowQueuingService> ();
  280. + WorkflowQueuingService qService = executionContext.GetService <WorkflowQueuingService> ();
  281. queue = qService.CreateWorkflowQueue (te.QueueName, true);
  282. queue.QueueItemArrived += OnQueueTimerItemArrived;
  283. executionContext.ExecutionContextManager.Workflow.TimerEventSubscriptionCollection.Add (te);
  284. @@ -341,8 +339,54 @@
  285. activity = activity.Parent;
  286. }
  287.  
  288. - return activity;
  289. - }
  290. + return activity;
  291. + }
  292. +
  293. + /// <summary>
  294. + /// Save activity to the given stream
  295. + /// </summary>
  296. + /// <param name="stream">stream to store data</param>
  297. + public void Save (Stream stream) {
  298. + BinaryFormatter formatter = new BinaryFormatter ();
  299. + Save (stream, formatter);
  300. + }
  301. +
  302. + /// <summary>
  303. + /// Save activity to the given stream using given formmatter
  304. + /// </summary>
  305. + /// <param name="stream">stream to store data</param>
  306. + /// <param name="formatter">formatter to be used during serialization</param>
  307. + public void Save (Stream stream, IFormatter formatter) {
  308. + if (stream == null)
  309. + throw new ArgumentNullException ("stream");
  310. + if (formatter == null)
  311. + throw new ArgumentNullException ("formatter");
  312. + formatter.Serialize (stream, this);
  313. + }
  314. +
  315. + /// <summary>
  316. + /// Load activity from the given stream
  317. + /// </summary>
  318. + /// <param name="stream">stream with serialized activity</param>
  319. + /// <returns>deserialized activity</returns>
  320. + public static Activity Load (Stream stream, Activity outerActivity) {
  321. + BinaryFormatter formatter = new BinaryFormatter ();
  322. + return Load (stream, outerActivity, formatter);
  323. + }
  324. +
  325. + /// <summary>
  326. + /// Load activity from the given stream
  327. + /// </summary>
  328. + /// <param name="stream">stream with serialized activity</param>
  329. + /// <param name="formatter">formatter to be used during deserialization</param>
  330. + /// <returns>deserialized activity</returns>
  331. + public static Activity Load (Stream stream, Activity outerActivity, IFormatter formatter) {
  332. + if (stream == null)
  333. + throw new ArgumentNullException ("stream");
  334. + if (formatter == null)
  335. + throw new ArgumentNullException ("formatter");
  336. + return (Activity)formatter.Deserialize (stream);
  337. + }
  338. }
  339. }
  340.  
  341. Index: /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs
  342. ===================================================================
  343. --- /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs (revision 120306)
  344. +++ /svn/olive/class/System.Workflow.ComponentModel/System.Workflow.ComponentModel/DependencyObject.cs (working copy)
  345. @@ -28,6 +28,7 @@
  346.  
  347. namespace System.Workflow.ComponentModel
  348. {
  349. + [Serializable]
  350. public abstract class DependencyObject : IComponent, IDisposable
  351. {
  352. private IDictionary <DependencyProperty, object> values;
  353. Index: /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog
  354. ===================================================================
  355. --- /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog (revision 120306)
  356. +++ /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/ChangeLog (working copy)
  357. @@ -1,3 +1,8 @@
  358. +2008-11-25 Anton Kytmanov <carga@mail.ru>
  359. +
  360. + * DependencyPropertyTest.cs: Test added for method DependencyProperty.FromName
  361. + and for method GetObjectData which is used during serialization
  362. +
  363. 2006-09-24 Jordi Mas i Hernandez <jordimash@gmail.com>
  364.  
  365. * WorkflowParameterBindingCollectionTest.cs: added
  366. Index: /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs
  367. ===================================================================
  368. --- /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs (revision 120306)
  369. +++ /svn/olive/class/System.Workflow.ComponentModel/Test/System.Workflow.ComponentModel/DependencyPropertyTest.cs (working copy)
  370. @@ -29,7 +29,8 @@
  371. using System.Security.Permissions;
  372. using System.Workflow.ComponentModel;
  373. using System.Collections;
  374. -using System.Collections.Generic;
  375. +using System.Collections.Generic;
  376. +using System.Runtime.Serialization.Formatters.Binary;
  377.  
  378. namespace MonoTests.System.Workflow.ComponentModel
  379. {
  380. @@ -69,8 +70,32 @@
  381. {
  382.  
  383. }
  384. - }
  385. -
  386. + }
  387. +
  388. + [Serializable]
  389. + public class SerializationTestHelperClass : DependencyObject {
  390. + public const string propertyName = "Name";
  391. +
  392. + private static DependencyProperty NameProperty = DependencyProperty.Register (propertyName, typeof (string),
  393. + typeof (SerializationTestHelperClass), new PropertyMetadata ("some default value"));
  394. +
  395. + public SerializationTestHelperClass () {
  396. + }
  397. +
  398. + public SerializationTestHelperClass (string name) {
  399. + Name = name;
  400. + }
  401. +
  402. + public string Name {
  403. + get {
  404. + return (string)GetValue (SerializationTestHelperClass.NameProperty);
  405. + }
  406. + set {
  407. + SetValue (SerializationTestHelperClass.NameProperty, value);
  408. + }
  409. + }
  410. + }
  411. +
  412. [Test]
  413. public void RegisterEvent ()
  414. {
  415. @@ -128,8 +153,53 @@
  416.  
  417. DependencyProperty dp2 = DependencyProperty.Register ("From", typeof(string),
  418. typeof (ClassProp3), new PropertyMetadata ("someone@example.com"));
  419. + }
  420. +
  421. + [Test]
  422. + public void TestFromNameMethod () {
  423. + string propertyName = "To";
  424. + Type ownerType = typeof (ClassProp3);
  425. + DependencyProperty expected = DependencyProperty.Register (propertyName, typeof (string),
  426. + ownerType, new PropertyMetadata ("someone@mail.ru"));
  427. +
  428. + DependencyProperty actual = DependencyProperty.FromName (propertyName, ownerType);
  429. +
  430. + Assert.IsNotNull (actual, "#K1#1");
  431. + Assert.AreEqual (expected.Name, actual.Name, "#K1#2");
  432. + Assert.AreEqual (expected.OwnerType, actual.OwnerType, "#K1#3");
  433. + Assert.AreEqual (expected.PropertyType, actual.PropertyType, "#K1#4");
  434. + Assert.AreSame (expected, actual, "#K1#5");
  435. +
  436. + actual = DependencyProperty.FromName ("garbage", ownerType);
  437. +
  438. + Assert.IsNull (actual, "#K1#11");
  439. + }
  440. +
  441. + [Test]
  442. + public void TestGetObjectDataMethod () {
  443. + string activityName = "TestSerialization";
  444. + string propertyName = SerializationTestHelperClass.propertyName;
  445. +
  446. + SerializationTestHelperClass expected = new SerializationTestHelperClass (activityName);
  447. + object actual = null;
  448. +
  449. + BinaryFormatter formatter = new BinaryFormatter ();
  450. + using (MemoryStream ms = new MemoryStream ()) {
  451. + formatter.Serialize (ms, expected);
  452. + ms.Position = 0;
  453. + actual = formatter.Deserialize (ms);
  454. + }
  455. +
  456. + Assert.IsNotNull (actual, "#K2#1");
  457. + Assert.IsTrue (actual is SerializationTestHelperClass, "#K2#2");
  458. +
  459. + DependencyProperty actualDepProp = DependencyProperty.FromName (propertyName, typeof (SerializationTestHelperClass));
  460. + Assert.IsNotNull (actualDepProp, "#K2#3");
  461. + Assert.AreEqual (propertyName, actualDepProp.Name, "#K2#4");
  462. + Assert.AreEqual (typeof (SerializationTestHelperClass), actualDepProp.OwnerType, "#K2#5");
  463. + Assert.AreEqual (typeof (string), actualDepProp.PropertyType, "#K2#6");
  464. + Assert.AreEqual (activityName, ((SerializationTestHelperClass)actual).Name, "#K2#7");
  465. }
  466. -
  467. }
  468. }
Add Comment
Please, Sign In to add comment