source: trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/ErasureTargetBase.cs @ 2509

Revision 2509, 3.5 KB checked in by lowjoel, 2 years ago (diff)

Redesign the Eraser Plugin framework.

  • Split the plugin-dependent interfaces and related support classes out to Eraser.Plugins assembly
    • The extension interfaces are in the Eraser.Plugins.ExtensionPoints? namespace.
      • New IClientTool interface for plugins to create Eraser-hosted tools (e.g. #147)
    • The Registrars are in the Eraser.Plugins.Registrars namespace
    • Base types are now interfaces, no longer abstract base classes
    • Version the Eraser.plugins assembly differently from the rest of the project so that other plugins can target different versions of Eraser with the same assembly. Change the Eraser.Plugins assembly version only if there is an API change.
  • Plugin loading behaviour:
    • Core plugins will be loaded before the rest of the plugins, but they will be loaded only by assembly name and not by path
    • Non-core plugin loading is handled by the Manager Library and not the Plugin code
    • The PluginInstance? class is now the PluginInfo? class
    • There is no longer a need to indicate the default file and unused space erasure methods, PRNGs etc; they are now hardcoded to prevent plugins from changing defaults.
  • The separate command line for the Eraser shell extension has been removed.
    • The Erase on Restart menu item has been removed (since it is a scheduling option and should be set in the Task Properties Dialog)
  • Task Progress information is now pulled from the Eraser core instead of pushed via events.
  • New persistent store class to generalise the use of the old Settings class
  • IDragAndDropConfigurerFactory for transforming drag-and-drop operations to erasure targets. This removes the Eraser.exe assembly's dependency on Eraser.DefaultPlugins?.

Closes #363.

Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.Runtime.Serialization;
27using System.Security.Permissions;
28
29using Eraser.Util;
30using Eraser.Plugins;
31using Eraser.Plugins.Registrars;
32using Eraser.Plugins.ExtensionPoints;
33
34namespace 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}
Note: See TracBrowser for help on using the repository browser.