-
Notifications
You must be signed in to change notification settings - Fork 8
Feature/launcher provider create db #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
37fdc8c
9d5f2cf
c5593f6
2266c4b
a43ac62
0e82442
ab2ff0d
80ebe2c
a771542
47c7b2e
b1417d2
8229cb5
3f9ae8e
024eeda
2117298
0dc4147
2611bf3
d20c498
41ba7a7
c9c4b79
84669e9
e8f83e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Grpc.Core; | ||
| using QS.Cloud.Core; | ||
| using QS.Project.Versioning; | ||
| using System.Threading; | ||
|
|
||
| namespace QS.Cloud.Client.Clients { | ||
| public class DataBaseManagementCloudClient : CloudClientByBasicAuth { | ||
| private IApplicationInfo applicationInfo { get; set; } | ||
| public DataBaseManagementCloudClient(IBasicAuthInfoProvider basicAuthInfoProvider) | ||
| : base(basicAuthInfoProvider, "core.cloud.qsolution.ru", 443) | ||
| { | ||
| this.applicationInfo = applicationInfo; | ||
| } | ||
|
|
||
| public CreateDataBaseResponse CreateDataBase(string dbName, string dbTitle, IApplicationInfo applicationInfo) { | ||
| var client = new DataBaseManagement.DataBaseManagementClient(Channel); | ||
| var request = new CreateDataBaseRequest { Name = dbName, Title = dbTitle, ProductId = applicationInfo.ProductCode }; | ||
| return client.CreateDataBase(request, headers); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,46 @@ | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using QS.DbManagement; | ||
| using QS.DBScripts; | ||
| using QS.DBScripts.Controllers; | ||
| using QS.DBScripts.Models; | ||
| using QS.Utilities.Extensions; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using QS.Utilities.Extensions; | ||
|
|
||
| namespace QS.Cloud.Client { | ||
| namespace QS.Cloud.Client.DataBase { | ||
| public class QsCloudConnectionTypeBase : ConnectionTypeBase { | ||
|
|
||
| public QsCloudConnectionTypeBase() { | ||
| Title = "QS: Облако"; | ||
| ConnectionTypeName = "QSCloud"; | ||
|
|
||
| Parameters.Add(new ConnectionParameter("Account","Организация")); | ||
| Parameters.Add(new ConnectionParameter("Login","Пользователь")); | ||
|
|
||
| IconBytes = Assembly.GetExecutingAssembly().GetResourceByteArray("QS.Cloud.Client.Icons.qscloud.ico"); | ||
|
|
||
| CreatorFactory = args => { | ||
| var provider = (QSCloudProvider)args.Provider; | ||
| var scripts = args.ServiceProvider.GetRequiredService<IDbScriptsConfiguration>(); | ||
| return new QsCloudDbCreator( | ||
| provider.BaseId, | ||
| provider.AuthInfo, | ||
| scripts, | ||
| args.Progress, | ||
| args.Interaction, | ||
| args.CancellationToken); | ||
| }; | ||
| } | ||
|
|
||
| public override bool CanConnect(IEnumerable<ConnectionParameterValue> parameters) { | ||
| return parameters.Any(p => p.Name == "Account" && !string.IsNullOrEmpty(p.Value)) && | ||
| parameters.Any(p => p.Name == "Login" && !string.IsNullOrEmpty(p.Value)); | ||
| } | ||
|
|
||
| public override IDbProvider CreateProvider(IList<ConnectionParameterValue> parameters, string password = null) | ||
| => new QSCloudProvider(parameters, password); | ||
| public override IDbProvider CreateProvider(IList<ConnectionParameterValue> parameters, string password = null) { | ||
| return new QSCloudProvider(parameters, password); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| using QS.Cloud.Core; | ||
| using QS.DBScripts; | ||
| using QS.DBScripts.Controllers; | ||
| using QS.DBScripts.Models; | ||
| using QS.Dialog; | ||
| using System; | ||
| using System.Threading; | ||
|
|
||
| namespace QS.Cloud.Client.DataBase | ||
| { | ||
| public class QsCloudDbCreator : IDbCreatorModel | ||
| { | ||
| static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); | ||
|
|
||
| private readonly int baseId; | ||
| private readonly IProgressBarDisplayable progress; | ||
| private readonly IDbCreatorInteraction interaction; | ||
| private readonly IDbScriptsConfiguration configuration; | ||
| private readonly CancellationToken cancellationToken; | ||
|
|
||
| private LoginManagementCloudClient loginClient; | ||
|
|
||
| public QsCloudDbCreator( | ||
| int baseId, | ||
| BasicAuthInfoProvider authInfo, | ||
| IDbScriptsConfiguration configuration, | ||
| IProgressBarDisplayable progress, | ||
| IDbCreatorInteraction interaction, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| this.baseId = baseId; | ||
| loginClient = new LoginManagementCloudClient(authInfo); | ||
| this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); | ||
| this.progress = progress ?? throw new ArgumentNullException(nameof(progress)); | ||
| this.interaction = interaction ?? throw new ArgumentNullException(nameof(interaction)); | ||
| this.cancellationToken = cancellationToken; | ||
| } | ||
|
|
||
| public bool RunCreation(string dbName, string dbTitle) { | ||
| try { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| StartSessionResponse session = loginClient.StartSession(baseId); | ||
|
|
||
| if(!session.Success) { | ||
| interaction.ReportError("Ошибка в создании сессии", "Запрос в облако"); | ||
| return false; | ||
| } | ||
| if(!session.IsAdmin) { | ||
| interaction.ReportError("Вы не имеете прав Администратора", "Запрос в облако"); | ||
| return false; | ||
| } | ||
|
|
||
| var infoProvider = new SessionInfoProvider(sessionId: session.SessionId); | ||
| var sessionLife = new AliveCloudClient(infoProvider); | ||
| sessionLife.NewMessage += (mes) => { | ||
| progress.Update("Сессия: " + mes + " в статусе " + sessionLife.LastStatus.ToString()); | ||
| }; | ||
| sessionLife.KeepAlive(); | ||
|
|
||
| var creator = new MySqlDbCreateModel( | ||
| session.Db.Server, session.Db.Port, session.Db.Login, session.Db.Password, | ||
| configuration.MakeCreationScript(), progress, interaction, cancellationToken); | ||
| creator.FillBaseGuid = false; | ||
| bool success = creator.RunCreation(session.Db.BaseName, dbTitle); | ||
|
|
||
| sessionLife.Dispose(); | ||
| return success; | ||
| } | ||
| catch(OperationCanceledException) { | ||
| logger.Info("Создание базы в облаке отменено пользователем."); | ||
| return false; | ||
| } | ||
| catch(Exception ex) { | ||
| logger.Error(ex, "Ошибка при создании базы в облаке."); | ||
| interaction.ReportError(ex.Message, null); | ||
| throw; | ||
| } | ||
| finally { | ||
| if(progress.IsStarted) | ||
| progress.Close(); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package QS.Cloud.Core; | ||
|
|
||
| service DataBaseManagement{ | ||
| // Создать пустую базу | ||
| rpc CreateDataBase (CreateDataBaseRequest) returns (CreateDataBaseResponse); | ||
| } | ||
|
|
||
| message CreateDataBaseRequest{ | ||
| string name = 1; | ||
| string title = 2; | ||
| uint32 product_id = 3; | ||
| } | ||
|
|
||
| message CreateDataBaseResponse{ | ||
| int32 base_id = 1; | ||
| string base_guid = 2; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using System; | ||
| using QS.DbManagement; | ||
|
|
||
| namespace QS.Launcher.ViewModels.PageViewModels.DataBase { | ||
| /// <summary> | ||
| /// Один шаг пайплайна создания базы | ||
| /// </summary> | ||
| public sealed class DbCreationPhase { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем для этого целый класс?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Это делает прогресс страницу универсальной, просто атомарная операция, мне кажется, классы и нужны, чтобы инкапсулировать подобную логику. |
||
| public string Title { get; } | ||
| public Func<CreatorFactoryArgs, bool> Action { get; } | ||
|
|
||
| public DbCreationPhase(string title, Func<CreatorFactoryArgs, bool> action) { | ||
| Title = title ?? throw new ArgumentNullException(nameof(title)); | ||
| Action = action ?? throw new ArgumentNullException(nameof(action)); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не согласен, с решением, по сути ты смешиваешь зачем то 2 различные функциональности, вход в саму админку сервера и вход в базу. Просто в моем представлении у IDbProvider не может быть базы в принцепе. Или я не понял задумки.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я все же пока что оставил BaseId он его получает от сервера после создания, чтобы потом при наполнении базы получить эту базу, иначе он никак не сможет его передать. потому что интферфейс создания базы возвращает только bool успешности, можно сделать более универсальый тип вывода функции создания, но как будто это только для облака нужно будет,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
при этом правйдер базу не наполняет, он лишь несет данные после создания базы