public void Init(string wsuri, string realm) { _factory = new DefaultWampChannelFactory(); _channel = _factory.CreateJsonChannel(wsuri, realm); try { _channel.Open().Wait(); services = _channel.RealmProxy.Services; // register procedures for remote calling services.RegisterCallee(this).Wait(); // publishing onPublishSystemStatusSubject = services.GetSubject <RPiHomeSecurityStatus>("com.rpihomesecurity.onstatus"); monitor = _channel.RealmProxy.Monitor; monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; IsConnected = true; Console.WriteLine("WAMP connection success"); } catch (Exception e) { Console.WriteLine("Failure to Initialise WAMP connection. Is crossbar started?" + e.Message); } }
public async Task <bool> Run <TRetorno, TParametro>(CalleeRequest <TRetorno, TParametro> calleeReq) where TParametro : class { try { RegisterOptions registerOptions = new RegisterOptions(); bool result = false; IWampClientConnectionMonitor monitor = this._channel.RealmProxy.Monitor; monitor.ConnectionEstablished += OnConnectionEstablished; monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; registerOptions.Invoke = "roundrobin"; var operation = new AbstractCalleeOperation <TRetorno, TParametro>(calleeReq.Run, calleeReq.NomeMetodo); IWampRealmProxy realm = this._channel.RealmProxy; Task <IAsyncDisposable> registrationTask = realm.RpcCatalog.Register(operation, registerOptions); result = this._channel.RealmProxy.Monitor.IsConnected; return(result); } catch (System.Exception ex) { throw; } }
public async Task <bool> Run(PubContent <TMensagem> mensagem) { bool result = false; IWampClientConnectionMonitor monitor = this._channel.RealmProxy.Monitor; if (string.IsNullOrEmpty(mensagem.NomeFila)) { throw new Exception("Informe um tópico!!"); } monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; ISubject <TMensagem> subject = null; try { subject = this._channel.RealmProxy.Services.GetSubject <TMensagem>(mensagem.NomeFila); subject.OnNext(mensagem.Mensagem); result = true; } catch (Exception ex) { throw ex; } return(result); }
public async Task <bool> Run(SubContent <TMensagem> mensagem) { bool result = false; IWampClientConnectionMonitor monitor = this._channel.RealmProxy.Monitor; if (string.IsNullOrEmpty(mensagem.NomeFila)) { throw new Exception("Informe um tópico!!"); } monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; IWampRealmServiceProvider services = this._channel.RealmProxy.Services; ISubject <TMensagem> helloSubject = services.GetSubject <TMensagem>(mensagem.NomeFila); IDisposable subscription = helloSubject.Subscribe <TMensagem>(x => { mensagem.MessageListener(x); }); result = true; return(result); }
static async Task Main(string[] args) { const string url = "ws://127.0.0.1:8080/ws"; const string realm = "realm1"; DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(); IWampClientAuthenticator authenticator = new TicketAuthenticator(); IWampChannel channel = channelFactory.CreateJsonChannel(url, realm, authenticator); IWampRealmProxy realmProxy = channel.RealmProxy; IWampClientConnectionMonitor monitor = realmProxy.Monitor; monitor.ConnectionEstablished += ConnectionEstablished; monitor.ConnectionBroken += ConnectionBroken; await channel.Open().ConfigureAwait(false); ITimeService proxy = realmProxy.Services.GetCalleeProxy <ITimeService>(); try { string now = await proxy.Now(); Console.WriteLine("call result {0}", now); } catch (Exception e) { Console.WriteLine("call error {0}", e); } Console.ReadLine(); }
public WampCaller(IWampServerProxy proxy, IWampFormatter <TMessage> formatter, IWampClientConnectionMonitor monitor) { mProxy = proxy; mFormatter = formatter; mMonitor = monitor; monitor.ConnectionBroken += OnConnectionBroken; monitor.ConnectionError += OnConnectionError; }
public PublisherDisposable(object instance, Delegate @delegate, EventInfo @event, string topicUri, IWampClientConnectionMonitor monitor) { mInstance = instance; mDelegate = @delegate; mEvent = @event; mTopicUri = topicUri; mMonitor = monitor; monitor.ConnectionBroken += OnConnectionBroken; monitor.ConnectionError += OnConnectionError; }
public WampChannel(IControlledWampConnection <TMessage> connection, IWampRpcClientFactory <TMessage> rpcClientFactory, IWampPubSubClientFactory <TMessage> pubSubClientFactory, WampServerProxyBuilder <TMessage, IWampClient <TMessage>, IWampServer> serverProxyBuilder, IWampAuxiliaryClientFactory <TMessage> connectionMonitorFactory) { mConnection = connection; mRpcClientFactory = rpcClientFactory; mPubSubClientFactory = pubSubClientFactory; mServerProxyBuilder = serverProxyBuilder; mConnectionMonitor = connectionMonitorFactory.CreateMonitor(connection); }
public ClientInvocationHandler(IWampRpcOperationCatalogProxy catalogProxy, IWampClientConnectionMonitor monitor) { mCatalogProxy = catalogProxy; mMonitor = monitor; mDisconnectionTaskCompletionSource = new TaskCompletionSource <Exception>(); mDisconnectionWaitHandle = new ManualResetEvent(false); mMonitor.ConnectionError += OnConnectionError; mMonitor.ConnectionBroken += OnConnectionBroken; }
public async Task <bool> Run(CallerResult <TRetorno, TParametro> rpcPub) { RegisterOptions registerOptions = new RegisterOptions(); var callback = new AbstractCallerCallback <TRetorno>(rpcPub.Resultado); bool result = true; IWampClientConnectionMonitor monitor = this._channel.RealmProxy.Monitor; monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; registerOptions.Invoke = "roundrobin"; IWampRealmProxy realm = this._channel.RealmProxy; var parameters = new object[] { rpcPub.Parametros }; realm.RpcCatalog.Invoke(callback, new CallOptions(), rpcPub.NomeMetodo, parameters); return(result); }
/// <summary> /// Initializes a new instance of <see cref="WampChannelReconnector"/>. /// </summary> /// <param name="channel">The channel used to connect.</param> /// <param name="connector">The Task to use in order to connect.</param> public WampChannelReconnector(IWampChannel channel, Func <Task> connector) { IWampClientConnectionMonitor monitor = channel.RealmProxy.Monitor; var connectionBrokenObservable = Observable.FromEventPattern <WampSessionCloseEventArgs> (x => monitor.ConnectionBroken += x, x => monitor.ConnectionBroken -= x) .Select(x => Unit.Default); var onceAndConnectionBroken = Observable.Return(Unit.Default).Concat (connectionBrokenObservable); IObservable <IObservable <Unit> > reconnect = from connectionBroke in onceAndConnectionBroken let tryReconnect = Observable.FromAsync(connector) .Catch <Unit, Exception>(x => Observable.Empty <Unit>()) select tryReconnect; mMerged = reconnect.Concat(); }
public WampClientSubject(IWampTopicProxy topic, IWampClientConnectionMonitor monitor) { mTopic = topic; mObservable = CreateObservable(topic, monitor); }
public WampTopicContainerProxy(IWampServerProxy proxy, IWampFormatter <TMessage> formatter, IWampClientConnectionMonitor monitor) { mProxy = proxy; mSubscriber = new WampSubscriber <TMessage>(proxy, formatter, monitor); mPublisher = new WampPublisher <TMessage>(proxy, formatter, monitor); }
public WampRpcOperationCatalogProxy(IWampServerProxy proxy, IWampFormatter <TMessage> formatter, IWampClientConnectionMonitor monitor) { mCallee = new WampCallee <TMessage>(proxy, formatter, monitor); mCaller = new WampCaller <TMessage>(proxy, formatter, monitor); }
private async static Task Run(string wsuri, string realm) { Console.WriteLine("Connecting to {0}, realm {1}", wsuri, realm); DefaultWampChannelFactory factory = new DefaultWampChannelFactory(); IWampChannel channel = factory.CreateJsonChannel(wsuri, realm); IWampClientConnectionMonitor monitor = channel.RealmProxy.Monitor; monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; await channel.Open().ConfigureAwait(false); IWampRealmServiceProvider services = channel.RealmProxy.Services; // SUBSCRIBE to a topic and receive events ISubject <string> helloSubject = services.GetSubject <string>("com.example.onhello"); IDisposable subscription = helloSubject.Subscribe (x => Console.WriteLine("event for 'onhello' received: {0}", x)); Console.WriteLine("subscribed to topic 'onhello'"); // REGISTER a procedure for remote calling Add2Service callee = new Add2Service(); await services.RegisterCallee(callee) .ConfigureAwait(false); Console.WriteLine("procedure add2() registered"); // PUBLISH and CALL every second... forever ISubject <int> onCounterSubject = services.GetSubject <int>("com.example.oncounter"); IMul2Service proxy = services.GetCalleeProxy <IMul2Service>(); int counter = 0; while (true) { // PUBLISH an event onCounterSubject.OnNext(counter); Console.WriteLine("published to 'oncounter' with counter {0}", counter); counter++; // CALL a remote procedure try { int result = await proxy.Multiply(counter, 3) .ConfigureAwait(false); Console.WriteLine("mul2() called with result: {0}", result); } catch (WampException ex) { if (ex.ErrorUri != "wamp.error.no_such_procedure") { Console.WriteLine("call of mul2() failed: " + ex); } } await Task.Delay(TimeSpan.FromSeconds(1)) .ConfigureAwait(false); } }
private async static Task Run(string wsuri, string realm) { Console.WriteLine("Connecting to {0}, realm {1}", wsuri, realm); WampChannelFactory factory = new WampChannelFactory(); IWampChannel channel = factory.ConnectToRealm(realm) .WebSocketTransport(wsuri) .JsonSerialization() .Build(); IWampClientConnectionMonitor monitor = channel.RealmProxy.Monitor; monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; await channel.Open().ConfigureAwait(false); IWampRealmServiceProvider services = channel.RealmProxy.Services; // SUBSCRIBE to a topic and receive events HelloSubscriber subscriber = new HelloSubscriber(); IAsyncDisposable subscriptionDisposable = await services.RegisterSubscriber(subscriber) .ConfigureAwait(false); Console.WriteLine("subscribed to topic 'onhello'"); // REGISTER a procedure for remote calling Add2Service callee = new Add2Service(); IAsyncDisposable registrationDisposable = await services.RegisterCallee(callee) .ConfigureAwait(false); Console.WriteLine("procedure add2() registered"); // PUBLISH and CALL every second... forever CounterPublisher publisher = new CounterPublisher(); IDisposable publisherDisposable = channel.RealmProxy.Services.RegisterPublisher(publisher); IMul2Service proxy = services.GetCalleeProxy <IMul2Service>(); int counter = 0; while (true) { // PUBLISH an event publisher.Publish(counter); Console.WriteLine("published to 'oncounter' with counter {0}", counter); counter++; // CALL a remote procedure try { int result = await proxy.Multiply(counter, 3) .ConfigureAwait(false); Console.WriteLine("mul2() called with result: {0}", result); } catch (WampException ex) { if (ex.ErrorUri != "wamp.error.no_such_procedure") { Console.WriteLine("call of mul2() failed: " + ex); } } await Task.Delay(TimeSpan.FromSeconds(1)) .ConfigureAwait(false); } }
private static IObservable <IWampSerializedEvent> CreateObservable(IWampTopicProxy topic, IWampClientConnectionMonitor monitor) { IObservable <IWampSerializedEvent> connectionError = Observable.FromEventPattern <WampConnectionErrorEventArgs> (x => monitor.ConnectionError += x, x => monitor.ConnectionError -= x) .SelectMany(x => Observable.Throw <IWampSerializedEvent>(x.EventArgs.Exception)); IObservable <IWampSerializedEvent> connectionComplete = Observable.FromEventPattern <WampSessionCloseEventArgs> (x => monitor.ConnectionBroken += x, x => monitor.ConnectionBroken -= x) .SelectMany(x => Observable.Throw <IWampSerializedEvent>(new WampConnectionBrokenException(x.EventArgs))); ClientObservable messages = new ClientObservable(topic); IObservable <IWampSerializedEvent> result = Observable.Merge(messages, connectionError, connectionComplete); return(result); }