public string GetDataDirectory(IApiEntryPoint entryPoint) { string basePath; if (HttpContext.Current != null) { basePath = HttpContext.Current.Server.MapPath("~/EntryPointData"); } else { basePath = AppDomain.CurrentDomain.GetData("Data Directory") as string; if (string.IsNullOrEmpty(basePath)) { basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EntryPointData"); } } if (string.IsNullOrEmpty(basePath)) { throw new InvalidOperationException("failed to resolve data directory"); } string apidata = Path.Combine(basePath, entryPoint.Name); if (!Directory.Exists(apidata)) { Directory.CreateDirectory(apidata); } return apidata; }
public string GetDataDirectory(IApiEntryPoint entryPoint) { string basePath; if (HttpContext.Current != null) { basePath = HttpContext.Current.Server.MapPath("~/EntryPointData"); } else { basePath = AppDomain.CurrentDomain.GetData("Data Directory") as string; if (string.IsNullOrEmpty(basePath)) { basePath = Path.Combine(Environment.CurrentDirectory, "EntryPointData"); } } if (string.IsNullOrEmpty(basePath)) { throw new InvalidOperationException("failed to resolve data directory"); } string apidata = Path.Combine(basePath, entryPoint.Name); if (!Directory.Exists(apidata)) { Directory.CreateDirectory(apidata); } return(apidata); }
public void Clear(IApiEntryPoint entrypoint) { IEnumerable<string> toRemove = Cache.Keys.Cast<string>().Where(x => x.StartsWith(entrypoint.GetType() + ":")); foreach (string remove in toRemove) { Cache.Remove(remove); } }
public void Clear(IApiEntryPoint entrypoint) { IEnumerable <string> toRemove = Cache.Keys.Cast <string>().Where(x => x.StartsWith(entrypoint.GetType() + ":")); foreach (string remove in toRemove) { Cache.Remove(remove); } }
private static string GetKey(IApiEntryPoint point, string key) { return(point.GetType() + ":" + key); }
public void Remove(IApiEntryPoint entrypoint, string key) { Cache.Remove(GetKey(entrypoint, key)); }
public bool Exists(IApiEntryPoint entrypoint, string key) { return(Cache.ContainsKey(GetKey(entrypoint, key))); }
public void Set(IApiEntryPoint entrypoint, string key, object @object) { Cache[GetKey(entrypoint, key)] = @object; }
public object Get(IApiEntryPoint entrypoint, string key) { return(Cache[GetKey(entrypoint, key)]); }
protected override void DoProcess(HttpContextBase context) { Log.Debug("strating request. context: '{0}'", ApiContext); //Neeeded to rollback errors context.Response.Buffer = true; context.Response.BufferOutput = true; IApiEntryPoint instance = null; try { Log.Debug("method invoke"); ApiResponce.Count = ApiContext.Count; ApiResponce.StartIndex = ApiContext.StartIndex; if (Method != null) { if (!string.IsNullOrEmpty(Method.Name)) { instance = Container.ResolveNamed <IApiEntryPoint>(Method.Name, new TypedParameter(typeof(ApiContext), ApiContext)); } else { instance = Container.Resolve <IApiEntryPoint>(); } var responce = ApiManager.InvokeMethod(Method, ApiContext, instance); if (responce is Exception) { SetError(context, (Exception)responce, HttpStatusCode.InternalServerError); } else { // success PostProcessResponse(context, responce); } } else { SetError(context, new MissingMethodException("Method not found"), HttpStatusCode.NotFound); } } catch (TargetInvocationException targetInvocationException) { if (targetInvocationException.InnerException is ItemNotFoundException) { SetError(context, targetInvocationException.InnerException, HttpStatusCode.NotFound, "The record could not be found"); } else if (targetInvocationException.InnerException is ArgumentException) { SetError(context, targetInvocationException.InnerException, HttpStatusCode.BadRequest, "Invalid arguments"); } else if (targetInvocationException.InnerException is SecurityException) { SetError(context, targetInvocationException.InnerException, HttpStatusCode.Forbidden, "Access denied"); } else if (targetInvocationException.InnerException is InvalidOperationException) { SetError(context, targetInvocationException.InnerException, HttpStatusCode.Forbidden); } else { SetError(context, targetInvocationException.InnerException, HttpStatusCode.InternalServerError); } } catch (Exception e) { SetError(context, e, HttpStatusCode.InternalServerError); } Exception responseError; try { RespondTo(Method, context); return; } catch (ThreadAbortException e) { //Do nothing. someone killing response Log.Error(e, "thread aborted. response not sent"); return; } catch (HttpException exception) { responseError = exception; SetError(context, exception, (HttpStatusCode)exception.GetHttpCode());//Set the code of throwed exception } catch (Exception exception) { responseError = exception; SetError(context, exception, HttpStatusCode.InternalServerError); } Log.Error(responseError, "error happened while sending response. can't be here"); RespondTo(Method, context);//If we got there then something went wrong }
private static string GetKey(IApiEntryPoint point, string key) { return point.GetType() + ":" + key; }
public bool Exists(IApiEntryPoint entrypoint, string key) { return Cache.ContainsKey(GetKey(entrypoint, key)); }
public object Get(IApiEntryPoint entrypoint, string key) { return Cache[GetKey(entrypoint, key)]; }