2010-04-07 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Messaging / System.Messaging / MessageQueueCriteria.cs
blobdde103b768f8537874feb292fea9e828a4c5dfe5
1 //
2 // System.Messaging
3 //
4 // Authors:
5 // Peter Van Isacker (sclytrack@planetinternet.be)
6 // Rafael Teixeira (rafaelteixeirabr@hotmail.com)
7 //
8 // (C) 2003 Peter Van Isacker, Rafael Teixeira
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
33 namespace System.Messaging
35 public class MessageQueueCriteria
37 public MessageQueueCriteria()
39 ClearAll();
42 private bool setCategory;
43 private Guid category;
44 public Guid Category
46 get
48 if (!setCategory)
49 throw new InvalidOperationException();
50 return category;
52 set
54 category = value;
55 setCategory = true;
59 private bool setCreatedAfter;
60 private DateTime createdAfter;
61 public DateTime CreatedAfter
63 get
65 if (!setCreatedAfter)
66 throw new InvalidOperationException();
67 return createdAfter;
69 set
71 createdAfter = value;
72 setCreatedAfter = true;
76 private bool setCreatedBefore;
77 private DateTime createdBefore;
78 public DateTime CreatedBefore
80 get
82 if (!setCreatedBefore)
83 throw new InvalidOperationException();
84 return createdBefore;
86 set
88 createdBefore = value;
89 setCreatedBefore = true;
93 private bool setLabel;
94 private string label;
95 public string Label
97 get
99 if (!setLabel)
100 throw new InvalidOperationException();
101 return label;
103 set
105 label = value;
106 setLabel = true;
110 [MonoTODO]
111 private bool invalidMachineName(string name)
113 return false;
116 private bool setMachineName;
117 private string machineName;
118 public string MachineName
120 get
122 if (!setMachineName)
123 throw new InvalidOperationException();
124 return machineName;
126 set
128 if (invalidMachineName(value))
129 throw new InvalidOperationException();
130 machineName = value;
131 setMachineName = true;
135 private bool setModifiedAfter;
136 private DateTime modifiedAfter;
137 public DateTime ModifiedAfter
139 get
141 if (!setModifiedAfter)
142 throw new InvalidOperationException();
143 return modifiedAfter;
145 set
147 modifiedAfter = value;
148 setModifiedAfter = true;
152 private bool setModifiedBefore;
153 private DateTime modifiedBefore;
154 public DateTime ModifiedBefore
156 get
158 if (!setModifiedBefore)
159 throw new InvalidOperationException();
160 return modifiedBefore;
162 set
164 modifiedBefore = value;
165 setModifiedBefore = true;
169 public void ClearAll()
171 setCategory = false;
172 setCreatedAfter = false;
173 setCreatedBefore = false;
174 setLabel = false;
175 setMachineName = false;
176 setModifiedAfter = false;
177 setModifiedBefore = false;
180 // To be called by the MessageQueue.GetPublicQueues(MessageQueueCriteria criteria) method
181 internal bool Match(
182 Guid category,
183 DateTime created,
184 string label,
185 string machineName,
186 DateTime modified)
188 if (setCategory && this.category != category)
189 return false;
190 if (setCreatedAfter && created < createdAfter)
191 return false;
192 if (setCreatedBefore && created > createdBefore)
193 return false;
194 if (setLabel && this.label != label)
195 return false;
196 if (setMachineName && this.machineName != machineName)
197 return false;
198 if (setModifiedAfter && modified < modifiedAfter)
199 return false;
200 if (setModifiedBefore && modified > modifiedBefore)
201 return false;
202 return true;