public object Lookup(BridgeContext context) {
     object result = null;
     if (_cache.TryGetValue(GetCacheKey(context), out result)) {
         return result;
     }
     return null;
 }
        // Generate hash from Method and all args
        private long GetCacheKey(BridgeContext context) {
            HashCodeCombiner hasher = new HashCodeCombiner();

            hasher.AddObject(context.BridgeUrl);
            hasher.AddObject(context.ServiceRequest.Method);
            ComputeHashCode(context.ServiceRequest.Args, hasher);

            return hasher.CombinedHash;
        }
Beispiel #3
0
        // Generate hash from Method and all args
        private long GetCacheKey(BridgeContext context)
        {
            HashCodeCombiner hasher = new HashCodeCombiner();

            hasher.AddObject(context.BridgeUrl);
            hasher.AddObject(context.ServiceRequest.Method);
            ComputeHashCode(context.ServiceRequest.Args, hasher);

            return(hasher.CombinedHash);
        }
Beispiel #4
0
        public object Lookup(BridgeContext context)
        {
            object result = null;

            if (_cache.TryGetValue(GetCacheKey(context), out result))
            {
                return(result);
            }
            return(null);
        }
Beispiel #5
0
 protected void BuildBridgeContext(string bridgePath, BridgeRequest request)
 {
     _context = new BridgeContext(request, bridgePath);
 }
Beispiel #6
0
        // Helper function that resolve the config parameter values, client args, and expressions
        private static void ResolveParameters(Dictionary <string, BridgeParameterInfo> parameterInfo, Dictionary <string, object> args, BridgeContext context)
        {
            foreach (BridgeParameterInfo paramInfo in parameterInfo.Values)
            {
                object paramValue = null;

                // Fill in server side values as default always
                if (paramInfo.Value != null)
                {
                    paramValue = paramInfo.Value;
                }

                // REVIEW: what happens if doesn't exist and no default, should probably throw here?  or just use null (using null for now)
                if (!paramInfo.ServerOnly)
                {
                    if (context.BridgeRequest.Args.Contains(paramInfo.Name))
                    {
                        paramValue = context.BridgeRequest.Args[paramInfo.Name];
                    }
                }

                // Handle expressions of form value= "% appsettings | querystring : key %"
                string paramValueString = paramValue as string;
                if (paramValueString != null)
                {
                    paramValue = TryParseExpression(paramValueString, context);
                }

                args[paramInfo.ServerName] = paramValue;
            }
        }
