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); 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); }
private static string GetUri(AppArguments appArguments) { var uri = appArguments.Uri.ToString(); if (uri.EndsWith('/')) { return(uri); } return($"{uri}/"); }
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); }
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)); }