Skip to content

Commit

Permalink
[tool] 구독을 원하는 데이터베이스의 메타데이터를 반환하는 로그인 함수 추가
Browse files Browse the repository at this point in the history
cremaconsole.exe 에서 사용하는 내장 함수 `login` 경우 모든 데이터베이스의 메타데이터를 반환하
기 때문에 데이터베이스, 테이블, 타입의 개수가 많은 경우 성능을 저하시킨다.
따라서 원하는 데이터베이스의 메타데이터만 반환하는 API 추가함

추가된 API 목록
- cremaconsole.exe `loginDataBase` 함수
- DataBaseCollectionService.SubscribeDataBase API

기존 대비 성능 개선 효과
- 성능: 3.5s -> 0.4s 로 단축됨
- 데이터 트래픽: 기존 70203188 Bytes -> 2004556 Bytes
  • Loading branch information
powerumc committed Jun 4, 2019
1 parent ae063c8 commit 81720c1
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 91 deletions.
47 changes: 47 additions & 0 deletions client/Ntreev.Crema.Javascript/Methods/LoginDataBaseMethod.cs
Original file line number Diff line number Diff line change
@@ -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<string, string, string, string, string>(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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Compile Include="Authenticator.cs" />
<None Include="Consoles\RunFileCommand.cs" />
<Compile Include="Consoles\RunCommand.cs" />
<Compile Include="Methods\LoginDataBaseMethod.cs" />
<Compile Include="Methods\LoginMethod.cs" />
<Compile Include="Methods\LogoutMethod.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
11 changes: 11 additions & 0 deletions client/Ntreev.Crema.Javascript/ScriptMethodContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
82 changes: 57 additions & 25 deletions client/Ntreev.Crema.Services/CremaHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPlugin>)) as IEnumerable<IPlugin>;
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
{
Expand All @@ -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<IPlugin>)) as IEnumerable<IPlugin>;
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();
Expand Down
13 changes: 11 additions & 2 deletions client/Ntreev.Crema.Services/Data/DataBaseCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -54,7 +56,7 @@ class DataBaseCollection : ContainerBase<DataBase>, IDataBaseCollection, IDataBa
private ItemsEventHandler<IDataBase> itemsAccessChanged;
private ItemsEventHandler<IDataBase> 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;
Expand All @@ -68,8 +70,15 @@ public DataBaseCollection(CremaHost cremaHost, string address, ServiceInfo servi
{
service.Faulted += Service_Faulted;
}
var result = this.service.Subscribe(cremaHost.AuthenticationToken);
ResultBase<DataBaseCollectionMetaData> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ntreev.Crema.ServiceModel.DataBaseCollectionMetaData> 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<Ntreev.Crema.ServiceModel.DataBaseCollectionMetaData> 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();

Expand Down Expand Up @@ -165,6 +168,10 @@ public Ntreev.Crema.ServiceModel.ResultBase DefinitionType(Ntreev.Crema.ServiceM
return base.Channel.Subscribe(authenticationToken);
}

public Ntreev.Crema.ServiceModel.ResultBase<Ntreev.Crema.ServiceModel.DataBaseCollectionMetaData> SubscribeDataBase(System.Guid authenticationToken, string dataBase) {
return base.Channel.SubscribeDataBase(authenticationToken, dataBase);
}

public Ntreev.Crema.ServiceModel.ResultBase Unsubscribe() {
return base.Channel.Unsubscribe();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configurationSnapshot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-microsoft-com:xml-wcfconfigurationsnapshot">
<behaviors />
<bindings>
<binding digest="System.ServiceModel.Configuration.NetTcpBindingElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data name=&quot;NetTcpBinding_IDataBaseCollectionService&quot;&gt;&lt;security mode=&quot;None&quot; /&gt;&lt;/Data&gt;" bindingType="netTcpBinding" name="NetTcpBinding_IDataBaseCollectionService" />
<binding digest="System.ServiceModel.Configuration.NetTcpBindingElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data name=&quot;NetTcpBinding_IDataBaseCollectionService&quot;&gt;&lt;security mode=&quot;None&quot;&gt;&lt;transport sslProtocols=&quot;None&quot; /&gt;&lt;/security&gt;&lt;/Data&gt;" bindingType="netTcpBinding" name="NetTcpBinding_IDataBaseCollectionService" />
</bindings>
<endpoints>
<endpoint normalizedDigest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;net.tcp://localhost:4004/DataBaseCollectionService&quot; binding=&quot;netTcpBinding&quot; bindingConfiguration=&quot;NetTcpBinding_IDataBaseCollectionService&quot; contract=&quot;DataBaseCollectionService.IDataBaseCollectionService&quot; name=&quot;NetTcpBinding_IDataBaseCollectionService&quot; /&gt;" digest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;net.tcp://localhost:4004/DataBaseCollectionService&quot; binding=&quot;netTcpBinding&quot; bindingConfiguration=&quot;NetTcpBinding_IDataBaseCollectionService&quot; contract=&quot;DataBaseCollectionService.IDataBaseCollectionService&quot; name=&quot;NetTcpBinding_IDataBaseCollectionService&quot; /&gt;" contractName="DataBaseCollectionService.IDataBaseCollectionService" name="NetTcpBinding_IDataBaseCollectionService" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<SavedWcfConfigurationInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="9.1" CheckSum="bU0rByQfi/L+kuiMh/z/IOFVaX0=">
<SavedWcfConfigurationInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="9.1" CheckSum="XhWk4dWk1jFrXpNy8g9upoz7Dp8=">
<bindingConfigurations>
<bindingConfiguration bindingType="netTcpBinding" name="NetTcpBinding_IDataBaseCollectionService">
<properties>
Expand Down Expand Up @@ -105,8 +105,8 @@
<property path="/security/transport/extendedProtectionPolicy/customServiceNames" isComplexType="true" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.Configuration.ServiceNameElementCollection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>(컬렉션)</serializedValue>
</property>
<property path="/security/transport/sslProtocols" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Authentication.SslProtocols, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Tls, Tls11, Tls12</serializedValue>
<property path="/security/transport/sslProtocols" isComplexType="false" isExplicitlyDefined="true" clrType="System.Security.Authentication.SslProtocols, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>None</serializedValue>
</property>
<property path="/security/message" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.MessageSecurityOverTcpElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.MessageSecurityOverTcpElement</serializedValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SubscribeDataBase">
<soap12:operation soapAction="http://www.ntreev.com/IDataBaseCollectionService/SubscribeDataBase" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Unsubscribe">
<soap12:operation soapAction="http://www.ntreev.com/IDataBaseCollectionService/Unsubscribe" style="document" />
<wsdl:input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<wsdl:message name="IDataBaseCollectionService_Subscribe_OutputMessage">
<wsdl:part name="parameters" element="tns:SubscribeResponse" />
</wsdl:message>
<wsdl:message name="IDataBaseCollectionService_SubscribeDataBase_InputMessage">
<wsdl:part name="parameters" element="tns:SubscribeDataBase" />
</wsdl:message>
<wsdl:message name="IDataBaseCollectionService_SubscribeDataBase_OutputMessage">
<wsdl:part name="parameters" element="tns:SubscribeDataBaseResponse" />
</wsdl:message>
<wsdl:message name="IDataBaseCollectionService_Unsubscribe_InputMessage">
<wsdl:part name="parameters" element="tns:Unsubscribe" />
</wsdl:message>
Expand Down Expand Up @@ -191,6 +197,10 @@
<wsdl:input wsaw:Action="http://www.ntreev.com/IDataBaseCollectionService/Subscribe" message="tns:IDataBaseCollectionService_Subscribe_InputMessage" />
<wsdl:output wsaw:Action="http://www.ntreev.com/IDataBaseCollectionService/SubscribeResponse" message="tns:IDataBaseCollectionService_Subscribe_OutputMessage" />
</wsdl:operation>
<wsdl:operation msc:isInitiating="true" msc:isTerminating="false" name="SubscribeDataBase">
<wsdl:input wsaw:Action="http://www.ntreev.com/IDataBaseCollectionService/SubscribeDataBase" message="tns:IDataBaseCollectionService_SubscribeDataBase_InputMessage" />
<wsdl:output wsaw:Action="http://www.ntreev.com/IDataBaseCollectionService/SubscribeDataBaseResponse" message="tns:IDataBaseCollectionService_SubscribeDataBase_OutputMessage" />
</wsdl:operation>
<wsdl:operation msc:isInitiating="true" msc:isTerminating="false" name="Unsubscribe">
<wsdl:input wsaw:Action="http://www.ntreev.com/IDataBaseCollectionService/Unsubscribe" message="tns:IDataBaseCollectionService_Unsubscribe_InputMessage" />
<wsdl:output wsaw:Action="http://www.ntreev.com/IDataBaseCollectionService/UnsubscribeResponse" message="tns:IDataBaseCollectionService_Unsubscribe_OutputMessage" />
Expand Down
Loading

0 comments on commit 81720c1

Please sign in to comment.