/// <summary> /// Returns an AnalyticsItem from an xml node /// </summary> /// <param name="node"> /// xml node /// </param> /// <returns> /// an instance of an AnalyticsItem class /// </returns> /// TODO - should be deprecated. Keep for backward compatibility for now public static AnalyticsItem Parse(XElement node) { try { var item = new AnalyticsItem { Date = node.GetAttributeValue(AttributeNameDate, DateTime.MinValue), Action = node.GetAttributeValue(AttributeNameAction, string.Empty), ClientId = node.GetAttributeValue(AttributeNameClientId, string.Empty), ReferrerClientId = node.GetAttributeValue(AttributeNameReferrerClientId, string.Empty), ClientAppType = node.GetAttributeValue(AttributeNameClientAppType, string.Empty), Flights = Utils.ToList(node.GetAttributeValue(AttributeNameFlights, string.Empty)), SessionId = node.GetAttributeValue(AttributeNameSessionId, string.Empty), EventId = node.GetAttributeValue(AttributeNameTrackingId, Guid.Empty), ParentEventId = node.GetAttributeValue(AttributeNameCorrelationId, Guid.Empty), DealId = node.GetAttributeValue(AttributeNameDealId, Guid.Empty), UserId = node.GetAttributeValue(AttributeNameUserId, string.Empty), AdditionalUserIds = Utils.ToList(node.GetAttributeValue(AttributeNameAdditionalUserIds, string.Empty)), Milliseconds = node.GetAttributeValue(AttributeNameMilliseconds, 0), DataCenter = node.GetAttributeValue(AttributeNameDataCenter, string.Empty) }; if (node.FirstNode != null) { item.Payload = node.FirstNode.ToString(); } return(item); } catch { Log.Error("invalid analytics item found in the queue"); return(null); } }
/// <summary> /// Copies the item to this instance /// </summary> /// <param name="item"> /// analytics item /// </param> public void ReadFrom(AnalyticsItem item) { string flightsStr = string.Empty; string additionalUserIdsStr = string.Empty; if (item.Flights != null) { HashSet <string> uniqueFlights = new HashSet <string>(item.Flights); var orderedFlights = uniqueFlights.OrderBy(elem => elem); // Make flights list deterministic flightsStr = string.Join(",", orderedFlights); } if (item.AdditionalUserIds != null) { HashSet <string> uniqueUserIds = new HashSet <string>(item.AdditionalUserIds); var orderedUserIds = uniqueUserIds.OrderBy(elem => elem); // Make additional user ids list deterministic additionalUserIdsStr = string.Join(",", orderedUserIds); } this.Action = item.Action; this.Date = item.Date; this.DealId = item.DealId; this.UserId = item.UserId; this.AdditionalUserIds = additionalUserIdsStr; this.SessionId = item.SessionId; this.TrackingId = item.EventId; this.CorrelationId = item.ParentEventId; this.ClientId = item.ClientId; this.ReferrerClientId = item.ReferrerClientId; this.ClientAppType = item.ClientAppType; this.Flights = flightsStr; this.Milliseconds = item.Milliseconds; this.DataCenter = item.DataCenter; if (item.JPayload != null) { this.Payload = JsonConvert.SerializeObject(item.JPayload); } else { //Backward compatibility this.Payload = item.Payload; } }
/// <summary> /// Adds a new item to the analytics client /// </summary> /// <param name="analyticsItem"> /// </param> public void Add(AnalyticsItem analyticsItem) { if (QueueUploaderEnabled) { if (this.localQueue.Count < MaxQueuedItems) { this.localQueue.Enqueue(analyticsItem); this.resetEvent.Set(); } else { if (!maxQueueErrorEventStopwatch.IsRunning || this.maxQueueErrorEventStopwatch.Elapsed > TimeSpan.FromMinutes(1)) { // items won't be counted // log critical error Log.Error("Local analytics queue (memory) contains {0} items.", this.localQueue.Count); maxQueueErrorEventStopwatch.Restart(); } } } }