Esempio n. 1
0
        public async Task Invoke(HttpContext context)
        {
            var visitorId = context.Request.Cookies["VisitorId"];

            if (visitorId == null)
            {
                visitorId = Guid.NewGuid().ToString();
                //don the necessary staffs here to save the count by one
                context.Response.Cookies.Append("VisitorId", visitorId, new CookieOptions()
                {
                    Path     = "/",
                    HttpOnly = true,
                    //Secure = false,
                    Expires = DateTime.Now.AddMonths(1)
                });
            }
            CounterProcessor.Visit(visitorId);

            await _requestDelegate(context);
        }
Esempio n. 2
0
        public static IServiceCollection AddViCounter(this IServiceCollection service,
                                                      ViCounterOptions options = default(ViCounterOptions))
        {
            if (options != null)
            {
                if (options.RefreshInterval < 3)
                {
                    options.RefreshInterval = 3;
                }

                if (options.ActivityDuration < 1)
                {
                    options.ActivityDuration = 1;
                }

                ViCounterSettings.RefreshInterval  = options.RefreshInterval;
                ViCounterSettings.ActivityDuration = options.ActivityDuration;
            }
            CounterProcessor.Init();
            return(service);
        }