private CorrelationVectorV1(string baseVector, int extension, bool immutable)
 {
     this.BaseVector = baseVector;
     this.extension  = extension;
     this.Version    = CorrelationVectorVersion.V1;
     this.immutable  = immutable || CorrelationVectorV1.IsOversized(baseVector, extension);
 }
        /// <summary>
        /// Increments the current extension by one. Do this before passing the value to an
        /// outbound message header.
        /// </summary>
        /// <returns>
        /// The new value as a string that you can add to the outbound message header
        /// indicated by <see cref="HeaderName"/>.
        /// </returns>
        public override string Increment()
        {
            if (this.immutable)
            {
                return(this.Value);
            }
            int snapshot = 0;
            int next     = 0;

            do
            {
                snapshot = this.extension;
                if (snapshot == int.MaxValue)
                {
                    return(this.Value);
                }
                next = snapshot + 1;
                if (CorrelationVectorV1.IsOversized(this.BaseVector, next))
                {
                    this.immutable = true;
                    return(this.Value);
                }
            }while (snapshot != Interlocked.CompareExchange(ref this.extension, next, snapshot));
            return(string.Concat(this.BaseVector, ".", next));
        }
Beispiel #3
0
        public static CorrelationVector Spin(string correlationVector, SpinParameters parameters)
        {
            CorrelationVectorVersion version = InferVersion(correlationVector);

            switch (version)
            {
            case CorrelationVectorVersion.V1:
                return(CorrelationVectorV1.Spin(correlationVector, parameters));

            case CorrelationVectorVersion.V2:
                return(CorrelationVectorV2.Spin(correlationVector, parameters));

            default:
                return(null);
            }
        }
        /// <summary>
        /// Creates a new correlation vector by extending an existing value. This should be
        /// done at the entry point of an operation.
        /// </summary>
        /// <param name="correlationVector">
        /// Taken from the message header indicated by <see cref="HeaderName"/>.
        /// </param>
        /// <returns>A new correlation vector extended from the current vector.</returns>
        public new static CorrelationVectorV1 Extend(string correlationVector)
        {
            if (CorrelationVectorV1.IsImmutable(correlationVector))
            {
                return(CorrelationVectorV1.Parse(correlationVector));
            }

            if (CorrelationVectorV1.ValidateCorrelationVectorDuringCreation)
            {
                CorrelationVectorV1.Validate(correlationVector);
            }

            if (CorrelationVectorV1.IsOversized(correlationVector, 0))
            {
                return(CorrelationVectorV1.Parse(correlationVector + CorrelationVectorV1.TerminationSign));
            }

            return(new CorrelationVectorV1(correlationVector, 0, false));
        }
        /// <summary>
        /// Creates a new correlation vector by parsing its string representation
        /// </summary>
        /// <param name="correlationVector">correlationVector</param>
        /// <returns>CorrelationVector</returns>
        public new static CorrelationVectorV1 Parse(string correlationVector)
        {
            if (!string.IsNullOrEmpty(correlationVector))
            {
                int  p         = correlationVector.LastIndexOf('.');
                bool immutable = CorrelationVectorV1.IsImmutable(correlationVector);
                if (p > 0)
                {
                    string extensionValue = immutable ? correlationVector.Substring(p + 1, correlationVector.Length - p - 1 - CorrelationVectorV1.TerminationSign.Length)
                        : correlationVector.Substring(p + 1);
                    int extension;
                    if (int.TryParse(extensionValue, out extension) && extension >= 0)
                    {
                        return(new CorrelationVectorV1(correlationVector.Substring(0, p), extension, immutable));
                    }
                }
            }

            return(new CorrelationVectorV1());
        }
 /// <summary>
 /// Determines whether two instances of the <see cref="CorrelationVectorV1"/> class
 /// are equal.
 /// </summary>
 /// <param name="vector">
 /// The correlation vector you want to compare with the current correlation vector.
 /// </param>
 /// <returns>
 /// True if the specified correlation vector is equal to the current correlation
 /// vector; otherwise, false.
 /// </returns>
 public bool Equals(CorrelationVectorV1 vector)
 {
     return(string.Equals(this.Value, vector.Value, StringComparison.Ordinal));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CorrelationVectorV1"/> class.
 /// This should only be called when no correlation
 /// vector was found in the message header.
 /// </summary>
 public CorrelationVectorV1()
     : this(CorrelationVectorV1.GetUniqueValue(), 0, false)
 {
 }