コード例 #1
0
        public override Exchange Execute(Exchange exchange)
        {
            Camel.TryLog(exchange, "consumer", _sedaProcessor.UriInformation.ComponentName);

            _sedaProcessor.Process(exchange);
            return exchange;
        }
コード例 #2
0
        public static bool Evaluate(Exchange exchange, string expression)
        {
            try
            {
                var expressionParts = expression.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                var operatorType = expressionParts[1];
                var lhs = expressionParts[0];
                var rhs = expressionParts[2];

                var lhsResult = ResolveSpecifiedUriPart(lhs, exchange);
                var rhsResult = ResolveSpecifiedUriPart(rhs, exchange);

                switch (operatorType)
                {
                    case "=":
                        return lhsResult == rhsResult;
                    case "!=":
                        return lhsResult != rhsResult;
                    case "<=":
                        return lhsResult != rhsResult;
                    case ">=":
                        return lhsResult != rhsResult;

                }
            }
            catch (Exception exception)
            {
            }

            return false;
        }
コード例 #3
0
        public override void Process(Exchange exchange)
        {
            var xE = XElement.Parse(exchange.InMessage.Body.ToString().Replace("\\r\\n", ""));

            var xElement = xE.Element("claim-type");
            if (xElement != null)
            {
                exchange.InMessage.SetHeader("response-message", "ola .. in tcp/ip test processor");

                var ans = DateTime.Now.Second % 3;
                var xml = new XElement("payments",
                    new XElement("code", ans != 0 ? "00" : "91"),
                    new XElement("information", new XElement("payment", new XAttribute("ref", "12345")),
                    new XElement("payment", new XAttribute("ref", "34343")),
                    new XElement("payment", new XAttribute("ref", "33411")),
                    new XElement("payment", new XAttribute("ref", "41445")),
                    new XElement("payment", new XAttribute("ref", "55553")))
                    ).ToString(SaveOptions.DisableFormatting);

                exchange.InMessage.Body = xml;
                exchange.InMessage.SetHeader("email_address", "*****@*****.**");
            }

            exchange.Exception.Push(new Exception("Error processing transaction request"));
        }
コード例 #4
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            try
            {
                var host = endPointDescriptor.GetUriProperty("host");
                var isBodyXml = endPointDescriptor.GetUriProperty<bool>("isBodyXml");
                var database = endPointDescriptor.GetUriProperty("database");
                var collection = endPointDescriptor.GetUriProperty("collection");
                var createCollection = endPointDescriptor.GetUriProperty<bool>("createCollection");
                var operation = endPointDescriptor.GetUriProperty<OperationType>("operation");

                var client = new MongoClient("mongodb://" + host);
                var db = client.GetServer().GetDatabase(database);

                if (!db.CollectionExists(collection) && createCollection)
                    db.CreateCollection(collection);

                var bson = exchange.InMessage.Body.ToString();

                if (isBodyXml)
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(exchange.InMessage.Body.ToString());
                    bson = JsonConvert.SerializeXmlNode(doc);
                }
                var bsonDoc = BsonDocument.Parse(bson);
                ServeOperation(db, exchange, endPointDescriptor, bsonDoc, operation, collection);
            }
            catch (Exception exception)
            {
                Console.WriteLine("{0}-{1}", exception.Message, exception.StackTrace);
            }
            return exchange;
        }
コード例 #5
0
        public static void HandleTransform(XElement step, Route routeObj, Exchange exchange)
        {
            try
            {
                var transformXml = step.Elements().First();
                var opName = transformXml.Name.ToString();

                switch (opName)
                {
                    case "simple":
                        ProcessSimple(transformXml, routeObj, exchange);
                        break;
                    case "xpath":
                        break;
                }
            }
            catch (AggregateException aggregateException)
            {

            }
            catch (Exception exception)
            {

            }
        }
コード例 #6
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            try
            {
                var inReverse = endPointDescriptor.GetUriProperty("reverse", false);
                var useOut = endPointDescriptor.GetUriProperty("useout", false);

                var body = useOut ? exchange.OutMessage.Body.ToString() : exchange.InMessage.Body.ToString();

                if (!inReverse)
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(body);
                    var jsonText = JsonConvert.SerializeXmlNode(doc);
                    exchange.InMessage.Body = jsonText;
                }
                else
                {
                    var doc = JsonConvert.DeserializeXmlNode(body);
                    exchange.InMessage.Body = doc.InnerXml;
                }
                Camel.TryLog(exchange, "processor", endPointDescriptor.ComponentName);
            }
            catch (Exception exception)
            {

            }
            return base.Process(exchange, endPointDescriptor);
        }
