Beispiel #1
0
        public static void Execute(XElement loopTag, Exchange exchange, Route route)
        {
            var expressionTag = loopTag.Elements().FirstOrDefault();

            if (expressionTag == null || (expressionTag.Name != "count"))
            {
                return;
            }

            var xpression = expressionTag.Value;
            var count     = SimpleExpression.ResolveSpecifiedUriPart(xpression, exchange);

            var mCount = Convert.ToInt32(count);

            for (var i = 0; i < mCount; i++)
            {
                var data = loopTag.Elements().Skip(1);
                foreach (var dataItem in data)
                {
                    try
                    {
                        RouteStep.ExecuteRouteStep(dataItem, route, exchange);
                    }
                    catch (Exception exception)
                    {
                    }
                }
            }
        }
        public static void Process(XElement multicastElement, Exchange exchange)
        {
            try
            {
                var toElements = multicastElement.Elements("to");
                var xElements  = toElements as XElement[] ?? toElements.ToArray();
                if (!xElements.Any())
                {
                    return;
                }

                foreach (var toTag in xElements)
                {
                    RouteStep.ExecuteRouteStep(toTag, exchange.Route, exchange);
                }
            }
            catch (Exception exception)
            {
            }
        }
        public static void DoWhen(XElement choicElement, Exchange exchange)
        {
            var whenElements = choicElement.Elements("when");
            var passed       = false;

            foreach (var whenElement in whenElements)
            {
                passed = CheckRequiremnt(whenElement, exchange);
                if (!passed)
                {
                    continue;
                }

                var functions = whenElement.Elements().Skip(1);
                foreach (var xmlStep in functions)
                {
                    RouteStep.ExecuteRouteStep(xmlStep, exchange.Route, exchange);
                }
                break;
            }

            if (!passed)
            {
                //handle otherwise
                var otherwiseXml = choicElement.Element("otherwise");
                if (otherwiseXml == null)
                {
                    return;
                }

                var otherwiseFunctions = otherwiseXml.Elements();

                foreach (var xmlStep in otherwiseFunctions)
                {
                    RouteStep.ExecuteRouteStep(xmlStep, exchange.Route, exchange);
                }
            }
        }
        /// <summary>
        /// ProcessChannel
        /// </summary>
        /// <param name="splitElement"></param>
        /// <param name="exchange"></param>
        public static void Execute(XElement splitElement, Exchange exchange)
        {
            try
            {
                if (splitElement == null)
                {
                    return;
                }

                var spliterXml = splitElement.Elements().FirstOrDefault();
                if (spliterXml == null)
                {
                    return;
                }

                ISplitterStrategy strategy = null;
                var strategyAttr           = splitElement.Attribute("strategy");

                if (strategyAttr != null)
                {
                    strategy = SynapseContext.LoadBean(strategyAttr.Value.ToString(CultureInfo.InvariantCulture)) as ISplitterStrategy;
                }

                var result = new List <String>();
                if (strategy != null)
                {
                    result = strategy.Split(exchange);
                }
                else
                {
                    var splitterName = spliterXml.Name.ToString();
                    switch (splitterName)
                    {
                    case "xpath":
                        result = SplitByXPath(spliterXml.Value, exchange);
                        break;

                    case "simple":
                        result = SplitSimple(spliterXml.Value, exchange);
                        break;
                    }
                }

                if (result == null)
                {
                    return;
                }

                var nextSteps = strategy == null?splitElement.Elements().Skip(1) : splitElement.Elements();

                //process each
                foreach (var nextStep in nextSteps)
                {
                    try
                    {
                        //hold original message
                        var originalMessage = exchange.InMessage.Body;
                        foreach (var item in result)
                        {
                            var exchangeMsg = item;

                            var splitterExchange = exchange.CloneExchange(new Message
                            {
                                Body             = exchangeMsg,
                                HeaderCollection = exchange.InMessage.HeaderCollection
                            },
                                                                          new Message(),
                                                                          exchange.Route);

                            RouteStep.ExecuteRouteStep(nextStep, exchange.Route, splitterExchange);
                        }
                        //restore original message
                        exchange.InMessage.Body = originalMessage;
                    }
                    catch (Exception exception)
                    {
                    }
                }
            }
            catch (Exception exception)
            {
            }
        }