public void LogRequest(InspectorInfo inspector) { if (inspector == null) throw new ArgumentNullException("inspector"); var request = CreateRequestInfo(inspector); _cache.Store(inspector, request); BroadcastRequestInfo(inspector, request); }
private IList<RequestInfo> GetInternal(InspectorInfo inspector) { if (inspector == null) throw new ArgumentNullException("inspector"); var requests = Cache["inspectR" + inspector.Id] as IList<RequestInfo>; if (requests == null) { requests = new List<RequestInfo>(); } return requests; }
public InspectorInfo CreateInspector(bool isprivate) { var inspector = new InspectorInfo() { IsPrivate = isprivate }; _dbContext.Inspectors.Add(inspector); _dbContext.SaveChanges(); return inspector; }
public void AddInspectorToUser(string userName, InspectorInfo info) { var user = _dbContext.GetUserProfile(userName); if (user == null) { user = CreateUserProfileInternal(userName); } if (user.Inspectors.All(i => i.Id != info.Id)) { user.Inspectors.Add(info); } _dbContext.SaveChanges(); }
public InspectorInfo Create(bool isprivate) { var inspector = new InspectorInfo() { IsPrivate = isprivate }; using (var context = new InspectRContext()) { context.Inspectors.Add(inspector); context.SaveChanges(); } return inspector; }
public void Store(InspectorInfo inspector, RequestInfo request) { var requests = GetInternal(inspector); // keep only last 50 requests for now, cleanup at 100+ if (requests.Count >= 100) { requests = requests.Skip(requests.Count - 50).Take(50).ToList(); } requests.Add(request); Cache.Insert("inspectR" + inspector.Id, requests, null, Cache.NoAbsoluteExpiration, TimeSpan.FromDays(1)); //using (var context = new InspectRContext()) //{ // context.Requests.Add(new RequestInfoEntry(inspector, request)); // context.SaveChanges(); //} }
public void Collect(RequestInfo info, InspectorInfo inspector) { var context = HttpContext.Current; var req = context.Request; info.Client.HostAddress = req.UserHostAddress; info.Client.HostName = req.UserHostName; info.Client.Agent = req.UserAgent; info.Client.Languages = req.UserLanguages; info.ContentLength = req.ContentLength; info.ContentType = req.ContentType; // info.Cookies = req.Cookies; // info.Form = req.Form; info.Headers = req.Headers.AsKeyValuePairList(); info.HttpMethod = req.HttpMethod; info.RequestType = req.RequestType; info.RawUrl = req.RawUrl; info.QueryString = req.Url.Query; if (req.UrlReferrer != null) { info.UrlReferrer = req.UrlReferrer.ToString(); } // TODO: nicer way of getting body? req.InputStream.Position = 0; using (var rdr = new StreamReader(req.InputStream)) { info.Content = rdr.ReadToEnd(); } if (ContentDecoders.Decoders.ContainsKey(req.ContentType)) { var contentDecoder = ContentDecoders.Decoders[req.ContentType]; if (contentDecoder != null) { info.Content = contentDecoder(info.Content); } } }
public void RemoveAll(InspectorInfo inspector) { Cache.Remove("inspectR" + inspector.Id); }
public IEnumerable<RequestInfo> Get(InspectorInfo inspector) { return GetInternal(inspector); }
public RequestInfoEntry(InspectorInfo inspector, RequestInfo requestInfo) { Id = Guid.NewGuid(); InspectorId = inspector.Id; Created = DateTime.Now; Data = new JavaScriptSerializer().Serialize(requestInfo); }
private void BroadcastRequestInfo(InspectorInfo inspector, RequestInfo request) { var context = GlobalHost.ConnectionManager.GetHubContext<InspectRHub>(); context.Clients.Group(inspector.UniqueKey).requestLogged(inspector, request); }
private void StoreRequestInfo(InspectorInfo inspector, RequestInfo request) { var cache = _httpContext.Cache; // TODO: cache somewhere else var requests = cache["inspectR" + inspector.Id] as IList<RequestInfo>; if (requests == null) { requests = new List<RequestInfo>(); } // keep only last 50 requests for now, cleanup at 100+ if (requests.Count >= 100) { requests = requests.Skip(requests.Count - 50).Take(50).ToList(); } requests.Add(request); cache.Insert("inspectR" + inspector.Id, requests, null, Cache.NoAbsoluteExpiration, TimeSpan.FromDays(1)); //using (var context = new InspectRContext()) //{ // context.Requests.Add(new RequestInfoEntry(inspector, request)); // context.SaveChanges(); //} }
private RequestInfo CreateRequestInfo(InspectorInfo inspector) { var info = new RequestInfo(); collector.Collect(info, inspector, _httpContext); return info; }
private RequestInfo CreateRequestInfo(InspectorInfo inspector) { var info = new RequestInfo(); _collector.Collect(info, inspector); return info; }