public void FromMessage()
        {
            var translator = new EndpointInteractionInformationResponseConverter();

            var msg = new EndpointInteractionInformationResponseMessage(
                new EndpointId("a"),
                new MessageId(),
                InteractionConnectionState.Denied);
            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(EndpointInteractionInformationResponseData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(msg.State.ToString(), ((EndpointInteractionInformationResponseData)data).State);
        }
Esempio n. 2
0
        /// <summary>
        /// Continues the handshake process between the current endpoint and the specified endpoint.
        /// </summary>
        /// <param name="connection">The ID of the endpoint that started the handshake.</param>
        /// <param name="subjectGroups">The handshake information for the endpoint.</param>
        /// <param name="messageId">The ID of the message that carried the handshake information.</param>
        public void ContinueHandshakeWith(EndpointId connection, CommunicationSubjectGroup[] subjectGroups, MessageId messageId)
        {
            bool shouldSendConnect;

            lock (m_Lock)
            {
                StorePotentialEndpoint(connection);
                if (!m_EndpointApprovalState.ContainsKey(connection))
                {
                    return;
                }

                var tickList = m_EndpointApprovalState[connection];
                tickList.HaveReceivedSubjects = true;

                bool foundAtLeastOneSubjectMatch = false;
                foreach (var subject in m_InteractionSubjects.RequiredSubjects())
                {
                    if (!m_InteractionSubjects.ContainsGroupRequirementsForSubject(subject))
                    {
                        continue;
                    }

                    var providedGroup = subjectGroups.FirstOrDefault(s => s.Subject.Equals(subject));
                    if (providedGroup == null)
                    {
                        continue;
                    }

                    var haveRequiredTypesForSubject = true;
                    var commands = new List <OfflineTypeInformation>();

                    var requiredGroup = m_InteractionSubjects.GroupRequirementsFor(subject);
                    foreach (var requiredCommandType in requiredGroup.Commands)
                    {
                        var providedCommand = providedGroup.Commands.FirstOrDefault(c => requiredCommandType.IsPartialMatch(c));
                        if (providedCommand == null)
                        {
                            haveRequiredTypesForSubject = false;
                            break;
                        }

                        var bestMatch = requiredCommandType.HighestVersionMatch(providedCommand);
                        commands.Add(bestMatch);
                    }

                    var notifications = new List <OfflineTypeInformation>();
                    if (haveRequiredTypesForSubject)
                    {
                        foreach (var requiredNotificationType in requiredGroup.Notifications)
                        {
                            var providedNotification = providedGroup.Notifications.FirstOrDefault(n => requiredNotificationType.IsPartialMatch(n));
                            if (providedNotification == null)
                            {
                                haveRequiredTypesForSubject = false;
                                break;
                            }

                            var bestMatch = requiredNotificationType.HighestVersionMatch(providedNotification);
                            notifications.Add(bestMatch);
                        }
                    }

                    if (haveRequiredTypesForSubject)
                    {
                        tickList.SelectedCommands.AddRange(commands);
                        tickList.SelectedNotifications.AddRange(notifications);

                        foundAtLeastOneSubjectMatch = true;
                    }
                }

                var state   = foundAtLeastOneSubjectMatch ? InteractionConnectionState.Desired : InteractionConnectionState.Neutral;
                var message = new EndpointInteractionInformationResponseMessage(
                    m_Current,
                    messageId,
                    state);
                m_SendMessage(connection, message, CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending);
                tickList.SendResponse = state;

                if (tickList.IsComplete())
                {
                    CloseOrApproveConnection(connection);
                }

                shouldSendConnect = !tickList.HaveSendSubjects;
            }

            if (shouldSendConnect)
            {
                InitiateHandshakeWith(connection);
            }
        }