Example #1
0
        /// <summary>
        /// Serializes the specified message.
        /// </summary>
        /// <typeparam name="T">The type of the message body.</typeparam>
        /// <param name="message">The message.</param>
        /// <param name="includeExtension">Whether or not to include a message header extension.</param>
        /// <returns>The encoded byte array containing the message data.</returns>
        public static byte[] Serialize <T>(this EtpMessage <T> message, bool includeExtension = false) where T : IEtpMessageBody
        {
            var @objects = message.Extension != null && includeExtension
                ? new IEtpRecord[] { message.Header, message.Extension, message.Body }
                : new IEtpRecord[] { message.Header, message.Body };

            var content = Serialize(@objects);

            return(System.Text.Encoding.UTF8.GetBytes(content));
        }
Example #2
0
        /// <summary>
        /// Converts the RequestSession message into an <see cref="EtpEndpointDetails"/> instance.
        /// </summary>
        /// <param name="body">The message to convert.</param>
        /// <returns>The created instance.</returns>
        public static EtpEndpointDetails ToEndpointDetails(this EtpMessage <IRequestSession> message)
        {
            var capabilities = new EtpEndpointCapabilities(message.EtpVersion);

            capabilities.LoadFrom(message.Body.EndpointCapabilities);
            return(new EtpEndpointDetails(
                       capabilities,
                       message.Body.RequestedProtocols.Select(p => new EtpEndpointProtocol(p, false)).ToList(),
                       message.Body.SupportedDataObjects.Select(o => new EtpSupportedDataObject(o)).ToList(),
                       message.Body.SupportedCompression.ToList() ?? new List <string>(),
                       message.Body.SupportedFormats?.ToList() ?? new List <string> {
                Formats.Xml
            }
                       ));
        }
Example #3
0
 /// <summary>
 /// Converts the OpenSession message into an <see cref="EtpEndpointInfo"/> instance.
 /// </summary>
 /// <param name="message">The message to convert.</param>
 /// <returns>The created instance.</returns>
 public static EtpEndpointInfo ToEndpointInfo(this EtpMessage <IOpenSession> message)
 {
     return(EtpEndpointInfo.FromId(message.Body.ApplicationName, message.Body.ApplicationVersion, message.Body.ServerInstanceId));
 }
