Exemplo n.º 1
0
        public static void BuildSample(IAppBuilder app)
        {
            // add eventsource middleware
            app.EventSource(envKey);
            app.Run(context => {

                // get the event stream (not captured yet)
                var eventStream = context.Environment[envKey] as IEventStream;

                // create some timers to send mesages
                var timer = new System.Threading.Timer(_ => {
                    var ts = DateTime.UtcNow.ToString("O");
                    eventStream.WriteAsync("Timer1:" + ts + message + "\n");
                }, null, 1,  50);
                var timer2 = new System.Threading.Timer(_ => {
                    var ts = DateTime.UtcNow.ToString("O");
                    eventStream.WriteAsync("Timer 2:" + ts + "\n");
                }, null, 1,  25);

                // Capture the eventstream by calling Open and pass in the 
                // clean-up logic for when this client closes the stream
                var task =  eventStream.Open(() => {
                    Console.WriteLine("Closed");
                    timer.Dispose();
                    timer2.Dispose();
                });

                eventStream.WriteAsync("Started\n");
                return task;
            });
        }
Exemplo n.º 2
0
 public void openStreamAndWrite(IAppBuilder builder)
 {
     builder.EventSource(environmentKey);
     builder.Run(this.openStreamAndWrite);
 }
Exemplo n.º 3
0
 public void openClose(IAppBuilder builder)
 {
     builder.EventSource(environmentKey);
     builder.Run(this.openClose);
 }
Exemplo n.º 4
0
 public void openStream(IAppBuilder builder)
 {
     builder.EventSource(environmentKey);
     builder.Run(this.captureStream);
 }
Exemplo n.º 5
0
 public void noEvents(IAppBuilder builder)
 {
     builder.EventSource(environmentKey);
     builder.Run(this.writeContextResponse);
 }