Example #1
0
        public void TestEventLog()
        {
            var client = SetupHelper.Client;
              var time = SetupHelper.BooksApp.TimeService;
              // 'api/events/public' is an endpoint for sending event data if there's no user logged in.
              // it is enabled if we register EventsPost controller
              var clickEvt = new EventData() {
            Id = Guid.NewGuid(), EventType = "BannerClick", StartedOn = time.UtcNow.AddSeconds(-1), Duration = 1,
            Location = "somewhere", Value = 1.0, StringValue = "Touch", Parameters = new Dictionary<string, string>()
              };
              clickEvt.Parameters["Param1"] = "Value1";
              var status = client.ExecutePost<EventData[], HttpStatusCode>(new []{clickEvt}, "api/events/public");

              //Login as dora, try other endpoint for posting events for logged in users
              LoginAs("dora");
              var clickEvt2 = new EventData() {
            Id = Guid.NewGuid(), EventType = "BannerClick", StartedOn = time.UtcNow.AddSeconds(-1), Duration = 1,
            Location = "somewhere", Value = 1.0, StringValue = "Touch", Parameters = new Dictionary<string, string>()
              };
              clickEvt2.Parameters["Param2"] = "Value2";
              status = client.ExecutePost<EventData[], HttpStatusCode>(new [] {clickEvt2}, "api/events");
              Logout();

              // let's search and find this event. We need to be logged in as site admin
              // Login as Kevin, he is site admin
              SetupHelper.BooksApp.Flush(); //force flush it
              this.LoginAs("Kevin");
              var events = client.ExecuteGet<SearchResults<EventData>>("api/logs/events?eventtype={0}",  "BannerClick");
              Assert.IsTrue(events.Results.Count >= 2, "Expected to find an event");
              Assert.AreEqual("BannerClick", events.Results[0].EventType, "Expected BannerClick event type.");
              Assert.AreEqual("BannerClick", events.Results[1].EventType, "Expected BannerClick event type.");
              // by default events are sorted by StartedOn-DESC, so first submitted is the last
              var lastEvt = events.Results[1];
              //get event details
              var evt1 = client.ExecuteGet<EventData>("api/logs/events/{0}", lastEvt.Id);
              Assert.IsNotNull(evt1, "Expected event object by Id");
              Assert.AreEqual(1, evt1.Parameters.Count, "Expected one parameter");
              Assert.AreEqual("Value1", evt1.Parameters["Param1"], "Wrong param value.");
              Logout();
        }
Example #2
0
 public static IEvent NewEvent(this IEntitySession session, EventData data)
 {
     var ev = session.NewEntity<IEvent>();
       ev.Id = data.Id;
       ev.EventType = data.EventType;
       ev.StartedOn = data.StartedOn ?? session.Context.App.TimeService.UtcNow;
       ev.Duration = data.Duration;
       ev.Location = data.Location;
       ev.UserId = data.UserId;
       ev.SessionId = data.SessionId;
       ev.TenantId = data.TenantId;
       ev.Value = data.Value;
       ev.StringValue = data.StringValue ?? data.Value + string.Empty;
       if (data.Parameters != null && data.Parameters.Count > 0)
     foreach (var de in data.Parameters) {
       var prm = session.NewEntity<IEventParameter>();
       prm.Event = ev;
       prm.Name = de.Key;
       prm.Value = de.Value;
     }
       return ev;
 }
Example #3
0
 public static EventData ToModel(this IEvent evt, bool details = false)
 {
     var model = new EventData() {
     Id = evt.Id, EventType = evt.EventType, StartedOn = evt.StartedOn, Duration = evt.Duration,
     UserId = evt.UserId, SessionId = evt.SessionId, TenantId = evt.TenantId, Location = evt.Location,
     Value = evt.Value, StringValue = evt.StringValue
       };
       if (details)
     model.Parameters = evt.Parameters.ToDictionary(e => e.Name, e => e.Value);
       return model;
 }