public void InvokeBehavior(IBuilder builder)
        {
            var runner = new UnitOfWorkBehavior();

            var context = new IncomingContext(new RootContext(builder), new TransportMessage());

            runner.Invoke(context, () => { });

        }
Esempio n. 2
0
        public object MutateIncoming(object message, IncomingContext incomingContext)
        {
            this.incomingContext = incomingContext;

            ForEachMember(
                message,
                DecryptMember,
                IsEncryptedMember
                );

            return(message);
        }
        public void Should_shortcut_the_pipeline_if_existing_message_is_found()
        {
            var incomingTransportMessage = new TransportMessage();

            fakeOutbox.ExistingMessage = new OutboxMessage(incomingTransportMessage.Id);

            var context = new IncomingContext(null, incomingTransportMessage);

            Invoke(context);

            Assert.Null(fakeOutbox.StoredMessage);
        }
Esempio n. 4
0
        public string Decrypt(EncryptedValue encryptedValue, IncomingContext incomingContext)
        {
            string keyIdentifier;

            if (TryGetKeyIdentifierHeader(out keyIdentifier, incomingContext))
            {
                return(DecryptUsingKeyIdentifier(encryptedValue, keyIdentifier));
            }
            else
            {
                Log.WarnFormat("Encrypted message has no '" + Headers.RijndaelKeyIdentifier + "' header. Possibility of data corruption. Please upgrade endpoints that send message with encrypted properties.");
                return(DecryptUsingAllKeys(encryptedValue));
            }
        }
        public void Should_not_dispatch_the_message_if_handle_current_message_later_was_called()
        {
            var incomingTransportMessage = new TransportMessage();


            var context = new IncomingContext(null, incomingTransportMessage)
            {
                handleCurrentMessageLaterWasCalled = true
            };

            Invoke(context);

            Assert.False(fakeOutbox.WasDispatched);
        }
        public void Invoke(IncomingContext context, Action next)
        {
            next();
            var subscriptionMessageType = GetSubscriptionMessageTypeFrom(context.PhysicalMessage);

            if (subscriptionMessageType != null)
            {
                action(new SubscriptionEventArgs
                {
                    MessageType             = subscriptionMessageType,
                    SubscriberReturnAddress = context.PhysicalMessage.ReplyToAddress
                }, scenarioContext);
            }
        }
        public void Should_not_store_the_message_if_handle_current_message_later_was_called()
        {
            var incomingTransportMessage = new TransportMessage();

            var context = new IncomingContext(null, incomingTransportMessage)
            {
                handleCurrentMessageLaterWasCalled = true
            };

            context.Set(new OutboxMessage("SomeId"));

            Invoke(context);

            Assert.Null(fakeOutbox.StoredMessage);
        }
Esempio n. 8
0
        /// <summary>
        /// Incoming call handler.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="CollectionEventArgs{TEntity}"/> instance containing the event data.</param>
        private void CallsOnIncoming(ICallCollection sender, CollectionEventArgs <ICall> args)
        {
            args.AddedResources.ForEach(call =>
            {
                // Get the compliance recording parameters.

                // The context associated with the incoming call.
                IncomingContext incomingContext =
                    call.Resource.IncomingContext;

                // The RP participant.
                string observedParticipantId =
                    incomingContext.ObservedParticipantId;

                // If the observed participant is a delegate.
                IdentitySet onBehalfOfIdentity =
                    incomingContext.OnBehalfOf;

                // If a transfer occured, the transferor.
                IdentitySet transferorIdentity =
                    incomingContext.Transferor;

                string countryCode        = null;
                EndpointType?endpointType = null;

                // Note: this should always be true for CR calls.
                if (incomingContext.ObservedParticipantId == incomingContext.SourceParticipantId)
                {
                    // The dynamic location of the RP.
                    countryCode = call.Resource.Source.CountryCode;

                    // The type of endpoint being used.
                    endpointType = call.Resource.Source.EndpointType;
                }

                IMediaSession mediaSession = Guid.TryParse(call.Id, out Guid callId)
                    ? this.CreateLocalMediaSession(callId)
                    : this.CreateLocalMediaSession();

                // Answer call
                call?.AnswerAsync(mediaSession).ForgetAndLogExceptionAsync(
                    call.GraphLogger,
                    $"Answering call {call.Id} with scenario {call.ScenarioId}.");
            });
        }
Esempio n. 9
0
        private void ProcessMessagesFromBridge()
        {
            using (SqlConnection conn = new SqlConnection(Context.BridgeConnectionString.Invoke()))
            {
                conn.Open();
                string     sql = "SELECT MessageId, Source, Destination, Intent, Processed, Headers, Body FROM [dbo].[Bridge] WHERE Processed = 0 AND (Destination = @Destination OR Destination IS NULL)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@Destination", Settings.EndpointName());
                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    string id        = reader.GetString(reader.GetOrdinal("MessageId"));
                    string source    = reader.GetString(reader.GetOrdinal("Source"));
                    string dest      = reader.IsDBNull(reader.GetOrdinal("Destination")) ? null : reader.GetString(reader.GetOrdinal("Destination"));
                    string intent    = reader.GetString(reader.GetOrdinal("Intent"));
                    var    msgIntent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), intent);
                    Dictionary <string, string> headers = JsonConvert.DeserializeObject <Dictionary <string, string> >(reader.GetString(reader.GetOrdinal("Headers")));
                    var messageTypes = headers[Headers.EnclosedMessageTypes].Split(';').Select(i => Type.GetType(i)).ToList();
                    if (ShouldHandleMessage(dest, messageTypes))
                    {
                        var    bodyStream = reader.GetStream(reader.GetOrdinal("Body"));
                        byte[] body       = new byte[bodyStream.Length];
                        body = GetByteArray(bodyStream);


                        //Let's treat this message as a normal incoming message.
                        var transportMessage = new TransportMessage(id, headers);
                        transportMessage.Body          = body;
                        transportMessage.MessageIntent = msgIntent;
                        var incomingContext = new IncomingContext(null, transportMessage);
                        incomingContext.Set <IBuilder>(Builder);
                        PipelineExecutor.InvokePipeline(PipelineExecutor.Incoming.Select(i => i.BehaviorType), incomingContext);

                        var cmd2 = new SqlCommand("UPDATE [dbo].[Bridge] SET Processed = 1 WHERE MessageId = @MessageId", conn);
                        cmd2.Parameters.AddWithValue("@MessageId", id);
                        cmd2.ExecuteNonQuery();
                    }
                }
            }
        }
Esempio n. 10
0
        protected virtual bool TryGetKeyIdentifierHeader(out string keyIdentifier, IncomingContext incomingContext)
        {
            var headers = incomingContext.IncomingLogicalMessage.Headers;

            return(headers.TryGetValue(Headers.RijndaelKeyIdentifier, out keyIdentifier));
        }
 protected override bool TryGetKeyIdentifierHeader(out string keyIdentifier, IncomingContext incomingContext)
 {
     keyIdentifier = IncomingKeyIdentifier;
     return(IncomingKeyIdentifier != null);
 }