/// <summary>
        /// Used by filter test to propagate results back to the UI.
        /// </summary>
        /// <param name="test"></param>
        /// <param name="passed"></param>
        private void Test_OnFilterTestResult(DiagnosticsEntry entry)
        {
            // TODO: Build UI for this.
            m_logger.Info("OnFilterTestResult {0} {1}", entry.Test.ToString(), entry.Passed);
            if (entry.Exception != null)
            {
                m_logger.Error("OnFilterTestResult Exception: {0}", entry.Exception.ToString());
            }

            if (entry.Test == FilterTest.BlockingTest || entry.Test == FilterTest.DnsFilterTest)
            {
                CitadelApp.Current.Dispatcher.InvokeAsync(() =>
                {
                    (CitadelApp.Current.MainWindow as Windows.MainWindow).ShowUserMessage("Test Details", entry.Details);
                });
            }

            if (entry.Test == FilterTest.AllTestsCompleted)
            {
                return;
            }

            CitadelApp.Current.Dispatcher.InvokeAsync(() =>
            {
                // FIXME: Don't do CitadelApp.Current.MainWindow as Windows.MainWindow, pass it instead.
                DiagnosticsEntries.Add(new DiagnosticsEntryViewModel(CitadelApp.Current.MainWindow as Windows.MainWindow, entry));
            });
        }
示例#2
0
 public void ReportDiagnostics(Uri documentUri, DiagnosticsEntry entry) {
     // Do not add if module is library, etc. Only handle user code.
     if (Module.ModuleType == ModuleType.User) {
         lock (_lock) {
             _diagnostics.Add(entry);
         }
     }
 }
 public static DiagnosticsEntryViewModel FromModel(DiagnosticsEntry model)
 {
     return(new DiagnosticsEntryViewModel()
     {
         Kind = model.Kind,
         Severity = model.Severity,
         Span = model.Span,
         Parameters = model.Parameters.Select(t => t.ToString()).ToArray()
     });
 }
 public static Diagnostic ToDiagnostic(this DiagnosticsEntry diagnostic, string source = "Python")
 {
     return(new Diagnostic {
         range = diagnostic.SourceSpan,
         severity = diagnostic.Severity.ToDiagnosticSeverity(),
         source = source,
         code = diagnostic.ErrorCode,
         message = diagnostic.Message,
     });
 }
示例#5
0
        public void StoreDiagnosticsData(TCommand request, Exception exception)
        {
            var diagnosticsStore = _httpContextAccessor?.HttpContext?.RequestServices?.GetService <IDiagnosticsModuleStore>();

            if (diagnosticsStore != null)
            {
                var exceptionData = new DiagnosticsEntry(_httpContextAccessor.HttpContext, request.GetType().FullName, exception, request);
                diagnosticsStore.StoreData(exceptionData);
            }
        }
示例#6
0
        private void FormatError(string input, DiagnosticsEntry entry)
        {
            using (new ConsoleColorRegion(ConsoleColor.Red))
            {
                switch (entry.Kind)
                {
                case DiagnosticKind.UnexpectedToken:
                    Console.WriteLine($"{input}\n{MakeArrow(entry.Span)}\n Expected token: {entry.Parameters[0]}\n But found: {entry.Parameters[1]}");
                    break;

                default:
                    Console.WriteLine($"Error: {entry.Kind}");
                    break;
                }
            }
        }
