示例#1
0
        private void Upload(string distinctId, bool isLogin, string eventName, Dictionary <string, object> properties,
                            string platform, string xwhen)
        {
            if (eventName == null)
            {
                eventName = "";
            }

            ValidHandle.CheckProperty(distinctId, eventName, properties, this.xcontextSuperProperties.Count);
            Dictionary <string, object> eventMap = new Dictionary <string, object>(8);

            eventMap.Add("xwho", distinctId);

            if (xwhen != null && xwhen.Trim().Length > 0)
            {
                if (xwhen.Trim().Length != 13 || !Regex.IsMatch(xwhen, RegexString.REG_XWHEN))
                {
                    Console.WriteLine($"The param xwhen {xwhen.Trim()} not a millisecond timestamp.");
                }

                try
                {
                    long when = long.Parse(xwhen.Trim());
                    eventMap.Add("xwhen", when);
                }
                catch (Exception e)
                {
                    Console.WriteLine("The param xwhen %s not a timestamp." + xwhen.Trim());
                }
            }
            else
            {
                if (EventName.ALIAS.GetEnumDescription().StartsWith(eventName))
                {
                    //为了防止alise事件和别的事件的xwhen相同
                    eventMap.Add("xwhen", TimeHelper.CurrentTimeMillis() - 3);
                }
                else
                {
                    eventMap.Add("xwhen", TimeHelper.CurrentTimeMillis());
                }
            }

            eventMap.Add("xwhat", eventName);
            eventMap.Add("appid", appId);
            Dictionary <string, object> newProperties = new Dictionary <string, object>(16);
            string profile = "$profile";

            if (!eventName.StartsWith(profile) && !eventName.StartsWith(EventName.ALIAS.GetEnumDescription()))
            {
                AddDictionary(ref newProperties, xcontextSuperProperties);
            }

            newProperties.Add("$debug", (int)debugMode);
            if (properties != null)
            {
                AddDictionary(ref newProperties, properties);
            }

            AddDictionary(ref newProperties, egBaseProperties);
            newProperties.Add("$is_login", isLogin);
            string newPlatForm = GetPlatForm(platform);

            if (newPlatForm != null && newPlatForm.Trim().Length > 0)
            {
                newProperties.Add("$platform", newPlatForm);
            }

            eventMap.Add("xcontext", newProperties);
            this.collecter.Debug(IsDebug());
            bool ret = this.collecter.Send(eventMap);

            if (eventName.StartsWith(profile) && IsDebug() && ret)
            {
                Console.WriteLine(string.Format("{0} success.", eventName.Substring(1)));
            }
        }