Esempio n. 1
0
        protected void Error(Exception exception, string message)
        {
            HttpRequestMessage request    = this.Request?.AsHttpRequestMessage();
            TraceEntry         traceEntry = request?.GetTraceEntry();

            this.Logger.Error(message, request, "ASP.NET MVC Log", 0UL, string.Empty, traceEntry, exception);
        }
Esempio n. 2
0
        protected void Fatal(Exception exception)
        {
            HttpRequestMessage request    = this.Request?.AsHttpRequestMessage();
            TraceEntry         traceEntry = request?.GetTraceEntry();

            this.Logger.Critical(exception.Message, request, "ASP.NET MVC Log", 0UL, string.Empty, traceEntry, exception);
        }
Esempio n. 3
0
        protected void Fatal(string message)
        {
            HttpRequestMessage request    = this.Request?.AsHttpRequestMessage();
            TraceEntry         traceEntry = request?.GetTraceEntry();

            this.Logger.Critical(message, this.Request.AsHttpRequestMessage(), "ASP.NET MVC Log", 0UL, string.Empty, traceEntry);
        }
        /// <summary>
        ///     Withes the trace entry.
        /// </summary>
        /// <param name="httpClient">The HTTP client.</param>
        /// <param name="traceEntry">The trace entry.</param>
        /// <returns>HttpClient.</returns>
        public static HttpClient WithTraceEntry(this HttpClient httpClient, TraceEntry traceEntry = null)
        {
            if (traceEntry == null)
            {
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-CID", App.Host.RoleInstance);
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-RID", Guid.NewGuid().ToGuidString());
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-SID", Guid.NewGuid().ToGuidString());
            }
            else
            {
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-CID", traceEntry.ClientId + "," + App.Host.RoleInstance);
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-RID", traceEntry.RequestId ?? Guid.NewGuid().ToGuidString());
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-SID", traceEntry.SessionId ?? Guid.NewGuid().ToGuidString());
                if (traceEntry.SourceIP.IsNullOrEmpty())
                {
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-IP", traceEntry.SourceIP);
                }
                if (traceEntry.SourceUserAgent.IsNullOrEmpty())
                {
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-UA", traceEntry.SourceUserAgent);
                }
                if (traceEntry.UserId.IsNullOrEmpty())
                {
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-JYM-UID", traceEntry.UserId);
                }
            }

            return(httpClient);
        }
