Exemplo n.º 1
0
        /// <summary>
        /// Creates a default subscription filter for a send port.
        /// </summary>
        /// <param name="targetApplication">The application in the target.</param>
        /// <param name="sendPort">The send port containing the filter to replicate.</param>
        /// <returns>A subscription filter.</returns>
        private SubscriptionFilter CreateDefaultSubscriptionFilter(Application targetApplication, SendPort sendPort)
        {
            _logger.LogDebug(TraceMessages.CreatingDefaultSendPortSubscription, RuleName, sendPort.Name);

            // Create filter expression
            string targetFilterExpression;

            if (sendPort.IsStatic)
            {
                targetFilterExpression = $"{ModelConstants.BizTalkSpTransportId} = '{targetApplication.Name.FormatKey()}.{sendPort.Name.FormatKey()}.{sendPort.PrimaryTransport.TransportType.Name}'";
            }
            else
            {
                // It's a dynamic port, so won't have a primary transport
                targetFilterExpression = $"{ModelConstants.BizTalkSpTransportId} = '{targetApplication.Name.FormatKey()}.{sendPort.Name.FormatKey()}'";
            }

            // Create a group, doesn't matter too much what the operation is as there is only one filter
            var targetFilterGroup = new OrFilterGroup();

            targetFilterGroup.Filters.Add(new Filter()
            {
                FilterExpression = targetFilterExpression
            });

            _logger.LogTrace(TraceMessages.CreatedSubscriptionFilterStatement, RuleName, targetFilterExpression);

            // Create filter and return
            var subscriptionFilter = new SubscriptionFilter(targetFilterGroup);

            _logger.LogTrace(TraceMessages.CreatedDefaultSubscriptionFilterGroupForSendPort, RuleName, targetFilterGroup.Operation, sendPort.Name);

            return(subscriptionFilter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a subscription and filter on the message subscriber for the receive port response handler.
        /// </summary>
        /// <param name="messageSubscriber">The message subscriber.</param>
        /// <param name="receivePort">The receive port.</param>
        private void CreateMessageSubscriberFilter(MessageSubscriber messageSubscriber, ReceivePort receivePort)
        {
            var topicChannelKey             = _messageBoxChannelKey;
            var receivePortSubscriptionName = receivePort.Name.FormatKey();

            // Find topic channel to add subscriptions to
            var topicChannelObject = Model.FindMessagingObject(topicChannelKey);

            if (topicChannelObject.application != null && topicChannelObject.messagingObject != null)
            {
                var topicChannel = (TopicChannel)topicChannelObject.messagingObject;

                // Subscriptions will be created independent of subscribers so that messages can be delivered to
                // the subscriptions, meaning the subscription lifetime is not tied to the consumer.  This is a durable
                // subscription and the only ones we intend to create.
                messageSubscriber.IsDurable = true;

                // Create subscription and name it after the receive port
                var subscription = new Subscription(receivePortSubscriptionName, topicChannel.TopicName)
                {
                    IsDurable = messageSubscriber.IsDurable
                };

                _logger.LogDebug(TraceMessages.CreatingReceivePortSubscription, RuleName, receivePort.Name);

                // Create filter expression against the receive port ID
                var targetFilter = new Filter()
                {
                    FilterExpression = $"{ModelConstants.BizTalkAckReceivePortId} = '{((Dictionary<string, object>)messageSubscriber.Properties[ModelConstants.ConfigurationEntry])[ModelConstants.BizTalkAckReceivePortId]}'"
                };

                // Create a group, doesn't matter too much what the operation is as there is only one filter
                var targetFilterGroup = new OrFilterGroup();
                targetFilterGroup.Filters.Add(targetFilter);

                _logger.LogTrace(TraceMessages.CreatedSubscriptionFilterStatement, RuleName, targetFilter.FilterExpression);

                // Create filter
                subscription.Filters.Add(new SubscriptionFilter(targetFilterGroup));

                _logger.LogTrace(TraceMessages.CreatedSubscriptionFilterGroupForReceivePort, RuleName, targetFilterGroup.Operation, receivePort.Name);

                // Add subscription to channel
                topicChannel.Subscriptions.Add(subscription);

                // Relate subscription on channel to the subscriber
                messageSubscriber.TopicSubscriptions.Add(topicChannel.TopicName, subscription.Name);
            }
            else
            {
                var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindMessagingObjectWithKeyInTargetModel, MessagingObjectType.Channel, topicChannelKey);
                _logger.LogError(error);
                Context.Errors.Add(new ErrorMessage(error));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a subscription and filter on the endpoint for the response topic of the response path of the receive port.
        /// </summary>
        /// <param name="endpoint">The endpointsubscriber.</param>
        /// <param name="receivePort">The receive port.</param>
        private void CreateEndpointFilter(Endpoint endpoint, ReceivePort receivePort)
        {
            var topicChannelKey             = _messageBoxResponseChannelKey;
            var receivePortSubscriptionName = receivePort.Name.FormatKey();

            // Find topic channel to add subscriptions to
            var topicChannelObject = Model.FindMessagingObject(topicChannelKey);

            if (topicChannelObject.application != null && topicChannelObject.messagingObject != null)
            {
                var topicChannel = (TopicChannel)topicChannelObject.messagingObject;

                // Create subscription and name it after the receive port
                var subscription = new Subscription(receivePortSubscriptionName, topicChannel.TopicName)
                {
                    IsDurable = true,
                    IsOrdered = true
                };

                _logger.LogDebug(TraceMessages.CreatingReceivePortResponseSubscription, RuleName, receivePort.Name);

                // Create filter expression against the receive port ID
                var targetFilter = new Filter()
                {
                    FilterExpression = $"{ModelConstants.BizTalkAckReceivePortId} = '{((Dictionary<string, object>)endpoint.Properties[ModelConstants.ConfigurationEntry])[ModelConstants.BizTalkReceivePortId]}'"
                };

                // Create a group, doesn't matter too much what the operation is as there is only one filter
                var targetFilterGroup = new OrFilterGroup();
                targetFilterGroup.Filters.Add(targetFilter);

                _logger.LogTrace(TraceMessages.CreatedSubscriptionFilterStatement, RuleName, targetFilter.FilterExpression);

                // Create filter
                subscription.Filters.Add(new SubscriptionFilter(targetFilterGroup));

                _logger.LogTrace(TraceMessages.CreatedSubscriptionFilterGroupForReceivePort, RuleName, targetFilterGroup.Operation, receivePort.Name);

                // Add subscription to channel
                topicChannel.Subscriptions.Add(subscription);

                // Relate subscription on channel to the endpoint
                endpoint.Properties.Add(ModelConstants.ResponseSubscription, subscription.Name);
            }
            else
            {
                var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindMessagingObjectWithKeyInTargetModel, MessagingObjectType.Channel, topicChannelKey);
                _logger.LogError(error);
                Context.Errors.Add(new ErrorMessage(error));
            }
        }
Exemplo n.º 4
0
        private Filter Convert(Ctrl.FilterGroup group)
        {
            FilterGroup newGroup;

            if (group.Operatror == Ctrl.FilterGroupOperatorEnum.And)
            {
                newGroup = new AndFilterGroup();
            }
            else
            {
                newGroup = new OrFilterGroup();
            }

            foreach (var filter in group.Filters)
            {
                newGroup.FilterItems.Add(ConvertToProviderPluginFilter(filter));
            }

            return(newGroup);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a default subscription filter for a send port.
        /// </summary>
        /// <param name="targetApplication">The application in the target.</param>
        /// <param name="sendPort">The send port containing the filter to replicate.</param>
        /// <returns>A subscription filter.</returns>
        private SubscriptionFilter CreateSubscriptionFilter(Application targetApplication, SendPort sendPort)
        {
            _logger.LogDebug(TraceMessages.CreatingSendPortSubscription, RuleName, sendPort.Name);

            // Create an overall OR filter group so that if any sub-group matches a condition
            var targetFilterGroup = new OrFilterGroup();

            // Add default
            string defaultTargetFilterExpression;

            if (sendPort.IsStatic)
            {
                defaultTargetFilterExpression = $"{ModelConstants.BizTalkSpTransportId} = '{targetApplication.Name.FormatKey()}.{sendPort.Name.FormatKey()}.{sendPort.PrimaryTransport.TransportType.Name}'";
            }
            else
            {
                // It's a dynamic port, so won't have a primary transport
                defaultTargetFilterExpression = $"{ModelConstants.BizTalkSpTransportId} = '{targetApplication.Name.FormatKey()}.{sendPort.Name.FormatKey()}'";
            }

            targetFilterGroup.Groups.Add(new AndFilterGroup()
            {
                Filters = { new Filter()
                            {
                                FilterExpression = defaultTargetFilterExpression
                            } }
            });

            // Loop around the filter groups, converting each one to an AND filter group with a list of filter expressions
            foreach (var sendPortFilterGroup in sendPort.FilterExpression.Group)
            {
                var targetFilterSubGroup = new AndFilterGroup();
                foreach (var statement in sendPortFilterGroup.Statement)
                {
                    Filter filter             = null;
                    var    expressionProperty = MapSubscriptionFilterProperty(statement.Property);

                    switch (statement.Operator)
                    {
                    // Equals
                    case 0:

                        filter = new Filter()
                        {
                            FilterExpression = $"{expressionProperty} = '{statement.Value}'"
                        };
                        break;

                    // LessThan
                    case 1:

                        filter = new Filter()
                        {
                            FilterExpression = $"{expressionProperty} < '{statement.Value}'"
                        };
                        break;

                    // LessThanEqualTo
                    case 2:

                        filter = new Filter()
                        {
                            FilterExpression = $"{expressionProperty} <= '{statement.Value}'"
                        };
                        break;

                    // GreaterThan
                    case 3:

                        filter = new Filter()
                        {
                            FilterExpression = $"{expressionProperty} > '{statement.Value}'"
                        };
                        break;

                    // GreaterThanEqualTo
                    case 4:

                        filter = new Filter()
                        {
                            FilterExpression = $"{expressionProperty} >= '{statement.Value}'"
                        };
                        break;

                    // NotEqual
                    case 5:

                        filter = new Filter()
                        {
                            FilterExpression = $"{expressionProperty} != '{statement.Value}'"
                        };
                        break;

                    // Exists
                    case 6:

                        filter = new Filter()
                        {
                            FilterExpression = $"EXISTS ( {expressionProperty} )"
                        };
                        break;

                    default:

                        _logger.LogError(ErrorMessages.SubscriptionFilterOperatorNotSupported, statement.Operator);
                        Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.SubscriptionFilterOperatorNotSupported, statement.Operator)));

                        continue;
                    }

                    targetFilterSubGroup.Filters.Add(filter);

                    _logger.LogTrace(TraceMessages.CreatedSubscriptionFilterStatement, RuleName, filter.FilterExpression);
                }

                _logger.LogTrace(TraceMessages.CreatedSubscriptionFilterSubGroup, RuleName, targetFilterSubGroup.Operation, targetFilterSubGroup.Filters.Count);

                // Add to filter group
                targetFilterGroup.Groups.Add(targetFilterSubGroup);
            }

            _logger.LogTrace(TraceMessages.CreatedSubscriptionFilterGroupForSendPort, RuleName, targetFilterGroup.Operation, sendPort.Name);

            // Create filter and return
            var subscriptionFilter = new SubscriptionFilter(targetFilterGroup);

            return(subscriptionFilter);
        }