コード例 #7
0
        private void ValidateUser(Exchange exchange)
        {
            var token = exchange.InMessage.GetHeader<String>("securityToken");
            if (!string.IsNullOrWhiteSpace(token))
            {
                try
                {
                    var secToken = JWT.JsonWebToken.Decode(token, Encoding.ASCII.GetBytes("password"));
                    var userInfo = JsonConvert.DeserializeObject<UserAuth.UserInfo>(secToken);

                    if (userInfo.Name == "adeola")
                    {
                        var data = new UserAuth { SessionToken = "djsdjhj3i9sdhnw3", ResponseCode = ResponseCode.Success };
                        exchange.InMessage.Body = JsonConvert.SerializeObject(data);
                    }else
                    {
                        var data = new UserAuth { SessionToken = "", ResponseCode = ResponseCode.InCorrectAuthenticationParamaters, ResponseMsg = "Incorrect login details" };
                        exchange.InMessage.Body = JsonConvert.SerializeObject(data);
                    }
                }
                catch (Exception e)
                {
                    var data = new UserAuth { SessionToken = "", ResponseCode = ResponseCode.AuthenticationUnknownError, ResponseMsg = e.Message };
                    exchange.InMessage.Body = JsonConvert.SerializeObject(data);
                }
            }
            else
            {
                var data = new UserAuth { SessionToken = "", ResponseCode = ResponseCode.Unknown };
                exchange.InMessage.Body = JsonConvert.SerializeObject(data);
            }
        }
コード例 #8
0
        public static void DoWhen(XElement choicElement, Exchange exchange)
        {
            var whenElements = choicElement.Elements("when");

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

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

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

            var otherwiseFunctions = otherwiseXml.Elements();

            foreach (var xmlStep in otherwiseFunctions)
            {
                RouteStep.ProcessStep(xmlStep, exchange.Route, exchange);
            }
        }
コード例 #9
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            try
            {
                Camel.TryLog(exchange, "provider", endPointDescriptor.ComponentName);

                var dbHost = endPointDescriptor.ComponentPath;
                var port = endPointDescriptor.GetUriProperty<int>("port");
                var couchDbDatabase = exchange.InMessage.GetHeader("CouchDbDatabase");
                var createDb = endPointDescriptor.GetUriProperty<bool>("createDb");
                var document = exchange.InMessage.Body;

                var dbUrl = string.Format("http://{0}:{1}", dbHost, port);
                var conn = new Connection(new Uri(dbUrl));

                if (createDb && !conn.ListDatabases().Contains(couchDbDatabase))
                {
                    conn.CreateDatabase(couchDbDatabase.ToString());
                }
            }
            catch (Exception exception)
            {
            }

            return base.Process(exchange, endPointDescriptor);
        }
コード例 #10
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <param name="loopTag"></param>
        /// <param name="exchange"></param>
        /// <param name="route"></param>
        public static void Execute(XElement loopTag, Exchange exchange, Route route)
        {
            Camel.TryLog(exchange, "processor", "loop");
            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.ProcessStep(dataItem, route, exchange);
                    }
                    catch (Exception exception)
                    {

                    }
                }
            }
        }
コード例 #11
0
        private static bool CheckRequiremnt(XElement whenElement, Exchange exchange)
        {
            var conditionXml = whenElement.Elements().FirstOrDefault();
            if (conditionXml == null)
                return false;

            var conditionType = conditionXml.Name.ToString();
            switch (conditionType)
            {
                case "simple":
                    return ProcessSimple(conditionXml, exchange);
                    break;
                case "xpath":
                    return ProcessXPath(conditionXml, exchange);
                    break;
                case "method":
                    return ProcessBean(conditionXml, exchange);
                    break;
                case "processor-method":
                    return ProcessExchangeBean(conditionXml, exchange);
                    break;
                default:
                    return false;
            }

            return false;
        }
コード例 #12
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)
            {

            }
        }
コード例 #13
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            var baseApiUri = endPointDescriptor.ComponentPath;
            var location = endPointDescriptor.GetUriProperty("location", "");
            var resultHeader = endPointDescriptor.GetUriProperty("resultHeader");
            var lat = endPointDescriptor.GetUriProperty("lat");
            var lon = endPointDescriptor.GetUriProperty("lon");

            using (var client = new WebClient())
            {
                if (!string.IsNullOrEmpty(lat))
                    client.QueryString.Add("lat", lat);
                if (!string.IsNullOrEmpty(lon))
                    client.QueryString.Add("lon", lon);

                var finaUrl = string.Format("{0}?q={1}", baseApiUri, location);
                var result = client.DownloadString(finaUrl);

                if (!string.IsNullOrEmpty(resultHeader))
                    exchange.InMessage.SetHeader("resultHeader", result);
                else
                {
                    exchange.InMessage.Body = result;
                }
            }
            return exchange;
        }
