Exemplo n.º 1
0
        public void CreatePublishSubscriberChannel(PublishSubscribeChannel publishSubscribeChannel, IChannelManager channelmanager)
        {
            if (publishSubscribeChannel.ConnectionStringExtractorType != null)
            {
                var extractorconnectionstring = _factory.Create <IValueSettingFinder>(publishSubscribeChannel.ConnectionStringExtractorType);

                var toconnectionextractor = publishSubscribeChannel.ToConnectionStringExtractor as Func <IValueSettingFinder, string>;

                if (toconnectionextractor != null)
                {
                    try
                    {
                        var connectionstring = toconnectionextractor(extractorconnectionstring);

                        var created = channelmanager.CreateIfNotExistPublishSubscribeChannel(connectionstring, publishSubscribeChannel.Path);

                        if (created)
                        {
                            Console.WriteLine($"Created {publishSubscribeChannel.Path} publish subscriber channel");
                        }
                        else
                        {
                            Console.WriteLine($"Publish subscriber channel {publishSubscribeChannel.Path} already exists");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Exception {publishSubscribeChannel.Path} publish subscriber channel: {ex}");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void CreatePublishSubscriberChannel(PublishSubscribeChannel channel, IChannelManager manager, StringBuilder errors)
        {
            if (channel.ConnectionStringExtractorType != null)
            {
                var finder = _factory.Create <IValueSettingFinder>(channel.ConnectionStringExtractorType);

                var extractor = channel.ConnectionStringExtractor as Func <IValueSettingFinder, string>;

                channel.ConnectionString = extractor?.Invoke(finder);

                if (string.IsNullOrWhiteSpace(channel.ConnectionString))
                {
                    var error = $"Empty connection string, publish subscriber channel {channel.Path}";

                    errors.AppendLine(error);

                    _logger.Log(error);

                    return;
                }

                if (string.IsNullOrWhiteSpace(channel.Path))
                {
                    var error = $"Empty path, publish subscriber channel {channel.Path}";

                    errors.AppendLine(error);

                    _logger.Log(error);

                    return;
                }

                try
                {
                    var created = manager.CreateIfNotExistPublishSubscribeChannel(channel.ConnectionString, channel.Path);

                    if (created)
                    {
                        _logger.Log($"Created {channel.Path} publish subscriber channel");
                    }
                    else
                    {
                        _logger.Log($"Publish subscriber channel {channel.Path} already exists");
                    }
                }
                catch (Exception ex)
                {
                    var error = $"Exception {channel.Path} publish subscriber channel: {ex}";

                    errors.AppendLine(error);

                    _logger.Log(error);
                }
            }
        }