From 3392be8c7d91d32941fb0e6ecc5d8c30b8ff7bf2 Mon Sep 17 00:00:00 2001 From: Sinan Date: Mon, 8 Oct 2018 11:34:21 +0200 Subject: [PATCH 1/3] Add factory singleton for participants A singleton to create participants with the current repository and current connection settings --- rsb-cil-test/Program.cs | 9 ++-- rsb-cil/Rsb/Factory.cs | 56 ++++++++++++++++++++++ .../Rsb/Transport/Socket/SocketConfiguration.cs | 14 ++++++ rsb-cil/rsb-cil.csproj | 4 +- 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 rsb-cil/Rsb/Factory.cs create mode 100644 rsb-cil/Rsb/Transport/Socket/SocketConfiguration.cs diff --git a/rsb-cil-test/Program.cs b/rsb-cil-test/Program.cs index 16eeed1..6cff907 100644 --- a/rsb-cil-test/Program.cs +++ b/rsb-cil-test/Program.cs @@ -74,12 +74,15 @@ namespace rsbciltest listener.Deactivate(); - Console.WriteLine("\nConverter test:"); + Console.WriteLine("\nFactory Test:"); + + SocketConfiguration.Hostname = host; + SocketConfiguration.Port = port; DefaultConverterRepository.Instance.addConverter(new ProtocolBufferConverter(JointAngles.Descriptor)); - Informer repoInformer = new Informer("/test/repo", new OutConnector(new BusClientConnection(host, port), DefaultConverterRepository.Instance.SerializationConverterSelector)); - Listener repoListener = new Listener(new InPushConnector(new BusClientConnection(host, port), new Scope("/"), DefaultConverterRepository.Instance.DeserializationConverterSelector)); + Informer repoInformer = Factory.Instance.CreateInformer("/test/repo"); + Listener repoListener = Factory.Instance.CreateListener("/"); repoListener.EventReceived += (e) => { diff --git a/rsb-cil/Rsb/Factory.cs b/rsb-cil/Rsb/Factory.cs new file mode 100644 index 0000000..08c431e --- /dev/null +++ b/rsb-cil/Rsb/Factory.cs @@ -0,0 +1,56 @@ +using Rsb.Transport.Socket; +using Rsb.Converter; + +namespace Rsb +{ + public class Factory + { + private static readonly Factory instance = new Factory(); + + // Explicit static constructor to tell C# compiler + // not to mark type as beforefieldinit + static Factory() + { + } + + private Factory() + { + } + + public static Factory Instance + { + get + { + return instance; + } + } + + public Informer CreateInformer(Scope scope) { + + return new Informer(scope, + new OutConnector( + new BusClientConnection(SocketConfiguration.Hostname, SocketConfiguration.Port), + DefaultConverterRepository.Instance.SerializationConverterSelector)); + } + + public Informer CreateInformer(string scope) { + return CreateInformer(new Scope(scope)); + } + + public Listener CreateListener(Scope scope) + { + + return new Listener( + new InPushConnector( + new BusClientConnection(SocketConfiguration.Hostname, SocketConfiguration.Port), + scope, + DefaultConverterRepository.Instance.DeserializationConverterSelector + )); + } + + public Listener CreateListener(string scope) { + return CreateListener(new Scope(scope)); + } + + } +} diff --git a/rsb-cil/Rsb/Transport/Socket/SocketConfiguration.cs b/rsb-cil/Rsb/Transport/Socket/SocketConfiguration.cs new file mode 100644 index 0000000..ad2a126 --- /dev/null +++ b/rsb-cil/Rsb/Transport/Socket/SocketConfiguration.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Rsb.Transport.Socket +{ + public static class SocketConfiguration + { + public static int Port = 55555; + public static string Hostname = "localhost"; + } +} diff --git a/rsb-cil/rsb-cil.csproj b/rsb-cil/rsb-cil.csproj index 4b191fb..347bc05 100644 --- a/rsb-cil/rsb-cil.csproj +++ b/rsb-cil/rsb-cil.csproj @@ -51,6 +51,7 @@ + @@ -60,6 +61,7 @@ + @@ -88,4 +90,4 @@ - + \ No newline at end of file -- 2.14.2.windows.1