Example #1
0
        public T GetConfiguration <T>() where T : class, new()
        {
            if (typeof(T) == typeof(UnicastBusConfig))
            {
                //read from existing config
                UnicastBusConfig config = (UnicastBusConfig)ConfigurationManager
                                          .GetSection(typeof(UnicastBusConfig).Name);
                if (config == null)
                {
                    //create new config if it doesn't exist
                    config = new UnicastBusConfig
                    {
                        MessageEndpointMappings = new MessageEndpointMappingCollection()
                    };
                }
                //append mapping to config
                config.MessageEndpointMappings.Add(
                    new MessageEndpointMapping
                {
                    AssemblyName = "assembly",
                    Endpoint     = "queue@machinename"
                });
                return(config as T);
            }

            // To in app.config for other sections not defined in this method, otherwise return null.
            return(ConfigurationManager.GetSection(typeof(T).Name) as T);
        }
        public T GetConfiguration <T>() where T : class, new()
        {
            // the part you are overriding
            if (typeof(T) == typeof(UnicastBusConfig))
            {
                var config = new UnicastBusConfig();
                var coll   = config.MessageEndpointMappings;
                coll.Add(new MessageEndpointMapping
                {
                    Endpoint = "ProviderDomain",
                    Messages = "DDD.Provider.Messages",
                });

                //coll.Add(new MessageEndpointMapping
                //{
                //    Endpoint = "ProviderDomain",
                //    Messages = "DDD.Provider.Domain",
                //});


                return(config as T);
            }
            else if (typeof(T) == typeof(MessageForwardingInCaseOfFaultConfig))
            {
                var errorQUeue = new MessageForwardingInCaseOfFaultConfig
                {
                    ErrorQueue = "EmailServiceErrorQueue"
                };
                return(errorQUeue as T);
            }
            // leaving the rest of the configuration as is:
            return(ConfigurationManager.GetSection(typeof(T).Name) as T);
        }
Example #3
0
        static void DetectObsoleteConfiguration(UnicastBusConfig unicastBusConfig)
        {
            if (!string.IsNullOrWhiteSpace(unicastBusConfig?.ForwardReceivedMessagesTo))
            {
                throw new NotSupportedException($"The {nameof(UnicastBusConfig.ForwardReceivedMessagesTo)} attribute in the {nameof(UnicastBusConfig)} configuration section is no longer supported. Switch to the code API by using '{nameof(EndpointConfiguration)}.ForwardReceivedMessagesTo' instead.");
            }

            if (!string.IsNullOrWhiteSpace(unicastBusConfig?.DistributorControlAddress))
            {
                throw new NotSupportedException($"The {nameof(UnicastBusConfig.DistributorControlAddress)} attribute in the {nameof(UnicastBusConfig)} configuration section is no longer supported. Remove this from the configuration section. Switch to the code API by using '{nameof(EndpointConfiguration)}.EnlistWithLegacyMSMQDistributor' instead.");
            }

            if (!string.IsNullOrWhiteSpace(unicastBusConfig?.DistributorDataAddress))
            {
                throw new NotSupportedException($"The {nameof(UnicastBusConfig.DistributorDataAddress)} attribute in the {nameof(UnicastBusConfig)} configuration section is no longer supported. Remove this from the configuration section. Switch to the code API by using '{nameof(EndpointConfiguration)}.EnlistWithLegacyMSMQDistributor' instead.");
            }

            if (unicastBusConfig?.TimeToBeReceivedOnForwardedMessages > TimeSpan.Zero)
            {
                Logger.Error($"The use of the {nameof(UnicastBusConfig.TimeToBeReceivedOnForwardedMessages)} attribute in the {nameof(UnicastBusConfig)} configuration section is discouraged and will be removed in the next major version.");
            }

            if (!string.IsNullOrWhiteSpace(unicastBusConfig?.TimeoutManagerAddress))
            {
                Logger.Error($"The use of the {nameof(UnicastBusConfig.TimeoutManagerAddress)} attribute in the {nameof(UnicastBusConfig)} configuration section is discouraged and will be removed in the next major version. Switch to the code API by using  '{nameof(EndpointConfiguration)}.UseExternalTimeoutManager' instead.");
            }

            if (unicastBusConfig?.MessageEndpointMappings != null)
            {
                Logger.Error($"The use of the {nameof(UnicastBusConfig.MessageEndpointMappings)} in the {nameof(UnicastBusConfig)} configuration section is discouraged and will be removed in the next major version. Switch to the code API by using  '{nameof(EndpointConfiguration)}.UseTransport<T>().Routing()' instead.");
            }
        }
Example #4
0
        public T GetConfiguration <T>() where T : class, new()
        {
            if (typeof(T) == typeof(UnicastBusConfig))
            {
                // read from existing config
                var config = (UnicastBusConfig)ConfigurationManager
                             .GetSection(typeof(UnicastBusConfig).Name);
                if (config == null)
                {
                    // create new config if it doesn't exist
                    config = new UnicastBusConfig
                    {
                        MessageEndpointMappings = new MessageEndpointMappingCollection()
                    };
                }
                // append mapping to config
                var endpointMapping = new MessageEndpointMapping
                {
                    AssemblyName = "assembly",
                    Endpoint     = "queue@machinename"
                };
                config.MessageEndpointMappings.Add(endpointMapping);
                return(config as T);
            }

            return(ConfigurationManager.GetSection(typeof(T).Name) as T);
        }
