Пример #1
0
 public void ReadTimestampHeader(NameValueCollection headers)
 {
     this.SafeLog(delegate
     {
         if (headers != null && headers.AllKeys.Contains("X-DiscoveryLogTimestamp"))
         {
             string text = headers["X-DiscoveryLogTimestamp"];
             if (!string.IsNullOrWhiteSpace(text))
             {
                 string[] array = text.Split(new char[]
                 {
                     ','
                 });
                 if (array.Length == 2)
                 {
                     long num  = 0L;
                     long num2 = 0L;
                     if (long.TryParse(array[0], out num2) && long.TryParse(array[1], out num))
                     {
                         long num3 = DateTime.UtcNow.Ticks - num;
                         if (num3 > 0L)
                         {
                             this.offset                       = num3 + num2;
                             Recorder.Record record            = this.Start("CallLatency", TraceType.InfoTrace, true);
                             record.Attributes["WORKDURATION"] = num3;
                             this.End(record);
                         }
                     }
                 }
             }
         }
     });
 }
Пример #2
0
 public void Write(NameValueCollection headers, Action <string, string> protocolLog)
 {
     this.SafeLog(delegate
     {
         StringBuilder stringBuilder = new StringBuilder();
         JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
         Recorder.Record record        = this.Start("Logging", TraceType.InfoTrace, true);
         record.Attributes["CONVTIME"] = this.ConversionTime;
         record.Attributes["LOGTIME"]  = this.LoggingTime;
         this.End(record);
         javaScriptSerializer.Serialize(this.records.Values, stringBuilder);
         for (int i = 0; i < 10; i++)
         {
             string text  = string.Format("DiscoveryLog{0}", i);
             string text2 = this.Segment(stringBuilder, i, 10000);
             if (!string.IsNullOrEmpty(text2))
             {
                 this.WriteLog(text, text2, TraceType.InfoTrace);
                 if (protocolLog != null)
                 {
                     protocolLog(text, text2.Replace(',', '~'));
                 }
             }
             if (headers != null)
             {
                 string value = this.Segment(stringBuilder, i, 500);
                 if (!string.IsNullOrEmpty(value))
                 {
                     headers[text] = value;
                 }
             }
         }
     });
 }
Пример #3
0
        private void WriteLog(Recorder.Record record)
        {
            StringBuilder        stringBuilder        = new StringBuilder();
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            javaScriptSerializer.Serialize(record, stringBuilder);
            this.WriteLog(record.Description, stringBuilder.ToString(), record.TraceType);
        }
Пример #4
0
        public virtual void Fail(Exception ex)
        {
            Recorder.Trace(2L, TraceType.WarningTrace, "Executor.Fail Error:", ex);
            this.Context.Failures.Add(ex);
            Recorder.Record record = this.Policy.Recorder.Start(this.TaskType.Name, TraceType.ErrorTrace, true);
            SearchException ex2    = ex as SearchException;

            if (ex2 != null)
            {
                record.Attributes["FailError"]  = ex2.Error.ToString();
                record.Attributes["FailSource"] = ex2.Source;
            }
            record.Attributes["EX"] = ex.ToString();
            this.Policy.Recorder.End(record);
        }
Пример #5
0
        private Recorder.Record UpdateRecord(Recorder.Record existing, Recorder.Record source)
        {
            if (existing != null && source != null)
            {
                using (IEnumerator <string> enumerator = source.Attributes.Keys.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Recorder.< > c__DisplayClass15 CS$ < > 8__locals2 = new Recorder.< > c__DisplayClass15();
                        CS$ < > 8__locals2.key = enumerator.Current;
                        object sourceValue;
                        if (source.Attributes.TryGetValue(CS$ < > 8__locals2.key, out sourceValue))
                        {
                            existing.Attributes.AddOrUpdate(CS$ < > 8__locals2.key, sourceValue, delegate(string existingKey, object existingValue)
                            {
                                if (existingValue == null)
                                {
                                    return(sourceValue);
                                }
                                double num;
                                double num2;
                                if (double.TryParse(sourceValue.ToString(), out num) && double.TryParse(existingValue.ToString(), out num2))
                                {
                                    return(num + num2);
                                }
                                for (int i = 1; i < 10; i++)
                                {
                                    string key = string.Format("{0}{1}", CS$ < > 8__locals2.key, i);
                                    if (existing.Attributes.TryAdd(key, sourceValue))
                                    {
                                        break;
                                    }
                                }
                                return(existingValue);
                            });
                        }
                    }
                    goto IL_BE;
                }
            }
            if (source != null)
            {
                return(source);
            }
