- add methods to handle factories and channels

- implement service interfaces
- add first implementation of a few methods
pull/26/head
Simon Gockner 6 years ago
parent a9fde2d98b
commit 6686d62821
  1. 4
      GBase.Client/GBase.Client.csproj
  2. 64
      GBase.Client/GBaseClient.cs
  3. 5
      GBase.Client/Interfaces/IGBaseClient.cs

@ -26,4 +26,8 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.Http" Version="4.7.0" />
</ItemGroup>
</Project> </Project>

@ -2,17 +2,73 @@
// Created: 2020-02-10 // Created: 2020-02-10
// Copyright(c) 2020 SimonG. All Rights Reserved. // 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.Interfaces;
namespace GBase.Client namespace GBase.Client
{ {
public class GBaseClient : IGBaseClient public class GBaseClient : IGBaseClient //TODO: Add logging?
{ {
private readonly IGBaseClientSettings _settings;
public GBaseClient(IGBaseClientSettings settings) public GBaseClient(IGBaseClientSettings settings)
{ {
_settings = settings; GBaseServiceFactory = OpenFactory<IGBaseService>(settings.ServerProtocolGBaseEndpointAddress);
GBaseTableServiceFactory = OpenFactory<IGBaseTableService>(settings.ServerProtocolGBaseTableEndpointAddress);
GBaseEntryServiceFactory = OpenFactory<IGBaseEntryService>(settings.ServerProtocolGBaseEntryEndpointAddress);
}
private ChannelFactory<IGBaseService> GBaseServiceFactory { get; set; }
private ChannelFactory<IGBaseTableService> GBaseTableServiceFactory { get; set; }
private ChannelFactory<IGBaseEntryService> 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<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();
} }
} }
} }

@ -2,9 +2,12 @@
// Created: 2020-02-10 // Created: 2020-02-10
// Copyright(c) 2020 SimonG. All Rights Reserved. // Copyright(c) 2020 SimonG. All Rights Reserved.
using System;
using GBase.Api.Services;
namespace GBase.Client.Interfaces namespace GBase.Client.Interfaces
{ {
public interface IGBaseClient public interface IGBaseClient : IGBaseService, IGBaseTableService, IGBaseEntryService, IAsyncDisposable
{ {
} }

Loading…
Cancel
Save