Esempio n. 5
0
        static BufferSizeResult GetBufferSize(TraceEntry entry)
        {
            string streamType = "";
            uint   bufferSize = 0;

            const string regexString = "Added (?<d2>.*) chunk with duration (?<d1>.*) to cache. Size including active chunk (?<v>.*) ms";
            Regex        regex       = new Regex(regexString);

            if (regex.IsMatch(entry.Text))
            {
                ChunkFailureEventArgs result = new ChunkFailureEventArgs();
                var matches      = regex.Matches(entry.Text);
                var valueCapture = matches[0].Groups["v"].Captures;
                if (valueCapture.Count > 0)
                {
                    uint.TryParse(valueCapture[0].Value, NumberStyles.None, CultureInfo.CurrentCulture, out bufferSize);
                }
                var data2Capture = matches[0].Groups["d2"].Captures;
                if (data2Capture.Count > 0)
                {
                    streamType = data2Capture[0].Value.ToLowerInvariant();
                }
            }
            return(new BufferSizeResult(streamType, bufferSize));
        }
        public void Add(TraceEntry entry)
        {
            if (Entries.Count >= MaxTraceEntries)
                Entries.RemoveAt(0);

            Entries.Add(entry);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="JinyinmaoTraceEntryHandler" /> class.
 /// </summary>
 /// <param name="traceEntry">The trace entry.</param>
 /// <param name="userId">The user identifier.</param>
 public JinyinmaoTraceEntryHandler(TraceEntry traceEntry, string userId)
 {
     this.TraceEntry = traceEntry;
     if (userId.IsNotNullOrEmpty())
     {
         this.TraceEntry.UserId = userId;
     }
 }
        public void Add(TraceEntry entry)
        {
            if (Entries.Count >= MaxTraceEntries)
            {
                Entries.RemoveAt(0);
            }

            Entries.Add(entry);
        }
Esempio n. 9
0
 public void AddTraceEntry(TestPosition position, string message)
 {
     _top = new TraceEntry()
     {
         Position = position,
         Message  = message,
         Next     = _top
     };
 }
Esempio n. 10
0
 public void AddTraceEntry(TestPosition position, string message)
 {
     _top = new TraceEntry()
     {
         Position = position,
         Message = message,
         Next = _top
     };
 }
        /// <summary>
        ///     Creates a new instance of the <see cref="T:System.Net.Http.HttpClient" />.
        /// </summary>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="traceEntry">The trace entry.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="handlers">The list of HTTP handler that delegates the processing of HTTP response messages to another handler.</param>
        /// <returns>A new instance of the <see cref="T:System.Net.Http.HttpClient" />.</returns>
        public static HttpClient Create(string serviceName, TraceEntry traceEntry, string userId, params DelegatingHandler[] handlers)
        {
            if (userId.IsNotNullOrEmpty())
            {
                traceEntry.UserId = userId;
            }

            return(Create(serviceName, traceEntry, handlers));
        }
Esempio n. 12
0
 public void UnwindToPosition(TestPosition position)
 {
     while (_top != null)
     {
         if (!_top.Position.IsOnPathTo(position))
             _top = _top.Next;
         else
             break;
     }
 }
Esempio n. 13
0
        private static void OutputEntry(TraceEntry traceEntryTree, int indent)
        {
            OutputIndent(indent);
            Console.WriteLine("|{0}", traceEntryTree.Content);

            indent++;
            foreach (TraceEntry child in traceEntryTree.Children)
            {
                OutputEntry(child, indent);
            }
        }
Esempio n. 14
0
        public void Transformations_AbstractTrace_RevokeEntry_NewEntry()
        {
            var dummy      = new Dummy();
            var traceEntry = new TraceEntry <Dummy, Dummy>(ruleDependent, dummy, dummy);

            Assert.IsFalse(trace.TraceIn(ruleDependent, dummy).Contains(traceEntry));

            trace.RevokeEntry(traceEntry);

            Assert.IsFalse(trace.TraceIn(ruleDependent, dummy).Contains(traceEntry));
        }
Esempio n. 15
0
        /// <summary>
        ///     Called when an exception occurs.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public void OnException(ExceptionContext filterContext)
        {
            HttpRequestMessage request = filterContext.HttpContext?.Request?.AsHttpRequestMessage();

            if (request != null)
            {
                TraceEntry traceEntry = request.GetTraceEntry();

                this.Logger.Log(2, filterContext.Exception.Message, request, "ASP.NET MVC Error", 0UL, string.Empty, traceEntry, filterContext.Exception);
            }
        }
Esempio n. 16
0
        public void Add(TraceType type, string title, string description, string content)
        {
            var entry = new TraceEntry
            {
                Type = type,
                Title = title,
                Description = description,
                Content = content
            };

            Add(entry);
        }
        public void Add(TraceType type, string title, string description, string content)
        {
            var entry = new TraceEntry
            {
                Type        = type,
                Title       = title,
                Description = description,
                Content     = content
            };

            Add(entry);
        }
Esempio n. 18
0
        /// <summary>
        ///     Criticals the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="moeGrain">The MoeGrain.</param>
        /// <param name="clientId">The client identifier.</param>
        /// <param name="deviceId">The device identifier.</param>
        /// <param name="requestId">The request identifier.</param>
        /// <param name="sessionId">The session identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="errorCode">The error code.</param>
        /// <param name="errorCodeMessage">The error code message.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="payload">The payload.</param>
        public void Critical(string message, MoeGrain moeGrain, string clientId, string deviceId, string requestId, string sessionId, string userId, string tag = "None", ulong errorCode = 0, string errorCodeMessage = "", Exception exception = null, Dictionary <string, object> payload = null)
        {
            TraceEntry traceEntry = new TraceEntry
            {
                ClientId  = clientId,
                DeviceId  = deviceId,
                RequestId = requestId,
                SessionId = sessionId,
                UserId    = userId
            };

            this.Critical(message, (IJinyinmaoGrain)moeGrain, tag, errorCode, errorCodeMessage, traceEntry, exception, payload);
        }
Esempio n. 19
0
        /// <summary>
        ///     Warnings the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="clientId">The client identifier.</param>
        /// <param name="deviceId">The device identifier.</param>
        /// <param name="requestId">The request identifier.</param>
        /// <param name="sessionId">The session identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="errorCode">The error code.</param>
        /// <param name="errorCodeMessage">The error code message.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="payload">The payload.</param>
        public void Warning(string message, string clientId, string deviceId, string requestId, string sessionId, string userId, string tag = "None", ulong errorCode = 0, string errorCodeMessage = "", Exception exception = null, Dictionary <string, object> payload = null)
        {
            TraceEntry traceEntry = new TraceEntry
            {
                ClientId  = clientId,
                DeviceId  = deviceId,
                RequestId = requestId,
                SessionId = sessionId,
                UserId    = userId
            };

            this.Warning(message, tag, errorCode, errorCodeMessage, traceEntry, exception, payload);
        }
Esempio n. 20
0
 public void UnwindToPosition(TestPosition position)
 {
     while (_top != null)
     {
         if (!_top.Position.IsOnPathTo(position))
         {
             _top = _top.Next;
         }
         else
         {
             break;
         }
     }
 }
        /// <summary>
        ///     Creates a new instance of the <see cref="T:System.Net.Http.HttpClient" />.
        /// </summary>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="traceEntry">The trace entry.</param>
        /// <param name="handlers">The list of HTTP handler that delegates the processing of HTTP response messages to another handler.</param>
        /// <returns>A new instance of the <see cref="T:System.Net.Http.HttpClient" />.</returns>
        public static HttpClient Create(string serviceName, TraceEntry traceEntry, params DelegatingHandler[] handlers)
        {
            //List<DelegatingHandler> delegatingHandlers = new List<DelegatingHandler>
            //{
            //    new NBTraceEntryHandler(traceEntry),
            //    new NBHttpStatusHandler(),
            //    new NBLogHandler("HTTP Client Request", "HTTP Client Response"),
            //    new NBRetryHandler()
            //};
            //delegatingHandlers.AddRange(handlers);

            //HttpClient client = HttpClientFactory.Create(new HttpClientHandler
            //{
            //    AllowAutoRedirect = true,
            //    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            //}, delegatingHandlers.ToArray());

            HttpClient client = new HttpClient(new HttpClientHandler
            {
                AllowAutoRedirect      = true,
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            });

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json", 1.0));
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml", 0.5));
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*", 0.1));
            client.DefaultRequestHeaders.AcceptEncoding.Clear();
            client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip", 1.0));
            client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate", 0.5));
            client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("*", 0.1));
            client.Timeout = 1.Minutes();

            KeyValuePair <string, string>?permission = App.Configurations.GetPermission(serviceName);

            if (permission.HasValue)
            {
                client.BaseAddress = new Uri(permission.Value.Key);
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(NBAuthScheme.NBInternalAuth, permission.Value.Value);
            }
            else
            {
                client.BaseAddress = new Uri("http://service.nb.com.cn/");
            }

            return(client);
        }
        static SmoothStreamingEvent ConvertTraceToEvent(TraceEntry entry, EventType eventType, string regexString)
        {
            Regex regex = new Regex(regexString);

            if (regex.IsMatch(entry.Text))
            {
                SmoothStreamingEvent ssEvent = new SmoothStreamingEvent(entry);
                ssEvent.EventType      = eventType;
                ssEvent.Message        = entry.Text;
                ssEvent.MediaElementId = entry.MediaElementId;
                var matches      = regex.Matches(entry.Text);
                var valueCapture = matches[0].Groups["v"].Captures;
                if (valueCapture.Count > 0)
                {
                    double value;
                    if (double.TryParse(valueCapture[0].Value, NumberStyles.None, CultureInfo.CurrentCulture, out value))
                    {
                        ssEvent.Value = value;
                    }
                    else
                    {
                        ssEvent.Value = 0;
                    }
                }
                var data1Capture = matches[0].Groups["d1"].Captures;
                if (data1Capture.Count > 0)
                {
                    ssEvent.Data1 = data1Capture[0].Value;
                }
                var data2Capture = matches[0].Groups["d2"].Captures;
                if (data2Capture.Count > 0)
                {
                    ssEvent.Data2 = data2Capture[0].Value;
                }
                var data3Capture = matches[0].Groups["d3"].Captures;
                if (data3Capture.Count > 0)
                {
                    ssEvent.Data3 = data3Capture[0].Value;
                }
                return(ssEvent);
            }
            else
            {
                return(null);
            }
        }
        void ProcessBufferingEngineMessage(TraceEntry entry)
        {
            if (entry.MethodName == "AddChunkToCache")
            {
                SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.VideoBufferSize, "Added (?<d2>.*) chunk with duration (?<d1>.*) to cache. Size including active chunk (?<v>.*) ms");
                if (ssEvent != null)
                {
                    if (ssEvent.Data2 == "Audio")
                    {
                        ssEvent.EventType = EventType.AudioBufferSize;
                    }
                    Submit(ssEvent);
                }
            }
            else if (entry.MethodName == "RaiseBufferChangedEvent")
            {
                SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.BufferingStateChanged, "Rebuffer State: (?<d1>.), (?<d2>.*)");
                if (ssEvent != null)
                {
                    switch (ssEvent.Data1)
                    {
                    case "a":
                        ssEvent.Value = 0;
                        ssEvent.Data1 = "NotRebuffering";
                        break;

                    case "b":
                        ssEvent.Value = 1;
                        ssEvent.Data1 = "RebufferingDueToSeek";
                        break;

                    case "c":
                        ssEvent.Value = 1;
                        ssEvent.Data1 = "RebufferingDueToStartPlayback";
                        break;

                    case "d":
                        ssEvent.Value = 1;
                        ssEvent.Data1 = "RebufferingDueToUnderflow";
                        break;
                    }
                    Submit(ssEvent);
                }
            }
        }
