Exemple #1
0
        private static string GetUri(AppArguments appArguments)
        {
            var uri = appArguments.Uri.ToString();

            if (uri.EndsWith('/'))
            {
                return(uri);
            }

            return($"{uri}/");
        }
Exemple #2
0
        private static IDisposable Subscribe(IWampRealmProxy realmProxy, AppArguments appArguments, StreamWriter outputWriter)
        {
            var subscription = realmProxy.Services
                               .GetSubject <dynamic>(appArguments.Topic)
                               .Subscribe(message =>
            {
                Console.WriteLine(message);

                outputWriter?.WriteLine(message);
            });

            return(subscription);
        }
Exemple #3
0
        private static StreamWriter TryGetOutputWriter(AppArguments appArguments)
        {
            if (string.IsNullOrWhiteSpace(appArguments.OutputFilePath))
            {
                return(null);
            }

            var fileStream = File.Open(
                appArguments.OutputFilePath,
                appArguments.AppendOutput ? FileMode.Append : FileMode.Create,
                FileAccess.Write,
                FileShare.Read);

            return(new StreamWriter(fileStream, Encoding.UTF8, bufferSize: 16, leaveOpen: false));
        }
Exemple #4
0
        private static async Task <IWampChannel> ConnectAsync(AppArguments appArguments)
        {
            var factory = new DefaultWampChannelFactory();
            IWampClientAuthenticator clientAuthenticator = GetClientAuthenticator(appArguments.AuthMethod, appArguments.AuthId);

            var channel = clientAuthenticator == null
                ? factory.CreateJsonChannel(GetUri(appArguments), appArguments.Realm)
                : factory.CreateJsonChannel(GetUri(appArguments), appArguments.Realm, clientAuthenticator);

            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);
            };

            while (!channel.RealmProxy.Monitor.IsConnected)
            {
                try
                {
                    Console.WriteLine($"Trying to connect to the server {appArguments.Uri}...");

                    channel.Open().Wait();
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Failed to connect: {e.Message}");
                    Console.WriteLine("Retrying in 5 sec...");

                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            }

            return(channel);
        }