Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("");

            counterHelper.RawValue(Counters.GoToIndex, 0);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Esempio n. 2
0
 private static void ConfigureBindings(ContainerBuilder builder)
 {
     builder.Register(c => PerformanceHelper.CreateCounterHelper <Counters>())
     .SingleInstance()
     .As <CounterHelper <Counters> >();
     builder.RegisterType <Logger>().As <ILogger>();
 }
        public void RemoveInstancesAndDispose_MultiInstanceCounters_Works(int numOfCounters)
        {
            // Arrange
            var helpers = new List <CounterHelper <MultiInstanceCategory> >();

            for (int i = 0; i < numOfCounters; i++)
            {
                var instanceName = GetInstanceName(i);
                helpers.Add(PerformanceHelper.CreateCounterHelper <MultiInstanceCategory>(instanceName));
            }

            //Act
            helpers.ForEach(helper => helper.RemoveInstancesAndDispose());

            // Assert
            for (int i = 0; i < numOfCounters; i++)
            {
                // The counters still exist
                Assert.IsTrue(PerformanceCounterCategory.CounterExists(AvgCounterName, CategoryName));
                Assert.IsTrue(PerformanceCounterCategory.CounterExists(NumCounterName, CategoryName));

                // The instances should NOT
                Assert.IsFalse(
                    PerformanceCounterCategory.InstanceExists(GetInstanceName(i), CategoryName),
                    string.Format("{0} should not exist anymore", GetInstanceName(i)));

                var category      = PerformanceCounterCategory.GetCategories().First(cat => cat.CategoryName == CategoryName);
                var instanceNames = category.GetInstanceNames().OrderBy(name => name).ToArray();
                Assert.AreEqual(0, instanceNames.Count(), "There should be no instances left");
            }
        }
        static SiteNodeHelper()
        {
            _performanceHelper = PerformanceHelper.CreateCounterHelper <Counters>("Test");

            _performanceHelper.RawValue(Counters.SuccessfullHttpRequests, 0);
            _performanceHelper.RawValue(Counters.FailedHttpRequests, 0);
        }
        protected void Application_Start()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(HomeController).Assembly);
            builder.Register(f => LogManager.GetLogger("ForControllers")).
            As <ILogger>();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(builder.Build()));

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            logger.Info("Application Started");

            using (var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("Enter Home counter instance"))
            {
                counterHelper.RawValue(Counters.GoToHome, 0);
            }
            using (var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("Successful Log in counter instance"))
            {
                counterHelper.RawValue(Counters.SuccessLogIn, 0);
            }
            using (var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("Successful Log off counter instance"))
            {
                counterHelper.RawValue(Counters.successLogOff, 0);
            }
        }
Esempio n. 6
0
        private static void IncrementStartAppCounter()
        {
            var counterHelper = PerformanceHelper.CreateCounterHelper <PerformanceCounters>("Test counters");

            counterHelper.RawValue(PerformanceCounters.StartApplication, 0);
            counterHelper.RawValue(PerformanceCounters.SuccessLogIn, 0);
            counterHelper.RawValue(PerformanceCounters.SuccessLogOf, 0);
            counterHelper.Increment(PerformanceCounters.StartApplication);
        }
 private void MainForm_Load(object sender, EventArgs e)
 {
     counterHelper = PerformanceHelper.CreateCounterHelper <SingleInstance_PerformanceCounters>();
     if (counterHelper == null)
     {
         MessageBox.Show("Counter not installed. Attempting to install.");
         PerformanceHelper.Install(typeof(SingleInstance_PerformanceCounters));
     }
 }
Esempio n. 8
0
 public AccountController(UserManager <ApplicationUser> userManager)
 {
     _userManager  = userManager;
     counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("MvcMusicStore");
     if (ConfigurationManager.AppSettings["Logging"].AsBool())
     {
         logger = new Logger();
     }
 }
Esempio n. 9
0
        public ActionResult LogOff()
        {
            AuthenticationManager.SignOut();

            var counterHelper = PerformanceHelper.CreateCounterHelper <PerfomanceCounters>("Mvc project");

            counterHelper.Increment(PerfomanceCounters.LogOff);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 10
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            var counterHelper = PerformanceHelper.CreateCounterHelper <StoreCounters>("Store project");

            counterHelper.RawValue(StoreCounters.GoToHome, 0);
        }