Example #4
0
 /// <summary>
 /// Converts the RequestSession message into an <see cref="EtpEndpointInfo"/> instance.
 /// </summary>
 /// <param name="message">The message to convert.</param>
 /// <returns>The created instance.</returns>
 public static EtpEndpointInfo ToEndpointInfo(this EtpMessage <IRequestSession> message)
 {
     return(EtpEndpointInfo.FromId(message.Body.ApplicationName, message.Body.ApplicationVersion, message.Body.ClientInstanceId));
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NotificationEventArgs{T, TSubscription}"/> class.
 /// </summary>
 /// <param name="subscription">The original subscription.</param>
 /// <param name="notification">The notification message.</param>
 public NotificationEventArgs(EtpSubscription <TSubscription> subscription, EtpMessage <TNotification> notification)
 {
     Notification = notification;
     Subscription = subscription;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageEventArgs"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 public MessageEventArgs(EtpMessage message)
 {
     Message = message;
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResponseEventArgs{TRequest, TResponse}"/> class.
 /// </summary>
 /// <param name="request">The original request message.</param>
 /// <param name="exception">The protocol exception.</param>
 public VoidResponseEventArgs(EtpMessage <TRequest> request, EtpMessage <IProtocolException> exception)
     : base(request, exception)
 {
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DualResponseEventArgs{TRequest, TResponse1, TResponse2}"/> class.
 /// </summary>
 /// <param name="request">The original request message.</param>
 /// <param name="response1">The first type of response message.</param>
 /// <param name="response1">The second type of response message.</param>
 /// <param name="exception">The protocol exception.</param>
 public DualResponseEventArgs(EtpMessage <TRequest> request, EtpMessage <TResponse2> response2)
     : base(request, null)
 {
     Response2 = response2;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ListAndSingleRequestEventArgs{TRequest, TResponse1, TResponse2}"/> class.
 /// </summary>
 /// <param name="request">The request message.</param>
 public ListAndSingleRequestEventArgs(EtpMessage <TRequest> request)
     : base(request)
 {
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DualListRequestWithContextEventArgs{TRequest, TResponse1, TResponse2, TContext}"/> class.
 /// </summary>
 /// <param name="request">The request message.</param>
 public DualListRequestWithContextEventArgs(EtpMessage <TRequest> request)
     : base(request)
 {
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmptyRequestEventArgs{TRequest}"/> class.
 /// </summary>
 /// <param name="request">The request message.</param>
 public RequestEventArgsBase(EtpMessage <TRequest> request)
 {
     Request = request;
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RequestEventArgs{TRequest, TResponse}"/> class.
 /// </summary>
 /// <param name="request">The request message.</param>
 public RequestEventArgs(EtpMessage <TRequest> request)
     : base(request)
 {
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CancellationRequestEventArgs{TRequest, TCancellation}"/> class.
 /// </summary>
 /// <param name="request">The original request message.</param>
 /// <param name="cancellation">The cancellation request message.</param>
 public CancellationRequestEventArgs(EtpMessage <TRequest> request, EtpMessage <TCancellation> cancellation)
     : base(request)
 {
     Cancellation = cancellation;
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NotificationEventArgs{T, TSubscription}"/> class.
 /// </summary>
 /// <param name="subscription">The original subscription.</param>
 /// <param name="notification">The notification message.</param>
 /// <param name="data">The notification data.</param>
 public NotificationWithDataEventArgs(EtpSubscription <TSubscription> subscription, EtpMessage <TNotification> notification, EtpMessage <TData> data)
     : base(subscription, notification)
 {
     Data = data;
 }
Example #15
0
        public void EtpExtensions_Encode_And_Decode_Can_Round_Trip()
        {
            var expectedVersion = new v11.Datatypes.Version {
                Major = 1, Minor = 2, Revision = 3, Patch = 4
            };
            var bytes         = expectedVersion.EncodeToBytes();
            var actualVersion = EtpExtensions.DecodeFromBytes <v11.Datatypes.Version>(bytes);

            Assert.AreEqual(expectedVersion.Major, actualVersion.Major, nameof(expectedVersion.Major));
            Assert.AreEqual(expectedVersion.Minor, actualVersion.Minor, nameof(expectedVersion.Minor));
            Assert.AreEqual(expectedVersion.Revision, actualVersion.Revision, nameof(expectedVersion.Revision));
            Assert.AreEqual(expectedVersion.Patch, actualVersion.Patch, nameof(expectedVersion.Patch));

            var expectedValue = new v11.Datatypes.DataValue {
                Item = 1
            };

            bytes = expectedValue.EncodeToBytes();
            var actualValue = EtpExtensions.DecodeFromBytes <v11.Datatypes.DataValue>(bytes);

            Assert.AreEqual(expectedValue.Item, actualValue.Item, nameof(expectedValue.Item));

            expectedValue = new v11.Datatypes.DataValue {
                Item = 1.2
            };
            bytes       = expectedValue.EncodeToBytes();
            actualValue = EtpExtensions.DecodeFromBytes <v11.Datatypes.DataValue>(bytes);

            Assert.AreEqual(expectedValue.Item, actualValue.Item, nameof(expectedValue.Item));

            expectedValue = new v11.Datatypes.DataValue {
                Item = "test"
            };
            bytes       = expectedValue.EncodeToBytes();
            actualValue = EtpExtensions.DecodeFromBytes <v11.Datatypes.DataValue>(bytes);

            Assert.AreEqual(expectedValue.Item, actualValue.Item, nameof(expectedValue.Item));

            var expectedProtocol = new v11.Datatypes.SupportedProtocol {
                Protocol = 1, ProtocolVersion = expectedVersion, ProtocolCapabilities = new Dictionary <string, v11.Datatypes.DataValue> {
                    ["test"] = expectedValue
                }, Role = "store"
            };

            bytes = expectedProtocol.EncodeToBytes();
            var actualProtocol = EtpExtensions.DecodeFromBytes <v11.Datatypes.SupportedProtocol>(bytes);

            Assert.AreEqual(expectedProtocol.Protocol, actualProtocol.Protocol, nameof(expectedProtocol.Protocol));
            Assert.AreEqual(expectedProtocol.ProtocolVersion.Major, actualProtocol.ProtocolVersion.Major, nameof(expectedProtocol.ProtocolVersion.Major));
            Assert.AreEqual(expectedProtocol.ProtocolVersion.Minor, actualProtocol.ProtocolVersion.Minor, nameof(expectedProtocol.ProtocolVersion.Minor));
            Assert.AreEqual(expectedProtocol.ProtocolVersion.Revision, actualProtocol.ProtocolVersion.Revision, nameof(expectedProtocol.ProtocolVersion.Revision));
            Assert.AreEqual(expectedProtocol.ProtocolVersion.Patch, actualProtocol.ProtocolVersion.Patch, nameof(expectedProtocol.ProtocolVersion.Patch));
            Assert.AreEqual(expectedProtocol.Role, actualProtocol.Role, nameof(expectedProtocol.Role));
            Assert.AreEqual(1, actualProtocol.ProtocolCapabilities.Count, nameof(expectedProtocol.ProtocolCapabilities.Count));
            Assert.AreEqual(expectedValue.Item, actualProtocol.ProtocolCapabilities["test"].Item);

            var expectedRequestSession = new v11.Protocol.Core.RequestSession
            {
                ApplicationName    = "Application",
                ApplicationVersion = "Version",
                RequestedProtocols = new List <v11.Datatypes.SupportedProtocol> {
                    expectedProtocol
                },
                SupportedObjects = new List <string> {
                    "object"
                },
            };

            bytes = expectedRequestSession.EncodeToBytes();
            var actualRequestSession = EtpExtensions.DecodeFromBytes <v11.Protocol.Core.RequestSession>(bytes);

            Assert.AreEqual(expectedRequestSession.ApplicationName, actualRequestSession.ApplicationName, nameof(expectedRequestSession.ApplicationName));
            Assert.AreEqual(expectedRequestSession.ApplicationVersion, actualRequestSession.ApplicationVersion, nameof(expectedRequestSession.ApplicationVersion));
            Assert.AreEqual(expectedRequestSession.RequestedProtocols.Count, actualRequestSession.RequestedProtocols.Count, nameof(expectedRequestSession.RequestedProtocols.Count));
            Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].Protocol, actualRequestSession.RequestedProtocols[0].Protocol);
            Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].ProtocolVersion.Major, actualRequestSession.RequestedProtocols[0].ProtocolVersion.Major);
            Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].ProtocolVersion.Minor, actualRequestSession.RequestedProtocols[0].ProtocolVersion.Minor);
            Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].ProtocolVersion.Revision, actualRequestSession.RequestedProtocols[0].ProtocolVersion.Revision);
            Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].ProtocolVersion.Patch, actualRequestSession.RequestedProtocols[0].ProtocolVersion.Patch);
            Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].Role, actualRequestSession.RequestedProtocols[0].Role);
            Assert.AreEqual(1, actualRequestSession.RequestedProtocols[0].ProtocolCapabilities.Count);
            Assert.AreEqual(expectedValue.Item, actualProtocol.ProtocolCapabilities["test"].Item);
            Assert.AreEqual(expectedRequestSession.SupportedObjects.Count, actualRequestSession.SupportedObjects.Count, nameof(expectedRequestSession.SupportedObjects.Count));
            Assert.AreEqual(expectedRequestSession.SupportedObjects[0], actualRequestSession.SupportedObjects[0]);

            var expectedHeader = new v11.Datatypes.MessageHeader {
                MessageFlags = 0, Protocol = 1, MessageId = 2, CorrelationId = 3, MessageType = 4
            };
            var expectedMessage = new EtpMessage <v11.Protocol.Core.RequestSession>(expectedHeader, expectedRequestSession);

            bytes = expectedMessage.Encode();

            using (var inputStream = new MemoryStream(bytes))
                using (var decoder = new BinaryAvroDecoder(inputStream))
                {
                    var actualHeader = decoder.DecodeAvroObject <v11.Datatypes.MessageHeader>();
                    var actualBody   = decoder.DecodeAvroObject <v11.Protocol.Core.RequestSession>();

                    Assert.AreEqual(expectedHeader.MessageFlags, actualHeader.MessageFlags, nameof(expectedHeader.MessageFlags));
                    Assert.AreEqual(expectedHeader.Protocol, actualHeader.Protocol, nameof(expectedHeader.Protocol));
                    Assert.AreEqual(expectedHeader.MessageId, actualHeader.MessageId, nameof(expectedHeader.MessageId));
                    Assert.AreEqual(expectedHeader.CorrelationId, actualHeader.CorrelationId, nameof(expectedHeader.CorrelationId));
                    Assert.AreEqual(expectedHeader.MessageType, actualHeader.MessageType, nameof(expectedHeader.MessageType));

                    Assert.AreEqual(expectedRequestSession.ApplicationName, actualBody.ApplicationName, nameof(expectedRequestSession.ApplicationName));
                    Assert.AreEqual(expectedRequestSession.ApplicationVersion, actualBody.ApplicationVersion, nameof(expectedRequestSession.ApplicationVersion));
                    Assert.AreEqual(expectedRequestSession.RequestedProtocols.Count, actualBody.RequestedProtocols.Count, nameof(expectedRequestSession.RequestedProtocols.Count));
                    Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].Protocol, actualBody.RequestedProtocols[0].Protocol);
                    Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].ProtocolVersion.Major, actualBody.RequestedProtocols[0].ProtocolVersion.Major);
                    Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].ProtocolVersion.Minor, actualBody.RequestedProtocols[0].ProtocolVersion.Minor);
                    Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].ProtocolVersion.Revision, actualBody.RequestedProtocols[0].ProtocolVersion.Revision);
                    Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].ProtocolVersion.Patch, actualBody.RequestedProtocols[0].ProtocolVersion.Patch);
                    Assert.AreEqual(expectedRequestSession.RequestedProtocols[0].Role, actualBody.RequestedProtocols[0].Role);
                    Assert.AreEqual(1, actualBody.RequestedProtocols[0].ProtocolCapabilities.Count);
                    Assert.AreEqual(expectedValue.Item, actualProtocol.ProtocolCapabilities["test"].Item);
                    Assert.AreEqual(expectedRequestSession.SupportedObjects.Count, actualBody.SupportedObjects.Count, nameof(expectedRequestSession.SupportedObjects.Count));
                    Assert.AreEqual(expectedRequestSession.SupportedObjects[0], actualBody.SupportedObjects[0]);
                }
        }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DualResponseEventArgs{TRequest, TResponse1, TResponse2}"/> class.
 /// </summary>
 /// <param name="request">The original request message.</param>
 /// <param name="response1">The first type of response message.</param>
 /// <param name="response1">The second type of response message.</param>
 /// <param name="exception">The protocol exception.</param>
 public DualResponseEventArgs(EtpMessage <TRequest> request, EtpMessage <TResponse1> response1)
     : base(request, null)
 {
     Response1 = response1;
 }
