| 1 | /* |
|---|
| 2 | * $Id: ErasureTarget.cs 2132 2010-05-15 13:50:31Z lowjoel $ |
|---|
| 3 | * Copyright 2008-2010 The Eraser Project |
|---|
| 4 | * Original Author: Joel Low <lowjoel@users.sourceforge.net> |
|---|
| 5 | * Modified By: |
|---|
| 6 | * |
|---|
| 7 | * This file is part of Eraser. |
|---|
| 8 | * |
|---|
| 9 | * Eraser is free software: you can redistribute it and/or modify it under the |
|---|
| 10 | * terms of the GNU General Public License as published by the Free Software |
|---|
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
|---|
| 12 | * version. |
|---|
| 13 | * |
|---|
| 14 | * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|---|
| 16 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * A copy of the GNU General Public License can be found at |
|---|
| 19 | * <http://www.gnu.org/licenses/>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | using System; |
|---|
| 23 | using System.Collections.Generic; |
|---|
| 24 | using System.Linq; |
|---|
| 25 | using System.Text; |
|---|
| 26 | |
|---|
| 27 | using System.Runtime.Serialization; |
|---|
| 28 | using System.Security.Permissions; |
|---|
| 29 | |
|---|
| 30 | using Eraser.Util; |
|---|
| 31 | using Eraser.Plugins.Registrars; |
|---|
| 32 | |
|---|
| 33 | namespace Eraser.Plugins.ExtensionPoints |
|---|
| 34 | { |
|---|
| 35 | /// <summary> |
|---|
| 36 | /// Represents a generic target of erasure |
|---|
| 37 | /// </summary> |
|---|
| 38 | [Serializable] |
|---|
| 39 | public abstract class IErasureTarget : ISerializable, IRegisterable |
|---|
| 40 | { |
|---|
| 41 | #region Serialization code |
|---|
| 42 | protected IErasureTarget(SerializationInfo info, StreamingContext context) |
|---|
| 43 | { |
|---|
| 44 | Guid methodGuid = (Guid)info.GetValue("Method", typeof(Guid)); |
|---|
| 45 | if (methodGuid == Guid.Empty) |
|---|
| 46 | Method = ErasureMethodRegistrar.Default; |
|---|
| 47 | else |
|---|
| 48 | Method = Host.Instance.ErasureMethods[methodGuid]; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] |
|---|
| 52 | public virtual void GetObjectData(SerializationInfo info, StreamingContext context) |
|---|
| 53 | { |
|---|
| 54 | info.AddValue("Method", Method.Guid); |
|---|
| 55 | } |
|---|
| 56 | #endregion |
|---|
| 57 | |
|---|
| 58 | #region IRegisterable Members |
|---|
| 59 | |
|---|
| 60 | public abstract Guid Guid |
|---|
| 61 | { |
|---|
| 62 | get; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | #endregion |
|---|
| 66 | |
|---|
| 67 | /// <summary> |
|---|
| 68 | /// Constructor. |
|---|
| 69 | /// </summary> |
|---|
| 70 | protected IErasureTarget() |
|---|
| 71 | { |
|---|
| 72 | Method = ErasureMethodRegistrar.Default; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /// <summary> |
|---|
| 76 | /// The name of the type of the Erasure target. |
|---|
| 77 | /// </summary> |
|---|
| 78 | public abstract string Name |
|---|
| 79 | { |
|---|
| 80 | get; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /// <summary> |
|---|
| 84 | /// The method used for erasing the file. |
|---|
| 85 | /// </summary> |
|---|
| 86 | public IErasureMethod Method |
|---|
| 87 | { |
|---|
| 88 | get |
|---|
| 89 | { |
|---|
| 90 | return method; |
|---|
| 91 | } |
|---|
| 92 | set |
|---|
| 93 | { |
|---|
| 94 | if (!SupportsMethod(value)) |
|---|
| 95 | throw new ArgumentException(S._("The selected erasure method is not " + |
|---|
| 96 | "supported for this erasure target.")); |
|---|
| 97 | method = value; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /// <summary> |
|---|
| 102 | /// Gets the effective erasure method for the current target (i.e., returns |
|---|
| 103 | /// the correct erasure method for cases where the <see cref="Method"/> |
|---|
| 104 | /// property is <see cref="ErasureMethodRegistrar.Default"/> |
|---|
| 105 | /// </summary> |
|---|
| 106 | /// <returns>The Erasure method which the target should be erased with. |
|---|
| 107 | /// This function will never return <see cref="ErasureMethodRegistrar.Default"/></returns> |
|---|
| 108 | public virtual IErasureMethod EffectiveMethod |
|---|
| 109 | { |
|---|
| 110 | get |
|---|
| 111 | { |
|---|
| 112 | if (Method != ErasureMethodRegistrar.Default) |
|---|
| 113 | return Method; |
|---|
| 114 | |
|---|
| 115 | throw new InvalidOperationException("The effective method of the erasure " + |
|---|
| 116 | "target cannot be ErasureMethodRegistrar.Default"); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | /// <summary> |
|---|
| 121 | /// Checks whether the provided erasure method is supported by this current |
|---|
| 122 | /// target. |
|---|
| 123 | /// </summary> |
|---|
| 124 | /// <param name="method">The erasure method to check.</param> |
|---|
| 125 | /// <returns>True if the erasure method is supported, false otherwise.</returns> |
|---|
| 126 | public virtual bool SupportsMethod(IErasureMethod method) |
|---|
| 127 | { |
|---|
| 128 | return true; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | /// <summary> |
|---|
| 132 | /// Retrieves the text to display representing this target. |
|---|
| 133 | /// </summary> |
|---|
| 134 | public abstract string UIText |
|---|
| 135 | { |
|---|
| 136 | get; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | /// <summary> |
|---|
| 140 | /// The Progress Changed event handler of the owning task. |
|---|
| 141 | /// </summary> |
|---|
| 142 | protected internal Action<IErasureTarget, ProgressChangedEventArgs> OnProgressChanged |
|---|
| 143 | { |
|---|
| 144 | get; |
|---|
| 145 | internal set; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | /// <summary> |
|---|
| 149 | /// Gets an <see cref="IErasureTargetConfigurer"/> which contains settings for |
|---|
| 150 | /// configuring this task, or null if this erasure target has no settings to be set. |
|---|
| 151 | /// </summary> |
|---|
| 152 | /// <remarks>The result should be able to be passed to the <see cref="Configure"/> |
|---|
| 153 | /// function, and settings for this task will be according to the returned |
|---|
| 154 | /// control.</remarks> |
|---|
| 155 | public abstract IErasureTargetConfigurer Configurer |
|---|
| 156 | { |
|---|
| 157 | get; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | /// <summary> |
|---|
| 161 | /// Executes the given target. |
|---|
| 162 | /// </summary> |
|---|
| 163 | public abstract void Execute(); |
|---|
| 164 | |
|---|
| 165 | /// <summary> |
|---|
| 166 | /// The backing variable for the <see cref="Method"/> property. |
|---|
| 167 | /// </summary> |
|---|
| 168 | private IErasureMethod method; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | /// <summary> |
|---|
| 172 | /// Represents an interface for an abstract erasure target configuration |
|---|
| 173 | /// object. |
|---|
| 174 | /// </summary> |
|---|
| 175 | public interface IErasureTargetConfigurer : ICliConfigurer<IErasureTarget> |
|---|
| 176 | { |
|---|
| 177 | } |
|---|
| 178 | } |
|---|