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

Revision 2461, 3.4 KB checked in by lowjoel, 2 years ago (diff)

Added base class implementations for each of the IRegisterable types.

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