Exemple #1
0
 public SlackRtmClient(ISlackApiClient client, IWebSocketFactory webSocketFactory, SlackJsonSettings jsonSettings, IScheduler scheduler, ILogger logger)
 {
     _client       = client;
     _jsonSettings = jsonSettings;
     _webSocket    = new ReconnectingWebSocket(webSocketFactory, scheduler, logger, 0);
     _rawEvents    = DeserializeEvents(_webSocket, _jsonSettings);
 }
Exemple #2
0
        /// <summary>
        /// Creates new instance of <see cref="SockClient"/> object.
        /// </summary>
        /// <param name="keyId">Application key identifier.</param>
        /// <param name="polygonWebsocketApi">Polygon websocket API endpoint URL.</param>
        /// <param name="isStagingEnvironment">If <c>true</c> use staging.</param>
        /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
        public PolygonSockClient(
            String keyId,
            Uri polygonWebsocketApi,
            Boolean isStagingEnvironment,
            IWebSocketFactory webSocketFactory)
            : base(getUriBuilder(polygonWebsocketApi), webSocketFactory)
        {
            _keyId = keyId ?? throw new ArgumentException(
                               "Application key id should not be null", nameof(keyId));

            if (isStagingEnvironment &&
                !_keyId.EndsWith("-staging", StringComparison.Ordinal))
            {
                _keyId += "-staging";
            }

            _handlers = new Dictionary <String, Action <JToken> >(StringComparer.Ordinal)
            {
                { StatusMessage, handleAuthorization },
                { TradesChannel, handleTradesChannel },
                { QuotesChannel, handleQuotesChannel },
                { MinuteAggChannel, handleMinuteAggChannel },
                { SecondAggChannel, handleSecondAggChannel }
            };
        }
Exemple #3
0
 public SlackRtmClient(ISlackApiClient client, IWebSocketFactory webSocketFactory, SlackJsonSettings jsonSettings, IScheduler scheduler)
 {
     _rawEvents        = Subject.Synchronize(_eventSubject);
     _client           = client;
     _webSocketFactory = webSocketFactory;
     _jsonSettings     = jsonSettings;
     _scheduler        = scheduler;
 }
 public WebSocketManagerMiddleware(RequestDelegate next,
                                   IWebSocketFactory webSocketFactory,
                                   IWebSocketDataHandler webSocketDataHandler)
 {
     _next                 = next;
     _webSocketFactory     = webSocketFactory;
     _webSocketDataHandler = webSocketDataHandler;
 }
Exemple #5
0
 internal DevicePortal(IDevicePortalConnection connection,
                       Func <ICredentials, Func <HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool>, IHttpClient> createHttpClient,
                       IWebSocketFactory webSocketFactory = null)
 {
     this.deviceConnection = connection;
     this.HttpClient       = createHttpClient(connection.Credentials, this.ServerCertificateValidation);
     this.WebSockets       = webSocketFactory ?? new DefaultWebSocketFactory();
 }
Exemple #6
0
 public SlackRtmClient(string token)
 {
     _rawEvents        = Subject.Synchronize(_eventSubject);
     _webSocketFactory = Default.WebSocketFactory;
     _jsonSettings     = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes));
     _scheduler        = Scheduler.Default;
     _client           = new SlackApiClient(Default.Http(_jsonSettings), Default.UrlBuilder(_jsonSettings), _jsonSettings, token);
 }
 /// <summary>
 /// Creates new instance of <see cref="SockClient"/> object.
 /// </summary>
 /// <param name="configuration">Application configuration.</param>
 /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
 public SockClient(
     IConfiguration configuration,
     IWebSocketFactory webSocketFactory = null)
     : this(
         configuration["keyId"],
         configuration["secretKey"],
         configuration["alpacaRestApi"],
         webSocketFactory)
 {
 }
