From b6c2f602963cb6303823ae18fe63f94625079f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Wed, 17 Nov 2021 13:06:48 +0500 Subject: [PATCH] fix use fileshare only when needed. --- AsbCloudApp/Services/IDrillingProgramService.cs | 2 +- AsbCloudApp/Services/IFileService.cs | 4 ++-- AsbCloudDb/Readme.md | 4 +++- .../Services/DrillingProgramService.cs | 4 ++-- AsbCloudInfrastructure/Services/FileService.cs | 10 ++++------ AsbCloudInfrastructure/Services/GoogleDriveService.cs | 1 - AsbCloudInfrastructure/Services/ReportService.cs | 4 ++-- .../Controllers/DrillingProgramController.cs | 7 ++++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/AsbCloudApp/Services/IDrillingProgramService.cs b/AsbCloudApp/Services/IDrillingProgramService.cs index 8ed7d04a..55c42d51 100644 --- a/AsbCloudApp/Services/IDrillingProgramService.cs +++ b/AsbCloudApp/Services/IDrillingProgramService.cs @@ -9,7 +9,7 @@ namespace AsbCloudApp.Services Task CreateFileMarkAsync(FileMarkDto fileMarkDto, int idUser, CancellationToken token); Task GetOrCreateAsync(int idWell, int fileChangerId, CancellationToken token = default); - Task GetOrCreateSharedUrlAsync(int idWell, int idUser, CancellationToken token = default); + Task GetOrCreateSharedUrlAsync(int idWell, int idUser, IFileShareService fileShareService, CancellationToken token = default); Task MarkFileMarkAsDeletedAsync(int idMark, CancellationToken token); } } \ No newline at end of file diff --git a/AsbCloudApp/Services/IFileService.cs b/AsbCloudApp/Services/IFileService.cs index 85cfff6b..dd11a6ba 100644 --- a/AsbCloudApp/Services/IFileService.cs +++ b/AsbCloudApp/Services/IFileService.cs @@ -11,8 +11,8 @@ namespace AsbCloudApp.Services { string RootPath { get; } - Task GetSharedUrlAsync(int idFileInfo, int idUser, CancellationToken token); - Task GetSharedUrlAsync(FileInfoDto dto, int idUser, + Task GetSharedUrlAsync(int idFileInfo, int idUser, IFileShareService fileShareService, CancellationToken token); + Task GetSharedUrlAsync(FileInfoDto dto, int idUser, IFileShareService fileShareService, CancellationToken token = default); Task SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default); diff --git a/AsbCloudDb/Readme.md b/AsbCloudDb/Readme.md index 34fc70bc..b04de171 100644 --- a/AsbCloudDb/Readme.md +++ b/AsbCloudDb/Readme.md @@ -23,4 +23,6 @@ sudo -u postgres pg_dump -Fc -U postgres postgres -W > 2021-11-13_dump.sql.gz #restore ``` psql postgres < dump_file_name - ``` \ No newline at end of file + ``` + +sudo -u postgres psql -p 5499 -U postgres postgres -W < 2021-11-16_dump.sql.gz \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/DrillingProgramService.cs b/AsbCloudInfrastructure/Services/DrillingProgramService.cs index 39b56468..c22c9f7c 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgramService.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgramService.cs @@ -26,7 +26,7 @@ namespace AsbCloudInfrastructure.Services this.wellService = wellService; } - public async Task GetOrCreateSharedUrlAsync(int idWell, int idUser, CancellationToken token = default) + public async Task GetOrCreateSharedUrlAsync(int idWell, int idUser, IFileShareService fileShareService, CancellationToken token = default) { var fileInfo = await GetOrCreateAsync(idWell, idUser, token) .ConfigureAwait(false); @@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services if (fileInfo is null) return null; - var sharedUrl = await fileService.GetSharedUrlAsync(fileInfo, idUser, token) + var sharedUrl = await fileService.GetSharedUrlAsync(fileInfo, idUser, fileShareService, token) .ConfigureAwait(false); return sharedUrl; diff --git a/AsbCloudInfrastructure/Services/FileService.cs b/AsbCloudInfrastructure/Services/FileService.cs index c4f792f0..6c02152f 100644 --- a/AsbCloudInfrastructure/Services/FileService.cs +++ b/AsbCloudInfrastructure/Services/FileService.cs @@ -18,13 +18,11 @@ namespace AsbCloudInfrastructure.Services private readonly IQueryable dbSetConfigured; private readonly IAsbCloudDbContext db; - private readonly IFileShareService fileShareService; - public FileService(IAsbCloudDbContext db, IFileShareService fileShareService) + public FileService(IAsbCloudDbContext db) { RootPath = "files"; this.db = db; - this.fileShareService = fileShareService; dbSetConfigured = db.Files .Include(f => f.Author) .ThenInclude(u => u.Company) @@ -33,17 +31,17 @@ namespace AsbCloudInfrastructure.Services .ThenInclude(m => m.User); } - public async Task GetSharedUrlAsync(int idFileInfo, int idUser, + public async Task GetSharedUrlAsync(int idFileInfo, int idUser, IFileShareService fileShareService, CancellationToken token) { var fileInfo = await GetInfoAsync(idFileInfo, token); if (fileInfo is null) return null; - var sharedUrl = await GetSharedUrlAsync(fileInfo, idUser, token); + var sharedUrl = await GetSharedUrlAsync(fileInfo, idUser, fileShareService, token); return sharedUrl; } - public async Task GetSharedUrlAsync( FileInfoDto fileInfo, int idUser, + public async Task GetSharedUrlAsync( FileInfoDto fileInfo, int idUser, IFileShareService fileShareService, CancellationToken token) { var fileWebUrl = fileInfo.PublishInfo?.WebStorageFileUrl; diff --git a/AsbCloudInfrastructure/Services/GoogleDriveService.cs b/AsbCloudInfrastructure/Services/GoogleDriveService.cs index 41e85b9d..4b6193ef 100644 --- a/AsbCloudInfrastructure/Services/GoogleDriveService.cs +++ b/AsbCloudInfrastructure/Services/GoogleDriveService.cs @@ -11,7 +11,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Services; -using Google.Apis.Auth.OAuth2.Responses; namespace AsbCloudInfrastructure.Services { diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index 2ce4e54a..2c9cad6b 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -23,7 +23,7 @@ namespace AsbCloudInfrastructure.Services private readonly IReportsBackgroundQueue queue; public ReportService(IAsbCloudDbContext db, IConfiguration configuration, - ITelemetryService telemetryService, IFileService fileService, + ITelemetryService telemetryService, IReportsBackgroundQueue queue) { this.db = db; @@ -59,7 +59,7 @@ namespace AsbCloudInfrastructure.Services }; generator.Make(reportFileName); - var fileService = new FileService(context, new GoogleDriveService()); + var fileService = new FileService(context); var fileInfo = fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName).Result; progressHandler.Invoke(new diff --git a/AsbCloudWebApi/Controllers/DrillingProgramController.cs b/AsbCloudWebApi/Controllers/DrillingProgramController.cs index 5807a430..84d985bd 100644 --- a/AsbCloudWebApi/Controllers/DrillingProgramController.cs +++ b/AsbCloudWebApi/Controllers/DrillingProgramController.cs @@ -55,16 +55,17 @@ namespace AsbCloudWebApi.Controllers return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name); } - + /// /// Создает программу бурения /// /// id скважины + /// /// Токен отмены задачи /// Возвращает ссылку на файл программы бурения в облаке [HttpGet("webUrl")] [ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)] - public async Task GetOrCreateSharedUrlAsync(int idWell, CancellationToken token = default) + public async Task GetOrCreateSharedUrlAsync(int idWell, [FromServices]IFileShareService fileShareService, CancellationToken token = default) { var idCompany = User.GetCompanyId(); @@ -76,7 +77,7 @@ namespace AsbCloudWebApi.Controllers return Forbid(); var sharedUrl = await drillingProgramService.GetOrCreateSharedUrlAsync(idWell, - (int)idUser, token) + (int)idUser, fileShareService, token) .ConfigureAwait(false); return Ok(sharedUrl);