public void GetMethodNameTest() { string expected = "WhoCalledMeTests.GetMethodNameTest"; string actual = WhoCalledMe.GetMethodName(0); Assert.AreEqual(expected, actual); }
/// <summary> /// Wraps constructor /// </summary> /// <param name="url"></param> public void Initialize(string url) { if (_wrapped != null) { throw new InvalidOperationException("WebSocketWrapper has already been initialized for: " + _url); } _url = url; _wrapped = new WebSocket(url) { Log = { Level = Config.GetBool("websocket-log-trace") ? LogLevel.Trace : LogLevel.Error, // The stack frame number of 3 was derived from the usage of the Logger class in the WebSocketSharp library Output = (data, file) =>{ Log.Trace($"{WhoCalledMe.GetMethodName(3)}(): {data.Message}", true); } } }; _wrapped.OnOpen += (sender, args) => OnOpen(); _wrapped.OnMessage += (sender, args) => OnMessage(new WebSocketMessage(args.Data)); _wrapped.OnError += (sender, args) => OnError(new WebSocketError(args.Message, args.Exception)); _wrapped.OnClose += (sender, args) => OnClose(new WebSocketCloseData(args.Code, args.Reason, args.WasClean)); }
/// <summary> /// Creates new instance of <see cref="SockClient"/> object. /// </summary> /// <param name="keyId">Application key identifier.</param> /// <param name="secretKey">Application secret key.</param> /// <param name="alpacaRestApi">Alpaca REST API endpoint URL.</param> public SockClient( String keyId, String secretKey, Uri alpacaRestApi) { if (keyId == null) { throw new ArgumentException(nameof(keyId)); } if (secretKey == null) { throw new ArgumentException(nameof(secretKey)); } _keyId = keyId; _secretKey = secretKey; alpacaRestApi = alpacaRestApi ?? new Uri("https://api.alpaca.markets"); var uriBuilder = new UriBuilder(alpacaRestApi) { Scheme = alpacaRestApi.Scheme == "http" ? "ws" : "wss" }; uriBuilder.Path += "/stream"; _webSocket = new WebSocket(uriBuilder.Uri.ToString()) { Log = { Level = Config.GetBool("websocket-log-trace") ? LogLevel.Trace : LogLevel.Error, // The stack frame number of 3 was derived from the usage of the Logger class in the WebSocketSharp library Output = (data, file) =>{ Log.Trace($"{WhoCalledMe.GetMethodName(3)}(): {data.Message}", true); } } }; _webSocket.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls11 | SslProtocols.Tls12; _webSocket.OnOpen += handleOpened; _webSocket.OnClose += handleClosed; _webSocket.OnMessage += handleDataReceived; _webSocket.OnError += (sender, args) => { Console.WriteLine(args.Exception); OnError?.Invoke(args.Exception); }; }