Example #5
0
        public T GetConfiguration <T>() where T : class, new()
        {
            if (typeof(T) == typeof(UnicastBusConfig))
            {
                var config = (UnicastBusConfig)ConfigurationManager.GetSection(typeof(UnicastBusConfig).Name);
                if (config == null)
                {
                    config = new UnicastBusConfig
                    {
                        MessageEndpointMappings = new MessageEndpointMappingCollection()
                    };
                }

                foreach (var definition in _messageDefinitions.Where(md => md.MessageAction == MessageAction.Event))
                {
                    config.MessageEndpointMappings.Add(
                        new MessageEndpointMapping
                    {
                        AssemblyName = definition.MessageType.Assembly.FullName,
                        TypeFullName = definition.MessageType.FullName,
                        Endpoint     = definition.QueueName
                    });
                    return(config as T);
                }
            }

            return(ConfigurationManager.GetSection(typeof(T).Name) as T);
        }
Example #6
0
        public T GetConfiguration <T>() where T : class, new()
        {
            if (typeof(T) != typeof(UnicastBusConfig))
            {
                return(ConfigurationManager.GetSection(typeof(T).Name) as T);
            }

            var config = (UnicastBusConfig)ConfigurationManager.GetSection(typeof(UnicastBusConfig).Name);

            if (config == null)
            {
                config = new UnicastBusConfig
                {
                    MessageEndpointMappings = new MessageEndpointMappingCollection()
                };
            }

            config.MessageEndpointMappings.Add(
                new MessageEndpointMapping
            {
                AssemblyName = "Playground.Core",
                Namespace    = "Playground.Core.Messages",
                Endpoint     = "Playground.Service"
            });

            return(config as T);
        }
        private UnicastBusConfig GenerateUnicastBusConfig()
        {
            var config = new UnicastBusConfig();

            config.MessageEndpointMappings.Add(new MessageEndpointMapping()
            {
                Messages = "CodeSharp.ServiceFramework.Castles",
                Endpoint = this._inputQueue
            });
            return(config);
        }
Example #8
0
        public T GetConfiguration <T>() where T : class, new()
        {
            var config = new UnicastBusConfig()
            {
                MessageEndpointMappings = new MessageEndpointMappingCollection
                {
                    new MessageEndpointMapping {
                        AssemblyName = "Shared", Endpoint = "Samples.StepByStep.Server"
                    }
                }
            };

            return(config as T);
        }
Example #9
0
        private void ConfigureBusProperties(UnicastBusConfig unicastConfig)
        {
            if (unicastConfig == null)
            {
                return;
            }

            foreach (MessageEndpointMapping mapping in unicastConfig.MessageEndpointMappings)
            {
                assembliesToEndpoints[mapping.Messages] = mapping.Endpoint;
            }

            busConfig.ConfigureProperty(b => b.ForwardReceivedMessagesTo, unicastConfig.ForwardReceivedMessagesTo);
            busConfig.ConfigureProperty(b => b.MessageOwners, assembliesToEndpoints);
        }
        public T GetConfiguration <T>() where T : class, new()
        {
            if (typeof(T) == typeof(UnicastBusConfig))
            {
                var config = new UnicastBusConfig
                {
                    ForwardReceivedMessagesTo = "destinationQueue@machine"
                };

                return(config as T);
            }

            // Respect app.config for other sections not defined in this method
            return(ConfigurationManager.GetSection(typeof(T).Name) as T);
        }
        public T GetConfiguration <T>() where T : class, new()
        {
            //To Provide UnicastBusConfig
            if (typeof(T) == typeof(UnicastBusConfig))
            {
                UnicastBusConfig forwardingConfig = new UnicastBusConfig
                {
                    ForwardReceivedMessagesTo = "destinationQueue@machine"
                };

                return(forwardingConfig as T);
            }

            // To in app.config for other sections not defined in this method, otherwise return null.
            return(ConfigurationManager.GetSection(typeof(T).Name) as T);
        }
