Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
 public void TearDown()
 {
     _apiKeyService = null;
 }
Ejemplo n.º 3
0
 public void SetUp()
 {
     // No _databaseQueryService initialised for the APIKeyService.
     _apiKeyService = new APIKeyService();
 }