source: branches/eraser6/pluginsRewrite/Eraser.DefaultPlugins/ErasureTargets/ErasureTargetBase.cs @ 2464

Revision 2464, 3.4 KB checked in by lowjoel, 3 years ago (diff)

Further compile fixes.

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 virtual bool SupportsMethod(IErasureMethod method)
46        {
47            return true;
48        }
49
50        public abstract IErasureTargetConfigurer Configurer
51        {
52            get;
53        }
54
55        public abstract void Execute();
56
57        #endregion
58
59        #region Serialization code
60        protected ErasureTargetBase(SerializationInfo info, StreamingContext context)
61        {
62            Guid methodGuid = (Guid)info.GetValue("Method", typeof(Guid));
63            if (methodGuid == Guid.Empty)
64                Method = ErasureMethodRegistrar.Default;
65            else
66                Method = Host.Instance.ErasureMethods[methodGuid];
67        }
68
69        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
70        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
71        {
72            info.AddValue("Method", Method.Guid);
73        }
74        #endregion
75
76        #region IRegisterable Members
77
78        public abstract Guid Guid
79        {
80            get;
81        }
82
83        #endregion
84
85        /// <summary>
86        /// Constructor.
87        /// </summary>
88        protected ErasureTargetBase()
89        {
90            Method = ErasureMethodRegistrar.Default;
91        }
92
93        public IErasureMethod Method
94        {
95            get{
96                return method;
97            }
98            set
99            {
100                if (!SupportsMethod(value))
101                    throw new ArgumentException(S._("The selected erasure method is not " +
102                        "supported for this erasure target."));
103                method = value;
104            }
105        }
106
107        /// <summary>
108        /// Gets the effective erasure method for the current target (i.e., returns
109        /// the correct erasure method for cases where the <see cref="Method"/>
110        /// property is <see cref="ErasureMethodRegistrar.Default"/>
111        /// </summary>
112        /// <returns>The Erasure method which the target should be erased with.
113        /// This function will never return <see cref="ErasureMethodRegistrar.Default"/></returns>
114        public virtual IErasureMethod EffectiveMethod
115        {
116            get
117            {
118                if (Method != ErasureMethodRegistrar.Default)
119                    return Method;
120
121                throw new InvalidOperationException("The effective method of the erasure " +
122                    "target cannot be ErasureMethodRegistrar.Default");
123            }
124        }
125       
126       
127        /// <summary>
128        /// The backing variable for the <see cref="Method"/> property.
129        /// </summary>
130        private IErasureMethod method;
131    }
132}
Note: See TracBrowser for help on using the repository browser.