From 9ca7bf75e7bf79fd8604b28ef19dfc82172152a9 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 9 Sep 2022 15:29:46 +0500 Subject: [PATCH] Update nuget packs --- AsbCloudDb/AsbCloudDb.csproj | 4 +- .../AsbCloudInfrastructure.csproj | 11 +- .../AsbCloudWebApi.Tests.csproj | 12 +- AsbCloudWebApi/AsbCloudWebApi.csproj | 12 +- ConsoleApp1/ConsoleApp1.csproj | 11 +- ConsoleApp1/GoogleDriveService.cs | 145 ------------------ 6 files changed, 23 insertions(+), 172 deletions(-) delete mode 100644 ConsoleApp1/GoogleDriveService.cs diff --git a/AsbCloudDb/AsbCloudDb.csproj b/AsbCloudDb/AsbCloudDb.csproj index 38f953fe..16b1354f 100644 --- a/AsbCloudDb/AsbCloudDb.csproj +++ b/AsbCloudDb/AsbCloudDb.csproj @@ -6,11 +6,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index 36035215..b38c4f87 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -28,14 +28,13 @@ - - - - + + + - - + + diff --git a/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj b/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj index 3069a4b2..f8b181c5 100644 --- a/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj +++ b/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj @@ -7,12 +7,12 @@ - - - - - - + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/AsbCloudWebApi/AsbCloudWebApi.csproj b/AsbCloudWebApi/AsbCloudWebApi.csproj index 820753a6..4a1f5733 100644 --- a/AsbCloudWebApi/AsbCloudWebApi.csproj +++ b/AsbCloudWebApi/AsbCloudWebApi.csproj @@ -9,12 +9,12 @@ - - - - - - + + + + + + diff --git a/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1.csproj index 173388d2..da0e1e97 100644 --- a/ConsoleApp1/ConsoleApp1.csproj +++ b/ConsoleApp1/ConsoleApp1.csproj @@ -8,13 +8,15 @@ + + + - - + @@ -32,9 +34,4 @@ - - - - - diff --git a/ConsoleApp1/GoogleDriveService.cs b/ConsoleApp1/GoogleDriveService.cs deleted file mode 100644 index b26ea93e..00000000 --- a/ConsoleApp1/GoogleDriveService.cs +++ /dev/null @@ -1,145 +0,0 @@ -using Google.Apis.Auth.OAuth2; -using Google.Apis.Auth.OAuth2.Flows; -using Google.Apis.Auth.OAuth2.Responses; -using Google.Apis.Drive.v3; -using Google.Apis.Drive.v3.Data; -using Google.Apis.Services; -using Google.Apis.Util.Store; -using System.IO; -using System.Linq; - -// usage example at the very bottom -namespace ConsoleApp1 -{ - public class GoogleDriveService - { - private readonly DriveService service; - - public GoogleDriveService() - { // ключи для почты asbautodrilling@gmail.com. - var tokenResponse = new TokenResponse - { - AccessToken = "ya29.a0ARrdaM-lM7q0TIC_DXixR4oW63QUftjSPHl-8nIdvZwtqA8Z1bXtlYpDrQXj9UFTjW8FW8uqPMrdamUSp4kO4a9JX7FddkBWxaJ_omSJpqzDfnHTHA_7-zGMUohaAsmPLsQtFz_GUmB5ZoVLmA8xWdbJxVxU", - RefreshToken = "1//04FeDguc19IfgCgYIARAAGAQSNwF-L9Ir8U7wX2seanUzsxXXGgFzOYQqjbtN9O27ZZybbOobZjVAo_4_eFNLMX1ElPKOFVWsrJQ" - }; - - var applicationName = "Files"; // Use the name of the project in Google Cloud - var username = "asbautodrilling@gmail.com"; // Use your email - - var apiCodeFlow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer - { - ClientSecrets = new ClientSecrets - { - ClientId = "1020584579240-f7amqg35qg7j94ta1ntgitajq27cgh49.apps.googleusercontent.com", - ClientSecret = "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" - }, - Scopes = new[] { DriveService.Scope.Drive }, - DataStore = new FileDataStore(applicationName) - }); - - var credential = new UserCredential(apiCodeFlow, username, tokenResponse); - - var newService = new DriveService(new BaseClientService.Initializer - { - HttpClientInitializer = credential, - ApplicationName = applicationName - }); - this.service = newService; - } - - // public IEnumerable GetAllFiles() // get file names - // { - // var fileList = service.Files.List(); - // fileList.Fields = "files(id, webViewLink, size)"; - // //fileList.Q =$"mimeType!='application/vnd.google-apps.folder' and '{folder}' in parents"; - // //fileList.Fields = "nextPageToken, files(id, name, size, mimeType)"; - // - // var result = new List(); - // string pageToken = null; - // do - // { - // fileList.PageToken = pageToken; - // var filesResult = fileList.Execute(); - // var files = filesResult.Files; - // pageToken = filesResult.NextPageToken; - // result.AddRange(files); - // } while (pageToken != null); - // - // return result; - // } - - public string GetFileWebLink(string idFile) - { - var fileList = service.Files.List(); - fileList.Fields = "files(id, webViewLink, size)"; - var filesResult = fileList.Execute(); - var file = filesResult.Files.FirstOrDefault(f => f.Id == idFile); - return file?.WebViewLink ?? string.Empty; - } - - // У Гугла почему-то folder это и папка, и файл. - public string CreateFolder(string folderName) - { - var driveFolder = new Google.Apis.Drive.v3.Data.File(); - driveFolder.Name = folderName; - driveFolder.MimeType = "application/vnd.google-apps.folder"; - //driveFolder.Parents = new string[] { parent }; - var command = service.Files.Create(driveFolder); - var file = command.Execute(); - return file.Id; - } - - public void CreatePublicPermissionForFile(string idFile) - { - var permission = new Permission() { Type = "anyone", Role = "reader" }; - var addPermissionRequest = service.Permissions.Create(permission, idFile); - addPermissionRequest.Execute(); - } - - public string UploadFile(Stream file, string fileName, string fileMime, string fileDescription) - { - var driveFile = new Google.Apis.Drive.v3.Data.File(); - driveFile.Name = fileName; - driveFile.Description = fileDescription; - driveFile.MimeType = fileMime; - //driveFile.Parents = new [] {folder}; - - var request = service.Files.Create(driveFile, file, fileMime); - request.Fields = "id"; - - var response = request.Upload(); - if (response.Status != Google.Apis.Upload.UploadStatus.Completed) - throw response.Exception; - - return request.ResponseBody.Id; - } - - public void DeleteFile(string fileId) - { - var command = service.Files.Delete(fileId); - var result = command.Execute(); - } - } -} - -// usage example: - -// var service = new GoogleDriveService(); -// -// //var files = serviceWrapper.GetAllFiles(); -// -// // foreach (var file in files) -// // { -// // var permission = new Permission() { Type = "anyone", Role = "reader"}; -// // var createRequest = service.Permissions.Create(permission, file.Id); -// // createRequest.Execute(); -// // Console.WriteLine(file.WebViewLink); -// // } -// -// var path = "/home/cult/First.xlsx"; -// var fileInfo = new FileInfo(path); -// var fileStream = System.IO.File.Open(path, FileMode.Open); -// var uploadedFileId = service.UploadFileAsync(fileStream, fileInfo.Name, "", "uploaded"); -// service.CreatePublicPermissionForFileAsync(uploadedFileId); -// var webLink = service.GetFileWebLinkAsync(uploadedFileId); -// Console.WriteLine(webLink); \ No newline at end of file