コード例 #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="step"></param>
        /// <param name="exchange"></param>
        /// <param name="routeObj"></param>
        public static void Enrich(XElement step, Exchange exchange, Route routeObj)
        {
            try
            {
                var uri = step.Attribute("uri");
                var strategyref = step.Attribute("strategyref");

                if (uri == null || strategyref == null)
                    return;

                var uriInfo = UriDescriptor.Parse(uri.Value, exchange);
                var clonedExchange = exchange.CloneExchange();
                EndPointBuilder.HandleTo(uriInfo, clonedExchange, routeObj);

                //fetch strategy
                var stragegyObj = Camel.Registry[strategyref.Value] as AggregationStrategy;
                if (stragegyObj != null)
                {
                    stragegyObj.Aggregate(exchange, clonedExchange);
                }
            }
            catch (Exception exc)
            {

            }
        }
コード例 #2
0
        /// <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 = Camel.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.ProcessStep(nextStep, exchange.Route, splitterExchange);
                        }
                        //restore original message
                        exchange.InMessage.Body = originalMessage;
                    }
                    catch (Exception exception)
                    {

                    }
                }
            }
            catch (Exception exception)
            {

            }
        }