示例#1
0
        public void LogRequest(InspectorInfo inspector)
        {
            if (inspector == null) throw new ArgumentNullException("inspector");

            var request = CreateRequestInfo(inspector);

            _cache.Store(inspector, request);
            BroadcastRequestInfo(inspector, request);
        }
示例#2
0
 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;
 }
示例#3
0
        public InspectorInfo CreateInspector(bool isprivate)
        {
            var inspector = new InspectorInfo()
                {
                    IsPrivate = isprivate
                };

            _dbContext.Inspectors.Add(inspector);
            _dbContext.SaveChanges();

            return inspector;
        }
示例#4
0
        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;
        }
示例#6
0
        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);
                }
            }
        }
示例#8
0
 public void RemoveAll(InspectorInfo inspector)
 {
     Cache.Remove("inspectR" + inspector.Id);
 }
示例#9
0
 public IEnumerable<RequestInfo> Get(InspectorInfo inspector)
 {
     return GetInternal(inspector);
 }
示例#10
0
        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;
 }
示例#14
0
 private RequestInfo CreateRequestInfo(InspectorInfo inspector)
 {
     var info = new RequestInfo();
     _collector.Collect(info, inspector);
     return info;
 }