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 //
10 
11 //
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.
30 //
31 using System;
32 
33 namespace System.Messaging
34 {
35 	public class MessageQueueCriteria
36 	{
MessageQueueCriteria()37 		public MessageQueueCriteria()
38 		{
39 			ClearAll();
40 		}
41 
42 		private bool setCategory;
43 		private Guid category;
44 		public Guid Category
45 		{
46 			get
47 			{
48 				if (!setCategory)
49 					throw new InvalidOperationException();
50 				return category;
51 			}
52 			set
53 			{
54 				category = value;
55 				setCategory = true;
56 			}
57 		}
58 
59 		private bool setCreatedAfter;
60 		private DateTime createdAfter;
61 		public DateTime CreatedAfter
62 		{
63 			get
64 			{
65 				if (!setCreatedAfter)
66 					throw new InvalidOperationException();
67 				return createdAfter;
68 			}
69 			set
70 			{
71 				createdAfter = value;
72 				setCreatedAfter = true;
73 			}
74 		}
75 
76 		private bool setCreatedBefore;
77 		private DateTime createdBefore;
78 		public DateTime CreatedBefore
79 		{
80 			get
81 			{
82 				if (!setCreatedBefore)
83 					throw new InvalidOperationException();
84 				return createdBefore;
85 			}
86 			set
87 			{
88 				createdBefore = value;
89 				setCreatedBefore = true;
90 			}
91 		}
92 
93 		private bool setLabel;
94 		private string label;
95 		public string Label
96 		{
97 			get
98 			{
99 				if (!setLabel)
100 					throw new InvalidOperationException();
101 				return label;
102 			}
103 			set
104 			{
105 				label = value;
106 				setLabel = true;
107 			}
108 		}
109 
110 		[MonoTODO]
invalidMachineName(string name)111 		private bool invalidMachineName(string name)
112 		{
113 			return false;
114 		}
115 
116 		private bool setMachineName;
117 		private string machineName;
118 		public string MachineName
119 		{
120 			get
121 			{
122 				if (!setMachineName)
123 					throw new InvalidOperationException();
124 				return machineName;
125 			}
126 			set
127 			{
128 				if (invalidMachineName(value))
129 					throw new InvalidOperationException();
130 				machineName = value;
131 				setMachineName = true;
132 			}
133 		}
134 
135 		private bool setModifiedAfter;
136 		private DateTime modifiedAfter;
137 		public DateTime ModifiedAfter
138 		{
139 			get
140 			{
141 				if (!setModifiedAfter)
142 					throw new InvalidOperationException();
143 				return modifiedAfter;
144 			}
145 			set
146 			{
147 				modifiedAfter = value;
148 				setModifiedAfter = true;
149 			}
150 		}
151 
152 		private bool setModifiedBefore;
153 		private DateTime modifiedBefore;
154 		public DateTime ModifiedBefore
155 		{
156 			get
157 			{
158 				if (!setModifiedBefore)
159 					throw new InvalidOperationException();
160 				return modifiedBefore;
161 			}
162 			set
163 			{
164 				modifiedBefore = value;
165 				setModifiedBefore = true;
166 			}
167 		}
168 
ClearAll()169 		public void ClearAll()
170 		{
171 			setCategory = false;
172 			setCreatedAfter = false;
173 			setCreatedBefore = false;
174 			setLabel = false;
175 			setMachineName = false;
176 			setModifiedAfter = false;
177 			setModifiedBefore = false;
178 		}
179 
180 		// To be called by the MessageQueue.GetPublicQueues(MessageQueueCriteria criteria) method
Match( Guid category, DateTime created, string label, string machineName, DateTime modified)181 		internal bool Match(
182 			Guid category,
183 			DateTime created,
184 			string label,
185 			string machineName,
186 			DateTime modified)
187 		{
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;
203 		}
204 
205 	}
206 }
207