Repository navigation
Expand file tree
/
Copy pathMessageQueueInstaller.cs
More file actions
570 lines (509 loc) · 22.1 KB
/
Copy pathMessageQueueInstaller.cs
File metadata and controls
570 lines (509 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
//------------------------------------------------------------------------------
// <copyright file="MessageQueueInstaller.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
*/
namespace System.Messaging
{
using System.ComponentModel;
using System.Diagnostics;
using System;
using System.Configuration.Install;
using System.Collections;
using Microsoft.Win32;
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller"]/*' />
/// <devdoc>
/// <para>Allows you to install and configure a queue that your
/// application needs in order to run. This class is called by the installation
/// utility, installutil.exe, when installing a <see cref='System.Messaging.MessageQueue'/>
/// .</para>
/// <note type="rnotes">
/// Do we install the
/// backend queue resource or some MessageQueue object. I.e. is this creating a
/// new backend queue resource? Do we need to say anthing about checking for Path
/// existence?
/// </note>
/// </devdoc>
public class MessageQueueInstaller : ComponentInstaller
{
private bool authenticate = false;
private short basePriority = (short)0;
private Guid category = Guid.Empty;
private System.Messaging.EncryptionRequired encryptionRequired = System.Messaging.EncryptionRequired.Optional;
private string label = String.Empty;
private long maximumJournalSize = UInt32.MaxValue;
private long maximumQueueSize = UInt32.MaxValue;
private string multicastAddress = String.Empty;
private string path = String.Empty;
private bool transactional = false;
private bool useJournalQueue = false;
private AccessControlList permissions = null;
private UninstallAction uninstallAction = System.Configuration.Install.UninstallAction.Remove;
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.MessageQueueInstaller"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public MessageQueueInstaller()
: base()
{
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.MessageQueueInstaller1"]/*' />
/// <devdoc>
/// </devdoc>
public MessageQueueInstaller(MessageQueue componentToCopy)
: base()
{
InternalCopyFromComponent(componentToCopy);
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Authenticate"]/*' />
/// <devdoc>
/// <para> Indicates whether the queue to be installed only accepts authenticated messages.</para>
/// </devdoc>
[DefaultValue(false)]
public bool Authenticate
{
get
{
return authenticate;
}
set
{
authenticate = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.BasePriority"]/*' />
/// <devdoc>
/// <para>
/// Indicates the base priority used
/// to route a public queue's messages over the network.</para>
/// </devdoc>
[DefaultValue(0)]
public short BasePriority
{
get
{
return basePriority;
}
set
{
basePriority = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Category"]/*' />
/// <devdoc>
/// <para>
/// Indicates an implementation-specific queue type.</para>
/// <note type="rnotes">
/// Wording. Shorter
/// ("Indicates the queue's type") better here?
/// </note>
/// </devdoc>
[TypeConverterAttribute("System.ComponentModel.GuidConverter, " + AssemblyRef.System)]
public Guid Category
{
get
{
return category;
}
set
{
category = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.EncryptionRequired"]/*' />
/// <devdoc>
/// <para> Indicates whether the queue only accepts private
/// (encrypted) messages.</para>
/// </devdoc>
[DefaultValue(EncryptionRequired.Optional)]
public EncryptionRequired EncryptionRequired
{
get
{
return encryptionRequired;
}
set
{
if (!ValidationUtility.ValidateEncryptionRequired(value))
throw new InvalidEnumArgumentException("value", (int)value, typeof(EncryptionRequired));
encryptionRequired = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Label"]/*' />
/// <devdoc>
/// <para>Indicates a description of the queue.</para>
/// </devdoc>
[DefaultValue("")]
public string Label
{
get
{
return label;
}
set
{
if (value == null)
throw new ArgumentNullException("value");
label = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.MaximumJournalSize"]/*' />
/// <devdoc>
/// <para>Indicates the maximum size of the journal associated with the queue.</para>
/// </devdoc>
[TypeConverterAttribute(typeof(System.Messaging.Design.SizeConverter))]
public long MaximumJournalSize
{
get
{
return maximumJournalSize;
}
set
{
if (value < 0)
throw new ArgumentException(Res.GetString(Res.InvalidMaxJournalSize));
maximumJournalSize = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.MaximumQueueSize"]/*' />
/// <devdoc>
/// <para> Indicates the the maximum size of the queue.</para>
/// </devdoc>
[TypeConverterAttribute(typeof(System.Messaging.Design.SizeConverter))]
public long MaximumQueueSize
{
get
{
return maximumQueueSize;
}
set
{
if (value < 0)
throw new ArgumentException(Res.GetString(Res.InvalidMaxQueueSize));
maximumQueueSize = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.MulticastAddress"]/*' />
/// <devdoc>
/// <para>Gets or sets the IP multicast address associated with the queue.</para>
/// </devdoc>
[DefaultValue("")]
public string MulticastAddress
{
get
{
if (!MessageQueue.Msmq3OrNewer) //this feature is unavailable on win2k
throw new PlatformNotSupportedException(Res.GetString(Res.PlatformNotSupported));
return multicastAddress;
}
set
{
if (value == null)
throw new ArgumentNullException("value");
if (!MessageQueue.Msmq3OrNewer) //this feature is unavailable on win2k
throw new PlatformNotSupportedException(Res.GetString(Res.PlatformNotSupported));
multicastAddress = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Path"]/*' />
/// <devdoc>
/// <para>
/// Indicates the
/// location of
/// the queue that
/// will
/// be referenced by this object. .</para>
/// </devdoc>
[Editor("System.Messaging.Design.QueuePathEditor", "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
DefaultValue(""),
TypeConverter("System.Diagnostics.Design.StringValueConverter, " + AssemblyRef.SystemDesign)]
public string Path
{
get
{
return path;
}
set
{
if (!MessageQueue.ValidatePath(value, true))
throw new ArgumentException(Res.GetString(Res.PathSyntax));
if (value == null)
throw new ArgumentNullException("value");
this.path = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Permissions"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public AccessControlList Permissions
{
get
{
return permissions;
}
set
{
permissions = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Transactional"]/*' />
/// <devdoc>
/// If a queue is transactional, it can only accept messages that are sent as part
/// of a transaction. However, messages can be retrieved from a local transaction
/// queue with or without using a transaction.
/// </devdoc>
[DefaultValue(false)]
public bool Transactional
{
get
{
return transactional;
}
set
{
transactional = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.UninstallAction"]/*' />
/// <devdoc>
/// <para>Indicates what the installer does with the queue at uninstall time: remove it, restore it
/// to its pre-installation state, or leave it in its current installed state.</para>
/// </devdoc>
[DefaultValue(UninstallAction.Remove)]
public UninstallAction UninstallAction
{
get
{
return uninstallAction;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1803:AvoidCostlyCallsWherePossible")]
set
{
if (!Enum.IsDefined(typeof(UninstallAction), value))
throw new InvalidEnumArgumentException("value", (int)value, typeof(UninstallAction));
uninstallAction = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.UseJournalQueue"]/*' />
/// <devdoc>
/// <para>Indicates whether messages retrieved from the queue are also copied to the
/// associated journal queue.</para>
/// </devdoc>
[DefaultValue(false)]
public bool UseJournalQueue
{
get
{
return useJournalQueue;
}
set
{
useJournalQueue = value;
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Commit"]/*' />
/// <devdoc>
/// <para>Completes the installation process by committing <see cref='System.Messaging.MessageQueue'/>
/// installation information that was written to the registry by the <see cref='System.Messaging.MessageQueueInstaller.Install'/>
/// method. This method is meant to be used by installation tools, which
/// process the appropriate methods automatically.</para>
/// </devdoc>
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
Context.LogMessage(Res.GetString(Res.ClearingQueue, Path));
// make sure the queue is empty
// we don't do this in Install because it can't be undone.
MessageQueue queue = new MessageQueue(path);
queue.Purge();
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.CopyFromComponent"]/*' />
/// <devdoc>
/// <para>Copies the property values of a <see cref='System.Messaging.MessageQueue'/>
/// component to this <see cref='System.Messaging.MessageQueueInstaller'/>
/// . </para>
/// </devdoc>
public override void CopyFromComponent(IComponent component)
{
InternalCopyFromComponent(component);
}
private void InternalCopyFromComponent(IComponent component)
{
MessageQueue queue = component as MessageQueue;
if (queue == null)
throw new ArgumentException(Res.GetString(Res.NotAMessageQueue));
if (queue.Path != null && queue.Path != string.Empty)
Path = queue.Path;
else
throw new ArgumentException(Res.GetString(Res.IncompleteMQ));
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Install"]/*' />
/// <devdoc>
/// <para>Writes message queue information to the registry. This method is meant to be
/// used by installation tools, which process the appropriate methods
/// automatically</para>
/// </devdoc>
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
Context.LogMessage(Res.GetString(Res.CreatingQueue, Path));
bool exists = MessageQueue.Exists(path);
stateSaver["Exists"] = exists;
MessageQueue queue = null;
if (!exists)
queue = MessageQueue.Create(Path, Transactional);
else
{
// it exists. If it's got the right transactional property, we're OK.
// Otherwise we have to recreate.
queue = new MessageQueue(Path);
// save off the properties for rollback
stateSaver["Authenticate"] = queue.Authenticate;
stateSaver["BasePriority"] = queue.BasePriority;
stateSaver["Category"] = queue.Category;
stateSaver["EncryptionRequired"] = queue.EncryptionRequired;
stateSaver["Label"] = queue.Label;
stateSaver["MaximumJournalSize"] = queue.MaximumJournalSize;
stateSaver["MaximumQueueSize"] = queue.MaximumQueueSize;
stateSaver["Path"] = queue.Path;
stateSaver["Transactional"] = queue.Transactional;
stateSaver["UseJournalQueue"] = queue.UseJournalQueue;
if (MessageQueue.Msmq3OrNewer) //this feature is unavailable on win2k
stateSaver["MulticastAddress"] = queue.MulticastAddress;
if (queue.Transactional != Transactional)
{
// Messages won't be kept.
MessageQueue.Delete(Path);
queue = MessageQueue.Create(Path, Transactional);
}
}
// now change all the properties to how we want them.
queue.Authenticate = Authenticate;
queue.BasePriority = BasePriority;
queue.Category = Category;
queue.EncryptionRequired = EncryptionRequired;
queue.Label = Label;
queue.MaximumJournalSize = MaximumJournalSize;
queue.MaximumQueueSize = MaximumQueueSize;
queue.UseJournalQueue = UseJournalQueue;
if (MessageQueue.Msmq3OrNewer) //this feature is unavailable on win2k
queue.MulticastAddress = MulticastAddress;
if (permissions != null)
queue.SetPermissions(permissions);
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.IsEquivalentInstaller"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override bool IsEquivalentInstaller(ComponentInstaller otherInstaller)
{
MessageQueueInstaller other = otherInstaller as MessageQueueInstaller;
if (other == null)
return false;
return other.Path == Path;
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.RestoreQueue"]/*' />
/// <devdoc>
/// Called by Rollback and Uninstall to restore a queue to its state prior to Install
/// </devdoc>
private void RestoreQueue(IDictionary state)
{
bool exists = false;
if (state != null && state["Exists"] != null)
exists = (bool)state["Exists"];
else
// this can only happen at uninstall - the user might have deleted the .InstallState
// file since Install ran. It's probably best to leave things the way they are.
return;
if (exists)
{
Context.LogMessage(Res.GetString(Res.RestoringQueue, Path));
// the queue existed before install. Restore the properties
MessageQueue queue = null;
// first, restore the queue with the right Transactional property
if (!MessageQueue.Exists(Path))
{
// weird, but possible: the queue used to exist, but it doesn't now.
// put it back
queue = MessageQueue.Create(Path, (bool)state["Transactional"]);
}
else
{
queue = new MessageQueue(Path);
if (queue.Transactional != (bool)state["Transactional"])
{
// the transactional property doesn't match. Recreate so it does
MessageQueue.Delete(Path);
queue = MessageQueue.Create(Path, (bool)state["Transactional"]);
}
}
// now change all the other properties to how they were.
queue.Authenticate = (bool)state["Authenticate"];
queue.BasePriority = (short)state["BasePriority"];
queue.Category = (Guid)state["Category"];
queue.EncryptionRequired = (EncryptionRequired)state["EncryptionRequired"];
queue.Label = (string)state["Label"];
queue.MaximumJournalSize = (long)state["MaximumJournalSize"];
queue.MaximumQueueSize = (long)state["MaximumQueueSize"];
if (MessageQueue.Msmq3OrNewer) //this feature is unavailable on win2k
queue.MulticastAddress = (string)state["MulticastAddress"];
queue.UseJournalQueue = (bool)state["UseJournalQueue"];
queue.ResetPermissions();
}
else
{
Context.LogMessage(Res.GetString(Res.RemovingQueue, Path));
// it wasn't there before install, so let's make sure it still isn't
if (MessageQueue.Exists(path))
MessageQueue.Delete(path);
}
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Rollback"]/*' />
/// <devdoc>
/// <para> Rolls back queue information that was written to the registry
/// by the installation procedure. This method is meant to be used by installation
/// tools, which process the appropriate methods automatically.</para>
/// </devdoc>
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
RestoreQueue(savedState);
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.ShouldSerializeCategory"]/*' />
/// <devdoc>
/// <para>Indicates whether the value of the Category property should be persisted in
/// generated code.</para>
/// <note type="rnotes">
/// The similar
/// "ShouldSerializeServicesDependedOn" in ServiceInstaller had dev comments that
/// indicated "persisted in code-gen". Is generated code the operative issue
/// here also?
/// </note>
/// </devdoc>
private bool ShouldSerializeCategory()
{
return !Category.Equals(Guid.Empty);
}
/// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Uninstall"]/*' />
/// <devdoc>
/// <para>Uninstalls the queue by removing information concerning it from the registry.
/// If the <see cref='System.Messaging.MessageQueueInstaller.UninstallAction'/> is <see langword='Remove'/>,
/// Uninstall also deletes the queue associated with the <see cref='System.Messaging.MessageQueue'/>. </para>
/// </devdoc>
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
if (UninstallAction == UninstallAction.Remove)
{
Context.LogMessage(Res.GetString(Res.DeletingQueue, Path));
if (MessageQueue.Exists(Path))
MessageQueue.Delete(Path);
}
}
}
}