Example #1
0
 public MetaDataService(StatusService statusService, ExifService exifService,
                        ConfigService config, ImageCache imageCache, WorkService workService)
 {
     _statusService = statusService;
     _configService = config;
     _exifService   = exifService;
     _imageCache    = imageCache;
     _workService   = workService;
 }
    public UserTagFavouritesService(ExifService exifService, UserConfigService configService)
    {
        _configService = configService;
        _exifService   = exifService;

        _exifService.OnUserTagsAdded += AddRecentTags;

        string recents = configService.Get("FavouriteTags");

        if (!string.IsNullOrEmpty(recents))
        {
            RecentTags.AddRange(recents.Split(",").Select(x => x.Trim()).ToList());
        }
    }
Example #3
0
 public ImageRecognitionService(StatusService statusService, ObjectDetector objectDetector,
                                MetaDataService metadataService, AzureFaceService azureFace,
                                AccordFaceService accordFace, EmguFaceService emguService,
                                ThumbnailService thumbs, ConfigService configService,
                                ImageClassifier imageClassifier, ImageCache imageCache,
                                WorkService workService, ExifService exifService,
                                ImageProcessService imageProcessor)
 {
     _thumbService      = thumbs;
     _accordFaceService = accordFace;
     _azureFaceService  = azureFace;
     _statusService     = statusService;
     _objectDetector    = objectDetector;
     _metdataService    = metadataService;
     _emguFaceService   = emguService;
     _configService     = configService;
     _imageClassifier   = imageClassifier;
     _imageProcessor    = imageProcessor;
     _imageCache        = imageCache;
     _workService       = workService;
     _exifService       = exifService;
 }
Example #4
0
        /// <summary>
        /// Bootstrap the task scheduler - configuring all the background scheduled tasks
        /// that we'll want to run periodically, such as indexing, thumbnail generation,
        /// cleanup of temporary download files, etc., etc.
        /// </summary>
        private static void StartTaskScheduler(TaskService taskScheduler, DownloadService download,
                                               ThumbnailService thumbService, ExifService exifService)
        {
            var tasks = new List <ScheduledTask>();

            // Clean up old/irrelevant thumbnails once a week
            var thumbCleanupFreq = new TimeSpan(7, 0, 0, 0);

            tasks.Add(new ScheduledTask
            {
                Type = ScheduledTask.TaskType.CleanupThumbs,
                ExecutionFrequency = thumbCleanupFreq,
                WorkMethod         = () => thumbService.CleanUpThumbnails(thumbCleanupFreq),
                ImmediateStart     = false
            });


            // Clean up old download zips from the wwwroot folder
            var downloadCleanupFreq = new TimeSpan(6, 0, 0);

            tasks.Add(new ScheduledTask
            {
                Type = ScheduledTask.TaskType.CleanupDownloads,
                ExecutionFrequency = downloadCleanupFreq,
                WorkMethod         = () => download.CleanUpOldDownloads(downloadCleanupFreq),
                ImmediateStart     = false
            });

            // Purge keyword operation entries that have been processed
            var keywordCleanupFreq = new TimeSpan(24, 0, 0);

            tasks.Add(new ScheduledTask
            {
                Type = ScheduledTask.TaskType.CleanupKeywordOps,
                ExecutionFrequency = new TimeSpan(12, 0, 0),
                WorkMethod         = () => { _ = exifService.CleanUpKeywordOperations(keywordCleanupFreq); },
                ImmediateStart     = false
            });

            // Dump performance stats out to the logfile
            tasks.Add(new ScheduledTask
            {
                Type = ScheduledTask.TaskType.DumpPerformance,
                ExecutionFrequency = new TimeSpan(24, 0, 0),
                WorkMethod         = () => Stopwatch.WriteTotals(false),
                ImmediateStart     = false
            });

#if false
            // Disabled for now, don't think it's really required.
            // Flush the DB WriteCache (currently a no-op except for SQLite) ever 2 hours
            tasks.Add(new ScheduledTask
            {
                Type = ScheduledTask.TaskType.FlushDBWriteCache,
                ExecutionFrequency = new TimeSpan(2, 0, 0),
                WorkMethod         = () =>
                {
                    using var db = new ImageContext();

                    db.FlushDBWriteCache();
                }
            });
Example #5
0
        /// <summary>
        /// Called by the Blazor runtime - this is where we setup the HTTP request pipeline and
        /// initialise all the bits and pieces we need to run.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              DownloadService download, ThemeService themes, TaskService tasks,
                              ExifService exifService, ThumbnailService thumbService,
                              IndexingService indexService, ImageProcessService imageProcessing,
                              AzureFaceService azureFace, ImageRecognitionService aiService,
                              UserService userService, ConfigService configService, WorkService workService,
                              ImageCache imageCache, MetaDataService metaDataService, ObjectDetector objectDetector)
        {
            SyncfusionLicenseProvider.RegisterLicense("NTUxMzEwQDMxMzkyZTM0MmUzMGFRSFpzQUhjdUE2M2V4S1BmYSs5bk13dkpGbkhvam5Wb1VRbGVURkRsOHM9");

            var logLevel = configService.Get(ConfigSettings.LogLevel, Serilog.Events.LogEventLevel.Information);

            Logging.ChangeLogLevel(logLevel);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/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();
            }

            if (Logging.Verbose)
            {
                app.UseSerilogRequestLogging();
            }

            app.UseResponseCompression();
            app.UseRouting();
            app.UseResponseCaching();

            // Disable this for now
            // app.UseHttpsRedirection();

            // TODO: Do we need this if we serve all the images via the controller?
            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(ThumbnailService.PicturesRoot),
                RequestPath  = ThumbnailService.RequestRoot
            });

            // Enable auth
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                //endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action}");
                endpoints.MapControllers();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });

            // Prime the cache
            imageCache.WarmUp().Wait();

            // TODO: Save this in ConfigService
            string contentRootPath = Path.Combine(env.ContentRootPath, "wwwroot");

            // TODO: Fix this, or not if Skia doesn't need it
            imageProcessing.SetContentPath(contentRootPath);
            download.SetDownloadPath(contentRootPath);
            themes.SetContentPath(contentRootPath);

            // Start the work processing queue for AI, Thumbs, etc
            workService.StartService();

            // Start the face service before the thumbnail service
            azureFace.StartService().Wait();
            metaDataService.StartService();
            indexService.StartService();
            aiService.StartService();

            // ObjectDetector can throw a segmentation fault if the docker container is pinned
            // to a single CPU, so for now, to aid debugging, let's not even try and initialise
            // it if AI is disabled. See https://github.com/Webreaper/Damselfly/issues/334
            if (!configService.GetBool(ConfigSettings.DisableObjectDetector, false))
            {
                objectDetector.InitScorer();
            }

            // Validation check to ensure at least one user is an Admin
            userService.CheckAdminUser().Wait();

            StartTaskScheduler(tasks, download, thumbService, exifService);

            Logging.StartupCompleted();
            Logging.Log("Starting Damselfly webserver...");
        }