- move implementation of services from client to extra classes that get called from client

pull/26/head
Simon Gockner 6 years ago
parent 6686d62821
commit 7a1b449d28
  1. 61
      GBase.Client/GBaseClient.cs
  2. 3
      GBase.Client/Interfaces/IGBaseClient.cs
  3. 17
      GBase.Client/Services/GBaseEntryService.cs
  4. 37
      GBase.Client/Services/GBaseService.cs
  5. 17
      GBase.Client/Services/GBaseTableService.cs
  6. 46
      GBase.Client/Services/Service.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<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();
}
}
}

@ -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
{
}

@ -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>, IGBaseEntryService
{
public GBaseEntryService(string endpoint)
: base(endpoint)
{
}
}
}

@ -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>, 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;
}
}
}

@ -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>, IGBaseTableService
{
public GBaseTableService(string endpoint)
: base(endpoint)
{
}
}
}

@ -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<TService> : IAsyncDisposable
{
protected Service(string endpoint)
{
ServiceFactory = OpenFactory(endpoint);
}
private ChannelFactory<TService> ServiceFactory { get; }
private ChannelFactory<TService> OpenFactory(string endpoint)
{
ChannelFactory<TService> factory = new ChannelFactory<TService>(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();
}
}
}
Loading…
Cancel
Save