public CacheExecutionResult Execute(ChannelMethodHeuristicOptions options, HeuristicsInfo hInfo) { string method = options.Request.HttpMethod; if (method == "GET") { return(TryInvokeGetMethod(options, hInfo)); } else { return(TryInvokePostMethod(options, hInfo)); } }
private void _events_AddToHeuristics(object sender, AddHeuristicsEventArgs e) { EnableCacheAttribute cache = e.MethodInfo.GetCustomAttribute <EnableCacheAttribute>(); HeuristicsInfo addInfo = new HeuristicsInfo { Channel = e.Channel, ChannelMethod = e.MethodInfo, MethodResponse = e.MethodResponse, AddedTime = DateTime.Now, Parameters = e.Parameters, Duration = cache.Duration, DurationUnit = cache.Unit }; _cachedInfos.Add(addInfo); }
public bool IsMethodCached(Type channel, MethodInfo channelMethod, out HeuristicsInfo hInfo) { HeuristicsInfo cached = _cachedInfos.FirstOrDefault(x => x.Channel == channel && x.ChannelMethod == channelMethod); if (cached == null) { hInfo = null; return(false); } if (cached.Expired()) { hInfo = null; _cachedInfos.Remove(cached); return(false); } else { hInfo = cached; return(true); } }
private bool TryInvokePostMethod(ChannelMethodHeuristicOptions options, HeuristicsInfo hInfo) { if (options.Request.HasEntityBody) { ChannelMethodDeserializerFactory dsrFactory = new ChannelMethodDeserializerFactory(options.Request.InputStream); List <object> requestParameters = dsrFactory.DeserializeFromBody(_descriptor.GetMethodDescription(options.ChannelMethod), options.Request.ContentType); if (requestParameters == hInfo.Parameters) { _msgService.WriteHttpResponse(hInfo.MethodResponse, options.Response); return(true); } else { return(true); } } else { _msgService.WriteHttpResponse(hInfo.MethodResponse, options.Response); return(true); } }
private bool TryInvokeGetMethod(ChannelMethodHeuristicOptions options, HeuristicsInfo hInfo) { if (options.Request.QueryString.AllKeys.Length == 0) { _msgService.WriteHttpResponse(hInfo.MethodResponse, options.Response); return(true); } else { ChannelMethodDeserializerFactory dsrFactory = new ChannelMethodDeserializerFactory(options.Request.QueryString); List <object> requestParameters = dsrFactory.DeserializeFromQueryParameters(_descriptor.GetMethodDescription(options.ChannelMethod)); if (requestParameters == hInfo.Parameters) { _msgService.WriteHttpResponse(hInfo.MethodResponse, options.Response); return(true); } else { return(false); } } }
private CacheExecutionResult TryInvokeGetMethod(ChannelMethodHeuristicOptions options, HeuristicsInfo hInfo) { CacheExecutionResult result = new CacheExecutionResult(); if (options.Request.QueryString.AllKeys.Length == 0) { _msgService.WriteHttpResponse(hInfo.MethodResponse, options.Response); result.Executed = true; return(result); } else { ChannelMethodDeserializerFactory dsrFactory = new ChannelMethodDeserializerFactory(options.Request.QueryString); List <object> requestParameters = dsrFactory.DeserializeFromQueryParameters(_descriptor.GetMethodDescription(options.ChannelMethod)); if (ParameteresMatch(hInfo.Parameters, requestParameters)) { _msgService.WriteHttpResponse(hInfo.MethodResponse, options.Response); result.Executed = true; return(result); } else { result.Executed = false; result.DataProcessed = true; result.Data.HasData = true; result.Data.Parameters = requestParameters; return(result); } } }
private CacheExecutionResult TryInvokePostMethod(ChannelMethodHeuristicOptions options, HeuristicsInfo hInfo) { CacheExecutionResult result = new CacheExecutionResult(); if (options.Request.HasEntityBody) { ChannelMethodDeserializerFactory dsrFactory = new ChannelMethodDeserializerFactory(options.Request.InputStream); List <object> requestParameters = dsrFactory.DeserializeFromBody(_descriptor.GetMethodDescription(options.ChannelMethod), options.Request.ContentType); if (ParameteresMatch(hInfo.Parameters, requestParameters)) { _msgService.WriteHttpResponse(hInfo.MethodResponse, options.Response); result.Executed = true; } else { result.Executed = false; result.DataProcessed = true; result.Data.HasData = true; result.Data.Parameters = requestParameters; } } else { _msgService.WriteHttpResponse(hInfo.MethodResponse, options.Response); result.Executed = true; } return(result); }
private void _events_RemoveFromHeuristics(object sender, RemoveHeuristicsEventArgs e) { HeuristicsInfo expired = _cachedInfos.FirstOrDefault(x => x.Channel == e.Channel && x.ChannelMethod == e.ChannelMethod); _cachedInfos.Remove(expired); }