diff --git a/GBase.Client/GBaseClient.cs b/GBase.Client/GBaseClient.cs index c5578bd..5885fc4 100644 --- a/GBase.Client/GBaseClient.cs +++ b/GBase.Client/GBaseClient.cs @@ -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(settings.ServerProtocolGBaseEndpointAddress); - GBaseTableServiceFactory = OpenFactory(settings.ServerProtocolGBaseTableEndpointAddress); - GBaseEntryServiceFactory = OpenFactory(settings.ServerProtocolGBaseEntryEndpointAddress); + GBase = new GBaseService(settings.ServerProtocolGBaseEndpointAddress); + GBaseTable = new GBaseTableService(settings.ServerProtocolGBaseTableEndpointAddress); + GBaseEntry = new GBaseEntryService(settings.ServerProtocolGBaseEntryEndpointAddress); } - private ChannelFactory GBaseServiceFactory { get; set; } - private ChannelFactory GBaseTableServiceFactory { get; set; } - private ChannelFactory 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 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(); + await GBase.DisposeAsync(); + await GBaseTable.DisposeAsync(); + await GBaseEntry.DisposeAsync(); } } } \ No newline at end of file diff --git a/GBase.Client/Interfaces/IGBaseClient.cs b/GBase.Client/Interfaces/IGBaseClient.cs index 47eeca5..3285b5c 100644 --- a/GBase.Client/Interfaces/IGBaseClient.cs +++ b/GBase.Client/Interfaces/IGBaseClient.cs @@ -3,11 +3,10 @@ // Copyright(c) 2020 SimonG. All Rights Reserved. using System; -using GBase.Api.Services; namespace GBase.Client.Interfaces { - public interface IGBaseClient : IGBaseService, IGBaseTableService, IGBaseEntryService, IAsyncDisposable + public interface IGBaseClient : IAsyncDisposable { } diff --git a/GBase.Client/Services/GBaseEntryService.cs b/GBase.Client/Services/GBaseEntryService.cs new file mode 100644 index 0000000..37b8d6e --- /dev/null +++ b/GBase.Client/Services/GBaseEntryService.cs @@ -0,0 +1,17 @@ +// Author: Gockner, Simon +// Created: 2020-02-11 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using GBase.Api.Services; + +namespace GBase.Client.Services +{ + public class GBaseEntryService : Service, IGBaseEntryService + { + public GBaseEntryService(string endpoint) + : base(endpoint) + { + + } + } +} \ No newline at end of file diff --git a/GBase.Client/Services/GBaseService.cs b/GBase.Client/Services/GBaseService.cs new file mode 100644 index 0000000..8c99df3 --- /dev/null +++ b/GBase.Client/Services/GBaseService.cs @@ -0,0 +1,37 @@ +// Author: Gockner, Simon +// Created: 2020-02-11 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using GBase.Api.Services; + +namespace GBase.Client.Services +{ + public class GBaseService : Service, IGBaseService + { + public GBaseService(string endpoint) + : base(endpoint) + { + + } + + public bool AddTable() //TODO: Implement this function correctly + { + IGBaseService channel = OpenChannel(); + bool success = channel.AddTable(); + + CloseChannel(channel); + + return success; + } + + public bool RemoveTable() //TODO: Implement this function correctly + { + IGBaseService channel = OpenChannel(); + bool success = channel.RemoveTable(); + + CloseChannel(channel); + + return success; + } + } +} \ No newline at end of file diff --git a/GBase.Client/Services/GBaseTableService.cs b/GBase.Client/Services/GBaseTableService.cs new file mode 100644 index 0000000..184c2d4 --- /dev/null +++ b/GBase.Client/Services/GBaseTableService.cs @@ -0,0 +1,17 @@ +// Author: Gockner, Simon +// Created: 2020-02-11 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using GBase.Api.Services; + +namespace GBase.Client.Services +{ + public class GBaseTableService : Service, IGBaseTableService + { + public GBaseTableService(string endpoint) + : base(endpoint) + { + + } + } +} \ No newline at end of file diff --git a/GBase.Client/Services/Service.cs b/GBase.Client/Services/Service.cs new file mode 100644 index 0000000..a58b949 --- /dev/null +++ b/GBase.Client/Services/Service.cs @@ -0,0 +1,46 @@ +// Author: Gockner, Simon +// Created: 2020-02-11 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System; +using System.ServiceModel; +using System.Threading.Tasks; + +namespace GBase.Client.Services +{ + public abstract class Service : IAsyncDisposable + { + protected Service(string endpoint) + { + ServiceFactory = OpenFactory(endpoint); + } + + private ChannelFactory ServiceFactory { get; } + + private ChannelFactory OpenFactory(string endpoint) + { + ChannelFactory factory = new ChannelFactory(new BasicHttpBinding(), new EndpointAddress(endpoint)); + factory.Open(); + + return factory; + } + + protected TService OpenChannel() + { + TService channel = ServiceFactory.CreateChannel(); + ((IClientChannel)channel).Open(); + + return channel; + } + + protected void CloseChannel(TService service) + { + ((IClientChannel) service).Close(); + } + + public async ValueTask DisposeAsync() + { + ServiceFactory.Close(); + } + } +} \ No newline at end of file