public async Task StartAsync()
        {
            string cursor = await GetCurrentCursorFromDatabase("operations");

            _logger.Debug($"{nameof(cursor)}: {cursor}");

            await DeleteLastCursorId(cursor);

            _operationsRequestBuilder = _server.Operations.Cursor(cursor).Limit(10);

            _eventSource = _operationsRequestBuilder.Stream((sender, response) =>
            {
                var operationsRequestBuilder         = (OperationsRequestBuilder)sender;
                OperationRecordModel operationRecord = HandleOperationResponse(response);

                if (!string.IsNullOrEmpty(response.PagingToken))
                {
                    _eventSource.Headers.Remove("Last-Event-Id");
                    _eventSource.Headers.Add("Last-Event-Id", response.PagingToken);
                }
            });

            _eventSource.Error += (sender, args) =>
            {
                _logger.Error(args.Exception.Message, args.Exception);
            };

            _eventSource.Connect();
        }
예제 #2
0
        public void SocketWala(string uri)
        {
            var socket = new EventSource(uri);

            socket.Connect();
            socket.StateChange += StateChange;
            socket.Error       += Error;
            socket.Message     += Message;
        }
예제 #3
0
        public void SocketWala(string uri)
        {
            var sse = new EventSource(uri);

            sse.Connect();
            sse.StateChange += StateChange;
            sse.Error       += Error;
            sse.Message     += Message;
            sse.OnUpdate    += Update;
        }
예제 #4
0
        public static void ConnectToEventSource()
        {
            EventSource mySource = new EventSource();
            mySource.OpenEvent += new OpenEventHandler((object sender, OpenEventArgs e) =>
            {
                Console.WriteLine("Open Event");
            });

            mySource.MessageEvent += new MessageEventHandler((object sender,
            MessageEventArgs e) =>
            {
                Console.WriteLine(e.Data);
            });

            mySource.ErrorEvent += new ErrorEventHandler((object sender, ErrorEventArgs e) =>
            {
                Console.WriteLine("Error Event");
            });

            mySource.Connect("http://localhost:8001/sse");

            //mySocket.Disconnect();

            //            if (SocketCreated && (ws.readyState == 0 || ws.readyState == 1)) {  // Web Socket connecting or connected
            //                ws.close();
            //            } else {
            //                Log("Trying to connect to the server ...");
            //                try {
            //                    ws = new com.kaazing.gateway.client.html5.WebSocket("ws://localhost:8181/test"); // + document.getElementById("Connection").value
            //                    SocketCreated = true;
            //                } catch (ex) {
            //                    Log(ex, "ERROR");
            //                    return;
            //                }

            //                document.getElementById("ToggleConnection").innerHTML = "Disconnect";
            //                ws.onopen = WSonOpen;
            //                ws.onmessage = WSonMessage;
            //                ws.onclose = WSonClose;
            //                ws.onerror = WSonError;
            //            }
        }
        public EventSource Downstream(string path)
        {
            try
            {
                var url         = _host + path;
                var eventSource = new EventSource(url)
                {
                    Headers = new NameValueCollection {
                        { "Authorization", "Bearer " + _token }
                    }
                };

                eventSource.Connect();

                return(eventSource);
            }
            catch (Exception)
            {
                throw;
            }
        }