Пример #1
0
 public override string Evaluate(Token token)
 {
     TraceLog.Info("Entering CBR: " + Name);
     XDocument testedDocument = Config.TestedSelection.GetSelectedDocument(token);
     string targetNodeName = evaluator.GetTargetNodeName(testedDocument);
     return targetNodeName;
 }
Пример #2
0
        public void FinishToken(string updatingProcessorName, Token targetToken,
            SerializableXDocument resultMessage)
        {
            lock (syncLock)
            {
                MessageFlowState messageflowState = targetToken.GetMessageFlowState();
                if (messageflowState.AssignedProcessor == updatingProcessorName)
                {
                    storage.UpdateToken(targetToken, delegate(Token token)
                    {
                        token.UpdateMessageFlowState(mfs => { mfs.LastResponseFromProcessor = DateTime.Now; });
                    });

                    XDocument sourceMetadata = targetToken.GetSourceMetadata();
                    var sourceAdress = targetToken.GetSourceAddress();
                    if (sourceAdress != null)
                    {
                        string sourceGatewayName = sourceAdress.GatewayName;
                        GatewayAccessor sourceGateway = componentsAccessors.Values.OfType<GatewayAccessor>().SingleOrDefault(gwa => gwa.ComponentName == sourceGatewayName);
                        sourceGateway.ReceiveReturn(targetToken.Guid, resultMessage, new SerializableXDocument(sourceMetadata));
                    }

                    storage.UpdateToken(targetToken, delegate(Token token)
                    {
                        token.State = TokenState.Finished;
                    });
                }
            }
        }
Пример #3
0
        public void Evaluate(Token token)
        {
            TraceLog.Info(string.Format("Entering XSL transformation of '{0}' to message '{1}'",
                inputMessageSelection.SelectionPattern, outputMessageName));

            XDocument inputMessage = inputMessageSelection.GetSelectedDocument(token);
            var reader = inputMessage.Root.CreateReader();

            XDocument outputMessage;
            if (xslTransform.OutputSettings.OutputMethod != XmlOutputMethod.Xml) {
                StringWriter writer = new StringWriter();
                XmlDocument xmlInputMessage = new XmlDocument();
                xmlInputMessage.Load(reader);
                xslTransform.Transform(xmlInputMessage, null, writer);
                string result = writer.ToString();
                outputMessage = new XDocument(new XElement(XName.Get("content")));
                outputMessage.Root.Value = result;
            } else {
                StringBuilder outputBuilder = new StringBuilder();
                var writer = XmlWriter.Create(outputBuilder);
                xslTransform.Transform(reader, writer);
                outputMessage = XDocument.Parse(outputBuilder.ToString());
            }

            ProcessorService.CreateMessage(token, outputMessageName, outputMessage);
        }
Пример #4
0
        public override string Evaluate(Token token)
        {
            TraceLog.Info("Entering terminator: " + Name);
            XDocument resultMessage = null;
            if (Config.IsReturningOutput)
            {
                resultMessage = Config.ResultMessageSelection.GetSelectedDocument(token);
            }

            ProcessorService.FinishToken(token, resultMessage);
            return null;
        }
Пример #5
0
 public void AddMessageToToken(string updatingProcessorName, Token targetToken,
     string messageName, SerializableXDocument message)
 {
     lock (syncLock)
     {
         storage.UpdateToken(targetToken, delegate(Token token)
         {
             MessageFlowState messageflowState = token.GetMessageFlowState();
             if (messageflowState.AssignedProcessor == updatingProcessorName)
             {
                 token.UpdateMessageFlowState(mfs => { mfs.LastResponseFromProcessor = DateTime.Now; });
                 token.AddMessage(messageName, message);
             }
         });
     }
 }
Пример #6
0
 public override string Evaluate(Token token)
 {
     TraceLog.Info("Evaluating action: " + Name);
     Parallel.ForEach(actions, delegate(IActionPlugin action)
     {
         try
         {
             action.Evaluate(token);
         }
         catch (Exception ex)
         {
             ProcessorService.AddExceptionToToken(token, ex);
         }
     });
     return Config.NextNode.Name;
 }