コード例 #14
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            try
            {
                var protocol = endPointDescriptor.GetUriProperty<string>("protocol");

                switch (protocol)
                {
                    case "smtp":
                        Task.Factory.StartNew(() => SendMail(endPointDescriptor, exchange));
                        break;
                    case "imap":
                        break;
                }
            }
            catch (AggregateException aggregateException)
            {
                Console.WriteLine("aggr-error sending mail: {0}", aggregateException.Message);
            }
            catch (Exception exception)
            {
                Console.WriteLine("error sending mail: {0}", exception.Message);
            }

            return base.Process(exchange, endPointDescriptor);
        }
コード例 #15
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            try
            {
                var method = endPointDescriptor.GetUriProperty("method");
                var objectTypePath = endPointDescriptor.ComponentPath;
                var objectType = Type.GetType(objectTypePath);

                if (objectType != null)
                {
                    var objectInstance = Activator.CreateInstance(objectType, null);
                    if (!string.IsNullOrEmpty(method))
                    {
                        //process normalizer method
                        var methodMember = objectInstance.GetType()
                            .GetMethod(method, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

                        methodMember.Invoke(objectInstance, null);
                    }
                }
            }
            catch (Exception exception)
            {

            }

            return base.Process(exchange, endPointDescriptor);
        }
コード例 #16
0
        /// <summary>
        /// ProcessRouteInformation From Method
        /// </summary>
        /// <param name="leafDescriptor"></param>
        /// <param name="route"></param>
        public static void HandleFrom(UriDescriptor leafDescriptor, Route route, Exchange exchangeData = null)
        {
            try
            {
                //init endpoint
                DefaultEndpoint endPoint;
                if (Camel.EnPointCollection.TryGetValue(leafDescriptor.FullUri, out endPoint))
                {

                }
                else
                {
                    var execAssembly = Assembly.GetExecutingAssembly();
                    var types = execAssembly.GetTypes();

                    foreach (var namespaceToCheck in PermissibleNamespaces)
                    {
                        var typeData =
                            types.FirstOrDefault(
                                c =>
                                    c.FullName.Equals(
                                        string.Format("{0}.{1}.{2}", namespaceToCheck, leafDescriptor.ComponentName,
                                            leafDescriptor.ComponentName),
                                        StringComparison.InvariantCultureIgnoreCase) ||
                                    c.FullName.Equals(
                                        string.Format("{0}.{1}.{2}EndPoint", namespaceToCheck,
                                            leafDescriptor.ComponentName, leafDescriptor.ComponentName),
                                        StringComparison.InvariantCultureIgnoreCase));

                        if (typeData == null)
                            continue;

                        endPoint = (DefaultEndpoint) Activator.CreateInstance(typeData, leafDescriptor.FullUri, route);
                        Camel.EnPointCollection.TryAdd(leafDescriptor.FullUri, endPoint);
                        break;
                    }
                }

                if (endPoint != null)
                {
                    if (exchangeData == null)
                        endPoint.Start();
                    else
                    {
                        endPoint.StartWithExistingExchange(exchangeData);
                    }
                }
                else
                    throw new AppCoreException("end-point not found: " + leafDescriptor.ComponentName);
            }
            catch (AggregateException exception)
            {

            }
            catch (Exception exception)
            {
                throw new AppCoreException("error handling [from-tag] :" + exception.Message, exception);
            }
        }
コード例 #17
0
        public List<string> Split(Exchange exchange)
        {
            if (exchange.InMessage.Body == null)
                return null;

            var bodyLines = exchange.InMessage.Body.ToString().Split(new[] {Environment.NewLine}, StringSplitOptions.None);
            return bodyLines.ToList();
        }
コード例 #18
0
        public override Exchange Execute()
        {
            var exchange = new Exchange(_sedaProcessor.Route);
            Camel.TryLog(exchange, "consumer", _sedaProcessor.UriInformation.ComponentName);

            _sedaProcessor.Process(exchange);
            return exchange;
        }
