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 async void 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 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 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(); }