IL_BE:
            return(existing);
        }
Пример #6
0
 protected virtual void AttemptComplete()
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete");
     if ((this.queue.IsCompleted && this.current < 0) || this.IsCancelled)
     {
         Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete Started");
         if (this.currentRecord != null)
         {
             this.currentRecord.Attributes["COUNT"]        = this.itemCount;
             this.currentRecord.Attributes["WORKDURATION"] = this.totalDuration;
             this.Policy.Recorder.End(this.currentRecord);
             if (this.batchDurations.Count > 0)
             {
                 string          description = string.Format("{0}Batches", this.currentRecord.Description);
                 Recorder.Record record      = this.Policy.Recorder.Start(description, TraceType.InfoTrace, false);
                 int             num         = 0;
                 foreach (Tuple <long, long, long> tuple in this.batchDurations)
                 {
                     record.Attributes[string.Format("BATCH{0}START", num)]    = tuple.Item1;
                     record.Attributes[string.Format("BATCH{0}DURATION", num)] = tuple.Item2;
                     record.Attributes[string.Format("BATCH{0}COUNT", num)]    = tuple.Item3;
                     num++;
                 }
                 this.Policy.Recorder.End(record);
             }
         }
         if (this.ChainedExecutor != null)
         {
             Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete SignalNext");
             this.ChainedExecutor.SignalComplete();
         }
         else
         {
             Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete SignalRoot");
             if (this.Context != null && !this.Context.IsDisposed && this.Context.WaitHandle != null && !this.Context.WaitHandle.SafeWaitHandle.IsClosed)
             {
                 this.Context.WaitHandle.Set();
             }
         }
         Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete Completed");
     }
 }
Пример #7
0
        public virtual void Cancel(Exception ex)
        {
            Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.Cancel Called Error:", ex);
            if (!this.IsCancelled)
            {
                Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.Cancel First Cancel Error:", ex);
                this.Context.FatalException = ex;
                this.Context.CancellationTokenSource.Cancel(false);
                this.AttemptComplete();
            }
            Recorder.Record record = this.Policy.Recorder.Start(this.TaskType.Name, TraceType.FatalTrace, true);
            SearchException ex2    = ex as SearchException;

            if (ex2 != null)
            {
                record.Attributes["CancelError"]  = ex2.Error.ToString();
                record.Attributes["CancelSource"] = ex2.Source;
            }
            record.Attributes["EX"] = ex.ToString();
            this.Policy.Recorder.End(record);
        }
Пример #8
0
 public void End(Recorder.Record record)
 {
     this.SafeLog(delegate
     {
         long timestamp = this.Timestamp;
         try
         {
             record.Attributes["DURATION"] = (double)this.Timestamp - record.StartTime;
             if (!record.IsAggregateRecord || record.TraceType == TraceType.ErrorTrace || record.TraceType == TraceType.FatalTrace)
             {
                 this.WriteLog(record);
             }
             if (record.IsAggregateRecord)
             {
                 this.AppendRecord(record);
             }
         }
         finally
         {
             this.LoggingTime += this.Timestamp - timestamp;
         }
     });
 }
Пример #9
0
 private void AppendRecord(Recorder.Record record)
 {
     this.records.AddOrUpdate(record.Description, record, (string key, Recorder.Record existing) => this.UpdateRecord(existing, record));
 }