예제 #1
0
        // Entrypoint to the pipeline
        protected virtual void ExecuteBridgePipeline()
        {
            // Make the calls to all other bridge methods first
            BridgeMethodInfo methodInfo = GetMethodInfoForCall(BridgeRequest.Method);

            foreach (BridgeChainRequestInfo callInfo in methodInfo.BridgeChainRequests)
            {
                Dictionary <string, object> args = new Dictionary <string, object>();
                ResolveParameters(callInfo.Parameters, args, Context);
                BridgeRequest request = new BridgeRequest(callInfo.Method, args);
                object        results = BridgeHandler.Invoke(callInfo.BridgeUrl, request);
                Context.ResultsChain[callInfo.Name] = results;
            }

            TransformRequest();

            // Stop execution if we have a cache hit
            if (ResolveRequestCache())
            {
                return;
            }

            ProcessRequest();
            TransformResponse();
            UpdateResponseCache();
        }
예제 #2
0
        private BridgeMethodInfo GetMethodInfoForCall(string method)
        {
            BridgeMethodInfo methodInfo = null;

            if (!BridgeService.ServiceInfo.Methods.TryGetValue(method, out methodInfo))
            {
                throw new ArgumentException("No such method registered: " + method);
            }
            return(methodInfo);
        }
예제 #3
0
        // This is where the transformed response is placed into the cache
        public virtual void UpdateResponseCache()
        {
            BridgeMethodInfo methodInfo = GetMethodInfoForCall(BridgeRequest.Method);

            // First cache that has a hit we use
            foreach (IBridgeRequestCache cache in methodInfo.CacheInstances)
            {
                cache.Put(Context);
            }
        }
예제 #4
0
        // Hook to fullfill the request from the cache, return value of true stops execution of the bridge pipeline and returns what's in BridgeResponse.Response
        public virtual bool ResolveRequestCache()
        {
            BridgeMethodInfo methodInfo = GetMethodInfoForCall(BridgeRequest.Method);

            // First cache that has a hit we use
            foreach (IBridgeRequestCache cache in methodInfo.CacheInstances)
            {
                object rawResponse = cache.Lookup(Context);
                if (rawResponse != null)
                {
                    BridgeResponse.Response = rawResponse;
                    return(true);
                }
            }
            return(false);
        }
예제 #5
0
        private static void BuildCaches(XmlNode cacheNode, BridgeMethodInfo method)
        {
            if (cacheNode == null)
            {
                return;
            }
            XmlNodeList cacheNodes = cacheNode.SelectNodes("cache");

            foreach (XmlNode node in cacheNodes)
            {
                string              typeStr  = GetAttributeValue(node, "type", true);
                XmlNode             dataNode = GetSingleNode(node, "data", false);
                BridgeTransformData data     = BuildTransformData(dataNode);
                method.Caches.Add(new Pair(typeStr, data));
            }
        }
예제 #6
0
        public virtual void TransformRequest()
        {
            BridgeMethodInfo methodInfo = GetMethodInfoForCall(BridgeRequest.Method);

            // Set the server method name
            ServiceRequest.Method = methodInfo.ServerName;

            // Apply the parameter mapping/expressions
            ResolveParameters(methodInfo.Parameters, ServiceRequest.Args, Context);

            // Apply the credentials now only if the credentials aren't set already
            BridgeCredentialInfo credInfo = methodInfo.Credentials;

            if (ServiceRequest.Credentials == null && credInfo != null)
            {
                ServiceRequest.Credentials = new NetworkCredential((string)TryParseExpression(credInfo.User, Context), (string)TryParseExpression(credInfo.Password, Context), (string)TryParseExpression(credInfo.Domain, Context));
            }
        }
예제 #7
0
        public virtual void TransformResponse()
        {
            object           rawResponse = ServiceResponse.Response;
            BridgeMethodInfo methodInfo  = GetMethodInfoForCall(BridgeRequest.Method);

            foreach (Pair pair in methodInfo.ResponseTransforms)
            {
                Type   type;
                string typeStr = (string)pair.First;
                IBridgeResponseTransformer transformer = BridgeService.CreateInstance(typeStr, out type) as IBridgeResponseTransformer;
                if (transformer == null)
                {
                    throw new InvalidOperationException(typeStr + " is not of type IBridgeResponseTransformer");
                }
                transformer.Initialize((BridgeTransformData)pair.Second);
                rawResponse = transformer.Transform(rawResponse);
            }
            BridgeResponse.Response = rawResponse;
        }
예제 #8
0
        private static void BuildMethodRequestChain(XmlNode callNode, BridgeMethodInfo method)
        {
            XmlNodeList requests = callNode.SelectNodes("request");

            foreach (XmlNode node in requests)
            {
                BridgeChainRequestInfo callInfo = new BridgeChainRequestInfo();
                callInfo.Name      = GetAttributeValue(node, "name", true);
                callInfo.BridgeUrl = GetAttributeValue(node, "bridgeUrl", true);
                callInfo.Method    = GetAttributeValue(node, "method", true);
                method.BridgeChainRequests.Add(callInfo);

                XmlNode inputNode = GetSingleNode(node, "input", false);
                if (inputNode == null)
                {
                    callInfo.Parameters = new Dictionary <string, BridgeParameterInfo>(0);
                }
                else
                {
                    callInfo.Parameters = BuildParams(inputNode);
                }
            }
        }