Esempio n. 11
0
        public IActionResult Index()
        {
            var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("");

            counterHelper.Increment(Counters.GoToIndex);

            _logger.LogError("Request header are empty");

            _logger.LogInformation("Method index finished");

            return(View());
        }
Esempio n. 12
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            using (var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("MvcMusicStore"))
            {
                counterHelper.RawValue(Counters.Login, 0);
            }
        }
        private void CreateAndCleanup(int countersToCreate, Action <CounterHelper <MultiInstanceCategory> > cleanupMethod)
        {
            for (int i = 0; i < countersToCreate; i++)
            {
                // Arrange
                var instanceName = GetInstanceName(i);
                var helper       = PerformanceHelper.CreateCounterHelper <MultiInstanceCategory>(instanceName);

                //Act
                cleanupMethod(helper);
            }
        }
Esempio n. 14
0
        // GET: /Home/
        public async Task <ActionResult> Index()
        {
            logger?.Debug("Enter to Home page");

            var counterHelper = PerformanceHelper.CreateCounterHelper <PerfomanceCounters>("Mvc project");

            counterHelper.Increment(PerfomanceCounters.VisitHomePage);


            return(View(await _storeContext.Albums
                        .OrderByDescending(a => a.OrderDetails.Count())
                        .Take(6)
                        .ToListAsync()));
        }
Esempio n. 15
0
        public async Task <ActionResult> Index()
        {
            logger.LogDebug("Enter to home page");

            using (var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("MvcMusicStore"))
            {
                counterHelper.Increment(Counters.Login);
            }

            return(View(await _storeContext.Albums
                        .OrderByDescending(a => a.OrderDetails.Count())
                        .Take(6)
                        .ToListAsync()));
        }
        public static IDependencyResolver ConfigureContainer()
        {
            var builder = new ContainerBuilder();

            // Register dependencies in controllers
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            builder.Register(c => PerformanceHelper.CreateCounterHelper <Counters>()).SingleInstance().As <CounterHelper <Counters> >();
            builder.RegisterType <Logger.Logger>().As <ILogger>();

            var container = builder.Build();

            // Set MVC DI resolver to use our Autofac container
            return(new AutofacDependencyResolver(container));
        }
Esempio n. 17
0
        protected override void OnApplicationStarted()
        {
            base.OnApplicationStarted();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            using (var counterHelper = PerformanceHelper.CreateCounterHelper <StoreCounters>("Test counter project"))
            {
                counterHelper.RawValue(StoreCounters.GoToHome, 0);
                counterHelper.RawValue(StoreCounters.LogInSuccess, 0);
                counterHelper.RawValue(StoreCounters.LogOffSuccess, 0);
            }
        }
Esempio n. 18
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            logger?.Info("Application started");

            using (var counterHelper = PerformanceHelper.CreateCounterHelper <PerfomanceCounters>("Mvc project"))
            {
                counterHelper.RawValue(PerfomanceCounters.VisitHomePage, 0);
                counterHelper.RawValue(PerfomanceCounters.LogIn, 0);
                counterHelper.RawValue(PerfomanceCounters.LogOff, 0);
            }
        }
        public static void RegisterDependencyResolver()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(HomeController).Assembly);
            builder.Register(c => LogManager.GetLogger("TestLogger"))
            .As <ILogger>();

            builder.Register(c => PerformanceHelper.CreateCounterHelper <MvcMusicStoreCounters>("MvcMusicStore project"))
            .SingleInstance()
            .As <CounterHelper <MvcMusicStoreCounters> >();

            var container = builder.Build();
            var resolver  = new AutofacDependencyResolver(container);

            DependencyResolver.SetResolver(resolver);
        }
Esempio n. 20
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Creation of counters
            using (var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("Counters"))
            {
                counterHelper.RawValue(Counters.SuccessfulLogin, 0);
                counterHelper.RawValue(Counters.SuccessfulLogoff, 0);
                counterHelper.RawValue(Counters.GoHome, 0);
            }

            logger.LogInfo("Application Started");
        }
