public DownloadController(
     OSSDbContext dbContext,
     IConfiguration configuration)
 {
     _dbContext     = dbContext;
     _configuration = configuration;
 }
Example #2
0
        public async Task DeleteInvalidFiles(OSSDbContext dbContext)
        {
            var allFiles = await dbContext.OSSFile.ToListAsync();

            // Delete files that not in record
            foreach (var bucket in await dbContext.Bucket.ToListAsync())
            {
                var bucketPath = $@"{Configuration["StoragePath"]}{_}Storage{_}{bucket.BucketName}{_}";
                if (!Directory.Exists(bucketPath))
                {
                    Directory.CreateDirectory(bucketPath);
                }
                foreach (var item in new DirectoryInfo(bucketPath).GetFiles())
                {
                    try
                    {
                        var fileid = Convert.ToInt32(Path.GetFileNameWithoutExtension(item.Name));
                        // If file is not exist in the database
                        if (!allFiles.Where(t => t.BucketId == bucket.BucketId).Any(t => t.FileKey == fileid))
                        {
                            _logger.LogWarning($"Deleted the file in disk: {item.FullName} because it was not found in database.");
                            File.Delete(item.FullName);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogWarning($"An error occured while analysing the file {item.FullName} because {e.Message}. We will delete it directly!");
                        File.Delete(item.FullName);
                    }
                }
            }
        }
Example #3
0
 public SecretController(
     OSSDbContext dbContext,
     ACTokenManager tokenManager)
 {
     _dbContext    = dbContext;
     _tokenManager = tokenManager;
 }
Example #4
0
 public SecretController(
     OSSDbContext dbContext,
     CoreApiService coreApiService)
 {
     _dbContext      = dbContext;
     _coreApiService = coreApiService;
 }
Example #5
0
 public ApiController(
     OSSDbContext dbContext,
     ImageCompresser imageCompresser,
     IConfiguration configuration)
 {
     _dbContext       = dbContext;
     _imageCompresser = imageCompresser;
     _configuration   = configuration;
 }
 public DownloadController(
     OSSDbContext dbContext,
     ImageCompressor imageCompressor,
     IConfiguration configuration)
 {
     _dbContext       = dbContext;
     _imageCompressor = imageCompressor;
     _configuration   = configuration;
 }
Example #7
0
 public AuthController(
     UserManager<OSSUser> userManager,
     SignInManager<OSSUser> signInManager,
     OSSDbContext _context)
 {
     _userManager = userManager;
     _signInManager = signInManager;
     _dbContext = _context;
 }
Example #8
0
 public TimedCleaner(
     IConfiguration configuration,
     ILogger <TimedCleaner> logger,
     OSSDbContext dbContext)
 {
     Configuration = configuration;
     _logger       = logger;
     _dbContext    = dbContext;
 }
Example #9
0
 public ApiController(
     OSSDbContext dbContext,
     IConfiguration configuration,
     ServiceLocation serviceLocation,
     ACTokenManager tokenManager)
 {
     _dbContext       = dbContext;
     _configuration   = configuration;
     _serviceLocation = serviceLocation;
     _tokenManager    = tokenManager;
 }
Example #10
0
        public static void SeedHostDb(OSSDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            // Host seed
            new InitialHostDbBuilder(context).Create();

            // Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
Example #11
0
 public ApiController(
     OSSDbContext dbContext,
     ImageCompresser imageCompresser,
     IConfiguration configuration,
     ServiceLocation serviceLocation,
     CoreApiService coreApiService)
 {
     _dbContext       = dbContext;
     _imageCompresser = imageCompresser;
     _configuration   = configuration;
     _serviceLocation = serviceLocation;
     _coreApiService  = coreApiService;
 }
Example #12
0
 public async Task DeleteInvalidRecords(OSSDbContext dbContext)
 {
     // Delete records that not in storage.
     foreach (var file in await dbContext.OSSFile.ToListAsync())
     {
         var path = $@"{Configuration["StoragePath"]}{_}Storage{_}{file.BelongingBucket.BucketName}{_}{file.FileKey}.dat";
         if (!File.Exists(path))
         {
             dbContext.Remove(file);
             _logger.LogWarning($"Deleted the file record in database: {file.BelongingBucket.BucketName}.{file.FileKey} because it was not found in storage.");
         }
     }
     await dbContext.SaveChangesAsync();
 }
Example #13
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, OSSDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseEnforceHttps();
            }

            app.UseStaticFiles();
            app.UseLanguageSwitcher();
            app.UseMvcWithDefaultRoute();
        }
Example #14
0
        private async Task AllClean(OSSDbContext _dbContext)
        {
            var outdatedFiles = (await _dbContext.OSSFile.Include(t => t.BelongingBucket).ToListAsync())
                                .Where(t => t.UploadTime + new TimeSpan(t.AliveDays, 0, 0, 0) < DateTime.Now)
                                .ToList();

            foreach (var file in outdatedFiles)
            {
                var path = $@"{Configuration["StoragePath"]}{_}Storage{_}{file.BelongingBucket.BucketName}{_}{file.FileKey}.dat";
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                _dbContext.OSSFile.Remove(file);
            }
            await _dbContext.SaveChangesAsync();

            _logger.LogInformation("Successfully cleaned all trash.");
        }
 public TenantRoleAndUserBuilder(OSSDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Example #16
0
 public ApiController(OSSDbContext dbContext)
 {
     this._dbContext = dbContext;
 }
Example #17
0
 public DefaultTenantBuilder(OSSDbContext context)
 {
     _context = context;
 }
Example #18
0
 public DefaultEditionCreator(OSSDbContext context)
 {
     _context = context;
 }
Example #19
0
 public InitialHostDbBuilder(OSSDbContext context)
 {
     _context = context;
 }
Example #20
0
 public DefaultSettingsCreator(OSSDbContext context)
 {
     _context = context;
 }
Example #21
0
 public HostRoleAndUserCreator(OSSDbContext context)
 {
     _context = context;
 }
Example #22
0
 public DefaultLanguagesCreator(OSSDbContext context)
 {
     _context = context;
 }
 public SecretController(
     OSSDbContext dbContext)
 {
     this._dbContext = dbContext;
 }