コード例 #1
0
 private void BeginTrace()
 {
     try
     {
         this._start = DateTime.UtcNow;
         this._sw.Start();
         this.FillInDefaultTags();
         if (AppContext.MeasurementTraceEnabled)
         {
             WJOPRequestContext current = WJOPRequestContext.Current;
             current.SequenceNum = current.SequenceNum + (long)1;
             WJOPRequestContext depth = WJOPRequestContext.Current;
             depth.Depth       = depth.Depth + (long)1;
             this._sequenceNum = WJOPRequestContext.Current.SequenceNum;
             this._depth       = WJOPRequestContext.Current.Depth;
             Dictionary <string, float> strs = new Dictionary <string, float>()
             {
                 { "method_in", 1f },
                 { "depth", (float)this._depth },
                 { "sequence_num", (float)this._sequenceNum }
             };
             Dictionary <string, float> strs1 = strs;
             DebugUtil.Log(string.Format(">>>>>BeginTrace {0}, CtxDetail {1}", this._scopeName, WJOPRequestContext.Current.DumpString));
             MeasurementHelper.WritePoint("mscope_request_trace", strs1, this._userTags, this._start);
         }
     }
     catch (Exception exception)
     {
         DebugUtil.LogException(exception);
     }
 }
コード例 #2
0
 private void EndTrace()
 {
     try
     {
         if (this._sw.IsRunning)
         {
             this._sw.Stop();
         }
         this._scopeExecTime = this._sw.ElapsedMilliseconds;
         this._end           = DateTime.UtcNow;
         Dictionary <string, float> strs = new Dictionary <string, float>()
         {
             { "hit", 1f },
             { "scope_exec_time", (float)this._scopeExecTime }
         };
         MeasurementHelper.WritePoint("mscope_statistic", strs, this._userTags, this._end);
         if (AppContext.MeasurementTraceEnabled)
         {
             Dictionary <string, float> strs1 = new Dictionary <string, float>()
             {
                 { "method_in", -1f },
                 { "depth", (float)this._depth },
                 { "sequence_num", (float)this._sequenceNum },
                 { "method_exec_time", (float)this._scopeExecTime }
             };
             Dictionary <string, float> strs2 = strs1;
             object[] requestId = new object[] { this._scopeName, WJOPRequestContext.Current.RequestId, this._depth, this._sequenceNum };
             DebugUtil.Log(string.Format("<<<<<EndTrace {0}, ReqID:{1}, Depth:{2}, SeqNO:{3}", requestId));
             MeasurementHelper.WritePoint("mscope_request_trace", strs2, this._userTags, this._end);
             WJOPRequestContext current = WJOPRequestContext.Current;
             current.Depth = current.Depth - (long)1;
         }
     }
     catch (Exception exception)
     {
         DebugUtil.LogException(exception);
     }
 }
コード例 #3
0
        private static string InvokeAPIStore(string serviceName, string relativeURL, string requestBody, string httpMethod, string contentType = "application/json; charset=utf-8", string encodingType = "utf-8", NameValueCollection addHeaders = null, IWebProxy proxy = null)
        {
            string         appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.ApiStore);
            string         str    = string.Concat(appUri, serviceName, relativeURL);
            HttpWebRequest length = (HttpWebRequest)WebRequest.Create(str);

            length.Method = httpMethod;
            if (!string.IsNullOrWhiteSpace(AppContext.AppKey))
            {
                if (addHeaders == null)
                {
                    addHeaders = new NameValueCollection();
                }
                addHeaders["AppKey"] = AppContext.AppKey;
                WJOPRequestContext.AttachToHttpHeaders(addHeaders);
            }
            if ((addHeaders == null ? false : addHeaders.Count > 0))
            {
                length.Headers.Add(addHeaders);
            }
            if (proxy != null)
            {
                length.Proxy = proxy;
            }
            length.ContentType   = contentType;
            length.ContentLength = (long)requestBody.Length;
            if (!string.IsNullOrWhiteSpace(requestBody))
            {
                Stream requestStream = length.GetRequestStream();
                try
                {
                    byte[] bytes = APIStoreHelper.GetBytes(encodingType, requestBody);
                    requestStream.Write(bytes, 0, (int)bytes.Length);
                }
                finally
                {
                    if (requestStream != null)
                    {
                        ((IDisposable)requestStream).Dispose();
                    }
                }
            }
            WebResponse  response     = length.GetResponse();
            string       empty        = string.Empty;
            StreamReader streamReader = new StreamReader(response.GetResponseStream());

            try
            {
                empty = streamReader.ReadToEnd();
                if (empty.StartsWith("ApiStore调用服务时发生错误"))
                {
                    throw new WebException(empty);
                }
            }
            finally
            {
                if (streamReader != null)
                {
                    ((IDisposable)streamReader).Dispose();
                }
            }
            return(empty);
        }