source: branches/eraser6/XmlTaskLists/Eraser.DefaultPlugins/ErasureTargets/ErasureTargetBase.cs @ 2584

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

Switch the Default Plugin's erasure targets to follow the new IXmlSerializable interface.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Rev URL
Line 
1/*
2 * $Id$
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.Xml;
27using System.Xml.Serialization;
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        public System.Xml.Schema.XmlSchema GetSchema()
72        {
73            return null;
74        }
75
76        public virtual void ReadXml(XmlReader reader)
77        {
78            Guid methodGuid = Guid.Empty;
79            if (reader.HasAttributes)
80                methodGuid = new Guid(reader.GetAttribute("method"));
81
82            if (methodGuid == Guid.Empty)
83                Method = ErasureMethodRegistrar.Default;
84            else
85                Method = Host.Instance.ErasureMethods[methodGuid];
86        }
87
88        public virtual void WriteXml(XmlWriter writer)
89        {
90            if (method != ErasureMethodRegistrar.Default)
91                writer.WriteAttributeString("method", method.Guid.ToString());
92        }
93        #endregion
94
95        #region IRegisterable Members
96
97        public abstract Guid Guid
98        {
99            get;
100        }
101
102        #endregion
103
104        /// <summary>
105        /// Constructor.
106        /// </summary>
107        protected ErasureTargetBase()
108        {
109            Method = ErasureMethodRegistrar.Default;
110        }
111
112        public IErasureMethod Method
113        {
114            get{
115                return method;
116            }
117            set
118            {
119                if (!SupportsMethod(value))
120                    throw new ArgumentException(S._("The selected erasure method is not " +
121                        "supported for this erasure target."));
122                method = value;
123            }
124        }
125
126        /// <summary>
127        /// Gets the effective erasure method for the current target (i.e., returns
128        /// the correct erasure method for cases where the <see cref="Method"/>
129        /// property is <see cref="ErasureMethodRegistrar.Default"/>
130        /// </summary>
131        /// <returns>The Erasure method which the target should be erased with.
132        /// This function will never return <see cref="ErasureMethodRegistrar.Default"/></returns>
133        public virtual IErasureMethod EffectiveMethod
134        {
135            get
136            {
137                if (Method != ErasureMethodRegistrar.Default)
138                    return Method;
139
140                throw new InvalidOperationException("The effective method of the erasure " +
141                    "target cannot be ErasureMethodRegistrar.Default");
142            }
143        }
144       
145        /// <summary>
146        /// The backing variable for the <see cref="Method"/> property.
147        /// </summary>
148        private IErasureMethod method;
149    }
150}
Note: See TracBrowser for help on using the repository browser.