|
|
|
|
@ -2,10 +2,9 @@ |
|
|
|
|
// Created: 2020-02-10 |
|
|
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved. |
|
|
|
|
|
|
|
|
|
using System.ServiceModel; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using GBase.Api.Services; |
|
|
|
|
using GBase.Client.Interfaces; |
|
|
|
|
using GBase.Client.Services; |
|
|
|
|
|
|
|
|
|
namespace GBase.Client |
|
|
|
|
{ |
|
|
|
|
@ -13,62 +12,22 @@ namespace GBase.Client |
|
|
|
|
{ |
|
|
|
|
public GBaseClient(IGBaseClientSettings settings) |
|
|
|
|
{ |
|
|
|
|
GBaseServiceFactory = OpenFactory<IGBaseService>(settings.ServerProtocolGBaseEndpointAddress); |
|
|
|
|
GBaseTableServiceFactory = OpenFactory<IGBaseTableService>(settings.ServerProtocolGBaseTableEndpointAddress); |
|
|
|
|
GBaseEntryServiceFactory = OpenFactory<IGBaseEntryService>(settings.ServerProtocolGBaseEntryEndpointAddress); |
|
|
|
|
GBase = new GBaseService(settings.ServerProtocolGBaseEndpointAddress); |
|
|
|
|
GBaseTable = new GBaseTableService(settings.ServerProtocolGBaseTableEndpointAddress); |
|
|
|
|
GBaseEntry = new GBaseEntryService(settings.ServerProtocolGBaseEntryEndpointAddress); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ChannelFactory<IGBaseService> GBaseServiceFactory { get; set; } |
|
|
|
|
private ChannelFactory<IGBaseTableService> GBaseTableServiceFactory { get; set; } |
|
|
|
|
private ChannelFactory<IGBaseEntryService> GBaseEntryServiceFactory { get; set; } |
|
|
|
|
|
|
|
|
|
public GBaseService GBase { get; } |
|
|
|
|
public GBaseTableService GBaseTable { get; } |
|
|
|
|
public GBaseEntryService GBaseEntry { get; } |
|
|
|
|
|
|
|
|
|
public bool AddTable() //TODO: Implement this function correctly |
|
|
|
|
{ |
|
|
|
|
IGBaseService channel = OpenChannel(GBaseServiceFactory); |
|
|
|
|
bool success = channel.AddTable(); |
|
|
|
|
|
|
|
|
|
CloseChannel(channel); |
|
|
|
|
|
|
|
|
|
return success; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool RemoveTable() //TODO: Implement this function correctly |
|
|
|
|
{ |
|
|
|
|
IGBaseService channel = OpenChannel(GBaseServiceFactory); |
|
|
|
|
bool success = channel.RemoveTable(); |
|
|
|
|
|
|
|
|
|
CloseChannel(channel); |
|
|
|
|
|
|
|
|
|
return success; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ChannelFactory<TService> OpenFactory<TService>(string endpoint) |
|
|
|
|
{ |
|
|
|
|
ChannelFactory<TService> factory = new ChannelFactory<TService>(new BasicHttpBinding(), new EndpointAddress(endpoint)); |
|
|
|
|
factory.Open(); |
|
|
|
|
|
|
|
|
|
return factory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private TService OpenChannel<TService>(ChannelFactory<TService> factory) |
|
|
|
|
{ |
|
|
|
|
TService channel = factory.CreateChannel(); |
|
|
|
|
((IClientChannel) channel).Open(); |
|
|
|
|
|
|
|
|
|
return channel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void CloseChannel<TService>(TService service) |
|
|
|
|
{ |
|
|
|
|
((IClientChannel) service).Close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async ValueTask DisposeAsync() |
|
|
|
|
{ |
|
|
|
|
GBaseServiceFactory.Close(); |
|
|
|
|
GBaseTableServiceFactory.Close(); |
|
|
|
|
GBaseEntryServiceFactory.Close(); |
|
|
|
|
await GBase.DisposeAsync(); |
|
|
|
|
await GBaseTable.DisposeAsync(); |
|
|
|
|
await GBaseEntry.DisposeAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |