/// <summary> /// Creates an <see cref="EtpClient"/> instance configurated with the /// current connection and authorization parameters. /// </summary> /// <param name="webSocketType">The WebSocket type.</param> /// <param name="etpSubProtocol">The ETP websocket sub-protocol</param> /// <param name="url">The WebSocket URL.</param> /// <returns>A new <see cref="IEtpClient"/> instance.</returns> protected IEtpClient CreateClient(WebSocketType webSocketType, string etpSubProtocol, string url, IDictionary <string, string> headers = null) { var version = GetType().Assembly.GetName().Version.ToString(); if (headers == null) { headers = Security.Authorization.Basic(TestSettings.Username, TestSettings.Password); } var client = EtpFactory.CreateClient(webSocketType, url, GetType().AssemblyQualifiedName, version, etpSubProtocol, headers); if (client.SupportedVersion == EtpVersion.v11) { client.Register <v11.Protocol.ChannelStreaming.IChannelStreamingConsumer, v11.Protocol.ChannelStreaming.ChannelStreamingConsumerHandler>(); client.Register <v11.Protocol.Discovery.IDiscoveryCustomer, v11.Protocol.Discovery.DiscoveryCustomerHandler>(); client.Register <v11.Protocol.Store.IStoreCustomer, v11.Protocol.Store.StoreCustomerHandler>(); } else { client.Register <v12.Protocol.ChannelStreaming.IChannelStreamingConsumer, v12.Protocol.ChannelStreaming.ChannelStreamingConsumerHandler>(); client.Register <v12.Protocol.Discovery.IDiscoveryCustomer, v12.Protocol.Discovery.DiscoveryCustomerHandler>(); client.Register <v12.Protocol.Store.IStoreCustomer, v12.Protocol.Store.StoreCustomerHandler>(); } return(client); }
/// <summary> /// Creates an <see cref="EtpClient"/> instance configurated with the /// current connection and authorization parameters. /// </summary> /// <param name="webSocketType">The WebSocket type.</param> /// <param name="etpVersion">The ETP version.</param> /// <param name="url">The WebSocket URL.</param> /// <param name="authorization">The client's authorization details.</param> /// <param name="etpEncoding">The encoding to use.</param> /// <returns>A new <see cref="IEtpClient"/> instance.</returns> protected IEtpClient CreateClient(WebSocketType webSocketType, EtpVersion etpVersion, string url, Security.Authorization authorization = null, EtpEncoding etpEncoding = EtpEncoding.Binary) { var version = GetType().Assembly.GetName().Version.ToString(); if (authorization == null) { authorization = Security.Authorization.Basic(TestSettings.Username, TestSettings.Password); } var endpointInfo = EtpFactory.CreateClientEndpointInfo(GetType().AssemblyQualifiedName, version, "ETP DevKit Integration Test"); var client = EtpFactory.CreateClient(webSocketType, url, etpVersion, etpEncoding, endpointInfo, authorization: authorization); if (etpVersion == EtpVersion.v11) { client.Register(new v11.Protocol.ChannelStreaming.ChannelStreamingConsumerHandler()); client.Register(new v11.Protocol.Discovery.DiscoveryCustomerHandler()); client.Register(new v11.Protocol.Store.StoreCustomerHandler()); } else { client.Register(new v12.Protocol.ChannelStreaming.ChannelStreamingConsumerHandler()); client.Register(new v12.Protocol.Discovery.DiscoveryCustomerHandler()); client.Register(new v12.Protocol.Store.StoreCustomerHandler()); } return(client); }
/// <summary> /// Creates an <see cref="EtpSocketServer"/> instance. /// </summary> /// <returns>A new <see cref="EtpSocketServer"/> instance.</returns> protected IEtpSelfHostedWebServer CreateServer(WebSocketType webSocketType) { var version = GetType().Assembly.GetName().Version.ToString(); var port = GetAvailablePort(); var server = EtpFactory.CreateSelfHostedWebServer(webSocketType, port, GetType().AssemblyQualifiedName, version); return(server); }
public async Task EtpClient_Connects_Using_Json_Encoding() { // Create a Basic authorization header dictionary var headers = Authorization.Basic(TestSettings.Username, TestSettings.Password); // Specify preference for JSON encoding headers[EtpSettings.EtpEncodingHeader] = Settings.Default.EtpEncodingJson; // Initialize an EtpClient with a valid Uri, app name and version, and headers using (var client = EtpFactory.CreateClient(TestSettings.ServerUrl, AppName, AppVersion, TestSettings.EtpSubProtocol, headers)) { // Open the connection (uses an async extension method) await client.OpenAsyncWithTimeout(); // Assert the current state of the connection Assert.IsTrue(client.IsOpen); } }
public async Task EtpClient_Opens_WebSocket_Connection() { // Create a Basic authorization header dictionary var auth = Authorization.Basic(TestSettings.Username, TestSettings.Password); // Initialize an EtpClient with a valid Uri, app name and version, and auth header using (var client = EtpFactory.CreateClient(TestSettings.ServerUrl, AppName, AppVersion, TestSettings.EtpSubProtocol, auth)) { // Register protocol handlers to be used in later tests client.Register <IChannelStreamingConsumer, ChannelStreamingConsumerHandler>(); client.Register <IDiscoveryCustomer, DiscoveryCustomerHandler>(); client.Register <IStoreCustomer, StoreCustomerHandler>(); // Open the connection (uses an async extension method) await client.OpenAsyncWithTimeout(); // Assert the current state of the connection Assert.IsTrue(client.IsOpen); // Explicit Close not needed as the WebSocket connection will be closed // automatically after leaving the scope of the using statement //client.Close("reason"); } }
private static void StartClient() { Console.WriteLine("Enter a valid Web Socket URI [{0}]:", WebSocketUri); var webSocketUri = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Select from the following options:"); Console.WriteLine(" O - open"); Console.WriteLine(" C - close"); Console.WriteLine(" Z - clear"); Console.WriteLine(" X - exit"); Console.WriteLine(" S - ChannelStreaming - Start"); Console.WriteLine(" D - Discovery - GetResources"); Console.WriteLine(); using (var client = EtpFactory.CreateClient(webSocketUri, ClientAppName, AppVersion, EtpSettings.EtpSubProtocolName)) { client.Register <IChannelStreamingConsumer, MockChannelStreamingConsumer>(); client.Register <IDiscoveryCustomer, DiscoveryCustomerHandler>(); client.Handler <IDiscoveryCustomer>().OnGetResourcesResponse += OnGetResourcesResponse; while (true) { var info = Console.ReadKey(); Console.WriteLine(" - processing..."); Console.WriteLine(); if (IsKey(info, "O")) { client.Open(); } else if (IsKey(info, "C")) { client.Close("EtpClient closed."); } else if (IsKey(info, "S")) { Console.WriteLine("Starting ChannelStreaming session..."); client.Handler <IChannelStreamingConsumer>() .Start(maxMessageRate: 2000); } else if (IsKey(info, "D")) { Console.WriteLine("Enter resource URI:"); var uri = Console.ReadLine(); Console.WriteLine(); client.Handler <IDiscoveryCustomer>() .GetResources(uri); } else if (IsKey(info, "Z")) { Console.Clear(); } else if (IsKey(info, "X")) { break; } } } }