Example #1
0
        public async Task <SystemDebugData> GetDebugDataAsync()
        {
            try
            {
                var data = (await container.Context.SystemDebugData.FirstOrDefaultAsync());
                if (data == null)
                {
                    data = new SystemDebugData();
                    await this.container.Context.AddAsync(data);

                    await this.container.Context.SaveChangesAsync();
                }
                return(data);
            }
            catch (Exception ex)
            {
                this.container.Error(ex);
                return(null);
            }
        }
Example #2
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);

            using (var repo = MainRepository.WithRead())
            {
                SystemData      system = null;
                SystemDebugData debug  = null;
                Task.Run(async() =>
                {
                    system = await repo.System.GetAsync();
                    debug  = await repo.System.GetDebugDataAsync();
                }).Wait();

                context.HttpContext.Request.Query.TryGetValue("p", out StringValues password);

                if (!system.IsDebug ||
                    (this.IsDebugCommand && !debug.CanUseDebugCommands) ||
                    (this.IsDebugCommand && !string.IsNullOrEmpty(debug.DebugPassword) && password.ToString() != debug.DebugPassword))
                {
                    ErrorCode.DebugModeOnlyError.Throw();
                }
            }
        }