Ejemplo n.º 1
0
        /// <summary>
        /// 埋点事件推送
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="buriedInformation"></param>
        /// <returns></returns>
        private async Task EventPublishAsync <T>(T buriedInformation)
        {
            var pheader = DownStreamHeaders();

            if (buriedInformation != null &&
                _httpContext != null &&
                pheader.Count > 0)
            {
                var logInfo = (BuriedInformationInput)Convert.ChangeType(buriedInformation, typeof(BuriedInformationInput));
                // 父级信息
                var buriedInfo = new BuriedInformation()
                {
                    ModName  = GetValue(pheader, "ModName"),
                    ProcName = GetValue(pheader, "ProcName"),
                    LaunchId = GetValue(pheader, "LaunchId"),
                    Token    = GetValue(pheader, "Token"),
                    BatchId  = GetValue(pheader, "BatchId"),
                    Seq      = GetValue(pheader, "Seq")
                };

                // 父级
                if (string.IsNullOrWhiteSpace(buriedInfo.Seq))
                {
                    buriedInfo.ParentSeq = "-1";
                }
                else
                {
                    buriedInfo.ParentSeq = buriedInfo.Seq;
                }
                // 请求头
                if (string.IsNullOrWhiteSpace(logInfo.HeaderParams) &&
                    _httpContext.User.Identity.IsAuthenticated)
                {
                    var dic = new Dictionary <string, object> {
                        { "Uid", _httpContext.User.Claims.First(c => c.Type == "Uid").Value },
                        { "RealName", _httpContext.User.Claims.First(c => c.Type == "Name").Value },
                        { "Mobile", _httpContext.User.Claims.First(c => c.Type == "MobilePhone").Value }
                    };
                    logInfo.HeaderParams = _jsonHelper.SerializeObject(dic);
                }
                // 索引
                var index = 0;
                if (_httpContext.Items.ContainsKey(BuriedIndex))
                {
                    index = Convert.ToInt32(_httpContext.Items[BuriedIndex]);
                }
                else
                {
                    _httpContext.Items.Add(BuriedIndex, 0);
                }

                // 埋点赋值
                buriedInfo.Seq              = string.Concat("PZGO_" + index);
                buriedInfo.BuriedTime       = DateTimeToUnixTimestamp(DateTime.Now).ToString();
                buriedInfo.ApiType          = logInfo.ApiType;
                buriedInfo.ApiUri           = logInfo.ApiUri;
                buriedInfo.BussinessDesc    = logInfo.BussinessDesc;
                buriedInfo.BussinessSuccess = logInfo.BussinessSuccess;
                buriedInfo.CalledResult     = logInfo.CalledResult;
                buriedInfo.Description      = logInfo.Description;
                buriedInfo.FuncName         = logInfo.FuncName;
                buriedInfo.HeaderParams     = logInfo.HeaderParams;
                buriedInfo.InputParams      = logInfo.InputParams;
                buriedInfo.TrgAlarm         = logInfo.TrgAlarm;
                buriedInfo.OutputParams     = logInfo.OutputParams;
                buriedInfo.Source           = "PZGO";
                buriedInfo.ErrorCode        = logInfo.ErrorCode;

                _httpContext.Items[ProjectSeq]  = buriedInfo.Seq; // 给下游准备请求头
                _httpContext.Items[BuriedIndex] = index + 1;      // 索引编号

                await _eventBus.PublishAsync(new BuriedEvent(buriedInfo));
            }
        }
Ejemplo n.º 2
0
 public BuriedEvent(BuriedInformation buriedInformation)
 {
     this.Id                = Guid.NewGuid();
     this.Timestamp         = DateTime.UtcNow;
     this.buriedInformation = buriedInformation;
 }