| 1 | /* |
|---|
| 2 | * $Id: ProgressManager.cs 2406 2012-01-12 05:19:39Z lowjoel $ |
|---|
| 3 | * Copyright 2008-2012 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 | using System.Runtime.Serialization; |
|---|
| 27 | using System.Security.Permissions; |
|---|
| 28 | |
|---|
| 29 | using Eraser.Util; |
|---|
| 30 | using Eraser.Plugins; |
|---|
| 31 | using Eraser.Plugins.Registrars; |
|---|
| 32 | using Eraser.Plugins.ExtensionPoints; |
|---|
| 33 | |
|---|
| 34 | namespace Eraser.DefaultPlugins |
|---|
| 35 | { |
|---|
| 36 | abstract class ErasureTargetBase : IErasureTarget |
|---|
| 37 | { |
|---|
| 38 | #region IErasureTarget Members |
|---|
| 39 | |
|---|
| 40 | public abstract string Name |
|---|
| 41 | { |
|---|
| 42 | get; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | public ITask Task |
|---|
| 46 | { |
|---|
| 47 | get; |
|---|
| 48 | set; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | public virtual bool SupportsMethod(IErasureMethod method) |
|---|
| 52 | { |
|---|
| 53 | return true; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | public abstract IErasureTargetConfigurer Configurer |
|---|
| 57 | { |
|---|
| 58 | get; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public abstract void Execute(); |
|---|
| 62 | |
|---|
| 63 | public SteppedProgressManager Progress |
|---|
| 64 | { |
|---|
| 65 | get; |
|---|
| 66 | protected set; |
|---|
| 67 | } |
|---|
| 68 | #endregion |
|---|
| 69 | |
|---|
| 70 | #region Serialization code |
|---|
| 71 | protected ErasureTargetBase(SerializationInfo info, StreamingContext context) |
|---|
| 72 | { |
|---|
| 73 | Guid methodGuid = (Guid)info.GetValue("Method", typeof(Guid)); |
|---|
| 74 | if (methodGuid == Guid.Empty) |
|---|
| 75 | Method = ErasureMethodRegistrar.Default; |
|---|
| 76 | else |
|---|
| 77 | Method = Host.Instance.ErasureMethods[methodGuid]; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] |
|---|
| 81 | public virtual void GetObjectData(SerializationInfo info, StreamingContext context) |
|---|
| 82 | { |
|---|
| 83 | info.AddValue("Method", Method.Guid); |
|---|
| 84 | } |
|---|
| 85 | #endregion |
|---|
| 86 | |
|---|
| 87 | #region IRegisterable Members |
|---|
| 88 | |
|---|
| 89 | public abstract Guid Guid |
|---|
| 90 | { |
|---|
| 91 | get; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | #endregion |
|---|
| 95 | |
|---|
| 96 | /// <summary> |
|---|
| 97 | /// Constructor. |
|---|
| 98 | /// </summary> |
|---|
| 99 | protected ErasureTargetBase() |
|---|
| 100 | { |
|---|
| 101 | Method = ErasureMethodRegistrar.Default; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | public IErasureMethod Method |
|---|
| 105 | { |
|---|
| 106 | get{ |
|---|
| 107 | return method; |
|---|
| 108 | } |
|---|
| 109 | set |
|---|
| 110 | { |
|---|
| 111 | if (!SupportsMethod(value)) |
|---|
| 112 | throw new ArgumentException(S._("The selected erasure method is not " + |
|---|
| 113 | "supported for this erasure target.")); |
|---|
| 114 | method = value; |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | /// <summary> |
|---|
| 119 | /// Gets the effective erasure method for the current target (i.e., returns |
|---|
| 120 | /// the correct erasure method for cases where the <see cref="Method"/> |
|---|
| 121 | /// property is <see cref="ErasureMethodRegistrar.Default"/> |
|---|
| 122 | /// </summary> |
|---|
| 123 | /// <returns>The Erasure method which the target should be erased with. |
|---|
| 124 | /// This function will never return <see cref="ErasureMethodRegistrar.Default"/></returns> |
|---|
| 125 | public virtual IErasureMethod EffectiveMethod |
|---|
| 126 | { |
|---|
| 127 | get |
|---|
| 128 | { |
|---|
| 129 | if (Method != ErasureMethodRegistrar.Default) |
|---|
| 130 | return Method; |
|---|
| 131 | |
|---|
| 132 | throw new InvalidOperationException("The effective method of the erasure " + |
|---|
| 133 | "target cannot be ErasureMethodRegistrar.Default"); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | /// <summary> |
|---|
| 138 | /// The backing variable for the <see cref="Method"/> property. |
|---|
| 139 | /// </summary> |
|---|
| 140 | private IErasureMethod method; |
|---|
| 141 | } |
|---|
| 142 | } |
|---|