示例#7
0
        public static IApplicationBuilder UseSqlServerRbkApiDiagnosticsModule(this IApplicationBuilder app)
        {
            app.UseExceptionHandler(builder =>
            {
                builder.Run(async context =>
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

                    var errorHandler = context.Features.Get <IExceptionHandlerFeature>();
                    if (errorHandler != null)
                    {
                        var scopeFactory = app.ApplicationServices.GetService <IServiceScopeFactory>();

                        // Must create a new scope because if we have any errors while saving the diagnostics data, the
                        // invalid data will be kept in the context and EF will tries to save it again
                        using (var scope = scopeFactory.CreateScope())
                        {
                            using (var database = scope.ServiceProvider.GetService <SqlServerDiagnosticsContext>())
                            {
                                var data = new DiagnosticsEntry(context, "GlobalExceptionHandler", errorHandler.Error, null);

                                await database.AddAsync(data);
                                await database.SaveChangesAsync();
                            }
                        }

                        await context.Response.WriteAsync(
                            JsonConvert.SerializeObject(new { Errors = new string[] { "Erro interno no servidor." } }))
                        .ConfigureAwait(false);
                    }
                });
            });

            var scopeFactory = app.ApplicationServices.GetService <IServiceScopeFactory>();

            using (var scope = scopeFactory.CreateScope())
            {
                using (var context = scope.ServiceProvider.GetService <SqlServerDiagnosticsContext>())
                {
                    context.Database.EnsureCreated();
                }
            }

            return(app);
        }
示例#8
0
            protected override Task <object> ExecuteAsync(Command request)
            {
                var data = new DiagnosticsEntry();

                data.ApplicationArea              = request.ApplicationArea;
                data.ApplicationLayer             = request.ApplicationLayer;
                data.ApplicationVersion           = request.ApplicationVersion;
                data.ClientBrowser                = request.ClientBrowser;
                data.DatabaseExceptions           = request.DatabaseExceptions;
                data.ClientDevice                 = request.ClientDevice;
                data.Domain                       = request.Domain;
                data.StackTrace                   = request.StackTrace;
                data.InputData                    = request.InputData;
                data.ExceptionMessage             = request.ExceptionMessage;
                data.ClientOperatingSystem        = request.ClientOperatingSystem;
                data.ClientOperatingSystemVersion = request.ClientOperatingSystemVersion;
                data.ExceptionSource              = request.ExceptionSource;
                data.ClientUserAgent              = request.ClientUserAgent;
                data.Username                     = request.Username;

                _context.StoreData(data);

                return(Task.FromResult <object>(null));
            }
示例#9
0
        public async Task <IEnumerable <CodeAction> > GetCodeActionsAsync(IDocumentAnalysis analysis, DiagnosticsEntry diagnostic, CancellationToken cancellationToken)
        {
            var finder = new ExpressionFinder(analysis.Ast, new FindExpressionOptions()
            {
                Names = true
            });
            var node = finder.GetExpression(diagnostic.SourceSpan);

            if (!(node is NameExpression nex))
            {
                return(Enumerable.Empty <CodeAction>());
            }

            var identifier = nex.Name;

            if (string.IsNullOrEmpty(identifier))
            {
                return(Enumerable.Empty <CodeAction>());
            }

            var codeActions = new List <CodeAction>();
            var diagnostics = new[] { diagnostic.ToDiagnostic() };

            // see whether it is one of abbreviation we specialize
            foreach (var moduleFullName in WellKnownAbbreviationMap.Where(kv => kv.Value == identifier).Select(kv => kv.Key))
            {
                var moduleName = GetModuleName(moduleFullName);

                await GetCodeActionsAsync(analysis, diagnostics, new Input(node, moduleName, moduleFullName), codeActions, cancellationToken);
            }

            // add then search given name as it is
            await GetCodeActionsAsync(analysis, diagnostics, new Input(node, identifier), codeActions, cancellationToken);

            return(codeActions);

            string GetModuleName(string moduleFullName)
            {
                var index = moduleFullName.LastIndexOf(".");

                return(index < 0 ? moduleFullName : moduleFullName.Substring(index + 1));
            }
        }
示例#10
0
        public DiagnosticsEntryViewModel(MainWindow mainWindow, DiagnosticsEntry entry)
        {
            m_mainWindow = mainWindow;

            Entry = entry;
        }
 public void Add(DiagnosticsEntry entry) => _diagnostics.Add(entry);
 public void StoreData(DiagnosticsEntry request)
 {
     _context.Data.Add(request);
     _context.SaveChanges();
 }