123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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<string, object> Properties
- {
- get
- {
- return GetDictionary();
- }
- }
- private string _distinctId { get; }
- private Dictionary<string, object> _customProperties { get; }
- public EventData(string eventName, string distinctId, Dictionary<string, object> customProperties = null)
- {
- Event = eventName;
- _distinctId = distinctId;
- _customProperties = customProperties;
- }
- private Dictionary<string, object> GetDictionary()
- {
- DateTime gtm = new DateTime(1970, 1, 1);
- long timeStamp = Convert.ToInt64(((TimeSpan)DateTime.UtcNow.Subtract(gtm)).TotalSeconds);
- var properties = new Dictionary<string, object>
- {
- { "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<string, object> Set { get; }
- public ProfileData(string projectToken, string distinctId, Dictionary<string, object> 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; }
- }
- }
|