public LinkDeserializationException(byte[] body, LinkMessageProperties properties, LinkRecieveMessageProperties recieveProperties, Exception innerException)
     : base("Cannot deserialize message, see InnerException for details", innerException)
 {
     Body = body;
     Properties = properties;
     RecieveProperties = recieveProperties;
 }
 public LinkProducerQueueMessage(byte[] body, LinkMessageProperties properties,
     LinkPublishProperties publishProperties, CancellationToken cancellation)
     : base(cancellation)
 {
     Body = body;
     Properties = properties;
     PublishProperties = publishProperties;
 }
        public void CorrelationIdProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.CorrelationIdPresent);
            Assert.Null(props.CorrelationId);

            props.CorrelationId = "test";

            Assert.Equal(props.CorrelationId, "test");
            Assert.True(props.CorrelationIdPresent);
        }
        public void ContentTypeProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.ContentTypePresent);
            Assert.Null(props.ContentType);

            props.ContentType = "test";

            Assert.Equal(props.ContentType, "test");
            Assert.True(props.ContentTypePresent);
        }
        public void ContentEncodingProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.ContentEncodingPresent);
            Assert.Null(props.ContentEncoding);

            props.ContentEncoding = "test";

            Assert.Equal(props.ContentEncoding, "test");
            Assert.True(props.ContentEncodingPresent);
        }
        public void ExpirationProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.ExpirationPresent);
            Assert.Null(props.Expiration);

            props.Expiration = TimeSpan.FromSeconds(1);

            Assert.Equal(TimeSpan.FromSeconds(1), props.Expiration);
            Assert.True(props.ExpirationPresent);
        }
 public void CopyTo()
 {
     var props = new LinkMessageProperties();
 }
        public void TimeStampProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.TimeStampPresent);
            Assert.Null(props.TimeStamp);

            props.TimeStamp = new DateTime(2015, 01, 01).ToUnixTime();

            Assert.Equal(new DateTime(2015, 01, 01), props.TimeStamp.Value.FromUnixTime());
            Assert.True(props.TimeStampPresent);
        }
 public LinkMessageProperties Clone()
 {
     var ret = new LinkMessageProperties();
     CopyTo(ret);
     return ret;
 }
        public void ReplyToProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.ReplyToPresent);
            Assert.Null(props.ReplyTo);

            props.ReplyTo = "test";

            Assert.Equal("test", props.ReplyTo);
            Assert.True(props.ReplyToPresent);
        }
        public void Enqueue(byte[] body, LinkMessageProperties properties, LinkRecieveMessageProperties recieveProperties, LinkMessageOnAckAsyncDelegate onAck,
            LinkMessageOnNackAsyncDelegate onNack)
        {
            if (_disposedCancellation.IsCancellationRequested)
                throw new ObjectDisposedException(GetType().Name);

            var cancellation = _messageCancellation;

            try
            {
                var message = new LinkMessage<byte[]>(body, properties, recieveProperties, onAck, onNack, cancellation);
                var holder = new MessageHolder(message, cancellation);
                _messageQueue.Enqueue(holder, cancellation);
            }
            catch (InvalidOperationException)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
        }
 public ILinkProducerConfigurationBuilder MessageProperties(LinkMessageProperties value)
 {
     Configuration.MessageProperties = value;
     return this;
 }
 /// <summary>
 /// Makes clone of instance
 /// </summary>
 public static LinkMessageProperties Clone(this LinkMessageProperties @this)
 => new LinkMessageProperties().Extend(@this);
 public void Ctor()
 {
     var props = new LinkMessageProperties();
 }
        /// <summary>
        /// Extend instance with other instances, returns instance.
        /// </summary>
        public static LinkMessageProperties Extend(this LinkMessageProperties @this,
                                                   params LinkMessageProperties[] others)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }

            if (others?.Any() == true)
            {
                foreach (var other in others)
                {
                    if (other.AppId != null)
                    {
                        @this.AppId = other.AppId;
                    }
                    if (other.ClusterId != null)
                    {
                        @this.ClusterId = other.ClusterId;
                    }
                    if (other.ContentEncoding != null)
                    {
                        @this.ContentEncoding = other.ContentEncoding;
                    }
                    if (other.ContentType != null)
                    {
                        @this.ContentType = other.ContentType;
                    }
                    if (other.CorrelationId != null)
                    {
                        @this.CorrelationId = other.CorrelationId;
                    }
                    if (other.DeliveryMode != LinkDeliveryMode.Default)
                    {
                        @this.DeliveryMode = other.DeliveryMode;
                    }
                    if (other.ReplyTo != null)
                    {
                        @this.ReplyTo = other.ReplyTo;
                    }
                    if (other.Expiration != null)
                    {
                        @this.Expiration = other.Expiration;
                    }
                    if (other.MessageId != null)
                    {
                        @this.MessageId = other.MessageId;
                    }
                    if (other.TimeStamp != null)
                    {
                        @this.TimeStamp = other.TimeStamp;
                    }
                    if (other.Type != null)
                    {
                        @this.Type = other.Type;
                    }
                    if (other.UserId != null)
                    {
                        @this.UserId = other.UserId;
                    }
                    if (other.Priority != null)
                    {
                        @this.Priority = other.Priority;
                    }

                    if (other.Headers.Any())
                    {
                        foreach (var header in other.Headers)
                        {
                            if (header.Value != null)
                            {
                                @this.Headers[header.Key] = header.Value;
                            }
                        }
                    }
                }
            }

            return(@this);
        }
        /// <summary>
        /// Extends instance with <see cref="IBasicProperties"/> instances, return instance
        /// </summary>
        internal static LinkMessageProperties Extend(this LinkMessageProperties @this, params IBasicProperties[] others)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }

            if (others?.Any() == true)
            {
                foreach (var other in others)
                {
                    if (other.IsAppIdPresent())
                    {
                        @this.AppId = other.AppId;
                    }
                    if (other.IsClusterIdPresent())
                    {
                        @this.ClusterId = other.ClusterId;
                    }
                    if (other.IsContentEncodingPresent())
                    {
                        @this.ContentEncoding = other.ContentEncoding;
                    }
                    if (other.IsContentTypePresent())
                    {
                        @this.ContentType = other.ContentType;
                    }
                    if (other.IsCorrelationIdPresent())
                    {
                        @this.CorrelationId = other.CorrelationId;
                    }
                    if (other.IsDeliveryModePresent())
                    {
                        @this.DeliveryMode = (LinkDeliveryMode)other.DeliveryMode;
                    }
                    if (other.IsReplyToPresent())
                    {
                        @this.ReplyTo = other.ReplyTo;
                    }
                    if (other.IsExpirationPresent())
                    {
                        @this.Expiration = TimeSpan.FromMilliseconds(int.Parse(other.Expiration));
                    }
                    if (other.IsMessageIdPresent())
                    {
                        @this.MessageId = other.MessageId;
                    }
                    if (other.IsTimestampPresent())
                    {
                        @this.TimeStamp = other.Timestamp.UnixTime;
                    }
                    if (other.IsTypePresent())
                    {
                        @this.Type = other.Type;
                    }
                    if (other.IsUserIdPresent())
                    {
                        @this.UserId = other.UserId;
                    }
                    if (other.IsPriorityPresent())
                    {
                        @this.Priority = other.Priority;
                    }

                    if (other.IsHeadersPresent() && other.Headers?.Any() == true)
                    {
                        foreach (var header in other.Headers)
                        {
                            if (header.Value != null)
                            {
                                @this.Headers[header.Key] = header.Value;
                            }
                        }
                    }
                }
            }

            return(@this);
        }
 public void SetMessageId(byte[] body, LinkMessageProperties properties, LinkPublishProperties publishProperties)
 {
     properties.MessageId = Guid.NewGuid().ToString("D");
 }
        public void CopyFrom(LinkMessageProperties from)
        {
            if (from == null)
                throw new ArgumentNullException(nameof(from));

            if (from.AppIdPresent) AppId = from.AppId;
            if (from.ClusterIdPresent) ClusterId = from.ClusterId;
            if (from.ContentEncodingPresent) ContentEncoding = from.ContentEncoding;
            if (from.ContentTypePresent) ContentType = from.ContentType;
            if (from.CorrelationIdPresent) CorrelationId = from.CorrelationId;
            if (from.DeliveryModePresent) DeliveryMode = @from.DeliveryMode;
            if (from.ReplyToPresent) ReplyTo = from.ReplyTo;
            if (from.ExpirationPresent) Expiration = from.Expiration;
            if (from.MessageIdPresent) MessageId = from.MessageId;
            if (from.TimeStampPresent) TimeStamp = from.TimeStamp;
            if (from.TypePresent) Type = from.Type;
            if (from.UserIdPresent) UserId = from.UserId;
            if (from.PriorityPresent) Priority = from.Priority;

            if (from.HeadersPresent)
            {
                foreach (var header in from.Headers)
                {
                    Headers[header.Key] = header.Value;
                }
            }
        }
        internal void CopyTo(LinkMessageProperties to)
        {
            if (to == null)
                throw new ArgumentNullException(nameof(to));

            if (AppIdPresent) to.AppId = AppId;
            if (ClusterIdPresent) to.ClusterId = ClusterId;
            if (ContentEncodingPresent) to.ContentEncoding = ContentEncoding;
            if (ContentTypePresent) to.ContentType = ContentType;
            if (CorrelationIdPresent) to.CorrelationId = CorrelationId;
            if (DeliveryModePresent) to.DeliveryMode = DeliveryMode;
            if (ReplyToPresent) to.ReplyTo = ReplyTo;
            if (ExpirationPresent) to.Expiration = Expiration;
            if (MessageIdPresent) to.MessageId = MessageId;
            if (TimeStampPresent) to.TimeStamp = TimeStamp;
            if (TypePresent) to.Type = Type;
            if (UserIdPresent) to.UserId = UserId;
            if (PriorityPresent) to.Priority = Priority;

            if (HeadersPresent)
            {
                foreach (var header in Headers)
                {
                    to.Headers[header.Key] = header.Value;
                }
            }
        }
        public void DeliveryModeProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.DeliveryModePresent);
            Assert.Equal(props.DeliveryMode, LinkMessageDeliveryMode.Transient);

            props.DeliveryMode = LinkMessageDeliveryMode.Persistent;

            Assert.Equal(LinkMessageDeliveryMode.Persistent, props.DeliveryMode);
            Assert.True(props.DeliveryModePresent);

            props = new LinkMessageProperties();

            Assert.False(props.DeliveryModePresent);
            Assert.Equal(LinkMessageDeliveryMode.Transient, props.DeliveryMode);

            props.DeliveryMode = LinkMessageDeliveryMode.Transient;

            Assert.Equal(LinkMessageDeliveryMode.Transient, props.DeliveryMode);
            Assert.True(props.DeliveryModePresent);
        }
        public void HeadersProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.HeadersPresent);
            Assert.Empty(props.Headers);

            props.Headers.Add("test", 1);

            Assert.Equal(props.Headers["test"], 1);
            Assert.True(props.HeadersPresent);
            Assert.NotEmpty(props.Headers);
        }
 /// <inheritdoc />
 public void SetMessageId(byte[] body, LinkMessageProperties properties, LinkPublishProperties publishProperties)
 {
     properties.MessageId = Guid.NewGuid().ToString("D");
 }
        public void MessageIdProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.MessageIdPresent);
            Assert.Null(props.MessageId);

            props.MessageId = "test";

            Assert.Equal("test", props.MessageId);
            Assert.True(props.MessageIdPresent);
        }
 public static object Deserialize(this ILinkMessageSerializer @this, Type bodyType,
     byte[] body, LinkMessageProperties properties)
 {
     var genericMethod = DeserializeMethod.MakeGenericMethod(bodyType);
     return genericMethod.Invoke(@this, new object[] { body, properties });
 }
        public void PriorityProperty()
        {
            var props = new LinkMessageProperties();

            Assert.False(props.PriorityPresent);
            Assert.Null(props.Priority);

            props.Priority = 5;

            Assert.Equal((byte) 5, props.Priority);
            Assert.True(props.PriorityPresent);
        }