Ejemplo n.º 1
0
 public WampSessionCloseEventArgs
     (SessionCloseType closeType,
     long sessionId,
     GoodbyeAbortDetails details,
     string reason)
 {
     mReason    = reason;
     mCloseType = closeType;
     mSessionId = sessionId;
     mDetails   = details;
 }
Ejemplo n.º 2
0
 private void TrySetCloseEventArgs(SessionCloseType sessionCloseType,
                                   GoodbyeAbortDetails details = null,
                                   string reason = null)
 {
     if (mCloseEventArgs == null)
     {
         mCloseEventArgs = new WampSessionCloseEventArgs
                               (sessionCloseType, mSession,
                               details,
                               reason);
     }
 }
Ejemplo n.º 3
0
        private void RaiseConnectionBroken(SessionCloseType sessionCloseType, GoodbyeAbortDetails details, string reason)
        {
            mConnectionBrokenRaised = true;

            WampSessionCloseEventArgs closeEventArgs = new WampSessionCloseEventArgs
                                                           (sessionCloseType, mSession,
                                                           details,
                                                           reason);

            SetOpenTaskErrorIfNeeded(new WampConnectionBrokenException(closeEventArgs));

            Interlocked.CompareExchange(ref mIsConnected, 0, 1);

            OnConnectionBroken(closeEventArgs);
        }
Ejemplo n.º 4
0
 private void RaiseSessionClosed(SessionCloseType sessionCloseType, long session, GoodbyeAbortDetails details, string reason)
 {
     RaiseSessionClosed
         (new WampSessionCloseEventArgs(sessionCloseType, session,
                                        details, reason));
 }
Ejemplo n.º 5
0
        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();
        }