Ejemplo n.º 1
0
        public MetricsEventsModule()
            : base("api/MetricsEvents")
        {
            Post[""] = _ =>
            {
                var metricsEvent = this.Bind <MetricsEvent>();
                lock (SyncRoot)
                {
                    var eventType = MetricsEventTypes.GetEventType(metricsEvent.EventType);

                    if (eventType == null)
                    {
                        eventType = new MetricsEventType(metricsEvent);
                    }
                    else
                    {
                        eventType.AddEvent(metricsEvent);
                    }

                    MetricsEventTypes.AddOrUpdateEventType(eventType);
                }

                return(Negotiate
                       .WithStatusCode(HttpStatusCode.Created));
            };
        }
        public MetricsEventTypesModule()
            : base("api/MetricsEventTypes")
        {
            Get["/{eventType}"] = _ =>
            {
                MetricsEventType eventType = MetricsEventTypes.GetEventType(_.eventType);
                return(Negotiate
                       .WithModel(eventType)
                       .WithStatusCode(HttpStatusCode.OK));
            };

            Post[""] = _ =>
            {
                var eventType = this.Bind <MetricsEventType>();
                MetricsEventTypes.AddOrUpdateEventType(eventType);

                string url = $"{Request.Url.SiteBase}{Request.Path}/{eventType.Name}";
                return(Negotiate
                       .WithHeader("Location", url)
                       .WithStatusCode(HttpStatusCode.Created));
            };

            Post["/Clear"] = _ =>
            {
                MetricsEventTypes.Clear();
                return(Negotiate
                       .WithStatusCode(HttpStatusCode.Created));
            };
        }
Ejemplo n.º 3
0
        public Task Consume(ConsumeContext <IMetricsEvent> context)
        {
            lock (SyncRoot)
            {
                var eventType = MetricsEventTypes.GetEventType(context.Message.EventType);

                if (eventType == null)
                {
                    eventType = new MetricsEventType(context.Message);
                }
                else
                {
                    eventType.AddEvent(context.Message);
                }

                MetricsEventTypes.AddOrUpdateEventType(eventType);
            }

            return(Console.Out.WriteLineAsync($"{context.Message.EventType}"));
        }