Exemple #8
0
 /// <summary>
 /// Creates new instance of <see cref="PolygonSockClient"/> object.
 /// </summary>
 /// <param name="configuration">Application configuration.</param>
 /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
 public PolygonSockClient(
     IConfiguration configuration,
     IWebSocketFactory webSocketFactory = null)
     : this(
         configuration?["keyId"],
         configuration?["polygonWebsocketApi"],
         Convert.ToBoolean(configuration?["staging"] ?? "false", CultureInfo.InvariantCulture),
         webSocketFactory)
 {
 }
Exemple #9
0
 /// <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>
 /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
 public SockClient(
     String keyId,
     String secretKey,
     Uri alpacaRestApi,
     IWebSocketFactory webSocketFactory)
     : base(getUriBuilder(alpacaRestApi), webSocketFactory)
 {
     _keyId     = keyId ?? throw new ArgumentException(nameof(keyId));
     _secretKey = secretKey ?? throw new ArgumentException(nameof(secretKey));
 }
 /// <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>
 /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
 public SockClient(
     String keyId,
     String secretKey,
     String alpacaRestApi = null,
     IWebSocketFactory webSocketFactory = null)
     : this(
         keyId,
         secretKey,
         new Uri(alpacaRestApi ?? "https://api.alpaca.markets"),
         webSocketFactory ?? new WebSocket4NetFactory())
 {
 }
Exemple #11
0
 /// <summary>
 /// Creates new instance of <see cref="PolygonSockClient"/> object.
 /// </summary>
 /// <param name="keyId">Application key identifier.</param>
 /// <param name="polygonWebsocketApi">Polygon websocket API endpoint URL.</param>
 /// <param name="isStagingEnvironment">If <c>true</c> use staging.</param>
 /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
 public PolygonSockClient(
     String keyId,
     String polygonWebsocketApi         = null,
     Boolean isStagingEnvironment       = false,
     IWebSocketFactory webSocketFactory = null
     )
     : this(
         keyId,
         new Uri(polygonWebsocketApi ?? "wss://alpaca.socket.polygon.io/stocks"),
         isStagingEnvironment,
         webSocketFactory ?? new WebSocket4NetFactory())
 {
 }
        /// <summary>
        /// Creates new instance of <see cref="SockClientBase"/> object.
        /// </summary>
        /// <param name="endpointUri">URL for websocket endpoint connection.</param>
        /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
        protected SockClientBase(
            UriBuilder endpointUri,
            IWebSocketFactory webSocketFactory)
        {
            _webSocket = webSocketFactory.CreateWebSocket(endpointUri.Uri);

            _webSocket.Opened += OnOpened;
            _webSocket.Closed += OnClosed;

            _webSocket.MessageReceived += OnMessageReceived;
            _webSocket.DataReceived    += OnDataReceived;

            _webSocket.Error += HandleError;
        }
