source: branches/eraser6/pluginsRewrite/Eraser.Plugins/ExtensionPoints/ErasureTarget.cs @ 2357

Revision 2357, 5.0 KB checked in by lowjoel, 2 years ago (diff)

Move all registrars to the Eraser.Plugins assembly. This is to prevent cyclic dependencies.

Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26
27using System.Runtime.Serialization;
28using System.Security.Permissions;
29
30using Eraser.Util;
31
32namespace Eraser.Plugins.ExtensionPoints
33{
34    /// <summary>
35    /// Represents a generic target of erasure
36    /// </summary>
37    [Serializable]
38    public abstract class ErasureTarget : ISerializable, IRegisterable
39    {
40        #region Serialization code
41        protected ErasureTarget(SerializationInfo info, StreamingContext context)
42        {
43            Guid methodGuid = (Guid)info.GetValue("Method", typeof(Guid));
44            if (methodGuid == Guid.Empty)
45                Method = ErasureMethodRegistrar.Default;
46            else
47                Method = Host.Instance.ErasureMethods[methodGuid];
48        }
49
50        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
51        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
52        {
53            info.AddValue("Method", Method.Guid);
54        }
55        #endregion
56
57        #region IRegisterable Members
58
59        public abstract Guid Guid
60        {
61            get;
62        }
63
64        #endregion
65
66        /// <summary>
67        /// Constructor.
68        /// </summary>
69        protected ErasureTarget()
70        {
71            Method = ErasureMethodRegistrar.Default;
72        }
73
74        /// <summary>
75        /// The name of the type of the Erasure target.
76        /// </summary>
77        public abstract string Name
78        {
79            get;
80        }
81
82        /// <summary>
83        /// The method used for erasing the file.
84        /// </summary>
85        public ErasureMethod Method
86        {
87            get
88            {
89                return method;
90            }
91            set
92            {
93                if (!SupportsMethod(value))
94                    throw new ArgumentException(S._("The selected erasure method is not " +
95                        "supported for this erasure target."));
96                method = value;
97            }
98        }
99
100        /// <summary>
101        /// Gets the effective erasure method for the current target (i.e., returns
102        /// the correct erasure method for cases where the <see cref="Method"/>
103        /// property is <see cref="ErasureMethodRegistrar.Default"/>
104        /// </summary>
105        /// <returns>The Erasure method which the target should be erased with.
106        /// This function will never return <see cref="ErasureMethodRegistrar.Default"/></returns>
107        public virtual ErasureMethod EffectiveMethod
108        {
109            get
110            {
111                if (Method != ErasureMethodRegistrar.Default)
112                    return Method;
113
114                throw new InvalidOperationException("The effective method of the erasure " +
115                    "target cannot be ErasureMethodRegistrar.Default");
116            }
117        }
118
119        /// <summary>
120        /// Checks whether the provided erasure method is supported by this current
121        /// target.
122        /// </summary>
123        /// <param name="method">The erasure method to check.</param>
124        /// <returns>True if the erasure method is supported, false otherwise.</returns>
125        public virtual bool SupportsMethod(ErasureMethod method)
126        {
127            return true;
128        }
129
130        /// <summary>
131        /// Retrieves the text to display representing this target.
132        /// </summary>
133        public abstract string UIText
134        {
135            get;
136        }
137
138        /// <summary>
139        /// The progress of this target.
140        /// </summary>
141        public ProgressManagerBase Progress
142        {
143            get;
144            protected set;
145        }
146
147        /// <summary>
148        /// The Progress Changed event handler of the owning task.
149        /// </summary>
150        protected internal Action<ErasureTarget, ProgressChangedEventArgs> OnProgressChanged
151        {
152            get;
153            internal set;
154        }
155
156        /// <summary>
157        /// Gets an <see cref="IErasureTargetConfigurer"/> which contains settings for
158        /// configuring this task, or null if this erasure target has no settings to be set.
159        /// </summary>
160        /// <remarks>The result should be able to be passed to the <see cref="Configure"/>
161        /// function, and settings for this task will be according to the returned
162        /// control.</remarks>
163        public abstract IErasureTargetConfigurer Configurer
164        {
165            get;
166        }
167
168        /// <summary>
169        /// Executes the given target.
170        /// </summary>
171        public abstract void Execute();
172
173        /// <summary>
174        /// The backing variable for the <see cref="Method"/> property.
175        /// </summary>
176        private ErasureMethod method;
177    }
178
179    /// <summary>
180    /// Represents an interface for an abstract erasure target configuration
181    /// object.
182    /// </summary>
183    public interface IErasureTargetConfigurer : ICliConfigurer<ErasureTarget>
184    {
185    }
186}
Note: See TracBrowser for help on using the repository browser.