private static Task <long?> Publish(IWampChannel publisherChannel, string topicUri, object[] arguments) { IWampTopicProxy topicProxy = publisherChannel.RealmProxy.TopicContainer.GetTopicByUri(topicUri); return(topicProxy.Publish(new PublishOptions(), arguments)); }
public TDelegate CreateKeywordsDelegate <TDelegate>(IWampTopicProxy proxy, PublishOptions publishOptions) { // Writes: topicProxy.Publish(publishOptions, // new object[0], // new Dictionary<string, object>() // { // {"@arg1", arg1}, // {"@arg2", arg2}, // {"@arg3", arg3}, // ...., // {"@argn", argn} // }); // where @arg1, @arg2, ..., @argn are the names of the delegate variables. Func <ParameterExpression[], Expression> callExpression = parameters => Expression.Call(Expression.Constant(proxy), mPublishKeywordsMethod, Expression.Constant(publishOptions), Expression.NewArrayInit(typeof(object), Enumerable.Empty <Expression>()), Expression.ListInit(Expression.New(typeof(Dictionary <string, object>)), parameters.Select(x => Expression.ElementInit(mAddMethod, Expression.Constant(x.Name, typeof(string)), Expression.Convert(x, typeof(object)))) )); return(InnerCreateDelegate <TDelegate>(callExpression)); }
private IDisposable RegisterToEvent(object instance, EventInfo @event, IPublisherRegistrationInterceptor interceptor) { string topic = interceptor.GetTopicUri(@event); IWampTopicProxy topicProxy = mProxy.TopicContainer.GetTopicByUri(topic); PublishOptions options = interceptor.GetPublishOptions(@event); Delegate createdDelegate; Type eventHandlerType = @event.EventHandlerType; if (IsPositional(eventHandlerType)) { createdDelegate = mEventHandlerGenerator.CreatePositionalDelegate(eventHandlerType, topicProxy, options); } else { createdDelegate = mEventHandlerGenerator.CreateKeywordsDelegate(eventHandlerType, topicProxy, options); } @event.AddEventHandler(instance, createdDelegate); PublisherDisposable disposable = new PublisherDisposable(instance, createdDelegate, @event, topic, mProxy.Monitor); return(disposable); }
public async Task SubscriberGetsEventContextWithPublisherId(bool?discloseMe) { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; MyOtherSubscriber mySubscriber = new MyOtherSubscriber(); IAsyncDisposable disposable = await subscriber.RealmProxy.Services.RegisterSubscriber (mySubscriber); IWampTopicProxy topicProxy = publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2"); long?publish = await topicProxy.Publish (new PublishOptions { DiscloseMe = discloseMe }, new object[] { 47, 23, "Hello" }); long?publisherId = mySubscriber.EventContext.EventDetails.Publisher; if (discloseMe == true) { Assert.That(publisherId, Is.EqualTo(dualChannel.PublisherSessionId)); } else { Assert.That(publisherId, Is.EqualTo(null)); } }
public async void SubscriberGetsEventContextWithPublicationId(bool?acknowledge) { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; MyOtherSubscriber mySubscriber = new MyOtherSubscriber(); IAsyncDisposable disposable = await subscriber.RealmProxy.Services.RegisterSubscriber (mySubscriber); IWampTopicProxy topicProxy = publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2"); long?publish = await topicProxy.Publish (new PublishOptions { Acknowledge = acknowledge }, new object[] { 47, 23, "Hello" }); if (acknowledge == true) { Assert.That(publish, Is.EqualTo(mySubscriber.EventContext.PublicationId)); } else { Assert.That(mySubscriber.EventContext.PublicationId, Is.Not.Null); } }
public async Task PublisherActionDelegateEventRaisePublishesEventWithPositionalArguments() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; MyOtherPublisher myPublisher = new MyOtherPublisher(); IDisposable disposable = publisher.RealmProxy.Services.RegisterPublisher (myPublisher); IWampTopicProxy topicProxy = subscriber.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2"); MyCustomSubscriber myCustomSubscriber = new MyCustomSubscriber(); IAsyncDisposable subscribe = await topicProxy.Subscribe(myCustomSubscriber, new SubscribeOptions()); myPublisher.RaiseMyEvent("Hello", 37, 23); Assert.That(myCustomSubscriber.ArgumentsKeywords, Is.Null.Or.Empty); ISerializedValue[] arguments = myCustomSubscriber.Arguments; Assert.That(arguments[0].Deserialize <string>(), Is.EqualTo("Hello")); Assert.That(arguments[1].Deserialize <int>(), Is.EqualTo(37)); Assert.That(arguments[2].Deserialize <int>(), Is.EqualTo(23)); }
public async Task SubscriberGetsArgumentsArrayEventAsPositionalTuple() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; var subject = subscriber.RealmProxy.Services.GetSubject ("com.myapp.topic2", new MyPositionalTupleEventConverter()); MyPositionalSubscriber mySubscriber = new MyPositionalSubscriber(); subject.Subscribe(mySubscriber); IWampTopicProxy topicProxy = publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2"); long?publish = await topicProxy.Publish(new PublishOptions(), new object[] { "Hello", 47, 23, }); Assert.That(mySubscriber.Number1, Is.EqualTo(47)); Assert.That(mySubscriber.Number2, Is.EqualTo(23)); Assert.That(mySubscriber.C, Is.EqualTo("Hello")); }
public async Task PositionalTupleObservableOnNextPublishesEventWithPositionalArguments() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; var subject = publisher.RealmProxy.Services.GetSubject ("com.myapp.mytopic2", new MyPositionalTupleEventConverter()); IWampTopicProxy topicProxy = subscriber.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2"); MyCustomSubscriber myCustomSubscriber = new MyCustomSubscriber(); IAsyncDisposable subscribe = await topicProxy.Subscribe(myCustomSubscriber, new SubscribeOptions()); // subject.OnNext(("Hello", 37, 23)); subject.OnNext(ValueTuple.Create("Hello", 37, 23)); Assert.That(myCustomSubscriber.ArgumentsKeywords, Is.Null.Or.Empty); ISerializedValue[] arguments = myCustomSubscriber.Arguments; Assert.That(arguments[0].Deserialize <string>(), Is.EqualTo("Hello")); Assert.That(arguments[1].Deserialize <int>(), Is.EqualTo(37)); Assert.That(arguments[2].Deserialize <int>(), Is.EqualTo(23)); }
public IWampSubject GetSubject(string topicUri) { IWampTopicProxy topicProxy = mProxy.TopicContainer.GetTopicByUri(topicUri); WampClientSubject result = new WampClientSubject(topicProxy, mProxy.Monitor); return(result); }
public async Task SubscriberGetsRetainedEvent(bool?publishRetained, bool?getRetained, int expectedCount, bool?acknowledge = null) { WampPlayground playground = new WampPlayground(); playground.Host.Open(); ChannelWithExtraData publisher = await playground.GetChannel().ConfigureAwait(false); ChannelWithExtraData subscriber = await playground.GetChannel().ConfigureAwait(false); IWampTopicProxy topicProxy = publisher.Channel.RealmProxy.TopicContainer.GetTopicByUri ("com.myapp.mytopic2"); long?lastPublicationId = null; for (int i = 0; i <= 42; i++) { lastPublicationId = await topicProxy.Publish (new PublishOptions { Retain = publishRetained, Acknowledge = acknowledge }, new object[] { i, 23, "Hello" }); } publisher.Channel.Close(); MyOtherSubscriber mySubscriber = new MyOtherSubscriber(); IAsyncDisposable disposable = await subscriber.Channel.RealmProxy.Services.RegisterSubscriber(mySubscriber, new SubscriberRegistrationInterceptor(new SubscribeOptions() { GetRetained = getRetained })) .ConfigureAwait(false); Assert.That(mySubscriber.Parameters.Count, Is.EqualTo(expectedCount)); if (expectedCount == 1) { MyTopic2Parameters actual = mySubscriber.Parameters[0]; Assert.That(actual.Number1, Is.EqualTo(42)); Assert.That(actual.Number2, Is.EqualTo(23)); Assert.That(actual.C, Is.EqualTo("Hello")); Assert.That(actual.EventContext.EventDetails.Retained, Is.EqualTo(true)); if (acknowledge == true) { Assert.That(actual.EventContext.PublicationId, Is.EqualTo(lastPublicationId)); } } }
protected override async Task RunAsync(IWampChannel channel) { await channel.Open().ConfigureAwait(false); await Task.Yield(); IWampTopicProxy topic = channel.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic1"); IObservable <int> timer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Select((x, i) => i); PublishOptions publishOptions = new PublishOptions() { DiscloseMe = true, Acknowledge = true }; async Task <(int value, long?publicationId)> TopicSelector(int value) { long?publicationId = await topic.Publish(publishOptions, new object[] { value }); return(value, publicationId); } void SubscriptionHandler((int value, long?publicationId) valueTuple) { (int value, long?publicationId) = valueTuple; Console.WriteLine($"Published with publication ID {publicationId}"); } void ErrorHandler(Exception ex) { Console.WriteLine($"An error has occurred: {ex}"); } using (IDisposable disposable = timer.SelectMany(value => TopicSelector(value)) .Subscribe(SubscriptionHandler, ex => ErrorHandler(ex))) { Console.WriteLine("Hit enter to stop publishing"); Console.ReadLine(); } Console.WriteLine("Stopped publishing"); Console.ReadLine(); }
public async Task SubscriberGetsArgumentsKeywordsEventAsKeywordTuple() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; var subject = subscriber.RealmProxy.Services.GetSubject ("com.myapp.topic2", new MyKeywordTupleEventConverter()); MyKeywordSubscriber mySubscriber = new MyKeywordSubscriber(); subject.Subscribe(mySubscriber); IWampTopicProxy topicProxy = publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2"); MyClass instance = new MyClass() { Counter = 1, Foo = new[] { 1, 2, 3 } }; long?publish = await topicProxy.Publish(new PublishOptions(), new object[0], new Dictionary <string, object>() { { "number1", 47 }, { "d", instance }, { "c", "Hello" }, { "number2", 23 }, }); Assert.That(mySubscriber.Number1, Is.EqualTo(47)); Assert.That(mySubscriber.Number2, Is.EqualTo(23)); Assert.That(mySubscriber.C, Is.EqualTo("Hello")); Assert.That(mySubscriber.D, Is.EqualTo(instance)); }
public TDelegate CreatePositionalDelegate <TDelegate>(IWampTopicProxy proxy, PublishOptions publishOptions) { // Writes: topicProxy.Publish(publishOptions, // new object[] // { // (object)arg1, // (object)arg2, // ..., // (object)argn // }); Func <ParameterExpression[], Expression> callExpression = parameters => Expression.Call(Expression.Constant(proxy), mPublishPositionalMethod, Expression.Constant(publishOptions), Expression.NewArrayInit(typeof(object), parameters.Select(x => Expression.Convert(x, typeof(object))))); return(InnerCreateDelegate <TDelegate>(callExpression)); }
public async Task SubscriberGetsEventAsParameters() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; MySubscriber mySubscriber = new MySubscriber(); IAsyncDisposable disposable = await subscriber.RealmProxy.Services.RegisterSubscriber (mySubscriber); IWampTopicProxy topicProxy = publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2"); MyClass instance = new MyClass() { Counter = 1, Foo = new[] { 1, 2, 3 } }; long?publish = await topicProxy.Publish(new PublishOptions(), new object[] { 47, 23, }, new Dictionary <string, object>() { { "d", instance }, { "c", "Hello" } }); Assert.That(mySubscriber.Number1, Is.EqualTo(47)); Assert.That(mySubscriber.Number2, Is.EqualTo(23)); Assert.That(mySubscriber.C, Is.EqualTo("Hello")); Assert.That(mySubscriber.D, Is.EqualTo(instance)); }
public async Task PublisherCustomDelegateEventRaisePublishesEventWithKeywordArguments() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; MyPublisher myPublisher = new MyPublisher(); IDisposable disposable = publisher.RealmProxy.Services.RegisterPublisher (myPublisher); IWampTopicProxy topicProxy = subscriber.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2"); MyCustomSubscriber myCustomSubscriber = new MyCustomSubscriber(); IAsyncDisposable subscribe = await topicProxy.Subscribe(myCustomSubscriber, new SubscribeOptions()); MyClass instance = new MyClass() { Counter = 1, Foo = new[] { 1, 2, 3 } }; myPublisher.RaiseMyEvent(37, 23, "Hello", instance); Assert.That(myCustomSubscriber.Arguments, Is.Empty); IDictionary <string, ISerializedValue> argumentsKeywords = myCustomSubscriber.ArgumentsKeywords; Assert.That(argumentsKeywords["number1"].Deserialize <int>(), Is.EqualTo(37)); Assert.That(argumentsKeywords["number2"].Deserialize <int>(), Is.EqualTo(23)); Assert.That(argumentsKeywords["c"].Deserialize <string>(), Is.EqualTo("Hello")); Assert.That(argumentsKeywords["d"].Deserialize <MyClass>(), Is.EqualTo(instance)); }
public async Task KeywordTupleObservableOnNextPublishesEventWithPositionalArguments() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; var subject = publisher.RealmProxy.Services.GetSubject ("com.myapp.topic2", new MyKeywordTupleEventConverter()); IWampTopicProxy topicProxy = subscriber.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2"); MyCustomSubscriber myCustomSubscriber = new MyCustomSubscriber(); IAsyncDisposable subscribe = await topicProxy.Subscribe(myCustomSubscriber, new SubscribeOptions()); MyClass instance = new MyClass() { Counter = 1, Foo = new[] { 1, 2, 3 } }; // subject.OnNext((37, 23, "Hello", instance)) subject.OnNext(ValueTuple.Create(37, 23, "Hello", instance)); Assert.That(myCustomSubscriber.Arguments, Is.Empty); IDictionary <string, ISerializedValue> argumentsKeywords = myCustomSubscriber.ArgumentsKeywords; Assert.That(argumentsKeywords["number1"].Deserialize <int>(), Is.EqualTo(37)); Assert.That(argumentsKeywords["number2"].Deserialize <int>(), Is.EqualTo(23)); Assert.That(argumentsKeywords["c"].Deserialize <string>(), Is.EqualTo("Hello")); Assert.That(argumentsKeywords["d"].Deserialize <MyClass>(), Is.EqualTo(instance)); }
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); }
private Task <IAsyncDisposable> AggregateSubscriberEventHandlers(object instance, ISubscriberRegistrationInterceptor interceptor) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } IEnumerable <Type> typesToExplore = GetTypesToExplore(instance); List <Task <IAsyncDisposable> > tasks = new List <Task <IAsyncDisposable> >(); foreach (Type type in typesToExplore) { foreach (MethodInfo method in type.GetPublicInstanceMethods()) { if (interceptor.IsSubscriberHandler(method)) { string topicUri = interceptor.GetTopicUri(method); SubscribeOptions subscribeOptions = interceptor.GetSubscribeOptions(method); IWampTopicProxy topicProxy = mProxy.TopicContainer.GetTopicByUri(topicUri); IWampRawTopicClientSubscriber methodInfoSubscriber = new MethodInfoSubscriber(instance, method, topicUri); Task <IAsyncDisposable> task = topicProxy.Subscribe(methodInfoSubscriber, subscribeOptions); tasks.Add(task); } } } Task <IAsyncDisposable> result = tasks.ToAsyncDisposableTask(); return(result); }
public static void Main(string[] args) { DefaultWampChannelFactory factory = new DefaultWampChannelFactory(); IWampChannel channel = factory.CreateJsonChannel(serverAddress, "realm1"); channel.Open().Wait(); IWampTopicProxy topicProxy = channel.RealmProxy.TopicContainer.GetTopicByUri(selectionChangedTopic); MySubscribeOptions options = new MySubscribeOptions(); // Set your options here options.@return = new string[] { "id" }; SubscribeContext context = new SubscribeContext(); topicProxy.Subscribe(new MySubscriber(context), options) .ContinueWith(t => context.unsubscribeDisposable = t.Result) .Wait(); Console.WriteLine("Add a child to an entity in the Wwise Authoring application."); Console.ReadLine(); }
public static void ClientCode() #endif { DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(); IWampClientAuthenticator authenticator; if (false) { authenticator = new WampCraClientAuthenticator(authenticationId: "joe", secret: "secret2"); } else { authenticator = new WampCraClientAuthenticator(authenticationId: "peter", secret: "secret1"); } IWampChannel channel = channelFactory.ConnectToRealm("realm1") .WebSocketTransport("ws://127.0.0.1:8080/ws") .JsonSerialization() .CraAuthentication("peter", "secret1") .Build(); channel.RealmProxy.Monitor.ConnectionEstablished += (sender, args) => { Console.WriteLine("connected session with ID " + args.SessionId); dynamic details = args.WelcomeDetails.OriginalValue.Deserialize <dynamic>(); Console.WriteLine("authenticated using method '{0}' and provider '{1}'", details.authmethod, details.authprovider); Console.WriteLine("authenticated with authid '{0}' and authrole '{1}'", details.authid, details.authrole); }; channel.RealmProxy.Monitor.ConnectionBroken += (sender, args) => { dynamic details = args.Details.OriginalValue.Deserialize <dynamic>(); Console.WriteLine("disconnected " + args.Reason + " " + details.reason + details); }; IWampRealmProxy realmProxy = channel.RealmProxy; #if NET45 await channel.Open().ConfigureAwait(false); #else channel.Open().Wait(); #endif // call a procedure we are allowed to call (so this should succeed) // IAdd2Service proxy = realmProxy.Services.GetCalleeProxy <IAdd2Service>(); try { #if NET45 var five = await proxy.Add2Async(2, 3) .ConfigureAwait(false); #else var five = proxy.Add2Async(2, 3).Result; #endif Console.WriteLine("call result {0}", five); } catch (Exception e) { Console.WriteLine("call error {0}", e); } // (try to) register a procedure where we are not allowed to (so this should fail) // Mul2Service service = new Mul2Service(); try { #if NET45 await realmProxy.Services.RegisterCallee(service) .ConfigureAwait(false); #else realmProxy.Services.RegisterCallee(service) .Wait(); #endif Console.WriteLine("huh, function registered!"); } #if NET45 catch (WampException ex) { Console.WriteLine("registration failed - this is expected: " + ex.ErrorUri); } #else catch (AggregateException ex) { WampException innerException = ex.InnerException as WampException; Console.WriteLine("registration failed - this is expected: " + innerException.ErrorUri); } #endif // (try to) publish to some topics // string[] topics = { "com.example.topic1", "com.example.topic2", "com.foobar.topic1", "com.foobar.topic2" }; foreach (string topic in topics) { IWampTopicProxy topicProxy = realmProxy.TopicContainer.GetTopicByUri(topic); try { #if NET45 await topicProxy.Publish(new PublishOptions() { Acknowledge = true }, new object[] { "hello" }) .ConfigureAwait(false); #else topicProxy.Publish(new PublishOptions() { Acknowledge = true }, new object[] { "hello" }) .Wait(); #endif Console.WriteLine("event published to topic " + topic); } #if NET45 catch (WampException ex) { Console.WriteLine("publication to topic " + topic + " failed: " + ex.ErrorUri); } #else catch (AggregateException ex) { WampException innerException = ex.InnerException as WampException; Console.WriteLine("publication to topic " + topic + " failed: " + innerException.ErrorUri); } #endif } }
static async Task Main(string[] arguments) { DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(); IWampChannel channel = channelFactory.ConnectToRealm("realm1") .WebSocketTransport(new Uri("ws://127.0.0.1:8080/ws")) .JsonSerialization() .CraAuthentication("peter", "secret1") //.CraAuthentication("joe", "secret2") .Build(); channel.RealmProxy.Monitor.ConnectionEstablished += (sender, args) => { Console.WriteLine("connected session with ID " + args.SessionId); WelcomeDetails details = args.WelcomeDetails; Console.WriteLine($"authenticated using method '{details.AuthenticationMethod}' and provider '{details.AuthenticationProvider}'"); Console.WriteLine($"authenticated with authid '{details.AuthenticationId}' and authrole '{details.AuthenticationRole}'"); }; channel.RealmProxy.Monitor.ConnectionBroken += (sender, args) => { GoodbyeAbortDetails details = args.Details; Console.WriteLine($"disconnected {args.Reason} {details.Message}"); }; IWampRealmProxy realmProxy = channel.RealmProxy; await channel.Open().ConfigureAwait(false); // call a procedure we are allowed to call (so this should succeed) // IAdd2Service proxy = realmProxy.Services.GetCalleeProxy <IAdd2Service>(); try { var five = await proxy.Add2Async(2, 3); Console.WriteLine("call result {0}", five); } catch (Exception e) { Console.WriteLine("call error {0}", e); } // (try to) register a procedure where we are not allowed to (so this should fail) // Mul2Service service = new Mul2Service(); try { await realmProxy.Services.RegisterCallee(service) .ConfigureAwait(false); Console.WriteLine("huh, function registered!"); } catch (WampException ex) { Console.WriteLine("registration failed - this is expected: " + ex.ErrorUri); } // (try to) publish to some topics // string[] topics = { "com.example.topic1", "com.example.topic2", "com.foobar.topic1", "com.foobar.topic2" }; foreach (string topic in topics) { IWampTopicProxy topicProxy = realmProxy.TopicContainer.GetTopicByUri(topic); try { await topicProxy.Publish(new PublishOptions() { Acknowledge = true }, new object[] { "hello" }) .ConfigureAwait(false); Console.WriteLine("event published to topic " + topic); } catch (WampException ex) { Console.WriteLine("publication to topic " + topic + " failed: " + ex.ErrorUri); } } Console.ReadLine(); }
public async Task AuthenticatedIntegrationTest() { WampAuthenticationPlayground playground = new WampAuthenticationPlayground (new WampCraUserDbAuthenticationFactory (new MyAuthenticationProvider(), new MyUserDb())); SetupHost(playground); IWampClientAuthenticator authenticator = new WampCraClientAuthenticator(authenticationId: "peter", secret: "secret1"); IWampChannel channel = playground.CreateNewChannel("realm1", authenticator); IWampRealmProxy realmProxy = channel.RealmProxy; await channel.Open().ConfigureAwait(false); // call a procedure we are allowed to call (so this should succeed) // IAdd2AsyncService proxy = realmProxy.Services.GetCalleeProxy <IAdd2AsyncService>(); int five = await proxy.Add2(2, 3).ConfigureAwait(false); Assert.That(five, Is.EqualTo(5)); // (try to) register a procedure where we are not allowed to (so this should fail) // Mul2Service service = new Mul2Service(); WampException registerException = null; try { await realmProxy.Services.RegisterCallee(service) .ConfigureAwait(false); } catch (WampException ex) { registerException = ex; } Assert.That(registerException, Is.Not.Null); // (try to) publish to some topics // string[] topics = { "com.example.topic1", "com.example.topic2", "com.foobar.topic1", "com.foobar.topic2" }; List <string> successfulTopics = new List <string>(); foreach (string topic in topics) { IWampTopicProxy topicProxy = realmProxy.TopicContainer.GetTopicByUri(topic); try { await topicProxy.Publish(new PublishOptions() { Acknowledge = true }, new object[] { "hello" }) .ConfigureAwait(false); successfulTopics.Add(topic); } catch (WampException ex) { } } Assert.That(successfulTopics, Is.EquivalentTo(new string[] { "com.foobar.topic1", "com.example.topic1" })); }
public Delegate CreateKeywordsDelegate(Type delegateType, IWampTopicProxy proxy, PublishOptions publishOptions) { return((Delegate)mCreateKeywordsDelegateMethod.MakeGenericMethod(delegateType) .Invoke(this, new object[] { proxy, publishOptions })); }
public WampClientSubject(IWampTopicProxy topic, IWampClientConnectionMonitor monitor) { mTopic = topic; mObservable = CreateObservable(topic, monitor); }
public ClientObservable(IWampTopicProxy topic) { mTopic = topic; }