示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Configure logger ASAP so that if the app crashes latter we can have logs of the crash
            ConfigureLogger();

            services.AddMvc().AddSessionStateTempDataProvider();
            //Add session support
            services.AddSession();
            // Allow the use of the MySQL Database as a service in this project.
            // Uses connection string from the project configuration
            // Passing it as a service ensures everything in the project will use this query service and use this connection string
            DatabaseQueryService dbQueryService = new DatabaseQueryService(Configuration.GetConnectionString("DefaultConnection"));
            EmailService         emailService   = new EmailService(Configuration.GetSection("EmailServiceConfiguration")["SourceEmailAddress"],
                                                                   Configuration.GetSection("EmailServiceConfiguration")["SourceEmailPassword"]);
            IConfigurationSection alertMonitoringConfig = Configuration.GetSection("AlertMonitoringServiceConfiguration");

            if (alertMonitoringConfig != null && Convert.ToBoolean(alertMonitoringConfig["Enabled"]))
            {
                Thread alertMonitoringThread = new Thread(delegate()
                {
                    int snoozeDurationMinutes = Convert.ToInt32(alertMonitoringConfig["SnoozeDurationMinutes"]);
                    AlertMonitoringService alertMonitoringService = new AlertMonitoringService(dbQueryService, emailService, snoozeDurationMinutes);
                    alertMonitoringService.StartMonitoring();
                });
                alertMonitoringThread.Start();
            }

            // Other services are constructed using the database query service, meaning they all use the same connection string
            AbstractGraphStatisticService graphStatisticService = new GraphStatisticService(dbQueryService);
            AbstractLocationService       locationService       = new LocationService(dbQueryService);
            AbstractCameraService         cameraService         = new CameraService(dbQueryService, graphStatisticService, locationService);
            AbstractAuthenticationService authenticationService = new AuthenticationService(dbQueryService);
            AbstractDataMessageService    dataMessageService    = new DataMessageService(dbQueryService);
            AbstractNotificationService   notificationService   = new NotificationService(dbQueryService);
            AbstractAlertService          alertService          = new AlertService(dbQueryService, cameraService, notificationService);
            AbstractAPIKeyService         apiKeyService         = new APIKeyService(dbQueryService);
            AbstractUserService           userService           = new UserService(dbQueryService, notificationService, Configuration.GetSection("WebServiceConfiguration")["Hostname"], emailService, apiKeyService);

            IConfigurationSection alertSummaryConfig = Configuration.GetSection("AlertSummaryServiceConfiguration");
            bool sendFramesAsJpg = alertMonitoringConfig != null && Convert.ToBoolean(alertSummaryConfig["SendFramesAsJpg"]);
            AlertSummaryService alertSummaryService = new AlertSummaryService(alertService, sendFramesAsJpg);

            services.Add(new ServiceDescriptor(typeof(AbstractAuthenticationService), authenticationService));
            services.Add(new ServiceDescriptor(typeof(AbstractCameraService), cameraService));
            services.Add(new ServiceDescriptor(typeof(AbstractDataMessageService), dataMessageService));
            services.Add(new ServiceDescriptor(typeof(AbstractLocationService), locationService));
            services.Add(new ServiceDescriptor(typeof(AbstractGraphStatisticService), graphStatisticService));
            services.Add(new ServiceDescriptor(typeof(AbstractAlertService), alertService));
            services.Add(new ServiceDescriptor(typeof(AbstractNotificationService), notificationService));
            services.Add(new ServiceDescriptor(typeof(AbstractUserService), userService));
            services.Add(new ServiceDescriptor(typeof(AbstractAPIKeyService), apiKeyService));
            services.Add(new ServiceDescriptor(typeof(AlertSummaryService), alertSummaryService));
        }
示例#2
0
        public void getCorrectGraphStatFor1DayTest()
        {
            Mock <IDatabaseQueryService> mockDBService = new Mock <IDatabaseQueryService>(MockBehavior.Loose);

            mockDBService.Setup(x => x.getGraphStatByTimeInterval(1, graphStats[0].Start, It.IsAny <DateTime>())).Returns(graphStats[0]);
            mockDBService.Setup(x => x.getGraphStatByTimeInterval(1, graphStats[1].Start, It.IsAny <DateTime>())).Returns(graphStats[1]);
            mockDBService.Setup(x => x.getGraphStatByTimeInterval(1, graphStats[2].Start, It.IsAny <DateTime>())).Returns(graphStats[2]);


            GraphStatisticService graphStatisticsService = new GraphStatisticService(mockDBService.Object);
            GraphStatistics       graphStatistics        = graphStatisticsService.GetGraphStatisticsByInterval(1, 1514808000, 1514980800, 86400);

            string[][] stats = new string[2][];
            stats[0] = new string[2] {
                "1515067200", "18"
            };
            stats[1] = new string[2] {
                "1514980800", "17"
            };
            Assert.That(graphStatistics.Stats, Is.EqualTo(stats));
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().AddSessionStateTempDataProvider();
            //Add session support
            services.AddSession();
            // Allow the use of the MySQL Database as a service in this project.
            // Uses connection string from the project configuration
            // Passing it as a service ensures everything in the project will use this query service and use this connection string
            DatabaseQueryService dbQueryService = new DatabaseQueryService(Configuration.GetConnectionString("DefaultConnection"));

            // Other services are constructed using the database query service, meaning they all use the same connection string
            AbstractGraphStatisticService graphStatisticService = new GraphStatisticService(dbQueryService);
            AbstractLocationService       locationService       = new LocationService(dbQueryService);
            AbstractCameraService         cameraService         = new CameraService(dbQueryService, graphStatisticService, locationService);
            AbstractAuthenticationService authenticationService = new AuthenticationService(dbQueryService);
            AbstractDataMessageService    dataMessageService    = new DataMessageService(dbQueryService);

            services.Add(new ServiceDescriptor(typeof(AbstractAuthenticationService), authenticationService));
            services.Add(new ServiceDescriptor(typeof(AbstractCameraService), cameraService));
            services.Add(new ServiceDescriptor(typeof(AbstractDataMessageService), dataMessageService));
            services.Add(new ServiceDescriptor(typeof(AbstractLocationService), locationService));
            services.Add(new ServiceDescriptor(typeof(AbstractGraphStatisticService), graphStatisticService));
        }