using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel.Design; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using Windows.Data.Json; using Windows.Globalization; namespace KdanCommon.Mixpanel.Data { public class EventData { [JsonProperty("event")] public string Event { get; } [JsonProperty("properties")] public Dictionary Properties { get { return GetDictionary(); } } private string _distinctId { get; } private Dictionary _customProperties { get; } public EventData(string eventName, string distinctId, Dictionary customProperties = null) { Event = eventName; _distinctId = distinctId; _customProperties = customProperties; } private Dictionary GetDictionary() { DateTime gtm = new DateTime(1970, 1, 1); long timeStamp = Convert.ToInt64(((TimeSpan)DateTime.UtcNow.Subtract(gtm)).TotalSeconds); var properties = new Dictionary { { "time", timeStamp }, { "distinct_id", _distinctId }, { "$insert_id", Guid.NewGuid().ToString("N") }, { "UwpRegion", new GeographicRegion().CodeTwoLetter} }; if (_customProperties != null) { foreach (var kvp in _customProperties) properties.Add(kvp.Key, kvp.Value); } return properties; } } public class ProfileData { [JsonProperty("token")] public string Token { get; } [JsonProperty("$distinct_id")] public string DistinctId { get; } [JsonProperty("$set")] public Dictionary Set { get; } public ProfileData(string projectToken, string distinctId, Dictionary customProperties = null) { Token = projectToken; DistinctId = distinctId; Set = customProperties; } } public class AliasData { [JsonProperty("event")] public string Event { get; set; } [JsonProperty("properties")] public Properties Properties { get; set; } } public class Properties { [JsonProperty("distinct_id")] public string DistinctId { get; set; } [JsonProperty("alias")] public string Alias { get; set; } [JsonProperty("token")] public string Token { get; set; } } }