public void CreateSubscriptionToPublishSubscribeChannel(SubscriptionToPublishSubscribeChannel subscriptionToPublishSubscribeChannel, IChannelManager channelmanager)
        {
            if (subscriptionToPublishSubscribeChannel.ConnectionStringExtractorType != null)
            {
                var extractorconnectionstring = _factory.Create <IValueSettingFinder>(subscriptionToPublishSubscribeChannel.ConnectionStringExtractorType);

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

                if (toconnectionextractor != null && !string.IsNullOrWhiteSpace(subscriptionToPublishSubscribeChannel.Path) && !string.IsNullOrWhiteSpace(subscriptionToPublishSubscribeChannel.Subscription) && ((subscriptionToPublishSubscribeChannel.All == false && !string.IsNullOrWhiteSpace(subscriptionToPublishSubscribeChannel.Origin.Key)) || subscriptionToPublishSubscribeChannel.All))
                {
                    try
                    {
                        var connectionstring = toconnectionextractor(extractorconnectionstring);

                        var created = channelmanager.CreateIfNotExistSubscriptionToPublishSubscribeChannel(connectionstring, subscriptionToPublishSubscribeChannel.Path, subscriptionToPublishSubscribeChannel.Subscription, subscriptionToPublishSubscribeChannel.Origin.Key, subscriptionToPublishSubscribeChannel.All);

                        if (created)
                        {
                            Console.WriteLine($"Created subscription to {subscriptionToPublishSubscribeChannel.Path}/{subscriptionToPublishSubscribeChannel.Subscription} publish subscriber channel");
                        }
                        else
                        {
                            Console.WriteLine($"Subscription to publish subscriber channel {subscriptionToPublishSubscribeChannel.Path}/{subscriptionToPublishSubscribeChannel.Subscription} already exists");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Exception {subscriptionToPublishSubscribeChannel.Path}/{subscriptionToPublishSubscribeChannel.Subscription} subscription to publish subscriber channel: {ex}");
                    }
                }
            }
        }
Beispiel #2
0
        public void CreateSubscriptionToPublishSubscribeChannel(SubscriptionToPublishSubscribeChannel subscription, IChannelManager manager, StringBuilder errors)
        {
            if (subscription.ConnectionStringExtractorType != null)
            {
                var finder = _factory.Create <IValueSettingFinder>(subscription.ConnectionStringExtractorType);

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

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

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

                    errors.AppendLine(error);

                    _logger.Log(error);

                    return;
                }

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

                    errors.AppendLine(error);

                    _logger.Log(error);

                    return;
                }

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

                    errors.AppendLine(error);

                    _logger.Log(error);

                    return;
                }

                if (subscription.Rules.Count == 0)
                {
                    var error = $"Missing rules, subscription to publish subscriber channel {subscription.Path}";

                    errors.AppendLine(error);

                    _logger.Log(error);

                    return;
                }

                try
                {
                    var created = manager.CreateIfNotExistSubscriptionToPublishSubscribeChannel(subscription.ConnectionString, subscription.Path, subscription.Subscription, subscription.Rules.FirstOrDefault());

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

                    errors.AppendLine(error);

                    _logger.Log(error);
                }
            }
        }