Changeset 411
- Timestamp:
- 9/27/2008 8:54:34 AM (5 years ago)
- File:
-
- 1 edited
-
branches/eraser6/DefaultPlugins/EraseCustom.cs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/DefaultPlugins/EraseCustom.cs
r348 r411 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Runtime.Serialization; 25 26 26 27 using Eraser.Manager; … … 28 29 namespace Eraser.DefaultPlugins 29 30 { 31 [Serializable] 30 32 class EraseCustom : PassBasedErasureMethod 31 33 { … … 65 67 /// Contains information necessary to create user-defined erasure methods. 66 68 /// </summary> 67 public class CustomErasureMethod 69 [Serializable] 70 public class CustomErasureMethod : ISerializable 68 71 { 72 public CustomErasureMethod() 73 { 74 Name = string.Empty; 75 GUID = Guid.Empty; 76 RandomizePasses = true; 77 Passes = null; 78 } 79 80 public CustomErasureMethod(SerializationInfo info, StreamingContext context) 81 { 82 Name = info.GetString("Name"); 83 GUID = (Guid)info.GetValue("GUID", GUID.GetType()); 84 RandomizePasses = info.GetBoolean("RandomizePasses"); 85 List<PassData> passes = (List<PassData>) 86 info.GetValue("Passes", typeof(List<PassData>)); 87 88 Passes = new ErasureMethod.Pass[passes.Count]; 89 for (int i = 0; i != passes.Count; ++i) 90 Passes[i] = passes[i]; 91 } 92 69 93 public string Name; 70 94 public Guid GUID; 71 95 public bool RandomizePasses; 72 96 public ErasureMethod.Pass[] Passes; 97 98 #region ISerializable Members 99 public void GetObjectData(SerializationInfo info, StreamingContext context) 100 { 101 info.AddValue("Name", Name); 102 info.AddValue("GUID", GUID); 103 info.AddValue("RandomizePasses", RandomizePasses); 104 105 List<PassData> passes = new List<PassData>(Passes.Length); 106 foreach (ErasureMethod.Pass pass in Passes) 107 passes.Add(new PassData(pass)); 108 info.AddValue("Passes", passes); 109 } 110 111 [Serializable] 112 private class PassData 113 { 114 public PassData(ErasureMethod.Pass pass) 115 { 116 if (pass.Function == ErasureMethod.Pass.WriteConstant) 117 { 118 Random = false; 119 OpaqueValue = pass.OpaqueValue; 120 } 121 else if (pass.Function == ErasureMethod.Pass.WriteRandom) 122 { 123 Random = true; 124 OpaqueValue = null; 125 } 126 else 127 throw new NotImplementedException("The custom erasure method can only comprise " + 128 "passes containining constat or random passes"); 129 } 130 131 public static implicit operator ErasureMethod.Pass(PassData pass) 132 { 133 ErasureMethod.Pass result = new ErasureMethod.Pass(pass.Random ? 134 ErasureMethod.Pass.WriteRandom : 135 ErasureMethod.Pass.WriteConstant, pass.OpaqueValue); 136 return result; 137 } 138 139 object OpaqueValue; 140 bool Random; 141 } 142 #endregion 73 143 } 74 144 }
Note: See TracChangeset
for help on using the changeset viewer.