Esempio n. 24
0
        public virtual void Setup()
        {
            TraceContext traceContext = TraceContext.Current;
            if (traceContext == null)
            {
                traceContext = TraceContext.Create();
            }

            traceContext.MarkBeginTime();
            MethodInfo methodInfo
                = MethodInfo.Create(System.Reflection.MethodBase.GetCurrentMethod());
            TraceEntry traceEntry
                = new TraceEntry(TraceEntryType.Statistics, methodInfo);

            traceContext.CurrentMethodInfo = methodInfo;
            traceContext.TraceEntryList.Add(traceEntry);
            methodInfo.MarkBeginTime();
        }
Esempio n. 25
0
        // Token: 0x060012B7 RID: 4791 RVA: 0x0004E3B0 File Offset: 0x0004C5B0
        public void Write(TraceEntry entry)
        {
            switch (entry.TraceType)
            {
            case TraceType.WarningTrace:
                this.Log(entry, "WARNING");
                return;

            case TraceType.ErrorTrace:
                this.Log(entry, "ERROR");
                return;

            case TraceType.PerformanceTrace:
                this.Log(entry, "PERFORMANCE");
                return;
            }
            this.Log(entry, "DEBUG");
        }
Esempio n. 26
0
        public void RootLogWriterCanBeSetOnInitialization()
        {
            var setupTracerFactory = new SetupLog();
            // Trace output is written to this guy
            var listLogWriter = new ListLogWriter <TraceEntry>(setupTracerFactory);

            using (var traceManager = new TraceManager(listLogWriter))
            {
                traceManager.Start();
                var tracer = traceManager.TracerFor(this);
                tracer.Info("Info");

                Assert.Single(listLogWriter);
                TraceEntry traceEntry = listLogWriter.First();
                Assert.Equal(GetType().GetCSharpName(), traceEntry.TracerName);
                Assert.Equal(TraceLevel.Info, traceEntry.TraceLevel);
            }
        }