Esempio n. 21
0
        protected void Application_Start()
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.Register(c => PerformanceHelper.CreateCounterHelper <Counters>()).SingleInstance().As <CounterHelper <Counters> >();
            builder.RegisterType <Models.Logger>().As <ILogger_MusicStore>();
            var container = builder.Build();
            var resolver  = new AutofacDependencyResolver(container);

            DependencyResolver.SetResolver(resolver);


            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            logger.LogInfo("Application started");
        }
Esempio n. 22
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            logger?.Trace("Login method started");

            if (ModelState.IsValid)
            {
                var user = await _userManager.FindAsync(model.UserName, model.Password);

                if (user != null)
                {
                    await SignInAsync(user, model.RememberMe);

                    var counterHelper = PerformanceHelper.CreateCounterHelper <PerfomanceCounters>("Mvc project");
                    counterHelper.Increment(PerfomanceCounters.LogIn);
                    logger?.Trace("Login method finished");
                    return(RedirectToLocal(returnUrl));
                }
                ModelState.AddModelError("", "Invalid username or password.");
                throw new ArgumentOutOfRangeException("Invalid username or password!");
            }
            logger?.Trace("Login method finished");
            return(View(model));
        }
Esempio n. 23
0
        protected void Application_Start()
        {
            //DI
            AutofacConfig.ContainerConfig();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            logger.Info("Application started");


            //Counters set to zero
            using (var counterHelper =
                       PerformanceHelper.CreateCounterHelper <Counters>("Monitoring project"))
            {
                counterHelper.RawValue(Counters.SuccessLogin, 0);
                counterHelper.RawValue(Counters.SuccessLogoff, 0);
                counterHelper.RawValue(Counters.AddsToCart, 0);
                logger.Info("All counters set to zero");
            }
        }
        public void CanCreate_MultiInstanceCounters(int numOfCounters)
        {
            // Arrange & Act
            var helpers = new List <CounterHelper <MultiInstanceCategory> >();

            for (int i = 0; i < numOfCounters; i++)
            {
                var instanceName = GetInstanceName(i);
                helpers.Add(PerformanceHelper.CreateCounterHelper <MultiInstanceCategory>(instanceName));
            }

            // Assert
            for (int i = 0; i < numOfCounters; i++)
            {
                Assert.IsTrue(PerformanceCounterCategory.CounterExists(AvgCounterName, CategoryName));
                Assert.IsTrue(PerformanceCounterCategory.CounterExists(NumCounterName, CategoryName));
                Assert.IsTrue(PerformanceCounterCategory.InstanceExists(GetInstanceName(i), CategoryName));

                var category      = PerformanceCounterCategory.GetCategories().First(cat => cat.CategoryName == CategoryName);
                var instanceNames = category.GetInstanceNames().OrderBy(name => name).ToArray();
                Assert.AreEqual(GetInstanceName(i), instanceNames[i]);
            }
        }
        protected void Application_Start()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(HomeController).Assembly);
            builder.Register(f => new Logger()).
            As <ILogger>();

            DependencyResolver.SetResolver(
                new AutofacDependencyResolver(builder.Build()));

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            using (var counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("Test project"))
            {
                counterHelper.RawValue(Counters.LogIn, 0);
                counterHelper.RawValue(Counters.LogOff, 0);
                counterHelper.RawValue(Counters.FailedLogIn, 0);
            }
        }
 static HomeController()
 {
     CounterHelper = PerformanceHelper.CreateCounterHelper <StoreCounters>("Test counter project");
 }
 static AccountController()
 {
     _loginCounter = PerformanceHelper.CreateCounterHelper <UserLoginCounter>("Login Counter");
 }
Esempio n. 28
0
 static HomeController()
 {
     counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("Enter Home counter instance");
 }
Esempio n. 29
0
 public AccountController(ILogger logger)
     : this(new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())))
 {
     this.logger   = logger;
     counterHelper = PerformanceHelper.CreateCounterHelper <Counters>("Monitoring project");
 }
 private CounterHelperService()
 {
     CounterHelper = PerformanceHelper.CreateCounterHelper <Counters>("CounterHelper");
 }