< Summary

Class:Microsoft.Azure.ServiceBus.CorrelationFilter
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Filters\CorrelationFilter.cs
Covered lines:0
Uncovered lines:81
Coverable lines:81
Total lines:281
Line coverage:0% (0 of 81)
Covered branches:0
Total branches:68
Branch coverage:0% (0 of 68)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-0%100%
.ctor(...)-0%0%
get_CorrelationId()-0%100%
set_CorrelationId(...)-0%100%
get_MessageId()-0%100%
set_MessageId(...)-0%100%
get_To()-0%100%
set_To(...)-0%100%
get_ReplyTo()-0%100%
set_ReplyTo(...)-0%100%
get_Label()-0%100%
set_Label(...)-0%100%
get_SessionId()-0%100%
set_SessionId(...)-0%100%
get_ReplyToSessionId()-0%100%
set_ReplyToSessionId(...)-0%100%
get_ContentType()-0%100%
set_ContentType(...)-0%100%
get_Properties()-0%0%
ToString()-0%0%
AppendPropertyExpression(...)-0%0%
GetHashCode()-0%0%
Equals(...)-0%100%
Equals(...)-0%0%
op_Equality(...)-0%0%
op_Inequality(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Filters\CorrelationFilter.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus
 5{
 6    using System;
 7    using System.Collections.Generic;
 8    using System.Text;
 9    using Primitives;
 10
 11    /// <summary>
 12    /// Represents the correlation filter expression.
 13    /// </summary>
 14    /// <remarks>
 15    /// <para>
 16    /// A CorrelationFilter holds a set of conditions that are matched against one of more of an arriving message's user
 17    /// A common use is a match against the <see cref="Message.CorrelationId"/> property, but the application can also c
 18    /// <see cref="Message.ContentType"/>, <see cref="Message.Label"/>, <see cref="Message.MessageId"/>, <see cref="Mess
 19    /// <see cref="Message.ReplyToSessionId"/>, <see cref="Message.SessionId"/>, <see cref="Message.To"/>, and any user-
 20    /// A match exists when an arriving message's value for a property is equal to the value specified in the correlatio
 21    /// the comparison is case-sensitive. When specifying multiple match properties, the filter combines them as a logic
 22    /// meaning all conditions must match for the filter to match.
 23    /// </para>
 24    /// <para>
 25    /// The CorrelationFilter provides an efficient shortcut for declarations of filters that deal only with correlation
 26    /// In this case the cost of the lexigraphical analysis of the expression can be avoided.
 27    /// Not only will correlation filters be optimized at declaration time, but they will also be optimized at runtime.
 28    /// Correlation filter matching can be reduced to a hashtable lookup, which aggregates the complexity of the set of 
 29    /// </para>
 30    /// </remarks>
 31    public sealed class CorrelationFilter : Filter
 32    {
 33        internal PropertyDictionary properties;
 34
 35        /// <summary>
 36        /// Initializes a new instance of the <see cref="CorrelationFilter" /> class with default values.
 37        /// </summary>
 038        public CorrelationFilter()
 39        {
 040        }
 41
 42        /// <summary>
 43        /// Initializes a new instance of the <see cref="CorrelationFilter" /> class with the specified correlation iden
 44        /// </summary>
 45        /// <param name="correlationId">The identifier for the correlation.</param>
 46        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="correlationId" /> is null or empt
 47        public CorrelationFilter(string correlationId)
 048            : this()
 49        {
 050            if (string.IsNullOrWhiteSpace(correlationId))
 51            {
 052                throw Fx.Exception.ArgumentNullOrWhiteSpace(nameof(correlationId));
 53            }
 54
 055            this.CorrelationId = correlationId;
 056        }
 57
 58        /// <summary>
 59        /// Identifier of the correlation.
 60        /// </summary>
 61        /// <value>The identifier of the correlation.</value>
 62        public string CorrelationId
 63        {
 064            get;
 065            set;
 66        }
 67
 68        /// <summary>
 69        /// Identifier of the message.
 70        /// </summary>
 71        /// <value>The identifier of the message.</value>
 72        /// <remarks>Max MessageId size is 128 chars.</remarks>
 73        public string MessageId
 74        {
 075            get;
 076            set;
 77        }
 78
 79        /// <summary>
 80        /// Address to send to.
 81        /// </summary>
 82        /// <value>The address to send to.</value>
 83        public string To
 84        {
 085            get;
 086            set;
 87        }
 88
 89        /// <summary>
 90        /// Address of the queue to reply to.
 91        /// </summary>
 92        /// <value>The address of the queue to reply to.</value>
 93        public string ReplyTo
 94        {
 095            get;
 096            set;
 97        }
 98
 99        /// <summary>
 100        /// Application specific label.
 101        /// </summary>
 102        /// <value>The application specific label.</value>
 103        public string Label
 104        {
 0105            get;
 0106            set;
 107        }
 108
 109        /// <summary>
 110        /// Session identifier.
 111        /// </summary>
 112        /// <value>The session identifier.</value>
 113        /// <remarks>Max size of sessionId is 128 chars.</remarks>
 114        public string SessionId
 115        {
 0116            get;
 0117            set;
 118        }
 119
 120        /// <summary>
 121        /// Session identifier to reply to.
 122        /// </summary>
 123        /// <value>The session identifier to reply to.</value>
 124        /// <remarks>Max size of ReplyToSessionId is 128.</remarks>
 125        public string ReplyToSessionId
 126        {
 0127            get;
 0128            set;
 129        }
 130
 131        /// <summary>
 132        /// Content type of the message.
 133        /// </summary>
 134        /// <value>The content type of the message.</value>
 135        public string ContentType
 136        {
 0137            get;
 0138            set;
 139        }
 140
 141        /// <summary>
 142        /// Application specific properties of the message.
 143        /// </summary>
 144        /// <value>The application specific properties of the message.</value>
 145        /// <remarks>
 146        /// Only following value types are supported:
 147        /// byte, sbyte, char, short, ushort, int, uint, long, ulong, float, double, decimal,
 148        /// bool, Guid, string, Uri, DateTime, DateTimeOffset, TimeSpan, Stream, byte[],
 149        /// and IList / IDictionary of supported types
 150        /// </remarks>
 0151        public IDictionary<string, object> Properties => this.properties ?? (this.properties = new PropertyDictionary())
 152
 153        /// <summary>
 154        /// Converts the value of the current instance to its equivalent string representation.
 155        /// </summary>
 156        /// <returns>A string representation of the current instance.</returns>
 157        public override string ToString()
 158        {
 0159            var stringBuilder = new StringBuilder();
 160
 0161            stringBuilder.Append("CorrelationFilter: ");
 162
 0163            var isFirstExpression = true;
 164
 0165            this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.CorrelationId", this.CorrelationId)
 0166            this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.MessageId", this.MessageId);
 0167            this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.To", this.To);
 0168            this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.ReplyTo", this.ReplyTo);
 0169            this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.Label", this.Label);
 0170            this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.SessionId", this.SessionId);
 0171            this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.ReplyToSessionId", this.ReplyToSess
 0172            this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.ContentType", this.ContentType);
 173
 0174            foreach (var pair in this.Properties)
 175            {
 0176                string propertyName = pair.Key;
 0177                object propertyValue = pair.Value;
 178
 0179                this.AppendPropertyExpression(ref isFirstExpression, stringBuilder, propertyName, propertyValue);
 180            }
 181
 0182            return stringBuilder.ToString();
 183        }
 184
 185        void AppendPropertyExpression(ref bool firstExpression, StringBuilder builder, string propertyName, object value
 186        {
 0187            if (value != null)
 188            {
 0189                if (firstExpression)
 190                {
 0191                    firstExpression = false;
 192                }
 193                else
 194                {
 0195                    builder.Append(" AND ");
 196                }
 197
 0198                builder.AppendFormat("{0} = '{1}'", propertyName, value);
 199            }
 0200        }
 201
 202        public override int GetHashCode()
 203        {
 0204            int hash = 13;
 205            unchecked
 206            {
 0207                hash = (hash * 7) + this.CorrelationId?.GetHashCode() ?? 0;
 0208                hash = (hash * 7) + this.MessageId?.GetHashCode() ?? 0;
 0209                hash = (hash * 7) + this.SessionId?.GetHashCode() ?? 0;
 210            }
 211
 0212            return hash;
 213        }
 214
 215        public override bool Equals(object obj)
 216        {
 0217            var other = obj as CorrelationFilter;
 0218            return this.Equals(other);
 219        }
 220
 221        public override bool Equals(Filter other)
 222        {
 0223            if (other is CorrelationFilter correlationFilter)
 224            {
 0225                if (string.Equals(this.CorrelationId, correlationFilter.CorrelationId, StringComparison.OrdinalIgnoreCas
 0226                    && string.Equals(this.MessageId, correlationFilter.MessageId, StringComparison.OrdinalIgnoreCase)
 0227                    && string.Equals(this.To, correlationFilter.To, StringComparison.OrdinalIgnoreCase)
 0228                    && string.Equals(this.ReplyTo, correlationFilter.ReplyTo, StringComparison.OrdinalIgnoreCase)
 0229                    && string.Equals(this.Label, correlationFilter.Label, StringComparison.OrdinalIgnoreCase)
 0230                    && string.Equals(this.SessionId, correlationFilter.SessionId, StringComparison.OrdinalIgnoreCase)
 0231                    && string.Equals(this.ReplyToSessionId, correlationFilter.ReplyToSessionId, StringComparison.Ordinal
 0232                    && string.Equals(this.ContentType, correlationFilter.ContentType, StringComparison.OrdinalIgnoreCase
 0233                    && (this.properties != null && correlationFilter.properties != null
 0234                        || this.properties == null && correlationFilter.properties == null))
 235                {
 0236                    if (this.properties != null)
 237                    {
 0238                        if (this.properties.Count != correlationFilter.properties.Count)
 239                        {
 0240                            return false;
 241                        }
 242
 0243                        foreach (var param in this.properties)
 244                        {
 0245                            if (!correlationFilter.properties.TryGetValue(param.Key, out var otherParamValue) ||
 0246                                (param.Value == null ^ otherParamValue == null) ||
 0247                                (param.Value != null && !param.Value.Equals(otherParamValue)))
 248                            {
 0249                                return false;
 250                            }
 251                        }
 252                    }
 253
 0254                    return true;
 255                }
 256            }
 257
 0258            return false;
 0259        }
 260
 261        public static bool operator == (CorrelationFilter o1, CorrelationFilter o2)
 262        {
 0263            if (ReferenceEquals(o1, o2))
 264            {
 0265                return true;
 266            }
 267
 0268            if (ReferenceEquals(o1, null) || ReferenceEquals(o2, null))
 269            {
 0270                return false;
 271            }
 272
 0273            return o1.Equals(o2);
 274        }
 275
 276        public static bool operator != (CorrelationFilter p1, CorrelationFilter p2)
 277        {
 0278            return !(p1 == p2);
 279        }
 280    }
 281}