Пример #1
0
        private void InitiateHandshakeWith(EndpointId endpoint)
        {
            lock (m_Lock)
            {
                if (!m_EndpointApprovalState.ContainsKey(endpoint))
                {
                    return;
                }

                var interactionInformation = new List <CommunicationSubjectGroup>();
                foreach (var subject in m_InteractionSubjects.ProvidedSubjects())
                {
                    if (m_InteractionSubjects.ContainsGroupProvisionsForSubject(subject))
                    {
                        interactionInformation.Add(m_InteractionSubjects.GroupProvisionsFor(subject));
                    }
                }

                Debug.Assert(m_EndpointApprovalState.ContainsKey(endpoint), "The endpoint tick list is not stored.");
                var tickList = m_EndpointApprovalState[endpoint];
                tickList.HaveSendSubjects = true;

                // Send message and wait for response.
                var message = new EndpointInteractionInformationMessage(
                    m_Current,
                    interactionInformation.ToArray());
                var sendTask = m_SendMessageAndWaitForResponse(
                    endpoint,
                    message,
                    CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending,
                    m_SendTimeout);
                sendTask.ContinueWith(HandleResponseToInteractionMessage, TaskContinuationOptions.ExecuteSynchronously);
            }
        }
        public void Create()
        {
            var id    = new EndpointId("a");
            var group = new[]
            {
                new CommunicationSubjectGroup(
                    new CommunicationSubject("a"),
                    new[]
                {
                    new VersionedTypeFallback(
                        new Tuple <OfflineTypeInformation, Version>(
                            new OfflineTypeInformation(
                                typeof(int).FullName,
                                typeof(int).Assembly.GetName()),
                            new Version(1, 0))),
                },
                    new[]
                {
                    new VersionedTypeFallback(
                        new Tuple <OfflineTypeInformation, Version>(
                            new OfflineTypeInformation(
                                typeof(double).FullName,
                                typeof(double).Assembly.GetName()),
                            new Version(1, 2))),
                }),
            };
            var msg = new EndpointInteractionInformationMessage(id, group);

            Assert.AreSame(id, msg.Sender);
            Assert.AreSame(group, msg.SubjectGroups);
        }
        public void Invoke()
        {
            var endpoint = new EndpointId("a");
            var group    = new[]
            {
                new CommunicationSubjectGroup(
                    new CommunicationSubject("a"),
                    new[]
                {
                    new VersionedTypeFallback(
                        new Tuple <OfflineTypeInformation, Version>(
                            new OfflineTypeInformation(
                                typeof(int).FullName,
                                typeof(int).Assembly.GetName()),
                            new Version(1, 0))),
                },
                    new[]
                {
                    new VersionedTypeFallback(
                        new Tuple <OfflineTypeInformation, Version>(
                            new OfflineTypeInformation(
                                typeof(double).FullName,
                                typeof(double).Assembly.GetName()),
                            new Version(1, 2))),
                }),
            };
            var message = new EndpointInteractionInformationMessage(endpoint, group);

            var handshake = new Mock <IHandleInteractionHandshakes>();
            {
                handshake.Setup(h => h.ContinueHandshakeWith(It.IsAny <EndpointId>(), It.IsAny <CommunicationSubjectGroup[]>(), It.IsAny <MessageId>()))
                .Callback <EndpointId, CommunicationSubjectGroup[], MessageId>(
                    (e, c, m) =>
                {
                    Assert.AreSame(endpoint, e);
                    Assert.AreSame(group, c);
                    Assert.AreSame(message.Id, m);
                })
                .Verifiable();
            }

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var action = new EndpointInteractionInformationProcessAction(handshake.Object, systemDiagnostics);

            action.Invoke(message);

            handshake.Verify(
                h => h.ContinueHandshakeWith(It.IsAny <EndpointId>(), It.IsAny <CommunicationSubjectGroup[]>(), It.IsAny <MessageId>()),
                Times.Once());
        }
Пример #4
0
        public void FromMessage()
        {
            var translator = new EndpointInteractionInformationConverter();

            var msg = new EndpointInteractionInformationMessage(
                new EndpointId("a"),
                new[]
            {
                new CommunicationSubjectGroup(
                    new CommunicationSubject("a"),
                    new[]
                {
                    new VersionedTypeFallback(
                        new Tuple <OfflineTypeInformation, Version>(
                            new OfflineTypeInformation(
                                typeof(int).FullName,
                                typeof(int).Assembly.GetName()),
                            new Version(1, 0))),
                },
                    new[]
                {
                    new VersionedTypeFallback(
                        new Tuple <OfflineTypeInformation, Version>(
                            new OfflineTypeInformation(
                                typeof(double).FullName,
                                typeof(double).Assembly.GetName()),
                            new Version(1, 2))),
                }),
            });
            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(EndpointInteractionInformationData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(msg.SubjectGroups.Length, ((EndpointInteractionInformationData)data).Groups.Length);

            Assert.AreEqual(
                msg.SubjectGroups[0].Subject,
                new CommunicationSubject(((EndpointInteractionInformationData)data).Groups[0].Subject));
            Assert.AreEqual(
                msg.SubjectGroups[0].Commands.Length,
                ((EndpointInteractionInformationData)data).Groups[0].Commands.Length);
            Assert.AreEqual(1, ((EndpointInteractionInformationData)data).Groups[0].Commands[0].Types.Length);
            Assert.AreEqual(
                typeof(int).FullName,
                ((EndpointInteractionInformationData)data).Groups[0].Commands[0].Types[0].Type.FullName);
            Assert.AreEqual(
                typeof(int).Assembly.GetName().Name,
                ((EndpointInteractionInformationData)data).Groups[0].Commands[0].Types[0].Type.AssemblyName);
            Assert.AreEqual(
                new Version(1, 0),
                ((EndpointInteractionInformationData)data).Groups[0].Commands[0].Types[0].Version);
            Assert.AreEqual(
                msg.SubjectGroups[0].Notifications.Length,
                ((EndpointInteractionInformationData)data).Groups[0].Notifications.Length);
            Assert.AreEqual(1, ((EndpointInteractionInformationData)data).Groups[0].Notifications[0].Types.Length);
            Assert.AreEqual(
                typeof(double).FullName,
                ((EndpointInteractionInformationData)data).Groups[0].Notifications[0].Types[0].Type.FullName);
            Assert.AreEqual(
                typeof(double).Assembly.GetName().Name,
                ((EndpointInteractionInformationData)data).Groups[0].Notifications[0].Types[0].Type.AssemblyName);
            Assert.AreEqual(
                new Version(1, 2),
                ((EndpointInteractionInformationData)data).Groups[0].Notifications[0].Types[0].Version);
        }