Esempio n. 27
0
        public MainWindow()
        {
            InitializeComponent();

            TreeRoot = new List <TraceEntry>();
            TraceEntry te = new TraceEntry(DateTime.MinValue, "Root");

            te.Description = "Root";
            TreeRoot.Add(te);

            if (Application.Current.Properties.Count == 1)
            {
                Console.WriteLine();
            }

            tbTraceFilename.Text = @"D:\workspaces\nickheap2\oe-traceview\input.log";

            //treeview.DataContext = this;
        }
        /// <summary>
        ///     Called by the ASP.NET MVC framework after the action result executes.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            HttpRequestMessage request  = filterContext.HttpContext.Request.AsHttpRequestMessage();
            HttpResponseBase   response = filterContext.HttpContext.Response;

            if (request != null && response != null)
            {
                TraceEntry traceEntry = request.GetTraceEntry();

                Dictionary <string, object> payload = new Dictionary <string, object>
                {
                    { "ResponseStatusCode", response.StatusCode }
                };

                this.Logger.Info($"Request End: {traceEntry.RequestId}", request, "ASP.NET MVC Response", 0UL, string.Empty, traceEntry, null, payload);
            }

            base.OnResultExecuted(filterContext);
        }
        /// <summary>
        ///     Creates a new instance of the <see cref="T:System.Net.Http.HttpClient" />.
        /// </summary>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="traceEntry">The trace entry.</param>
        /// <param name="handlers">The list of HTTP handler that delegates the processing of HTTP response messages to another handler.</param>
        /// <returns>A new instance of the <see cref="T:System.Net.Http.HttpClient" />.</returns>
        public static HttpClient Create(string serviceName, TraceEntry traceEntry, params DelegatingHandler[] handlers)
        {
            HttpClient client;

            if (!clients.TryGetValue(serviceName, out client))
            {
                List <DelegatingHandler> delegatingHandlers = new List <DelegatingHandler>
                {
                    new JinyinmaoServicePermissionHandler(serviceName),
                    //new JinyinmaoTraceEntryHandler(traceEntry),
                    new JinyinmaoHttpStatusHandler(),
                    new JinyinmaoLogHandler("HTTP Client Request", "HTTP Client Response"),
                    new JinyinmaoRetryHandler()
                };
                delegatingHandlers.AddRange(handlers);

                client = HttpClientFactory.Create(new HttpClientHandler
                {
                    AllowAutoRedirect      = true,
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                }, delegatingHandlers.ToArray());

                client.BaseAddress = new Uri("http://service.jinyinmao.com.cn/");

                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json", 1.0));
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml", 0.5));
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*", 0.1));
                client.DefaultRequestHeaders.AcceptEncoding.Clear();
                client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip", 1.0));
                client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate", 0.5));
                client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("*", 0.1));
                client.DefaultRequestHeaders.Connection.Add("keep-alive");

                client.Timeout = 3.Minutes();

                clients.Add(serviceName, client);
            }

            client.WithTraceEntry(traceEntry);

            return(client);
        }
 void ProcessBufferingEngineMessage(TraceEntry entry)
 {
     if (entry.MethodName == "AddChunkToCache")
     {
         SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.VideoBufferSize, "Added (?<d2>.*) chunk with duration (?<d1>.*) to cache. Size including active chunk (?<v>.*) ms");
         if (ssEvent != null)
         {
             if (ssEvent.Data2 == "Audio")
             {
                 ssEvent.EventType = EventType.AudioBufferSize;
             }
             Submit(ssEvent);
         }
     }
     else if (entry.MethodName == "RaiseBufferChangedEvent")
     {
         SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.BufferingStateChanged, "Rebuffer State: (?<d1>.), (?<d2>.*)");
         if (ssEvent != null)
         {
             switch (ssEvent.Data1)
             {
                 case "a":
                     ssEvent.Value = 0;
                     ssEvent.Data1 = "NotRebuffering";
                     break;
                 case "b":
                     ssEvent.Value = 1;
                     ssEvent.Data1 = "RebufferingDueToSeek";
                     break;
                 case "c":
                     ssEvent.Value = 1;
                     ssEvent.Data1 = "RebufferingDueToStartPlayback";
                     break;
                 case "d":
                     ssEvent.Value = 1;
                     ssEvent.Data1 = "RebufferingDueToUnderflow";
                     break;
             }
             Submit(ssEvent);
         }
     }
 }