Beispiel #7
0
        internal static object TryParseExpression(string param, BridgeContext context)
        {
            string exp = param;

            if (param.Length > MinimumExpressionLength && param.StartsWith("%", StringComparison.Ordinal) && param.EndsWith("%", StringComparison.Ordinal))
            {
                exp = param.Substring(1, param.Length - 2).Trim();
            }
            else
            {
                return(param);
            }

            string[] pieces = exp.Split(s_sep);
            if (pieces.Length > 1)
            {
                switch (pieces[0].Trim())
                {
                case "args":
                    string key = pieces[1].Trim();
                    if (context != null && context.BridgeRequest.Args.Contains(key))
                    {
                        return(context.BridgeRequest.Args[key]);
                    }
                    else
                    {
                        throw new ArgumentException("Failed to find object in Args: " + key + " for expression: " + param);
                    }

                case "appsettings":
                    return(WebConfigurationManager.AppSettings[pieces[1].Trim()]);

                case "resultschain":
                    if (context != null && pieces.Length == 3)
                    {
                        ICollection results = context.ResultsChain[pieces[1].Trim()] as ICollection;
                        if (results == null || results.Count == 0)
                        {
                            throw new ArgumentException("Results expression only works for a non empty Collection of IDictionary: " + param);
                        }

                        IEnumerator iterator = results.GetEnumerator();
                        iterator.MoveNext();
                        IDictionary dict = iterator.Current as IDictionary;
                        if (dict == null)
                        {
                            throw new ArgumentException("Results expression only works for a List of IDictionary: " + param);
                        }
                        string propertyKey = pieces[2].Trim();
                        string result      = dict[propertyKey] as string;
                        if (result != null)
                        {
                            return(result);
                        }
                        else
                        {
                            throw new ArgumentException("Failed to parse expression: Could not find: " + propertyKey + " in results for: " + param);
                        }
                    }
                    break;

                case "querystring":
                    return(HttpContext.Current.Request.QueryString[pieces[1].Trim()]);

                default:
                    throw new ArgumentException("Unknown expression type: " + param);
                }
            }
            throw new ArgumentException("Failed to parse expression, make sure its well formed: " + param);
        }
 public void Put(BridgeContext context) {
     _cache[GetCacheKey(context)] = context.BridgeResponse.Response;
 }
 protected void BuildBridgeContext(string bridgePath, BridgeRequest request) {
     _context = new BridgeContext(request, bridgePath);
 }
        // Helper function that resolve the config parameter values, client args, and expressions
        private static void ResolveParameters(Dictionary<string, BridgeParameterInfo> parameterInfo, Dictionary<string, object> args, BridgeContext context) {
            foreach (BridgeParameterInfo paramInfo in parameterInfo.Values) {
                object paramValue = null;

                // Fill in server side values as default always
                if (paramInfo.Value != null) {
                    paramValue = paramInfo.Value;
                }

                // REVIEW: what happens if doesn't exist and no default, should probably throw here?  or just use null (using null for now)
                if (!paramInfo.ServerOnly) {
                    if (context.BridgeRequest.Args.Contains(paramInfo.Name)) {
                        paramValue = context.BridgeRequest.Args[paramInfo.Name];
                    }
                }

                // Handle expressions of form value= "% appsettings | querystring : key %"
                string paramValueString = paramValue as string;
                if (paramValueString != null) {
                    paramValue = TryParseExpression(paramValueString, context);
                }

                args[paramInfo.ServerName] = paramValue;
            }
        }
        internal static object TryParseExpression(string param, BridgeContext context) {
            string exp = param;
            if (param.Length > MinimumExpressionLength && param.StartsWith("%", StringComparison.Ordinal) && param.EndsWith("%", StringComparison.Ordinal)) {
                exp = param.Substring(1, param.Length - 2).Trim();
            }
            else {
                return param;
            }

            string[] pieces = exp.Split(s_sep);
            if (pieces.Length > 1) {
                switch (pieces[0].Trim()) {
                    case "args":
                        string key = pieces[1].Trim();
                        if (context != null && context.BridgeRequest.Args.Contains(key)) {
                            return context.BridgeRequest.Args[key];
                        }
                        else {
                            throw new ArgumentException("Failed to find object in Args: " + key + " for expression: " + param);
                        }
                    case "appsettings":
                        return WebConfigurationManager.AppSettings[pieces[1].Trim()];
                    case "resultschain":
                        if (context != null && pieces.Length == 3) {
                            ICollection results = context.ResultsChain[pieces[1].Trim()] as ICollection;
                            if (results == null || results.Count == 0)
                                throw new ArgumentException("Results expression only works for a non empty Collection of IDictionary: " + param);

                            IEnumerator iterator = results.GetEnumerator();
                            iterator.MoveNext();
                            IDictionary dict = iterator.Current as IDictionary;
                            if (dict == null)
                                throw new ArgumentException("Results expression only works for a List of IDictionary: " + param);
                            string propertyKey = pieces[2].Trim();
                            string result = dict[propertyKey] as string;
                            if (result != null) {
                                return result;
                            }
                            else {
                                throw new ArgumentException("Failed to parse expression: Could not find: " + propertyKey + " in results for: " + param);
                            }
                        }
                        break;
                    case "querystring":
                        return HttpContext.Current.Request.QueryString[pieces[1].Trim()];
                    default:
                        throw new ArgumentException("Unknown expression type: " + param);
                }
            }
            throw new ArgumentException("Failed to parse expression, make sure its well formed: " + param);
        }
Beispiel #12
0
 public void Put(BridgeContext context)
 {
     _cache[GetCacheKey(context)] = context.BridgeResponse.Response;
 }