source: branches/eraser6/pluginsRewrite/Eraser.Manager/ErasureMethod.cs @ 2352

Revision 2352, 3.1 KB checked in by lowjoel, 3 years ago (diff)

Shifted all the plugin-extensible code to the Plugins assembly (Plugins.ExtensionPoints?). The code does not yet compile, because there are some inter-dependencies on the registrars.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
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.Text;
25
26using System.Reflection;
27using System.IO;
28
29using Eraser.Util;
30using Eraser.Plugins;
31using Eraser.Plugins.ExtensionPoints;
32
33namespace Eraser.Manager
34{
35    /// <summary>
36    /// Class managing all the erasure methods. This class pairs GUIDs with constructor
37    /// prototypes, and when an instance of the erasure method is required, a new
38    /// instance is created. This is unique to erasure methods since the other managers
39    /// do not have run-time equivalents; they all are compile-time.
40    /// </summary>
41    public class ErasureMethodRegistrar : Registrar<ErasureMethod>
42    {
43        #region Default Erasure method
44        private class DefaultMethod : ErasureMethod
45        {
46            public DefaultMethod()
47            {
48            }
49
50            public override string Name
51            {
52                get { return S._("(default)"); }
53            }
54
55            public override int Passes
56            {
57                get { return 0; }
58            }
59
60            public override Guid Guid
61            {
62                get { return Guid.Empty; }
63            }
64
65            public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize)
66            {
67                throw new InvalidOperationException("The DefaultMethod class should never " +
68                    "be used and should instead be replaced before execution!");
69            }
70
71            public override void Erase(Stream strm, long erasureLength, Prng prng,
72                ErasureMethod.ErasureMethodProgressFunction callback)
73            {
74                throw new InvalidOperationException("The DefaultMethod class should never " +
75                    "be used and should instead be replaced before execution!");
76            }
77        }
78
79        /// <summary>
80        /// A dummy method placeholder used for representing the default erase
81        /// method. Do not use this variable when trying to call the erase function,
82        /// this is just a placeholder and will throw a InvalidOperationException.
83        /// </summary>
84        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
85        public static readonly ErasureMethod Default = new DefaultMethod();
86        #endregion
87    }
88
89    public class ErasureMethodRegistrationEventArgs : EventArgs
90    {
91        /// <summary>
92        /// Constructor.
93        /// </summary>
94        /// <param name="value">The GUID of the newly registered/unregistered
95        /// erasure method.</param>
96        public ErasureMethodRegistrationEventArgs(Guid value)
97        {
98            Guid = value;
99        }
100
101        /// <summary>
102        /// The GUID of the newly registsered/unregistered erasure method.
103        /// </summary>
104        public Guid Guid { get; private set; }
105    }
106}
Note: See TracBrowser for help on using the repository browser.