/// <summary> /// Send a datacollect hit /// </summary> /// <param name="type">The hit type</param> /// <param name="hit">The hit content</param> /// <returns></returns> public async Task SendHit(HitType type, BaseHit hit) { if (visitor.IsPanic) { logger.Log(LogLevel.INFO, Model.Logs.LogCode.PANIC_NO_TRACKING); return; } await fsVisitorService.SendHit(visitor, type, hit); }
/// <summary> /// Send a datacollect hit /// </summary> /// <param name="type">The hit type</param> /// <param name="hit">The hit content</param> /// <returns></returns> public async Task SendHit(string visitorId, HitType type, BaseHit hit) { try { await sender.Send(visitorId, type, hit); } catch (Exception e) { exceptionHandler.Handle(e); } }
public async Task <IActionResult> Send( JsonElement hit) { BaseHit hitObj = null; try { var enumType = (HitType)Enum.Parse(typeof(HitType), hit.GetProperty("t").GetString()); switch (enumType) { case HitType.PAGEVIEW: hitObj = GetObject <Pageview>(hit); break; case HitType.SCREENVIEW: hitObj = GetObject <Screenview>(hit); break; case HitType.EVENT: hitObj = GetObject <Event>(hit); break; case HitType.TRANSACTION: hitObj = GetObject <Transaction>(hit); break; case HitType.ITEM: hitObj = GetObject <Item>(hit); break; } await VisitorController.Visitor.SendHit(enumType, hitObj); return(Ok()); } catch (Exception e) { return(BadRequest(new { error = e.Message, })); } }
public async Task Send(string visitorId, HitType type, BaseHit hit) { if (hit == null) { throw new ArgumentException("visitor should not be null"); } switch (type) { case HitType.EVENT: hit = hit as Event; break; case HitType.PAGEVIEW: hit = hit as Pageview; break; case HitType.SCREENVIEW: hit = hit as Screenview; break; case HitType.TRANSACTION: hit = hit as Transaction; break; case HitType.ITEM: hit = hit as Item; break; } if (hit == null) { exceptionHandler.Handle(new ArgumentException("Hit is malformed")); return; } try { hit.SetBaseInfos(type, environmentId, visitorId); var validationResult = hit.Validate(); if (!validationResult.Success) { exceptionHandler.Handle(new ArgumentException(string.Join(", ", validationResult.Errors))); return; } var json = JsonConvert.SerializeObject(hit, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json")) { HttpResponseMessage response = await httpClient.PostAsync(HitEndpointUrl, stringContent); response.EnsureSuccessStatusCode(); logger.Log(LogLevel.INFO, LogCode.HIT_SENT, new { hit }); } } catch (InvalidCastException e) { exceptionHandler.Handle(e); } catch (HttpRequestException e) { exceptionHandler.Handle(e); } }
/// <summary> /// Send a datacollect hit /// </summary> /// <param name="type">The hit type</param> /// <param name="hit">The hit content</param> /// <returns></returns> public async Task SendHit(Visitor visitor, HitType type, BaseHit hit) { await sender.Send(visitor.Id, type, hit); }