예제 #9
0
        private static void BuildMethodInfo(ServiceInfo serviceInfo, XmlNode node)
        {
            XmlNodeList methodNodes = node.SelectNodes("method");

            foreach (XmlNode methodNode in methodNodes)
            {
                string name       = GetAttributeValue(methodNode, "name", true);
                string serverName = GetAttributeValue(methodNode, "serverName", false);
                if (serverName == null)
                {
                    serverName = name;
                }

                string getEnabled = GetAttributeValue(methodNode, "getEnabled", false);
                bool   get        = (getEnabled != null && String.Equals(getEnabled, "true", StringComparison.OrdinalIgnoreCase));

                ResponseFormat mode           = ResponseFormat.Json;
                string         responseFormat = GetAttributeValue(methodNode, "responseFormat", false);
                if (responseFormat != null && String.Equals(responseFormat, "xml", StringComparison.OrdinalIgnoreCase))
                {
                    mode = ResponseFormat.Xml;
                }

                BridgeMethodInfo methodInfo = new BridgeMethodInfo(name, serverName, get, mode);
                XmlNode          inputNode  = GetSingleNode(methodNode, "input", false);
                if (inputNode == null)
                {
                    methodInfo.Parameters = new Dictionary <string, BridgeParameterInfo>(0);
                }
                else
                {
                    methodInfo.Parameters = BuildParams(inputNode);
                }

                XmlNode requests = GetSingleNode(methodNode, "requestChain", false);
                if (requests != null)
                {
                    BuildMethodRequestChain(requests, methodInfo);
                }

                // REVIEW: Only used on Soap stuff currently
                XmlNodeList includeNodes = methodNode.SelectNodes("xmlinclude");
                foreach (XmlNode includeNode in includeNodes)
                {
                    methodInfo.XmlIncludes.Add(GetAttributeValue(includeNode, "type", true));
                }

                XmlNode transformNode = GetSingleNode(methodNode, "transforms", false);
                BuildTransforms(transformNode, methodInfo);

                XmlNode cachingNode = GetSingleNode(methodNode, "caching", false);
                BuildCaches(cachingNode, methodInfo);

                XmlNode authNode = methodNode.SelectSingleNode("authentication");
                if (authNode != null)
                {
                    methodInfo.Credentials = ParseCredentials(authNode);
                }

                serviceInfo.Methods[name] = methodInfo;
            }
        }
        private static void BuildMethodInfo(ServiceInfo serviceInfo, XmlNode node) {
            XmlNodeList methodNodes = node.SelectNodes("method");
            foreach (XmlNode methodNode in methodNodes) {
                string name = GetAttributeValue(methodNode, "name", true);
                string serverName = GetAttributeValue(methodNode, "serverName", false);
                if (serverName == null) serverName = name;

                string getEnabled = GetAttributeValue(methodNode, "getEnabled", false);
                bool get = (getEnabled != null && String.Equals(getEnabled, "true", StringComparison.OrdinalIgnoreCase));

                ResponseFormat mode = ResponseFormat.Json;
                string responseFormat = GetAttributeValue(methodNode, "responseFormat", false);
                if (responseFormat != null && String.Equals(responseFormat, "xml", StringComparison.OrdinalIgnoreCase)) {
                    mode = ResponseFormat.Xml;
                }

                BridgeMethodInfo methodInfo = new BridgeMethodInfo(name, serverName, get, mode);
                XmlNode inputNode = GetSingleNode(methodNode, "input", false);
                if (inputNode == null) {
                    methodInfo.Parameters = new Dictionary<string, BridgeParameterInfo>(0);
                }
                else {
                    methodInfo.Parameters = BuildParams(inputNode);
                }

                XmlNode requests = GetSingleNode(methodNode, "requestChain", false);
                if (requests != null) {
                    BuildMethodRequestChain(requests, methodInfo);
                }

                // REVIEW: Only used on Soap stuff currently
                XmlNodeList includeNodes = methodNode.SelectNodes("xmlinclude");
                foreach (XmlNode includeNode in includeNodes) {
                    methodInfo.XmlIncludes.Add(GetAttributeValue(includeNode, "type", true));
                }

                XmlNode transformNode = GetSingleNode(methodNode, "transforms", false);
                BuildTransforms(transformNode, methodInfo);

                XmlNode cachingNode = GetSingleNode(methodNode, "caching", false);
                BuildCaches(cachingNode, methodInfo);

                XmlNode authNode = methodNode.SelectSingleNode("authentication");
                if (authNode != null) {
                    methodInfo.Credentials = ParseCredentials(authNode);
                }

                serviceInfo.Methods[name] = methodInfo;
            }
        }
        private static void BuildMethodRequestChain(XmlNode callNode, BridgeMethodInfo method) {
            XmlNodeList requests = callNode.SelectNodes("request");
            foreach (XmlNode node in requests) {
                BridgeChainRequestInfo callInfo = new BridgeChainRequestInfo();
                callInfo.Name = GetAttributeValue(node, "name", true);
                callInfo.BridgeUrl = GetAttributeValue(node, "bridgeUrl", true);
                callInfo.Method = GetAttributeValue(node, "method", true);
                method.BridgeChainRequests.Add(callInfo);

                XmlNode inputNode = GetSingleNode(node, "input", false);
                if (inputNode == null) {
                    callInfo.Parameters = new Dictionary<string, BridgeParameterInfo>(0);
                }
                else {
                    callInfo.Parameters = BuildParams(inputNode);
                }

            }
        }
 private static void BuildCaches(XmlNode cacheNode, BridgeMethodInfo method) {
     if (cacheNode == null) return;
     XmlNodeList cacheNodes = cacheNode.SelectNodes("cache");
     foreach (XmlNode node in cacheNodes) {
         string typeStr = GetAttributeValue(node, "type", true);
         XmlNode dataNode = GetSingleNode(node, "data", false);
         BridgeTransformData data = BuildTransformData(dataNode);
         method.Caches.Add(new Pair(typeStr, data));
     }
 }