| 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 | |
|---|
| 22 | using System; |
|---|
| 23 | using System.Collections.Generic; |
|---|
| 24 | using System.Linq; |
|---|
| 25 | using System.Text; |
|---|
| 26 | |
|---|
| 27 | using System.Runtime.Serialization; |
|---|
| 28 | using System.Security.Permissions; |
|---|
| 29 | |
|---|
| 30 | using Eraser.Util; |
|---|
| 31 | using Eraser.Util.ExtensionMethods; |
|---|
| 32 | using Eraser.Plugins; |
|---|
| 33 | using Eraser.Plugins.ExtensionPoints; |
|---|
| 34 | |
|---|
| 35 | namespace Eraser.Manager |
|---|
| 36 | { |
|---|
| 37 | /// <summary> |
|---|
| 38 | /// Maintains a collection of erasure targets. |
|---|
| 39 | /// </summary> |
|---|
| 40 | [Serializable] |
|---|
| 41 | public class ErasureTargetCollection : IList<ErasureTarget>, ISerializable |
|---|
| 42 | { |
|---|
| 43 | #region Constructors |
|---|
| 44 | internal ErasureTargetCollection(Task owner) |
|---|
| 45 | { |
|---|
| 46 | this.list = new List<ErasureTarget>(); |
|---|
| 47 | this.owner = owner; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | internal ErasureTargetCollection(Task owner, int capacity) |
|---|
| 51 | : this(owner) |
|---|
| 52 | { |
|---|
| 53 | list.Capacity = capacity; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | internal ErasureTargetCollection(Task owner, IEnumerable<ErasureTarget> targets) |
|---|
| 57 | : this(owner) |
|---|
| 58 | { |
|---|
| 59 | list.AddRange(targets); |
|---|
| 60 | } |
|---|
| 61 | #endregion |
|---|
| 62 | |
|---|
| 63 | #region Serialization Code |
|---|
| 64 | protected ErasureTargetCollection(SerializationInfo info, StreamingContext context) |
|---|
| 65 | { |
|---|
| 66 | list = (List<ErasureTarget>)info.GetValue("list", typeof(List<ErasureTarget>)); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] |
|---|
| 70 | public virtual void GetObjectData(SerializationInfo info, StreamingContext context) |
|---|
| 71 | { |
|---|
| 72 | info.AddValue("list", list); |
|---|
| 73 | } |
|---|
| 74 | #endregion |
|---|
| 75 | |
|---|
| 76 | #region IEnumerable<ErasureTarget> Members |
|---|
| 77 | public IEnumerator<ErasureTarget> GetEnumerator() |
|---|
| 78 | { |
|---|
| 79 | return list.GetEnumerator(); |
|---|
| 80 | } |
|---|
| 81 | #endregion |
|---|
| 82 | |
|---|
| 83 | #region IEnumerable Members |
|---|
| 84 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|---|
| 85 | { |
|---|
| 86 | return GetEnumerator(); |
|---|
| 87 | } |
|---|
| 88 | #endregion |
|---|
| 89 | |
|---|
| 90 | #region ICollection<ErasureTarget> Members |
|---|
| 91 | public void Add(ErasureTarget item) |
|---|
| 92 | { |
|---|
| 93 | list.Add(item); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | public void Clear() |
|---|
| 97 | { |
|---|
| 98 | foreach (ErasureTarget item in list) |
|---|
| 99 | Remove(item); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | public bool Contains(ErasureTarget item) |
|---|
| 103 | { |
|---|
| 104 | return list.Contains(item); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | public void CopyTo(ErasureTarget[] array, int arrayIndex) |
|---|
| 108 | { |
|---|
| 109 | list.CopyTo(array, arrayIndex); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | public int Count |
|---|
| 113 | { |
|---|
| 114 | get |
|---|
| 115 | { |
|---|
| 116 | return list.Count; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | public bool IsReadOnly |
|---|
| 121 | { |
|---|
| 122 | get |
|---|
| 123 | { |
|---|
| 124 | return false; |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | public bool Remove(ErasureTarget item) |
|---|
| 129 | { |
|---|
| 130 | int index = list.IndexOf(item); |
|---|
| 131 | if (index < 0) |
|---|
| 132 | return false; |
|---|
| 133 | |
|---|
| 134 | RemoveAt(index); |
|---|
| 135 | return true; |
|---|
| 136 | } |
|---|
| 137 | #endregion |
|---|
| 138 | |
|---|
| 139 | #region IList<ErasureTarget> Members |
|---|
| 140 | public int IndexOf(ErasureTarget item) |
|---|
| 141 | { |
|---|
| 142 | return list.IndexOf(item); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | public void Insert(int index, ErasureTarget item) |
|---|
| 146 | { |
|---|
| 147 | list.Insert(index, item); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | public void RemoveAt(int index) |
|---|
| 151 | { |
|---|
| 152 | list.RemoveAt(index); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | public ErasureTarget this[int index] |
|---|
| 156 | { |
|---|
| 157 | get |
|---|
| 158 | { |
|---|
| 159 | return list[index]; |
|---|
| 160 | } |
|---|
| 161 | set |
|---|
| 162 | { |
|---|
| 163 | list[index] = value; |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | #endregion |
|---|
| 167 | |
|---|
| 168 | /// <summary> |
|---|
| 169 | /// The owner of this list of targets. |
|---|
| 170 | /// </summary> |
|---|
| 171 | public Task Owner |
|---|
| 172 | { |
|---|
| 173 | get; |
|---|
| 174 | internal set; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | /// <summary> |
|---|
| 178 | /// The owner of this list of targets. All targets added to this list |
|---|
| 179 | /// will have the owner set to this object. |
|---|
| 180 | /// </summary> |
|---|
| 181 | private Task owner; |
|---|
| 182 | |
|---|
| 183 | /// <summary> |
|---|
| 184 | /// The list bring the data store behind this object. |
|---|
| 185 | /// </summary> |
|---|
| 186 | private List<ErasureTarget> list; |
|---|
| 187 | } |
|---|
| 188 | } |
|---|