Пример #7
0
 public void AddExceptionToToken(string updatingProcessorName, Token targetToken,
     string sourceNodeName, string message, string stackTrace)
 {
     lock (syncLock)
     {
         storage.UpdateToken(targetToken, delegate(Token token)
         {
             MessageFlowState messageflowState = token.GetMessageFlowState();
             if (messageflowState.AssignedProcessor == updatingProcessorName)
             {
                 token.UpdateMessageFlowState(mfs => { mfs.LastResponseFromProcessor = DateTime.Now; });
                 token.AddException(sourceNodeName, message, stackTrace);
             }
         });
     }
 }
Пример #8
0
 public void AddWork(Token token)
 {
     TraceLog.Info("Processor received a token with GUID " + token.Guid);
     lock (addWorkLock)
     {
         if (isStopping)
         {
             throw new InvalidOperationException(string.Format(
                 "Cannot add token with GUID '{0}' the a processor because it is just stopping.",
                 token.Guid));
         }
         if (token.State != TokenState.Finished)
         {
             tokensFinishedEvent.Reset();
             Interlocked.Increment(ref tokensCount);
             tokensToProcess.Add(token);
         }
     }
 }
Пример #9
0
        public void Evaluate(Token token)
        {
            TraceLog.Info(string.Format("Sending '{0}' to output endpoint '{1}'", messageSelection.SelectionPattern, targetEndpoint.ToString()));

            XDocument message = messageSelection.GetSelectedDocument(token);
            XDocument metadata = metadataSelection.GetSelectedDocument(token);

            XDocument outputMessage = null;
            Task sendTask = Task.Factory.StartNew(
                TraceLog.WrapWithExceptionLogging(delegate
                {
                    outputMessage = processorService.SendMessage(targetEndpoint, message, metadata);
                }));
            bool isFinished = sendTask.Wait(TimeSpan.FromSeconds(timeoutInSeconds));

            if (isFinished)
            {
                if (resultMessageName.Trim().Length > 0)
                {
                    processorService.CreateMessage(token, resultMessageName.Trim(),
                        outputMessage);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Dispatches the token to the processor.
        /// </summary>
        /// <param name="token"></param>
        public void Dispatch(Token token)
        {
            if (isStopping)
            {
                return;
            }
            lock (tokenDispatchingLock)
            {
                MessageFlowState messageflowState = token.GetMessageFlowState();
                if (messageflowState.AssignedProcessor != null)
                {
                    return; // Token is already dispatched
                }

                // NOTE: it compares to default GUID returned by the new Guid()
                if (messageflowState.MessageFlowGuid == new Guid())
                {
                    token = brokerService.UpdateTokenMessageFlow(token.Guid, messageFlowGuid);
                }
                try
                {
                    TraceLog.Info(string.Format(
                        "Dispatcher assigning token '{0}' to processor '{1}'",
                        token.Guid, processor.ComponentName));
                    token = brokerService.UpdateTokenLastResponseFromProcessor(token.Guid, DateTime.Now);
                    token = brokerService.UpdateTokenAssignedProcessor(token.Guid, processor.ComponentName);
                    token.State = TokenState.InProcessor;
                    processor.AddWork(token);
                }
                catch
                {
                    // NOTE: token retains the Received state
                    brokerService.UpdateTokenAssignedProcessor(token.Guid, null);
                }
            }
        }
Пример #11
0
 /// <summary>
 /// Finishes the token processing. It changes only the token state, not
 /// the message flow. Also it might send a reply message back to the
 /// source gateway.
 /// </summary>
 /// <param name="token">token to be finished</param>
 /// <param name="resultMessage">reply message going back the the original
 /// gateway; can be null</param>
 public void FinishToken(Token token, XDocument resultMessage)
 {
     SerializableXDocument serializableResultMessage = new SerializableXDocument(resultMessage);
     BrokerService.FinishToken(ProcessorName, token,
         serializableResultMessage);
 }
Пример #12
0
 private IEnumerable<Token> CreateTokens(IEnumerable<string> tokensXml)
 {
     List<Token> result = new List<Token>();
     foreach (string tokenXml in tokensXml) {
         Token token = new Token(tokenXml);
         result.Add(token);
     }
     return result;
 }
Пример #13
0
 /// <summary>
 /// Updates a token and stores the content into an exiting instance.
 /// </summary>
 /// <remarks>
 /// Loads a token specified by its GUID from the storage, updates it
 /// with a provided action, saves it and returns the provided token
 /// instance only with updated content.
 /// </remarks>
 /// <param name="token"></param>
 /// <param name="updater"></param>
 public void UpdateToken(Token token, Action<Token> updater)
 {
     lock (updateTokenLock) {
         Token currentToken = GetToken(token.Guid);
         updater(currentToken);
         SaveToken(currentToken);
         token.UpdateContent(currentToken.Content);
     }
 }
Пример #14
0
 public void SaveToken(Token token)
 {
     dataAccess.SaveToken(token);
 }
Пример #15
0
 public Token GetToken(Guid tokenGuid)
 {
     // TODO: what about GUID of a non-existent token
     string tokenXml = dataAccess.LoadToken(tokenGuid);
     Token result = new Token(tokenGuid, tokenXml);
     return result;
 }
Пример #16
0
 public void UpdateTokenMessageFlowState(string updatingProcessorName, Token targetToken,
     MessageFlowState messageFlowState)
 {
     lock (syncLock)
     {
         storage.UpdateToken(targetToken, delegate(Token token)
         {
             if (messageFlowState.AssignedProcessor == updatingProcessorName)
             {
                 messageFlowState.LastResponseFromProcessor = DateTime.Now;
                 token.SetMessageFlowState(messageFlowState);
             }
         });
     }
 }
Пример #17
0
        /// <summary>
        /// Receives an input message containing XML data in an XDocument.
        /// </summary>
        /// <remarks>
        /// This method is asynchronous and can simulate synchronous
        /// communication. The reply is send back from within a given result
        /// handler and a context is preseved.
        /// </remarks>
        /// <param name="message">XML message content in an XDocument</param>
        /// <param name="endpointName">input endpoint name; can be null</param>
        /// <param name="metadata">metadata about the input message; can be null</param>
        /// <param name="context">arbitrary context which should be retained
        /// until a possible reply; can be null</param>
        /// <param name="resultHandler">action to be performed with the reply
        /// message when the token processing has been finished</param>
        protected void ReceiveMessageXml(
            XDocument message,
            string endpointName,
            XDocument metadata,
            object context,
            MessageResultHandler resultHandler)
        {
            Token token = new Token();

            token.IsPersistent = AreInputTokensPersistent;
            token.SetSourceAddress(new EndpointAddress(Gateway.Name, AdapterName, endpointName));
            token.SaveSourceMetadata(metadata);
            token.AddMessage(Constants.InputMessageName, message);
            TraceLog.Info("Created token with GUID " + token.Guid);
            Gateway.ReceiveToken(token, context, resultHandler);
        }
Пример #18
0
        public void SaveToken(Token token)
        {
            string tokenXml = token.Content.XDocument.ToString();
            string inputMessage = token.GetMessage("input").ToString();
            EndpointAddress endpointAddress = token.GetSourceAddress();

            ExecuteProcedure("SaveToken",
                new SqlParameter[]
                {
                    new SqlParameter("InputGUID", token.Guid),
                    new SqlParameter("Token", tokenXml),
                    new SqlParameter("TokenState", token.State.ToString()),
                    new SqlParameter("Message", inputMessage),
                    (token.Created == DateTime.MinValue ? new SqlParameter("Created", DBNull.Value): new SqlParameter("Created", token.Created)),
                    (token.Received == DateTime.MinValue ? new SqlParameter("Received", DBNull.Value): new SqlParameter("Received", token.Received)),
                    (token.Dispatched == DateTime.MinValue ? new SqlParameter("Dispatched", DBNull.Value): new SqlParameter("Dispatched", token.Dispatched)),
                    (token.Finished == DateTime.MinValue ? new SqlParameter("Finished", DBNull.Value): new SqlParameter("Finished", token.Finished)),
                    new SqlParameter("IsPersistent", token.IsPersistent),
                    new SqlParameter("AdapterName", endpointAddress.AdapterName),
                    new SqlParameter("EndpointName", endpointAddress.EndpointName)
                }).Close();
        }
Пример #19
0
 /// <summary>
 /// Adds an exception to the token along with the name of the node
 /// where the exception was thrown.
 /// </summary>
 /// <param name="targetToken">token to which to add the exception
 /// </param>
 /// <param name="ex">exception to be added to the token</param>
 /// <param name="updatedToken">updated token</param>
 public void AddExceptionToToken(Token targetToken, Exception ex)
 {
     BrokerService.AddExceptionToToken(ProcessorName, targetToken,
         Node.Name, ex.Message, ex.StackTrace);
 }
Пример #20
0
        /// <summary>
        /// Performs a single step in the message flow graph traversal. This
        /// corresponds to moving along an edge from one node to another.
        /// </summary>
        /// <remarks>
        /// After each step the message flow state is saved to the token.
        /// </remarks>
        /// <param name="token">token to be processed</param>
        /// <returns>true if the traversal should continue; false if it has
        /// finished</returns>
        public bool DoStep(Token token)
        {
            #region Determine currentNode
            Node currentNode;
            string currentNodeName = token.GetMessageFlowState().NextNodeName;
            if (currentNodeName != null) {
                currentNode = nodesByName[currentNodeName];
            }
            else {
                currentNode = entryNode;
            }
            #endregion

            string nextNodeName = currentNode.Evaluate(token);

            MessageFlowState messageflowState = token.GetMessageFlowState();
            messageflowState.NextNodeName = nextNodeName;
            token.SetMessageFlowState(messageflowState);

            if ((token.IsPersistent) && (!(currentNode is CbrNode))) {
                Processor.BrokerService.UpdateTokenMessageFlowState(
                    Processor.Name, token, messageflowState);
            }

            bool shouldContinue = nextNodeName != null;
            return shouldContinue;
        }
Пример #21
0
 /// <summary>
 /// Creates a new message within the token.
 /// </summary>
 /// <param name="targetToken">token to which to add the new message
 /// </param>
 /// <param name="messageName">name of the new message</param>
 /// <param name="message">message content</param>
 /// <returns>updated token</returns>
 public void CreateMessage(
     Token targetToken,
     string messageName,
     XDocument message)
 {
     BrokerService.AddMessageToToken(ProcessorName, targetToken,
         messageName, new SerializableXDocument(message));
 }
Пример #22
0
 /// <summary>
 /// Evaluates the node with the given token.
 /// </summary>
 /// <param name="token"></param>
 /// <returns>
 /// Name of the next node or null if the processing is terminated.
 /// </returns>
 public abstract string Evaluate(Token token);
Пример #23
0
 public TokenRow(Token token)
 {
     Guid = token.Guid.ToString();
     State = token.State.ToString();
     ContentWithEnters = token.Content.XDocument.ToString();
     Content = ContentWithEnters.Replace(Environment.NewLine, " ");
 }
Пример #24
0
 public override string Evaluate(Token token)
 {
     return Config.NextNode.Name;
 }
Пример #25
0
 /// <summary>
 /// Persistently updates the state of the message flow of a given
 /// token, ie. the state of its processing.
 /// </summary>
 /// <param name="token">token to be updated</param>
 /// <seealso cref="XRouter.Common.MessageFlowState"/>
 public void MakeMessageFlowStatePersistent(Token token)
 {
     BrokerService.UpdateTokenMessageFlowState(ProcessorName, token,
         token.GetMessageFlowState());
 }
Пример #26
0
 public void SaveToken(Token token)
 {
     SaveToken(token.Guid, token.Content.XDocument.ToString());
 }
Пример #27
0
 public void AddWork(Token token)
 {
     processor.AddWork(token);
 }
Пример #28
0
 internal void ReceiveToken(Token token, object context, MessageResultHandler resultHandler = null)
 {
     if (resultHandler != null)
     {
         ResultHandlingInfo resultHandlingInfo = new ResultHandlingInfo(token.Guid, resultHandler, context);
         waitingResultMessageHandlers.AddOrUpdate(token.Guid, resultHandlingInfo, (key, oldValue) => resultHandlingInfo);
     }
     Broker.ReceiveToken(token);
 }
Пример #29
0
 public void ReceiveToken(Token token)
 {
     lock (syncLock)
     {
         token.State = TokenState.Received;
         storage.SaveToken(token);
         dispatcher.Dispatch(token);
     }
 }