From 6686d6282120c3efa8c4ab6ad6c7e04f655e25b4 Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Mon, 10 Feb 2020 16:42:49 +0100 Subject: [PATCH] - add methods to handle factories and channels - implement service interfaces - add first implementation of a few methods --- GBase.Client/GBase.Client.csproj | 4 ++ GBase.Client/GBaseClient.cs | 64 +++++++++++++++++++++++-- GBase.Client/Interfaces/IGBaseClient.cs | 5 +- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/GBase.Client/GBase.Client.csproj b/GBase.Client/GBase.Client.csproj index f6b50fc..30fe1b7 100644 --- a/GBase.Client/GBase.Client.csproj +++ b/GBase.Client/GBase.Client.csproj @@ -26,4 +26,8 @@ + + + + diff --git a/GBase.Client/GBaseClient.cs b/GBase.Client/GBaseClient.cs index 86aa6c9..c5578bd 100644 --- a/GBase.Client/GBaseClient.cs +++ b/GBase.Client/GBaseClient.cs @@ -2,17 +2,73 @@ // 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; namespace GBase.Client { - public class GBaseClient : IGBaseClient + public class GBaseClient : IGBaseClient //TODO: Add logging? { - private readonly IGBaseClientSettings _settings; - public GBaseClient(IGBaseClientSettings settings) { - _settings = settings; + GBaseServiceFactory = OpenFactory(settings.ServerProtocolGBaseEndpointAddress); + GBaseTableServiceFactory = OpenFactory(settings.ServerProtocolGBaseTableEndpointAddress); + GBaseEntryServiceFactory = OpenFactory(settings.ServerProtocolGBaseEntryEndpointAddress); + } + + private ChannelFactory GBaseServiceFactory { get; set; } + private ChannelFactory GBaseTableServiceFactory { get; set; } + private ChannelFactory GBaseEntryServiceFactory { get; set; } + + + 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 OpenFactory(string endpoint) + { + ChannelFactory factory = new ChannelFactory(new BasicHttpBinding(), new EndpointAddress(endpoint)); + factory.Open(); + + return factory; + } + + private TService OpenChannel(ChannelFactory factory) + { + TService channel = factory.CreateChannel(); + ((IClientChannel) channel).Open(); + + return channel; + } + + private void CloseChannel(TService service) + { + ((IClientChannel) service).Close(); + } + + public async ValueTask DisposeAsync() + { + GBaseServiceFactory.Close(); + GBaseTableServiceFactory.Close(); + GBaseEntryServiceFactory.Close(); } } } \ No newline at end of file diff --git a/GBase.Client/Interfaces/IGBaseClient.cs b/GBase.Client/Interfaces/IGBaseClient.cs index 34a623b..47eeca5 100644 --- a/GBase.Client/Interfaces/IGBaseClient.cs +++ b/GBase.Client/Interfaces/IGBaseClient.cs @@ -2,9 +2,12 @@ // Created: 2020-02-10 // Copyright(c) 2020 SimonG. All Rights Reserved. +using System; +using GBase.Api.Services; + namespace GBase.Client.Interfaces { - public interface IGBaseClient + public interface IGBaseClient : IGBaseService, IGBaseTableService, IGBaseEntryService, IAsyncDisposable { }