コード例 #1
0
ファイル: MarkdownTagHelper.cs プロジェクト: xsysfan/Routines
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var c          = (await output.GetChildContentAsync()).GetContent();
            var html       = InjectedManager.Markdown(c);
            var htmlString = new HtmlString(html);

            output.Content.SetHtmlContent(htmlString);
        }
コード例 #2
0
        public static string TestDependencies()
        {
            var t0       = typeof(UserContext);
            var t1       = typeof(RoutineClosure <UserContext>);
            var identity = InjectedManager.GetDefaultIdentity();

            return(InjectedManager.Markdown($"*** fail early {t1.GetType().Name} {t0.Assembly} {identity}***"));
        }
コード例 #3
0
ファイル: WcfRoutine.cs プロジェクト: xsysfan/Routines
        public static Exception TransformException(
            Exception exception,
            Guid correlationToken,
            Routines.MemberTag memberTag,
            string faultCodeNamespace /*, Func<Exception, string> markdownException*/)
        {
            var    code = default(string);
            string message;

            if (exception is AdminkaException adminkaException)
            {
                message = adminkaException.Message;
                code    = adminkaException.Code;
            }
            else
            {
                message = "Remote server error: " + exception.Message + "(" + exception.GetType().FullName + ")";
                if (exception.Data.Contains("Code"))
                {
                    code = exception.Data["Code"] as string;
                }
            }

            var routineError = new RoutineError()
            {
                CorrelationToken = correlationToken,
                MemberTag        = new MemberTag()
                {
                    Namespace = memberTag.Namespace,
                    Type      = memberTag.Type,
                    Member    = memberTag.Member
                },
                Message = message,
                AdminkaExceptionCode = code,

                Details = InjectedManager.Markdown(exception)
            };

            if (exception.Data.Count > 0)
            {
                var data = new Dictionary <string, string>();
                foreach (var k in exception.Data.Keys)
                {
                    if (k is string kStr && exception.Data[k] is string vStr)
                    {
                        data[kStr] = vStr;
                    }
                }
                if (data.Count > 0)
                {
                    routineError.Data = data;
                }
            }
            return(new WcfException(routineError, message, "UNSPECIFIED", faultCodeNamespace));
        }
コード例 #4
0
        // TODO setup ReturnUrl
        // For this every link to potentially forbidden should contain returnUrl parameter
        // one option to get it is HttpContext.Request.GetDisplayUrl();
        void Prepare()
        {
            var routineFeature   = this.HttpContext.Features.Get <AspRoutineFeature>();
            var exceptionHandler = this.HttpContext.Features.Get <IExceptionHandlerFeature>();
            var exception        = exceptionHandler?.Error;

            if (exception != null && routineFeature == null)
            {
                var markdown = InjectedManager.Markdown(exception);
                var correlationTokenRequest = this.HttpContext.Request.Headers["X-CorrelationToken"].FirstOrDefault();
                Guid.TryParse(correlationTokenRequest, out var correlationToken);

                //TODO add internal authorization log ?
                //applicationSettings.UnhandledExceptionLogger.TraceError(correlationToken, markdown);
            }

            RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

            Message = "Access denied. Ask network administrator to promote your user account.";
            Title   = "Security";

            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (environment == "Development")
            {
                ShowAdvancedInformation = true;
            }
            else
            {
                var isAdminPrivilege = false; // TODO: add this privilege through config file to the users with specific names
                if (isAdminPrivilege)
                {
                    ShowAdvancedInformation = true;
                }
            }
            if (ShowAdvancedInformation)
            {
                if (routineFeature != null && routineFeature.TraceDocument != null)
                {
                    var text = routineFeature.TraceDocument.Build();
                    ExceptionHtml = InjectedManager.ToHtml(text);
                }
                else if (exception != null)
                {
                    ExceptionHtml = InjectedManager.ToHtml(exception);
                }
                if (routineFeature != null)
                {
                    CorrelationToken = routineFeature.CorrelationToken.ToString();
                }
            }
        }
コード例 #5
0
        public static string GetErrorActionJson(Exception ex, string aspRequestId, bool isAdminPrivilege)
        {
            string content;

            if (isAdminPrivilege)
            {
                var markdownMessage = InjectedManager.Markdown(ex);
                var htmlMessage     = InjectedManager.ToHtmlException(markdownMessage);
                var source          = new { isAdminPrivilege = true, aspRequestId, htmlMessage };
                content = JsonConvert.SerializeObject(source);
            }
            else
            {
                var source = new { isAdminPrivilege = false, message = "There was been a problem with the website. We are working on resolving it." };
                content = JsonConvert.SerializeObject(source);
            }
            return(content);
        }
コード例 #6
0
        //public static bool FindSqlException(AggregateException aggregateException, out SqlException sqlException)
        //{
        //    sqlException = null;
        //    foreach (var ex in aggregateException.InnerExceptions)
        //    {
        //        if (ex is SqlException)
        //        {
        //            sqlException = (SqlException)ex;
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        void Prepare()
        {
            var exceptionHandler   = this.HttpContext.Features.Get <IExceptionHandlerFeature>();
            var aspRoutineFeature  = this.HttpContext.Features.Get <AspRoutineFeature>();
            var pageRoutineFeature = this.HttpContext.Features.Get <PageRoutineFeature>();

            // TODO: create url tree (where to go on error) and url to title (button name) map
            if (pageRoutineFeature != null)
            {
                ReturnUrl = pageRoutineFeature.Referrer;
            }

            var    unhandledException  = exceptionHandler?.Error;
            string detailsMarkdown     = default;
            var    isHandledByDocument = aspRoutineFeature != null && aspRoutineFeature.TraceDocument.IsExceptionHandled;

            if (unhandledException != null && !isHandledByDocument)
            {
                detailsMarkdown = InjectedManager.Markdown(unhandledException);
                var correlationTokenRequest = this.HttpContext.Request.Headers["X-CorrelationToken"].FirstOrDefault();
                Guid.TryParse(correlationTokenRequest, out var correlationToken);
                applicationSettings.UnhandledExceptionLogger.TraceError(correlationToken, detailsMarkdown);
            }
            RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

            //SqlException sqlException = null;
            var remoteServerErrorType = SqlServerManager.QuickAnalyze(unhandledException);

            if (remoteServerErrorType == RemoteServerErrorType.DOWN)
            {
                Message = "Adminka is currently down for maintenance. Back soon.";
                Title   = "Maintenance";
            }
            else if (remoteServerErrorType == RemoteServerErrorType.OVERLOADED)
            {
                Message = "Adminka is a bit overloaded right now... We are sorry asking you try again later";
                Title   = "Maintenance";
            }


            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (environment == "Development" || applicationSettings.ForceDetailsOnCustomErrorPage)
            {
                ShowAdvancedInformation = true;
            }
            else
            {
                var isAdminPrivilege = User.Claims.Any(c => c.Type == "PRIVILEGE" && c.Value == "ADMIN");
                if (isAdminPrivilege)
                {
                    ShowAdvancedInformation = true;
                }
            }
            if (ShowAdvancedInformation)
            {
                if (isHandledByDocument)
                {
                    var text = aspRoutineFeature.TraceDocument.Build();
                    ExceptionHtml = InjectedManager.ToHtml(text);
                }
                else if (unhandledException != null && detailsMarkdown != null)
                {
                    ExceptionHtml = InjectedManager.ToHtmlException(detailsMarkdown);
                }

                if (aspRoutineFeature != null)
                {
                    CorrelationToken = aspRoutineFeature.CorrelationToken.ToString();
                }
            }
        }