| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Configuration; |
| | | 6 | | using CoreWCF.Queue.Common; |
| | | 7 | | using MSMQ.Messaging; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Channels |
| | | 10 | | { |
| | | 11 | | public sealed class MsmqTransportBindingElement : MsmqBindingElementBase |
| | | 12 | | { |
| | | 13 | | private bool _useActiveDirectory = MsmqDefaults.UseActiveDirectory; |
| | | 14 | | |
| | 0 | 15 | | public MsmqTransportBindingElement() { } |
| | | 16 | | |
| | | 17 | | private MsmqTransportBindingElement(MsmqTransportBindingElement elementToBeCloned) |
| | 0 | 18 | | : base(elementToBeCloned) |
| | | 19 | | { |
| | 0 | 20 | | _useActiveDirectory = elementToBeCloned._useActiveDirectory; |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | public override string Scheme |
| | | 24 | | { |
| | | 25 | | get |
| | | 26 | | { |
| | 0 | 27 | | return "net.msmq"; |
| | | 28 | | } |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | public bool UseActiveDirectory |
| | | 32 | | { |
| | | 33 | | get |
| | | 34 | | { |
| | 0 | 35 | | return _useActiveDirectory; |
| | | 36 | | } |
| | | 37 | | set |
| | | 38 | | { |
| | 0 | 39 | | throw new NotImplementedException(); |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public override QueueTransportPump BuildQueueTransportPump(BindingContext context) |
| | | 44 | | { |
| | 0 | 45 | | IQueueTransport queueTransport = CreateMyQueueTransport(context); |
| | 0 | 46 | | return QueueTransportPump.CreateDefaultPump(queueTransport); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | private IQueueTransport CreateMyQueueTransport(BindingContext context) |
| | | 50 | | { |
| | 0 | 51 | | var serviceDispatcher = context.BindingParameters.Find<IServiceDispatcher>(); |
| | 0 | 52 | | var serviceProvider = context.BindingParameters.Find<IServiceProvider>(); |
| | 0 | 53 | | CreateQueue(serviceDispatcher.BaseAddress); |
| | 0 | 54 | | return new MsmqQueueTransport(serviceDispatcher, serviceProvider); |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | public override BindingElement Clone() |
| | | 58 | | { |
| | 0 | 59 | | return new MsmqTransportBindingElement(this); |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | private void CreateQueue(Uri localAddress) |
| | | 63 | | { |
| | 0 | 64 | | var queueName = MsmqQueueNameConverter.GetMsmqFormatQueueName(localAddress); |
| | 0 | 65 | | if (!MessageQueue.Exists(queueName)) |
| | | 66 | | { |
| | 0 | 67 | | MessageQueue.Create(queueName); |
| | | 68 | | } |
| | 0 | 69 | | } |
| | | 70 | | } |
| | | 71 | | } |