public async void Client_to_actor()
            {
                var actor = system.FreshActorOf <TestActor>();

                using (var observer = await ClientObservable.Create())
                {
                    await actor.Tell(new Attach { Observer = observer });

                    Notification @event = null;

                    var done         = new AutoResetEvent(false);
                    var subscription = observer.Subscribe((Notification e) =>
                    {
                        @event = e;
                        done.Set();
                    });

                    await actor.Tell(new Publish { Text = "c-a" });

                    done.WaitOne(TimeSpan.FromMilliseconds(100));
                    Assert.That(@event.Text, Is.EqualTo("c-a"));

                    subscription.Dispose();
                    await actor.Tell(new Publish { Text = "kaboom" });

                    done.WaitOne(TimeSpan.FromMilliseconds(100));
                    Assert.That(@event.Text, Is.EqualTo("c-a"));
                }
            }
Ejemplo n.º 2
0
 TestObserver(ClientObservable observable)
 {
     this.observable = observable;
     observable.Subscribe(message =>
     {
         Notifications.Add(message);
         Received.Set();
     });
 }
Ejemplo n.º 3
0
        public static void Initialize()
        {
            clients = GlobalHost.ConnectionManager.GetHubContext <Relay>().Clients;

            notifications = Task.Run(ClientObservable.Create).Result;
            notifications.Subscribe(On);

            Task.Run(Subscribe)
            .Wait();

            Task.Run(Resubscribe);
        }
Ejemplo n.º 4
0
        public async Task Join()
        {
            notifications = await ClientObservable.Create();

            notifications.Subscribe((ChatRoomMessage msg) =>
            {
                if (msg.User != user)
                {
                    Console.WriteLine(msg.Text);
                }
            });

            await room.Tell(new Join { User = user, Client = notifications });
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public static void Main()
        {
            Console.WriteLine("Running demo. Booting cluster might take some time ...\n");

            var properties = new Dictionary <string, string>
            {
                { "account", "UseDevelopmentStorage=true" }
            };

            var system = ActorSystem.Configure()
                         .Playground()
                         .Bootstrapper <ServiceLocator.Bootstrap>(properties)
                         .Assemblies(typeof(Api).Assembly)
                         .Done();

            system.Start();

            client = new Client(system, ClientObservable.Create().Result);
            client.Run();

            Console.WriteLine("Press Enter to terminate ...");
            Console.ReadLine();
        }
Ejemplo n.º 7
0
            public static async Task <TestObserver> Create()
            {
                var observable = await ClientObservable.Create();

                return(new TestObserver(observable));
            }
Ejemplo n.º 8
0
 public Client(IActorSystem system, ClientObservable observable)
 {
     this.system     = system;
     this.observable = observable;
 }