Exemple #13
0
        /// <summary>
        /// Creates new instance of <see cref="SockClient"/> object.
        /// </summary>
        /// <param name="keyId">Application key identifier.</param>
        /// <param name="polygonWebsocketApi">Polygon websocket API endpoint URL.</param>
        /// <param name="isStagingEnvironment">If <c>true</c> use staging.</param>
        /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
        public PolygonSockClient(
            String keyId,
            Uri polygonWebsocketApi,
            Boolean isStagingEnvironment,
            IWebSocketFactory webSocketFactory)
            : base(getUriBuilder(polygonWebsocketApi), webSocketFactory)
        {
            _keyId = keyId ?? throw new ArgumentException(nameof(keyId));

            if (isStagingEnvironment &&
                !_keyId.EndsWith("-staging"))
            {
                _keyId += "-staging";
            }
        }
        /// <summary>
        /// Creates new instance of <see cref="SockClientBase"/> object.
        /// </summary>
        /// <param name="endpointUri">URL for websocket endpoint connection.</param>
        /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
        protected SockClientBase(
            UriBuilder endpointUri,
            IWebSocketFactory webSocketFactory)
        {
            endpointUri = endpointUri ?? throw new ArgumentException(
                                    "Endpoint URL should not be null", nameof(endpointUri));
            webSocketFactory = webSocketFactory ?? throw new ArgumentException(
                                         "Web Socket factory should not be null", nameof(webSocketFactory));

            _webSocket = webSocketFactory.CreateWebSocket(endpointUri.Uri);

            _webSocket.Opened += OnOpened;
            _webSocket.Closed += OnClosed;

            _webSocket.MessageReceived += OnMessageReceived;
            _webSocket.DataReceived    += OnDataReceived;

            _webSocket.Error += HandleError;
        }
        public void SetUp()
        {
            _slackApiClient   = Substitute.For <ISlackApiClient>();
            _webSocketFactory = Substitute.For <IWebSocketFactory>();
            _jsonSettings     = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes));
            _testScheduler    = new TestScheduler();
            _sut = new SlackRtmClient(_slackApiClient, _webSocketFactory, _jsonSettings, _testScheduler);

            _opened    = new Subject <Unit>();
            _closed    = new Subject <Unit>();
            _errors    = new Subject <Exception>();
            _messages  = new Subject <string>();
            _webSocket = Substitute.For <IWebSocket>();
            _webSocket.Opened.Returns(_opened);
            _webSocket.Closed.Returns(_closed);
            _webSocket.Errors.Returns(_errors);
            _webSocket.Messages.Returns(_messages);
            _webSocket.State.Returns(WebSocketState.None);
        }
        /// <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>
        /// <param name="webSocketFactory">Factory class for web socket wrapper creation.</param>
        public SockClient(
            String keyId,
            String secretKey,
            Uri alpacaRestApi,
            IWebSocketFactory webSocketFactory)
            : base(getUriBuilder(alpacaRestApi), webSocketFactory)
        {
            _keyId = keyId ?? throw new ArgumentException(
                         "Application key id should not be null", nameof(keyId));
            _secretKey = secretKey ?? throw new ArgumentException(
                             "Application secret key should not be null", nameof(secretKey));

            _handlers = new Dictionary<string, Action<JToken>>(StringComparer.Ordinal)
            {
                { Listening, _ => { } },
                { Authorization, handleAuthorization },
                { AccountUpdates, handleAccountUpdate },
                { TradeUpdates, handleTradeUpdate }
            };
        }
Exemple #17
0
 public BaseWebSocketService(IWebSocketFactory webSocketFactory)
 {
     _webSocketClient = webSocketFactory.WebSocketClient;
 }
Exemple #18
0
 public StateAuditLogger(IWebSocketFactory webSocketFactory)
 {
     _webSocketFactory = webSocketFactory;
     _ws = webSocketFactory.New();
     _ws.Connect();
 }
 private void TestAuditSetupWithAssignedInputs(Guid resourceId, string workflowName, out IStateAuditLogger auditStateLogger, out Mock <IDev2Activity> activity, IWebSocketFactory webSocketFactory)
 {
     GetMockedDataObject(resourceId, workflowName, out activity, out Mock <IDSFDataObject> mockedDataObject);
     auditStateLogger = GetIAuditStateLogger(webSocketFactory);
 }
 private IStateAuditLogger GetIAuditStateLogger(IWebSocketFactory webSocketFactory)
 {
     return(new StateAuditLogger(webSocketFactory));
 }
Exemple #21
0
 public StockWebSocketService(IWebSocketFactory webSocketFactory)
     : base(webSocketFactory)
 {
 }
Exemple #22
0
 public static void Register(IWebSocketFactory factory)
 {
     _factory = factory;
 }
Exemple #23
0
 public GetExecutionHistory(IWebSocketFactory webSocketFactory, TimeSpan waitTimeOut)
 {
     _webSocketFactory = webSocketFactory;
     _waitTimeOut      = waitTimeOut;
 }
 public GetLogDataService(IWebSocketFactory webSocketFactory, TimeSpan waitTimeOut)
 {
     _webSocketFactory = webSocketFactory;
     _waitTimeOut      = waitTimeOut;
 }