Esempio n. 31
0
        static ChunkFailureEventArgs GetChunkError(TraceEntry entry)
        {
            const string regexString = "Download error for (?<d1>.*) chunk id (?<d2>.*) startTime (?<d3>.*) timeout = .*";
            Regex        regex       = new Regex(regexString);

            if (regex.IsMatch(entry.Text))
            {
                string streamType = string.Empty;
                int    chunkId    = 0;
                ulong  startTime  = 0;

                var matches      = regex.Matches(entry.Text);
                var data1Capture = matches[0].Groups["d1"].Captures;
                if (data1Capture.Count > 0)
                {
                    streamType = data1Capture[0].Value;
                }
                var data2Capture = matches[0].Groups["d2"].Captures;
                if (data2Capture.Count > 0)
                {
                    int value;
                    if (int.TryParse(data2Capture[0].Value, out value))
                    {
                        chunkId = value;
                    }
                }
                var data3Capture = matches[0].Groups["d3"].Captures;
                if (data3Capture.Count > 0)
                {
                    ulong value;
                    if (ulong.TryParse(data2Capture[0].Value, out value))
                    {
                        startTime = value;
                    }
                }

                ChunkFailureEventArgs result = new ChunkFailureEventArgs();
                result.ChunkId = string.Format("{0}/{1}", streamType, chunkId);
                return(result);
            }
            return(null);
        }
        /// <summary>
        ///     Called by the ASP.NET MVC framework before the action method executes.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpRequestMessage request = filterContext.HttpContext.Request.AsHttpRequestMessage();

            if (request != null)
            {
                TraceEntry traceEntry = request.GetTraceEntry();

                string requestIdString = traceEntry?.RequestId;
                if (requestIdString.IsNullOrEmpty())
                {
                    requestIdString = Guid.NewGuid().ToGuidString();
                    filterContext.HttpContext.Request.Headers.Add("X-JYM-RID", requestIdString);
                }

                this.Logger.Info($"Request Begin: {requestIdString}", request, "ASP.NET MVC Request", 0UL, string.Empty, traceEntry);
            }

            base.OnActionExecuting(filterContext);
        }
 static SmoothStreamingEvent ConvertTraceToEvent(TraceEntry entry, EventType eventType, string regexString)
 {
     Regex regex = new Regex(regexString);
     if (regex.IsMatch(entry.Text))
     {
         SmoothStreamingEvent ssEvent = new SmoothStreamingEvent(entry);
         ssEvent.EventType = eventType;
         ssEvent.Message = entry.Text;
         ssEvent.MediaElementId = entry.MediaElementId;
         var matches = regex.Matches(entry.Text);
         var valueCapture = matches[0].Groups["v"].Captures;
         if (valueCapture.Count > 0)
         {
             double value;
             if (double.TryParse(valueCapture[0].Value, NumberStyles.None, CultureInfo.CurrentCulture, out value))
                 ssEvent.Value = value;
             else
                 ssEvent.Value = 0;
         }
         var data1Capture = matches[0].Groups["d1"].Captures;
         if (data1Capture.Count > 0)
         {
             ssEvent.Data1 = data1Capture[0].Value;
         }
         var data2Capture = matches[0].Groups["d2"].Captures;
         if (data2Capture.Count > 0)
         {
             ssEvent.Data2 = data2Capture[0].Value;
         }
         var data3Capture = matches[0].Groups["d3"].Captures;
         if (data3Capture.Count > 0)
         {
             ssEvent.Data3 = data3Capture[0].Value;
         }
         return ssEvent;
     }
     else
     {
         return null;
     }
 }
