Example #1
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="collecter">消息收集器</param>
        /// <param name="appId">用户AppId</param>
        /// <param name="autoDelParam">是否自动删除校验不通过的属性 </param>
        public AnalysysDotNetSdk(ICollecter collecter, string appId, bool autoDelParam)
        {
            if (string.IsNullOrEmpty(appId))
            {
                throw new Exception("appId is empty");
            }

            this.collecter               = collecter ?? throw new Exception("collecter is null");
            this.appId                   = appId;
            this.egBaseProperties        = new Dictionary <string, object>(3);
            this.xcontextSuperProperties = new Dictionary <string, object>();
            this.autoDelParam            = autoDelParam;
            ValidHandle.SetDelNotValidParam(autoDelParam);
            InitBaseProperties();
        }
Example #2
0
        public void RegisterSuperProperties(Dictionary <string, object> superProperties)
        {
            int maxNum = 100;

            if (superProperties.Count > maxNum)
            {
                throw new Exception("Too many super properties. max number is 100.");
            }
            ValidHandle.CheckParam("", superProperties);
            IEnumerator <KeyValuePair <string, object> > dem = superProperties.GetEnumerator();

            while (dem.MoveNext())
            {
                this.xcontextSuperProperties.Add(dem.Current.Key, dem.Current.Value);
            }
            if (IsDebug())
            {
                Console.WriteLine("RegisterSuperProperties success");
            }
        }
Example #3
0
        private void Upload(string distinctId, bool isLogin, string eventName, Dictionary <string, object> properties, string platform)
        {
            ValidHandle.CheckProperty(distinctId, eventName, properties, this.xcontextSuperProperties.Count);
            Dictionary <string, object> eventMap = new Dictionary <string, object>(8);

            eventMap.Add("xwho", distinctId);
            eventMap.Add("xwhen", (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds);
            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(newProperties, xcontextSuperProperties);
            }
            newProperties.Add("$debug", (int)debugMode);
            if (properties != null)
            {
                AddDictionary(newProperties, properties);
            }
            AddDictionary(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)));
            }
        }
Example #4
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)));
            }
        }