コード例 #19
0
        private void ProcessResponse(string fileData, Exchange exchange, string fileFolderPath)
        {
            exchange.InMessage.SetHeader("fileFolderPath", fileFolderPath);
            exchange.InMessage.Body = fileData;

            Camel.TryLog(exchange);
            _fileProcessor.Process(exchange);
            exchange.OutMessage.Body = exchange.InMessage.Body;
        }
コード例 #20
0
        public override void Process(Exchange exchange)
        {
            var rawMsg = exchange.InMessage.Body.ToString();
            var data = JsonConvert.DeserializeObject<UserLogin>(rawMsg);

            var rsp = JsonConvert.SerializeObject(new UserLogin.UserLoginStatus { ResponseCode = "90000", ResponseMessage = "Success", });
            exchange.InMessage.Body = GetBankSummary();
            base.Process(exchange);
        }
コード例 #21
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            LogStack.Enqueue(new UriExchange { Exchange = exchange, UriDescriptor = endPointDescriptor });

            if (LogTask == null)
                LogTask = System.Threading.Tasks.Task.Factory.StartNew(ProcessLogQueue);

            return exchange;
        }
コード例 #22
0
        public bool IsHttpGenericRequest(Exchange exchange)
        {
            var request = XElement.Parse(exchange.InMessage.Body.ToString());
            var xElement = request.Element("routeid");
            if (xElement == null) return false;

            var routeId = xElement.Value;
            return routeId == "HTTPGENERIC";
        }
コード例 #23
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            var path = endPointDescriptor.ComponentPath;
            var route = Camel.GetRouteBy(path);

            if (route != null)
                route.CurrentRouteStep.ProcessChannel(exchange);

            return exchange;
        }
        public override Exchange Aggregate(Exchange oldExchange, Exchange newExchange)
        {
            var dateTime = XElement.Parse(newExchange.InMessage.Body.ToString());
            var result = XmlHelper.GetValue<DateTime>(dateTime, "datetime");

            var notifyRes = XElement.Parse(oldExchange.InMessage.Body.ToString());
            notifyRes.Add(new XElement("aggregator_date_time", result));
            oldExchange.InMessage.Body = notifyRes.ToString();
            return oldExchange;
        }
コード例 #25
0
        public void Log(Exchange exchange, string processorType, string componentName, Exception exception = null)
        {
            try
            {
                System.Threading.Tasks.Task.Factory.StartNew(() => InitLog(exchange, processorType, componentName));
            }
            catch (Exception)
            {

            }
        }
コード例 #26
0
        public override void Process(Exchange exchange)
        {
            var elem = XElement.Parse(exchange.InMessage.Body.ToString());

            elem.Add(new XElement("responsecode","00"));
            elem.Add(new XElement("responsemessage", "Successful"));
            elem.Add(new XElement("pin",Guid.NewGuid().ToString()));

            exchange.OutMessage.Body = elem.ToString();
            exchange.InMessage.SetHeader("htt-request-bean", DateTime.Now.ToString());
        }
コード例 #27
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            var fileData = exchange.OutMessage.Body != null ? exchange.OutMessage.Body.ToString() : "";
            var fileName = endPointDescriptor.ComponentPath;

            if (!string.IsNullOrEmpty(fileData) && !string.IsNullOrEmpty(fileName))
                File.AppendAllText(fileName, fileData);

            Camel.TryLog(exchange, "provider", endPointDescriptor.ComponentName);
            return exchange;
        }
コード例 #28
0
        public override void Process(Exchange exchange)
        {
            var body = exchange.InMessage.Body.ToString();

            if (body.EndsWith("\\r\\n"))
                body = body.Replace("\\r\\n", "");

            var msg = $"http://{body}";
            var xml = XElement.Parse(body);
            xml.Add(new XElement("response", "00"));
            exchange.InMessage.Body = xml.ToString();
        }
コード例 #29
0
        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            Route route;
            if (!Camel.RouteCollection.TryGetValue(endPointDescriptor.ComponentPath, out route))
                return exchange;

            Camel.TryLog(exchange, "producer", endPointDescriptor.ComponentName);

            exchange.Route = route;
            SedaDriver.SedaQueue.TryAdd(endPointDescriptor, exchange);
            return exchange;
        }
コード例 #30
0
 private static void Tap(Exchange exchange, string path, Route route)
 {
     try
     {
         var leafNodeParts = UriDescriptor.Parse(path, exchange);
         EndPointBuilder.HandleTo(leafNodeParts, exchange, route);
     }
     catch(Exception exception)
     {
         Console.WriteLine(exception.Message);
     }
 }