public static IEndpoint New(CreateMsmqEndpointSettings settings)
        {
            try
            {
                Guard.Against.Null(settings.Address, "An address for the endpoint must be specified");
                Guard.Against.Null(settings.ErrorAddress, "An error address for the endpoint must be specified");
                Guard.Against.Null(settings.Serializer, "A message serializer for the endpoint must be specified");

                var transport = MsmqTransportFactory.New(settings);
                
				// TODO Does this need to be a bus concern?
                PurgeExistingMessagesIfRequested(settings);

                var errorSettings = new CreateMsmqTransportSettings(settings.ErrorAddress, settings);
				if(transport.MsmqAddress.IsTransactional)
					settings.Transactional = true;

                IMsmqTransport errorTransport = MsmqTransportFactory.New(errorSettings);

                var endpoint = new MsmqEndpoint(settings.Address, settings.Serializer, transport, errorTransport);

                return endpoint;
            }
            catch (Exception ex)
            {
                throw new EndpointException(settings.Address.Uri, "Failed to create MSMQ endpoint", ex);
            }
        }
        public static IEndpoint New(CreateMsmqEndpointSettings settings)
        {
            try
            {
                Guard.Against.Null(settings.Address, "An address for the endpoint must be specified");
                Guard.Against.Null(settings.ErrorAddress, "An error address for the endpoint must be specified");
                Guard.Against.Null(settings.Serializer, "A message serializer for the endpoint must be specified");

                var transport = MsmqTransportFactory.New(settings);

                // TODO Does this need to be a bus concern?
                PurgeExistingMessagesIfRequested(settings);

                var errorSettings = new CreateMsmqTransportSettings(settings.ErrorAddress, settings);
                if (transport.MsmqAddress.IsTransactional)
                {
                    settings.Transactional = true;
                }

                IMsmqTransport errorTransport = MsmqTransportFactory.New(errorSettings);

                var endpoint = new MsmqEndpoint(settings.Address, settings.Serializer, transport, errorTransport);

                return(endpoint);
            }
            catch (Exception ex)
            {
                throw new EndpointException(settings.Address.Uri, "Failed to create MSMQ endpoint", ex);
            }
        }
        private static LocalTransportSettings ValidateLocalTransport(CreateMsmqTransportSettings settings)
        {
            var result = new LocalTransportSettings
            {
                Transactional = settings.Address.IsTransactional,
            };

            MsmqEndpointManagement.Manage(settings.Address, q =>
            {
                if (!q.Exists)
                {
                    if (!settings.CreateIfMissing)
                    {
                        throw new TransportException(settings.Address.Uri,
                                                     "The transport does not exist and automatic creation is not enabled");
                    }

                    q.Create(settings.Transactional || settings.Address.IsTransactional);
                }

                if (settings.RequireTransactional)
                {
                    if (!q.IsTransactional && (settings.Transactional || settings.Address.IsTransactional))
                    {
                        throw new TransportException(settings.Address.Uri,
                                                     "The transport is non-transactional but a transactional transport was requested");
                    }
                }

                result.Transactional = q.IsTransactional;
            });

            return(result);
        }
		private static LocalTransportSettings ValidateLocalTransport(CreateMsmqTransportSettings settings)
		{
			var result = new LocalTransportSettings
				{
					Transactional = settings.Address.IsTransactional,
				};

			MsmqEndpointManagement.Manage(settings.Address, q =>
				{
					if (!q.Exists)
					{
						if (!settings.CreateIfMissing)
							throw new TransportException(settings.Address.Uri,
								"The transport does not exist and automatic creation is not enabled");

						q.Create(settings.Transactional || settings.Address.IsTransactional);
					}

					if (settings.RequireTransactional)
					{
						if (!q.IsTransactional && (settings.Transactional || settings.Address.IsTransactional))
							throw new TransportException(settings.Address.Uri,
								"The transport is non-transactional but a transactional transport was requested");
					}

					result.Transactional = q.IsTransactional;
				});

			return result;
		}
		private static IMsmqTransport NewRemoteTransport(CreateMsmqTransportSettings settings)
		{
			if (settings.Address.IsTransactional)
				return new TransactionalMsmqTransport(settings.Address);

			return new NonTransactionalMsmqTransport(settings.Address);
		}
        public CreateMsmqTransportSettings(IEndpointAddress address, CreateMsmqTransportSettings source)
            : this()
        {
            Guard.Against.Null(address, "The address cannot be null");
            Guard.Against.Null(source, "The source settings cannot be null");

            Address = new MsmqEndpointAddress(address.Uri);
            Transactional = source.Transactional;
        }
Exemple #7
0
        public CreateMsmqTransportSettings(IEndpointAddress address, CreateMsmqTransportSettings source)
            : this()
        {
            Guard.Against.Null(address, "The address cannot be null");
            Guard.Against.Null(source, "The source settings cannot be null");

            Address       = new MsmqEndpointAddress(address.Uri);
            Transactional = source.Transactional;
        }
        private static IMsmqTransport NewRemoteTransport(CreateMsmqTransportSettings settings)
        {
            if (settings.Address.IsTransactional)
            {
                return(new TransactionalMsmqTransport(settings.Address));
            }

            return(new NonTransactionalMsmqTransport(settings.Address));
        }
		private static IMsmqTransport NewLocalTransport(CreateMsmqTransportSettings settings)
		{
			LocalTransportSettings transportSettings = ValidateLocalTransport(settings);

			if (transportSettings.Transactional)
				return new TransactionalMsmqTransport(settings.Address);

			return new NonTransactionalMsmqTransport(settings.Address);
		}
        private static IMsmqTransport NewLocalTransport(CreateMsmqTransportSettings settings)
        {
            LocalTransportSettings transportSettings = ValidateLocalTransport(settings);

            if (transportSettings.Transactional)
            {
                return(new TransactionalMsmqTransport(settings.Address));
            }

            return(new NonTransactionalMsmqTransport(settings.Address));
        }
		public static IMsmqTransport New(CreateMsmqTransportSettings settings)
		{
			try
			{
				if (settings.Address.IsLocal)
					return NewLocalTransport(settings);

				return NewRemoteTransport(settings);
			}
			catch (Exception ex)
			{
				throw new TransportException(settings.Address.Uri, "Failed to create MSMQ transport", ex);
			}
		}
        public static IMsmqTransport New(CreateMsmqTransportSettings settings)
        {
            try
            {
                if (settings.Address.IsLocal)
                {
                    return(NewLocalTransport(settings));
                }

                return(NewRemoteTransport(settings));
            }
            catch (Exception ex)
            {
                throw new TransportException(settings.Address.Uri, "Failed to create MSMQ transport", ex);
            }
        }