Esempio n. 34
0
        static uint GetPerceivedBandwidth(TraceEntry entry)
        {
            const string regexString = "NetworkHeuristicsModule - Perceived bandwidth using .* sliding windows and .* method is (?<v>.*) bytes/sec \\[(?<d1>.*)\\]";
            Regex        regex       = new Regex(regexString);

            if (regex.IsMatch(entry.Text))
            {
                ChunkFailureEventArgs result = new ChunkFailureEventArgs();
                var matches      = regex.Matches(entry.Text);
                var valueCapture = matches[0].Groups["v"].Captures;
                if (valueCapture.Count > 0)
                {
                    uint value;
                    if (uint.TryParse(valueCapture[0].Value, NumberStyles.None, CultureInfo.CurrentCulture, out value))
                    {
                        return(value);
                    }
                }
            }
            return(0);
        }
Esempio n. 35
0
        public void Tracer_Constructor()
        {
            Guid              activityId = Guid.NewGuid();
            string            operation  = "tracer test";
            MockLoggerManager manager    = new MockLoggerManager();

            LoggerManager.Start(manager, new Uri("http://test"));
            using (var tracer = new Tracer(operation, activityId))
            {
                Thread.Sleep(10);
            }

            Assert.IsNotNull(manager);
            Assert.IsNotNull(manager.Entry);
            Assert.IsNotNull(manager.Entry.Id);

            TraceEntry entry = manager.Entry as TraceEntry;

            Assert.IsNotNull(entry, "Entry is not of type TraceEntry");
            Assert.AreEqual(activityId, entry.ActivityId);
            Assert.AreEqual(operation, entry.Operation);
            Assert.AreEqual("Tracer_Constructor", entry.Method);
            Assert.IsTrue(entry.Duration > TimeSpan.Zero);
        }