Example #12
0
        public T GetConfiguration <T>() where T : class, new()
        {
            // the part you are overriding
            if (typeof(T) == typeof(UnicastBusConfig))
            {
                var config = new UnicastBusConfig();
                var coll   = config.MessageEndpointMappings;
                coll.Add(new MessageEndpointMapping
                {
                    Endpoint = "ProviderDomain",
                    Messages = "DDD.Provider.Domain.Contracts",
                });

                //coll.Add(new MessageEndpointMapping
                //{
                //    //AssemblyName = "DDD.Provider.Messages",
                //    Endpoint = "ProviderDomain",
                //    //Namespace = "DDD.Provider.Messages.Commands",
                //    Messages = "DDD.Provider.Domain",

                //    //  TypeFullName= "DDD.Provider.Messages.Commands.AddNewContractorCommand, DDD.Provider.Messages"
                //});
                //coll.Add(new MessageEndpointMapping
                //{
                //    AssemblyName = "DDD.Provider.Messages",
                //    Endpoint = "ProviderDomain",
                //    Messages = "DDD.Provider.Messages",
                //    //Namespace = "DDD.Provider.Messages.Events"
                //});

                return(config as T);
            }
            if (typeof(T) == typeof(MessageForwardingInCaseOfFaultConfig))
            {
                var errorQUeue = new MessageForwardingInCaseOfFaultConfig
                {
                    ErrorQueue = "ProviderErrorQueue"
                };
                return(errorQUeue as T);
            }
            // leaving the rest of the configuration as is:
            return(ConfigurationManager.GetSection(typeof(T).Name) as T);
        }
Example #13
0
        private static string GetLocalAddress(UnicastBusConfig unicastConfig)
        {
            if (unicastConfig != null)
            {
                if (!string.IsNullOrEmpty(unicastConfig.LocalAddress))
                {
                    return(unicastConfig.LocalAddress);
                }
            }

            var transportConfig = GetConfigSection <MsmqTransportConfig>();

            if (transportConfig == null || transportConfig.InputQueue == null)
            {
                return(null);
            }

            Logger.Warn("LocalAddress property of UnicastBusConfig not found. Using InputQueue property of MsmqTransportConfig instead. This will not be supported in the next version.");
            return(transportConfig.InputQueue);
        }
Example #14
0
        void ConfigureBusProperties(UnicastBusConfig unicastConfig)
        {
            if (unicastConfig != null)
            {
                busConfig.ConfigureProperty(b => b.ForwardReceivedMessagesTo, !string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo) ? Address.Parse(unicastConfig.ForwardReceivedMessagesTo) : Address.Undefined);
                busConfig.ConfigureProperty(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages);

                foreach (MessageEndpointMapping mapping in unicastConfig.MessageEndpointMappings)
                {
                    try
                    {
                        var messageType = Type.GetType(mapping.Messages, false);
                        if (messageType != null)
                        {
                            typesToEndpoints[messageType] = Address.Parse(mapping.Endpoint);
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Problem loading message type: " + mapping.Messages, ex);
                    }

                    try
                    {
                        var a = Assembly.Load(mapping.Messages);
                        foreach (var t in a.GetTypes())
                        {
                            typesToEndpoints[t] = Address.Parse(mapping.Endpoint);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException("Problem loading message assembly: " + mapping.Messages, ex);
                    }
                }
            }

            busConfig.ConfigureProperty(b => b.MessageOwners, typesToEndpoints);
        }
Example #15
0
        private void ConfigureLocalAddress(UnicastBusConfig unicastConfig)
        {
            var address = GetLocalAddress(unicastConfig);

            busConfig.ConfigureProperty(t => t.Address, address);
        }
Example #16
0
            public T GetConfiguration <T>() where T : class, new()
            {
                if (typeof(T) == typeof(UnicastBusConfig))
                {
                    Debug.WriteLine("Getting UnicastBusConfig");
                    var config = new UnicastBusConfig();
                    config.MessageEndpointMappings.Add(new MessageEndpointMapping
                    {
                        AssemblyName = "NSBUnityError.Commands",
                        Namespace    = "NSBUnityError.Commands",
                        Endpoint     = "NSBUnityError.Host"
                    });
                    return(config as T);
                }

                if (typeof(T) == typeof(TransportConfig))
                {
                    Debug.WriteLine("Getting TransportConfig");
                    var config = new TransportConfig
                    {
                        MaximumConcurrencyLevel = 1,
                        MaxRetries = 3
                    };
                    return(config as T);
                }

                if (typeof(T) == typeof(MessageForwardingInCaseOfFaultConfig))
                {
                    Debug.WriteLine("Getting MessageForwardingInCaseOfFaultConfig");
                    var config = new MessageForwardingInCaseOfFaultConfig
                    {
                        ErrorQueue = "error"
                    };
                    return(config as T);
                }

                if (typeof(T) == typeof(SecondLevelRetriesConfig))
                {
                    Debug.WriteLine("Getting SecondLevelRetriesConfig");
                    var config = new SecondLevelRetriesConfig
                    {
                        Enabled         = true,
                        NumberOfRetries = 3,
                        TimeIncrease    = TimeSpan.FromSeconds(10)
                    };
                    return(config as T);
                }

                if (typeof(T) == typeof(AuditConfig))
                {
                    Debug.WriteLine("Getting AuditConfig");
                    var config = new AuditConfig
                    {
                        QueueName = "audit"
                    };
                    return(config as T);
                }

                if (typeof(T) == typeof(AzureServiceBusQueueConfig))
                {
                    Debug.WriteLine("Getting AzureServiceBusQueueConfig");
                    var config = new AzureServiceBusQueueConfig
                    {
                        ConnectionString = _serviceBusConnectionString
                    };
                    return(config as T);
                }

                return(null);
            }