static void Main(string[] args) { CancellationTokenSource cts = new CancellationTokenSource(); InitLogging(); EventSource es = new EventSource(new Uri(@"http://ssetest.apphb.com/api/sse"), 50000); es.StateChanged += new EventHandler<StateChangedEventArgs>((o, e) => { Console.WriteLine("New state: " + e.State.ToString()); }); es.EventReceived += new EventHandler<ServerSentEventReceivedEventArgs>((o, e) => { Console.WriteLine("--------- Msg received -----------\n" + e.Message.ToString()); }); es.Start(cts.Token); Console.WriteLine("EventSource started"); ConsoleKey key; while ((key = Console.ReadKey().Key) != ConsoleKey.X) { if (key == ConsoleKey.C) { cts.Cancel(); Console.WriteLine("Eventsource is cancelled."); } else if (key==ConsoleKey.S) { cts = new CancellationTokenSource(); es.Start(cts.Token); } } }
public bool Start(string url) { cancellationTokenSource = new CancellationTokenSource(); listenUrl = url; es = new EventSource(new Uri(listenUrl), 1000); es.EventReceived += new EventHandler<ServerSentEventReceivedEventArgs>((o, e) => { if (e.Message.EventType == "data") { OnNewJsonData(e.Message.Data); } else if (e.Message.EventType == "patch") { OnNewJsonPatch(e.Message.Data); } else { Console.WriteLine(e.Message.ToString()); } }); es.Start(cancellationTokenSource.Token); started = true; return true; }
/// <summary> /// WebHookNotificationとの接続を確立します /// </summary> public void Initialize() { var cts = new CancellationTokenSource(); var es = new EventSource4Net.EventSource(new Uri("http://" + host + "/streaming/slack"), int.MaxValue); es.StateChanged += new EventHandler <StateChangedEventArgs>((o, e) => { Console.WriteLine("New state: " + e.State.ToString()); }); es.EventReceived += new EventHandler <ServerSentEventReceivedEventArgs>(OnSlackMessageReceived); es.Start(cts.Token); }
public override void Setup() { if (!IsConfigValid()) { throw new ArgumentNullException("", "Please enter your Spark Core Device Id and Access Token in Settings dialog."); } else { sparkClient = new SparkClient(Properties.Settings.Default.AccessToken, Properties.Settings.Default.DeviceId); eventSource = sparkClient.GetEventStream(); eventSource.EventReceived += eventSource_EventReceived; eventSource.Start(new CancellationToken()); } }
public void Connect () { Disconnect (); cancellationToken = new CancellationTokenSource (); eventClient = new EventSource (new Uri ("http://" + serverAddress + "/api/HomeAutomation.HomeGenie/Logging/RealTime.EventStream/"), serverCredential, 10000); eventClient.StateChanged += eventClient_StateChanged; eventClient.EventReceived += eventClient_EventReceived; eventClient.Start (cancellationToken.Token); serviceClient = new WebClient (); serviceClient.Credentials = serverCredential; serviceClient.DownloadStringCompleted += serviceClient_DownloadStringCompleted; DownloadData (); }
private async Task<int> ProcessURL(string url, string orgCode, string shortCode) { _Log.Trace("Started"); _Log.Debug(LogHelper.Get("Input Param:=", new { url = url, orgCode = orgCode })); TotalConnections = MultiMap.Count; EventSource Eventsource = new EventSource(new Uri(url), 1000); Eventsource.StateChanged += new EventHandler<StateChangedEventArgs>((o, e) => { LogStateChange(url, orgCode, e.State.ToString(), shortCode); }); Eventsource.EventReceived += new EventHandler<ServerSentEventReceivedEventArgs>((o, e) => { ProcessData(e.Message.ToString(), orgCode, shortCode); }); Eventsource.Start(CancellationToken.None); _Log.Trace("Ended"); return 1; }