Esempio n. 36
0
        /// <summary>
        ///     Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
        /// </summary>
        /// <returns>
        ///     Returns <see cref="T:System.Threading.Tasks.Task`1" />. The task object representing the asynchronous operation.
        /// </returns>
        /// <param name="request">The HTTP request message to send to the server.</param>
        /// <param name="cancellationToken">A cancellation token to cancel operation.</param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="request" /> was null.</exception>
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            TraceEntry traceEntry = request?.GetTraceEntry();

            string requestIdString = traceEntry?.RequestId ?? Guid.NewGuid().ToGuidString();

            this.Logger.Info($"Request Begin: {requestIdString}", request, this.RequestTag, 0UL, string.Empty, traceEntry);

            HttpResponseMessage response = await base.SendAsync(request, cancellationToken);

            Dictionary <string, object> payload = new Dictionary <string, object>
            {
                { "ResponseStatusCode", response.StatusCode }
            };

            if (response.Content != null && mediaTypes.Any(t => string.Equals(t, response.Content.Headers.ContentType.MediaType, StringComparison.OrdinalIgnoreCase)))
            {
                payload.Add("ResponseContent", (await response.Content.ReadAsStringAsync()).GetFirst(30000));
            }

            this.Logger.Info($"Request End: {requestIdString}", request, this.ResponseTag, 0UL, string.Empty, traceEntry, null, payload);

            return(response);
        }
 internal SmoothStreamingEvent(TraceEntry entry)
 {
     Ticks = entry.Date.Ticks;
 }
        /// <summary>
        /// Processes trace entries from the SSME and raises the EventCreated event for each relevant one
        /// </summary>
        /// <param name="entries">An array of SSME trace events to process</param>
        public void ParseTraceEntries(TraceEntry[] entries)
        {
            for (int i = 0; i < entries.Length; i++)
            {
                TraceEntry entry = entries[i];

                if (entry.TraceLevel == TraceLevel.Warning || entry.TraceLevel == TraceLevel.Fatal
                    || entry.TraceLevel == TraceLevel.Error || entry.TraceLevel == TraceLevel.Shutdown)
                {
                    if (entry.TraceArea == TraceArea.BufferingEngine)
                    {
                        if (entry.MethodName == "HandleDownloadError")
                        {
#if SSME_1_5_1287_0
                            SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.DownloadError, "Download error for (?<d1>.*) chunk id (?<d2>.*) startTime (?<d3>.*) physicalStartTime (?<d4>.*) timeout = .*");
#else
                            SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.DownloadError, "Download error for (?<d1>.*) chunk id (?<d2>.*) startTime (?<d3>.*) timeout = .*");
#endif
                            if (ssEvent != null) Submit(ssEvent);
                        }
                    }
                    else
                    {
                        SmoothStreamingEvent ssEvent = new SmoothStreamingEvent(entry);
                        ssEvent.Message = entry.Text;
                        ssEvent.Value = (int)entry.TraceLevel;
                        ssEvent.Data1 = entry.TraceLevel.ToString();
                        ssEvent.Data2 = entry.ClassName + "." + entry.MethodName;
                        ssEvent.EventType = EventType.ErrorMessage;
                        Submit(ssEvent);
                    }
                }
                else
                {
                    switch (entry.TraceArea)
                    {
                        case TraceArea.HttpWebResponse:
                            if (!entry.Text.Contains("200 OK"))
                            {
                                SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.HttpError, "HTTP Response:  (?<v>.*) .*, NetworkingStackType: (?<d1>.*)");
                                Submit(ssEvent);
                            }
                            break;
                        case TraceArea.Heuristics:
                            if (entry.MethodName == "GetPerceivedBandwidth")
                            {
                                SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.PerceivedBandwidth, "NetworkHeuristicsModule - Perceived bandwidth using .* sliding windows and .* method is (?<v>.*) bytes/sec \\[(?<d1>.*)\\]");
                                if (ssEvent != null) Submit(ssEvent);
                            }
                            break;
                        case TraceArea.BufferingEngine:
                            ProcessBufferingEngineMessage(entry);
                            break;
                        case TraceArea.MediaElement:
                            if (entry.MethodName == "SetPlaybackRate")
                            {
                                SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.SetPlaybackRate, "SetPlaybackRate: (?<v>.*)");
                                if (ssEvent != null)
                                {
                                    Submit(ssEvent);
                                    SmoothStreamingEvent dvrEvent = new SmoothStreamingEvent(entry);
                                    dvrEvent.EventType = EventType.DvrOperation;
                                    dvrEvent.Message = ssEvent.Message;
                                    dvrEvent.Data1 = DvrOperationType.SetPlaybackRate.ToString();
                                    dvrEvent.Value = ssEvent.Value;
                                    Submit(dvrEvent);
                                }
                            }
                            else if (entry.MethodName == "Position_set")
                            {
                                SmoothStreamingEvent ssEvent = ConvertTraceToEvent(entry, EventType.SetPosition, "Requested position (?<v>.*) \\(SS\\)");
                                if (ssEvent != null)
                                {
                                    Submit(ssEvent);
                                    SmoothStreamingEvent dvrEvent = new SmoothStreamingEvent(entry);
                                    dvrEvent.EventType = EventType.DvrOperation;
                                    dvrEvent.Message = ssEvent.Message;
                                    dvrEvent.Data1 = DvrOperationType.SetPosition.ToString();
                                    dvrEvent.Value = ssEvent.Value;
                                    Submit(dvrEvent);
                                }
                            }
                            else if (entry.MethodName == "Pause" && entry.Text == "Pause")
                            {
                                SmoothStreamingEvent ssEvent = new SmoothStreamingEvent(entry);
                                ssEvent.EventType = EventType.SetPlaybackState;
                                ssEvent.Data1 = entry.Text;
                                Submit(ssEvent);
                                SetPlaybackRate(ssEvent.Ticks, 0);
                            }
                            else if (entry.MethodName == "Play" && entry.Text == "Play")
                            {
                                SmoothStreamingEvent ssEvent = new SmoothStreamingEvent(entry);
                                ssEvent.EventType = EventType.SetPlaybackState;
                                ssEvent.Data1 = entry.Text;
                                Submit(ssEvent);
                                SetPlaybackRate(ssEvent.Ticks, 1);
                            }
                            break;
                        case TraceArea.Test:
                            try
                            {
                                // this trace message sometimes had bad data in it
                                string[] s = entry.Text.Split(' ');
                                if (s.Length == 17 && (s[5] == "V" || s[5] == "A"))
                                {
                                    SmoothStreamingEvent ssEvent = new SmoothStreamingEvent(entry);
#if SILVERLIGHT3
                                    ssEvent.Value = TimeSpan.Parse(s[2]).TotalMilliseconds;
#else
                                    ssEvent.Value = TimeSpan.Parse(s[2], CultureInfo.CurrentCulture).TotalMilliseconds;
#endif
                                    ssEvent.Data1 = s[10];
                                    ssEvent.Data2 = s[9];
                                    ssEvent.Data3 = s[7];
                                    if (s[6] == "200")
                                    {
                                        if (s[5] == "V")
                                        {
                                            ssEvent.EventType = EventType.VideoChunkDownload;
                                        }
                                        else
                                        {
                                            ssEvent.EventType = EventType.AudioChunkDownload;
                                        }
                                    }
                                    else
                                    {
                                        ssEvent.EventType = EventType.HttpError;
                                        ssEvent.Value = int.Parse(s[6], CultureInfo.CurrentCulture);
                                    }
                                    Submit(ssEvent);
                                }
                            }
                            catch
                            {
                                // ignore this exception, must have been a bad trace message
                            }
                            break;
                    }
                }
            }
        }
        static BufferSizeResult GetBufferSize(TraceEntry entry)
        {
            string streamType = "";
            uint bufferSize = 0;

            const string regexString = "Added (?<d2>.*) chunk with duration (?<d1>.*) to cache. Size including active chunk (?<v>.*) ms";
            Regex regex = new Regex(regexString);
            if (regex.IsMatch(entry.Text))
            {
                ChunkFailureEventArgs result = new ChunkFailureEventArgs();
                var matches = regex.Matches(entry.Text);
                var valueCapture = matches[0].Groups["v"].Captures;
                if (valueCapture.Count > 0)
                {
                    uint.TryParse(valueCapture[0].Value, NumberStyles.None, CultureInfo.CurrentCulture, out bufferSize);
                }
                var data2Capture = matches[0].Groups["d2"].Captures;
                if (data2Capture.Count > 0)
                {
                    streamType = data2Capture[0].Value.ToLowerInvariant();
                }
            }
            return new BufferSizeResult(streamType, bufferSize);
        }
        static ChunkFailureEventArgs GetChunkError(TraceEntry entry)
        {
            const string regexString = "Download error for (?<d1>.*) chunk id (?<d2>.*) startTime (?<d3>.*) timeout = .*";
            Regex regex = new Regex(regexString);
            if (regex.IsMatch(entry.Text))
            {
                string streamType = string.Empty;
                int chunkId = 0;
                ulong startTime = 0;

                var matches = regex.Matches(entry.Text);
                var data1Capture = matches[0].Groups["d1"].Captures;
                if (data1Capture.Count > 0)
                {
                    streamType = data1Capture[0].Value;
                }
                var data2Capture = matches[0].Groups["d2"].Captures;
                if (data2Capture.Count > 0)
                {
                    int value;
                    if (int.TryParse(data2Capture[0].Value, out value))
                    {
                        chunkId = value;
                    }
                }
                var data3Capture = matches[0].Groups["d3"].Captures;
                if (data3Capture.Count > 0)
                {
                    ulong value;
                    if (ulong.TryParse(data2Capture[0].Value, out value))
                    {
                        startTime = value;
                    }
                }

                ChunkFailureEventArgs result = new ChunkFailureEventArgs();
                result.ChunkId = string.Format("{0}/{1}", streamType, chunkId);
                return result;
            }
            return null;
        }
