From 81720c154233bd6da177518357fa3a2856858dbd Mon Sep 17 00:00:00 2001 From: powerumc Date: Tue, 4 Jun 2019 12:17:59 +0900 Subject: [PATCH] =?UTF-8?q?[tool]=20=EA=B5=AC=EB=8F=85=EC=9D=84=20?= =?UTF-8?q?=EC=9B=90=ED=95=98=EB=8A=94=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=9D=98=20=EB=A9=94=ED=83=80?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=A5=BC=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cremaconsole.exe 에서 사용하는 내장 함수 `login` 경우 모든 데이터베이스의 메타데이터를 반환하 기 때문에 데이터베이스, 테이블, 타입의 개수가 많은 경우 성능을 저하시킨다. 따라서 원하는 데이터베이스의 메타데이터만 반환하는 API 추가함 추가된 API 목록 - cremaconsole.exe `loginDataBase` 함수 - DataBaseCollectionService.SubscribeDataBase API 기존 대비 성능 개선 효과 - 성능: 3.5s -> 0.4s 로 단축됨 - 데이터 트래픽: 기존 70203188 Bytes -> 2004556 Bytes --- .../Methods/LoginDataBaseMethod.cs | 47 ++++++ .../Ntreev.Crema.Javascript.csproj | 1 + .../ScriptMethodContext.cs | 11 ++ client/Ntreev.Crema.Services/CremaHost.cs | 82 +++++++---- .../Data/DataBaseCollection.cs | 13 +- .../DataBaseCollectionService/Reference.cs | 7 + .../configuration.svcinfo | 2 +- .../configuration91.svcinfo | 6 +- .../DataBaseCollectionService/service.wsdl | 9 ++ .../www.ntreev.com.wsdl | 10 ++ .../www.ntreev.com.xsd | 135 ++++++++++-------- .../ICremaHost.cs | 1 + .../Data/DataBaseCollectionService.cs | 34 +++++ .../Data/IDataBaseCollectionService.cs | 3 + 14 files changed, 270 insertions(+), 91 deletions(-) create mode 100644 client/Ntreev.Crema.Javascript/Methods/LoginDataBaseMethod.cs diff --git a/client/Ntreev.Crema.Javascript/Methods/LoginDataBaseMethod.cs b/client/Ntreev.Crema.Javascript/Methods/LoginDataBaseMethod.cs new file mode 100644 index 000000000..f0246f596 --- /dev/null +++ b/client/Ntreev.Crema.Javascript/Methods/LoginDataBaseMethod.cs @@ -0,0 +1,47 @@ +//Released under the MIT License. +// +//Copyright (c) 2018 Ntreev Soft co., Ltd. +// +//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit +//persons to whom the Software is furnished to do so, subject to the following conditions: +// +//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the +//Software. +// +//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +using Ntreev.Crema.Services; +using Ntreev.Library; +using System; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ntreev.Crema.Javascript.Methods +{ + [Export(typeof(IScriptMethod))] + [PartCreationPolicy(CreationPolicy.NonShared)] + class LoginDataBaseMethod : ScriptMethodBase + { + protected override Delegate CreateDelegate() + { + return new Func(this.LoginDataBase); + } + + private string LoginDataBase(string address, string dataBaseName, string userID, string password) + { + if (this.Context is ScriptMethodContext context) + { + return context.Login(address, dataBaseName, userID, password); + } + throw new NotImplementedException(); + } + } +} diff --git a/client/Ntreev.Crema.Javascript/Ntreev.Crema.Javascript.csproj b/client/Ntreev.Crema.Javascript/Ntreev.Crema.Javascript.csproj index 9c793ff56..0f983a540 100644 --- a/client/Ntreev.Crema.Javascript/Ntreev.Crema.Javascript.csproj +++ b/client/Ntreev.Crema.Javascript/Ntreev.Crema.Javascript.csproj @@ -52,6 +52,7 @@ + diff --git a/client/Ntreev.Crema.Javascript/ScriptMethodContext.cs b/client/Ntreev.Crema.Javascript/ScriptMethodContext.cs index d5ac7195e..1ea7e9e29 100644 --- a/client/Ntreev.Crema.Javascript/ScriptMethodContext.cs +++ b/client/Ntreev.Crema.Javascript/ScriptMethodContext.cs @@ -54,6 +54,17 @@ public string Login(string address, string userID, string password) return this.token; } + public string Login(string address, string dataBase, string userID, string password) + { + if (this.token != null) + throw new ArgumentException("이미 로그인되어 있습니다."); + var token = this.cremaHost.Dispatcher.Invoke(() => this.cremaHost.Open(address, dataBase, userID, StringUtility.ToSecureString(password))); + var authenticator = this.cremaHost.GetService(typeof(Authenticator)) as Authenticator; + this.Initialize(authenticator); + this.token = $"{token}"; + return this.token; + } + public void Logout(string token) { if (token == null) diff --git a/client/Ntreev.Crema.Services/CremaHost.cs b/client/Ntreev.Crema.Services/CremaHost.cs index 87910a811..347bdbb53 100644 --- a/client/Ntreev.Crema.Services/CremaHost.cs +++ b/client/Ntreev.Crema.Services/CremaHost.cs @@ -155,31 +155,7 @@ public Guid Open(string address, string userID, SecureString password) { try { - this.address = AddressUtility.GetDisplayAddress(address); - this.log = new LogService(this.address.Replace(':', '_'), userID, AppUtility.UserAppDataPath); - this.log.Verbose = this.verbose; - this.userContext = new UserContext(this, this.ipAddress, serviceInfos[nameof(UserService)], userID, password); - var user = this.userContext.Users[userID]; - user.SetUserState(UserState.Online); - this.userID = userID; - this.authority = user.Authority; - - this.dataBases = new DataBaseCollection(this, this.ipAddress, serviceInfos[nameof(DataBaseCollectionService)]); - this.domainContext = new DomainContext(this, this.ipAddress, serviceInfos[nameof(DomainService)]); - this.isConnected = true; - this.configs = new CremaConfiguration(this.ConfigPath); - this.plugins = this.container.GetService(typeof(IEnumerable)) as IEnumerable; - foreach (var item in this.plugins) - { - var authentication = new Authentication(new AuthenticationProvider(user), item.ID); - this.authentications.Add(authentication); - item.Initialize(authentication); - } - - this.OnOpened(EventArgs.Empty); - this.token = Guid.NewGuid(); - CremaLog.Info($"Crema opened : {address} {userID}"); - return token; + return OpenInternal(address, null, userID, password); } catch { @@ -193,6 +169,62 @@ public Guid Open(string address, string userID, SecureString password) }); } + public Guid Open(string address, string dataBase, string userID, SecureString password) + { + if (this.isConnected == true) + throw new InvalidOperationException(Resources.Exception_AlreadyConnected); + + this.ipAddress = AddressUtility.GetIPAddress(address); + this.serviceInfos = GetServiceInfo(address).ToDictionary(item => item.Name); + + this.OnOpening(EventArgs.Empty); + return this.dispatcher.Invoke(() => + { + try + { + return OpenInternal(address, dataBase, userID, password); + } + catch + { + this.userContext?.Close(CloseInfo.Empty); + this.userContext = null; + this.log?.Dispose(); + this.log = null; + this.address = null; + throw; + } + }); + } + + private Guid OpenInternal(string address, string dataBase, string userID, SecureString password) + { + this.address = AddressUtility.GetDisplayAddress(address); + this.log = new LogService(this.address.Replace(':', '_'), userID, AppUtility.UserAppDataPath); + this.log.Verbose = this.verbose; + this.userContext = new UserContext(this, this.ipAddress, serviceInfos[nameof(UserService)], userID, password); + var user = this.userContext.Users[userID]; + user.SetUserState(UserState.Online); + this.userID = userID; + this.authority = user.Authority; + + this.dataBases = new DataBaseCollection(this, this.ipAddress, dataBase, serviceInfos[nameof(DataBaseCollectionService)]); + this.domainContext = new DomainContext(this, this.ipAddress, serviceInfos[nameof(DomainService)]); + this.isConnected = true; + this.configs = new CremaConfiguration(this.ConfigPath); + this.plugins = this.container.GetService(typeof(IEnumerable)) as IEnumerable; + foreach (var item in this.plugins) + { + var authentication = new Authentication(new AuthenticationProvider(user), item.ID); + this.authentications.Add(authentication); + item.Initialize(authentication); + } + + this.OnOpened(EventArgs.Empty); + this.token = Guid.NewGuid(); + CremaLog.Info($"Crema opened : {address} {userID}"); + return token; + } + public void SaveConfigs() { this.configs.Commit(); diff --git a/client/Ntreev.Crema.Services/Data/DataBaseCollection.cs b/client/Ntreev.Crema.Services/Data/DataBaseCollection.cs index 8e0a5626d..12a56cf0c 100644 --- a/client/Ntreev.Crema.Services/Data/DataBaseCollection.cs +++ b/client/Ntreev.Crema.Services/Data/DataBaseCollection.cs @@ -22,12 +22,14 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.ServiceModel; using System.Text; using System.Threading.Tasks; using Ntreev.Library; using System.Timers; +using Ntreev.Library.Serialization; namespace Ntreev.Crema.Services.Data { @@ -54,7 +56,7 @@ class DataBaseCollection : ContainerBase, IDataBaseCollection, IDataBa private ItemsEventHandler itemsAccessChanged; private ItemsEventHandler itemsLockChanged; - public DataBaseCollection(CremaHost cremaHost, string address, ServiceInfo serviceInfo) + public DataBaseCollection(CremaHost cremaHost, string address, string dataBase, ServiceInfo serviceInfo) { this.cremaHost = cremaHost; this.userContext = cremaHost.UserContext; @@ -68,8 +70,15 @@ public DataBaseCollection(CremaHost cremaHost, string address, ServiceInfo servi { service.Faulted += Service_Faulted; } - var result = this.service.Subscribe(cremaHost.AuthenticationToken); + + ResultBase result; + result = dataBase == null + ? this.service.Subscribe(cremaHost.AuthenticationToken) + : this.service.SubscribeDataBase(cremaHost.AuthenticationToken, dataBase); result.Validate(); + + XmlSerializerUtility.Write("./a.xml", result); + #if !DEBUG this.timer = new Timer(30000); this.timer.Elapsed += Timer_Elapsed; diff --git a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/Reference.cs b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/Reference.cs index 1ffa29152..a390be182 100644 --- a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/Reference.cs +++ b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/Reference.cs @@ -21,6 +21,9 @@ internal interface IDataBaseCollectionService { [System.ServiceModel.OperationContractAttribute(Action="http://www.ntreev.com/IDataBaseCollectionService/Subscribe", ReplyAction="http://www.ntreev.com/IDataBaseCollectionService/SubscribeResponse")] Ntreev.Crema.ServiceModel.ResultBase Subscribe(System.Guid authenticationToken); + [System.ServiceModel.OperationContractAttribute(Action="http://www.ntreev.com/IDataBaseCollectionService/SubscribeDataBase", ReplyAction="http://www.ntreev.com/IDataBaseCollectionService/SubscribeDataBaseResponse")] + Ntreev.Crema.ServiceModel.ResultBase SubscribeDataBase(System.Guid authenticationToken, string dataBase); + [System.ServiceModel.OperationContractAttribute(Action="http://www.ntreev.com/IDataBaseCollectionService/Unsubscribe", ReplyAction="http://www.ntreev.com/IDataBaseCollectionService/UnsubscribeResponse")] Ntreev.Crema.ServiceModel.ResultBase Unsubscribe(); @@ -165,6 +168,10 @@ public Ntreev.Crema.ServiceModel.ResultBase DefinitionType(Ntreev.Crema.ServiceM return base.Channel.Subscribe(authenticationToken); } + public Ntreev.Crema.ServiceModel.ResultBase SubscribeDataBase(System.Guid authenticationToken, string dataBase) { + return base.Channel.SubscribeDataBase(authenticationToken, dataBase); + } + public Ntreev.Crema.ServiceModel.ResultBase Unsubscribe() { return base.Channel.Unsubscribe(); } diff --git a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/configuration.svcinfo b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/configuration.svcinfo index e63cee694..1d2623038 100644 --- a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/configuration.svcinfo +++ b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/configuration.svcinfo @@ -2,7 +2,7 @@ - + diff --git a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/configuration91.svcinfo b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/configuration91.svcinfo index ba17a6676..28fe19aea 100644 --- a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/configuration91.svcinfo +++ b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/configuration91.svcinfo @@ -1,5 +1,5 @@ - + @@ -105,8 +105,8 @@ (컬렉션) - - Tls, Tls11, Tls12 + + None System.ServiceModel.Configuration.MessageSecurityOverTcpElement diff --git a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/service.wsdl b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/service.wsdl index ecb36172c..de3d1af30 100644 --- a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/service.wsdl +++ b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/service.wsdl @@ -34,6 +34,15 @@ + + + + + + + + + diff --git a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/www.ntreev.com.wsdl b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/www.ntreev.com.wsdl index 0bdec169b..0a5735edd 100644 --- a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/www.ntreev.com.wsdl +++ b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/www.ntreev.com.wsdl @@ -20,6 +20,12 @@ + + + + + + @@ -191,6 +197,10 @@ + + + + diff --git a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/www.ntreev.com.xsd b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/www.ntreev.com.xsd index 27985bc6f..5a9af28cb 100644 --- a/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/www.ntreev.com.xsd +++ b/client/Ntreev.Crema.Services/Service References/DataBaseCollectionService/www.ntreev.com.xsd @@ -31,6 +31,21 @@ + + + + + + + + + + + + + + + @@ -39,7 +54,7 @@ - + @@ -53,7 +68,7 @@ - + @@ -67,7 +82,7 @@ - + @@ -76,14 +91,14 @@ - + - + @@ -92,14 +107,14 @@ - + - + @@ -114,7 +129,7 @@ - + @@ -129,7 +144,7 @@ - + @@ -143,7 +158,7 @@ - + @@ -157,7 +172,7 @@ - + @@ -171,7 +186,7 @@ - + @@ -186,7 +201,7 @@ - + @@ -203,7 +218,7 @@ - + @@ -218,7 +233,7 @@ - + @@ -232,7 +247,7 @@ - + @@ -246,7 +261,7 @@ - + @@ -261,7 +276,7 @@ - + @@ -275,7 +290,7 @@ - + @@ -289,7 +304,7 @@ - + @@ -303,7 +318,7 @@ - + @@ -322,17 +337,17 @@ - - + + - - - + + + @@ -340,106 +355,106 @@ - - - + + + - - + + - - + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - + + - - - + + + - - - - - + + + + + - - - - + + + + diff --git a/common/Ntreev.Crema.Services.Sharing/ICremaHost.cs b/common/Ntreev.Crema.Services.Sharing/ICremaHost.cs index 0b946dbef..97a19c448 100644 --- a/common/Ntreev.Crema.Services.Sharing/ICremaHost.cs +++ b/common/Ntreev.Crema.Services.Sharing/ICremaHost.cs @@ -28,6 +28,7 @@ public interface ICremaHost : IServiceProvider, IDisposable, IDispatcherObject { #if CLIENT Guid Open(string address, string userID, SecureString password); + Guid Open(string address, string dataBase, string userID, SecureString password); string Address { get; } diff --git a/server/Ntreev.Crema.ServiceHosts/Data/DataBaseCollectionService.cs b/server/Ntreev.Crema.ServiceHosts/Data/DataBaseCollectionService.cs index 002a06dc3..0777f342e 100644 --- a/server/Ntreev.Crema.ServiceHosts/Data/DataBaseCollectionService.cs +++ b/server/Ntreev.Crema.ServiceHosts/Data/DataBaseCollectionService.cs @@ -85,6 +85,40 @@ public ResultBase Subscribe(Guid authenticationToken return result; } + + public ResultBase SubscribeDataBase(Guid authenticationToken, string dataBase) + { + var result = new ResultBase(); + try + { + this.userContext.Dispatcher.Invoke(() => + { + this.authentication = this.userContext.Authenticate(authenticationToken); + this.authentication.AddRef(this); + this.OwnerID = this.authentication.ID; + this.userContext.UsersLoggedOut += UserContext_UsersLoggedOut; + }); + result.Value = this.cremaHost.Dispatcher.Invoke(() => + { + this.AttachEventHandlers(); + this.logService.Debug($"[{this.OwnerID}] {nameof(DataBaseCollectionService)} {nameof(SubscribeDataBase)}"); + return new DataBaseCollectionMetaData + { + DataBases = new[] + { + this.cremaHost.DataBases[dataBase].GetMetaData(authentication) + } + }; + }); + result.SignatureDate = this.authentication.SignatureDate; + } + catch (Exception e) + { + result.Fault = new CremaFault(e); + } + return result; + } + public ResultBase Unsubscribe() { var result = new ResultBase(); diff --git a/server/Ntreev.Crema.ServiceHosts/Data/IDataBaseCollectionService.cs b/server/Ntreev.Crema.ServiceHosts/Data/IDataBaseCollectionService.cs index 90c94c3d2..011ccb46c 100644 --- a/server/Ntreev.Crema.ServiceHosts/Data/IDataBaseCollectionService.cs +++ b/server/Ntreev.Crema.ServiceHosts/Data/IDataBaseCollectionService.cs @@ -40,6 +40,9 @@ public interface IDataBaseCollectionService [OperationContract] ResultBase Subscribe(Guid authenticationToken); + [OperationContract] + ResultBase SubscribeDataBase(Guid authenticationToken, string dataBase); + [OperationContract] ResultBase Unsubscribe();