Example #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapRequestWithContextEventArgs{TRequest, TResponse, TContext}"/> class.
 /// </summary>
 /// <param name="request">The request message.</param>
 public MapRequestWithContextEventArgs(EtpMessage <TRequest> request)
     : base(request)
 {
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResponseEventArgsBase{TRequest}"/> class.
 /// </summary>
 /// <param name="request">The original request message that the message is in response to.</param>
 /// <param name="exception">The protocol exception received in response to the request, if any.</param>
 public ResponseEventArgsBase(EtpMessage <TRequest> request, EtpMessage <IProtocolException> exception)
 {
     Request   = request;
     Exception = exception;
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapRequestWithDataEventArgs{TRequest, TData, TResponse}"/> class.
 /// </summary>
 /// <param name="request">The request message.</param>
 /// <param name="data">The request data.</param>
 public MapRequestWithDataEventArgs(EtpMessage <TRequest> request, EtpMessage <TData> data)
     : base(request)
 {
     Data = data;
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResponseEventArgs{TRequest, TResponse}"/> class.
 /// </summary>
 /// <param name="request">The original request message.</param>
 /// <param name="exception">The protocol exception.</param>
 public ResponseEventArgs(EtpMessage <TRequest> request, EtpMessage <TResponse> response)
     : base(request, null)
 {
     Response = response;
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapAndListRequestEventArgs{TRequest, TResponse1, TResponse2}"/> class.
 /// </summary>
 /// <param name="request">The request message.</param>
 public MapAndListRequestEventArgs(EtpMessage <TRequest> request)
     : base(request)
 {
 }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FireAndForgetEventArgs{TMessage}"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 public FireAndForgetEventArgs(EtpMessage <TMessage> message)
 {
     Message = message;
 }
Example #23
0
 /// <summary>
 /// Initializes a new <see cref="EtpSubscription"/> instance.
 /// </summary>
 /// <param name="uuid">The subscription UUID.</param>
 /// <param name="message">The subscription message.</param>
 /// <param name="subscription">The subscription.</param>
 public EtpSubscription(Guid uuid, EtpMessage message, object subscription)
 {
     Uuid         = uuid;
     Message      = message;
     Subscription = subscription;
 }