Esempio n. 41
0
 public void UnwindAll()
 {
     _top = null;
 }
 static uint GetPerceivedBandwidth(TraceEntry entry)
 {
     const string regexString = "NetworkHeuristicsModule - Perceived bandwidth using .* sliding windows and .* method is (?<v>.*) bytes/sec \\[(?<d1>.*)\\]";
     Regex regex = new Regex(regexString);
     if (regex.IsMatch(entry.Text))
     {
         ChunkFailureEventArgs result = new ChunkFailureEventArgs();
         var matches = regex.Matches(entry.Text);
         var valueCapture = matches[0].Groups["v"].Captures;
         if (valueCapture.Count > 0)
         {
             uint value;
             if (uint.TryParse(valueCapture[0].Value, NumberStyles.None, CultureInfo.CurrentCulture, out value))
             {
                 return value;
             }
         }
     }
     return 0;
 }
Esempio n. 43
0
 // Token: 0x060012B8 RID: 4792 RVA: 0x0004E41A File Offset: 0x0004C61A
 private void Log(TraceEntry entry, string eventType)
 {
     this.log.Log(entry.Timestamp, this.requestId, eventType, entry.FormatString);
 }
Esempio n. 44
0
        public void Transformations_AbstractTrace_PublishEntry_RevokePublished()
        {
            var dummy = new Dummy();
            var traceEntry = new TraceEntry<Dummy, Dummy>(ruleDependent, dummy, dummy);

            Assert.IsFalse(trace.TraceIn(ruleDependent, dummy).Contains(traceEntry));

            trace.PublishEntry(traceEntry);
            trace.RevokeEntry(traceEntry);

            Assert.IsFalse(trace.TraceIn(ruleDependent, dummy).Contains(traceEntry));
        }