2 // System.Security.Policy.ApplicationTrustCollection class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System
.Collections
;
31 using System
.Globalization
;
32 using System
.Runtime
.InteropServices
;
34 namespace System
.Security
.Policy
{
37 public sealed class ApplicationTrustCollection
: ICollection
, IEnumerable
{
39 private ArrayList _list
;
41 internal ApplicationTrustCollection ()
43 _list
= new ArrayList ();
46 // constants (from beta1 - still useful ?)
48 // public const string ApplicationTrustProperty = "ApplicationTrust";
49 // public const string InstallReferenceIdentifier = "{3f471841-eef2-47d6-89c0-d028f03a4ad5}";
54 get { return _list.Count; }
57 public bool IsSynchronized
{
58 get { return false; }
// always false
61 public object SyncRoot
{
62 get { return this; }
// self
65 public ApplicationTrust
this [int index
] {
66 get { return (ApplicationTrust) _list [index]; }
69 public ApplicationTrust
this [string appFullName
] {
71 for (int i
=0; i
< _list
.Count
; i
++) {
72 ApplicationTrust at
= (_list
[i
] as ApplicationTrust
);
73 if (at
.ApplicationIdentity
.FullName
== appFullName
)
82 public int Add (ApplicationTrust trust
)
85 throw new ArgumentNullException ("trust");
86 if (trust
.ApplicationIdentity
== null) {
87 throw new ArgumentException (Locale
.GetText (
88 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
91 return _list
.Add (trust
);
94 public void AddRange (ApplicationTrust
[] trusts
)
97 throw new ArgumentNullException ("trusts");
99 foreach (ApplicationTrust t
in trusts
) {
100 if (t
.ApplicationIdentity
== null) {
101 throw new ArgumentException (Locale
.GetText (
102 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
108 public void AddRange (ApplicationTrustCollection trusts
)
111 throw new ArgumentNullException ("trusts");
113 foreach (ApplicationTrust t
in trusts
) {
114 if (t
.ApplicationIdentity
== null) {
115 throw new ArgumentException (Locale
.GetText (
116 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
127 public void CopyTo (ApplicationTrust
[] array
, int index
)
129 _list
.CopyTo (array
, index
);
132 void ICollection
.CopyTo (Array array
, int index
)
134 _list
.CopyTo (array
, index
);
137 public ApplicationTrustCollection
Find (ApplicationIdentity applicationIdentity
, ApplicationVersionMatch versionMatch
)
139 if (applicationIdentity
== null)
140 throw new ArgumentNullException ("applicationIdentity");
142 string fullname
= applicationIdentity
.FullName
;
144 switch (versionMatch
) {
145 case ApplicationVersionMatch
.MatchAllVersions
:
146 int pos
= fullname
.IndexOf (", Version=");
148 fullname
= fullname
.Substring (0, pos
);
150 case ApplicationVersionMatch
.MatchExactVersion
:
153 throw new ArgumentException ("versionMatch");
156 ApplicationTrustCollection coll
= new ApplicationTrustCollection ();
157 foreach (ApplicationTrust t
in _list
) {
158 if (t
.ApplicationIdentity
.FullName
.StartsWith (fullname
)) {
166 public ApplicationTrustEnumerator
GetEnumerator ()
168 return new ApplicationTrustEnumerator (this);
171 IEnumerator IEnumerable
.GetEnumerator ()
173 return (IEnumerator
) new ApplicationTrustEnumerator (this);
176 public void Remove (ApplicationTrust trust
)
179 throw new ArgumentNullException ("trust");
180 if (trust
.ApplicationIdentity
== null) {
181 throw new ArgumentException (Locale
.GetText (
182 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
185 RemoveAllInstances (trust
);
188 public void Remove (ApplicationIdentity applicationIdentity
, ApplicationVersionMatch versionMatch
)
190 ApplicationTrustCollection coll
= Find (applicationIdentity
, versionMatch
);
191 foreach (ApplicationTrust t
in coll
) {
192 RemoveAllInstances (t
);
196 public void RemoveRange (ApplicationTrust
[] trusts
)
199 throw new ArgumentNullException ("trusts");
201 foreach (ApplicationTrust t
in trusts
) {
202 RemoveAllInstances (t
);
206 public void RemoveRange (ApplicationTrustCollection trusts
)
209 throw new ArgumentNullException ("trusts");
211 foreach (ApplicationTrust t
in trusts
) {
212 RemoveAllInstances (t
);
218 internal void RemoveAllInstances (ApplicationTrust trust
)
220 for (int i
=_list
.Count
- 1; i
>= 0; i
--) {
221 if (trust
.Equals (_list
[i
]))