コード例 #1
0
ファイル: LogRecorder.cs プロジェクト: wondial/EntityModel
        /// <summary>
        ///   初始化
        /// </summary>
        public static void Initialize()
        {
            var sec = ConfigurationManager.Get("LogRecorder");

            if (sec != null)
            {
                TraceToConsole = sec.GetBool("console");
                LogMonitor     = sec.GetBool("monitor");
                LogDataSql     = sec.GetBool("sql");
                Level          = Enum.TryParse <LogLevel>(sec["level"], out var level) ? level : LogLevel.Warning;
            }
#if !NETCOREAPP
            if (LogMonitor)
            {
                AppDomain.MonitoringIsEnabled = true;
            }
#endif
            State = LogRecorderStatus.Initialized;
            var recorder = IocHelper.Create <ILogRecorder>();
            if (recorder != null && recorder != BaseRecorder)
            {
                _isTextRecorder = false;
                Recorder        = recorder;
                Recorder.Initialize();
            }
            BaseRecorder.Initialize();
        }
コード例 #2
0
        /// <summary>
        /// 与更新同时执行的SQL
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        protected override string AfterUpdateSql(string condition)
        {
            var context = IocHelper.Create <IBusinessContext>();
            var filter  = string.IsNullOrEmpty(condition) ? null : " WHERE " + condition;

            return($@"UPDATE `{WriteTableName}` 
SET {FieldDictionary["LastReviserID"]}={context.LoginUserId},
{FieldDictionary["LastModifyDate"]}=NOW(){filter};");
        }
コード例 #3
0
ファイル: RouteApp.cs プロジェクト: ym1100/MicroZero
 private static void OnError(Router router, Exception e, HttpContext context)
 {
     try
     {
         router.Data.Status = ZeroOperatorStatus.LocalException;
         ZeroTrace.WriteException("Route", e);
         IocHelper.Create <IRuntimeWaring>()?.Waring("Route", router.Data.Uri.LocalPath, e.Message);
         context.Response.WriteAsync(ApiResult.LocalErrorJson, Encoding.UTF8);
     }
     catch (Exception exception)
     {
         LogRecorder.Exception(exception);
     }
 }
コード例 #4
0
 /// <summary>
 ///     内部构造
 /// </summary>
 public static GlobalContext Reset()
 {
     if (Local.Value != null && !Local.Value.IsDisposed)
     {
         Local.Value.Dispose();
     }
     Local.Value = IocHelper.Create <GlobalContext>();
     if (Local.Value != null)
     {
         return(Local.Value);
     }
     IocHelper.AddScoped <GlobalContext, GlobalContext>();
     Local.Value = IocHelper.Create <GlobalContext>();
     return(Local.Value);
 }
コード例 #5
0
        public static void OnZeroEvent(object sender, ZeroNetEventArgument e)
        {
            switch (e.Event)
            {
            case ZeroNetEventType.AppRun:
                ZeroTrace.SystemLog("RpcTest", "Test is start");
                var test = IocHelper.Create <Tester>();
                test.StartTest();
                break;

            case ZeroNetEventType.AppStop:
                ZeroTrace.SystemLog("RpcTest", "Test is stop");
                test = IocHelper.Create <Tester>();
                test.Cancel.Cancel();
                break;
            }
        }
コード例 #6
0
        /// <summary>
        ///     保存前处理
        /// </summary>
        /// <param name="entity">保存的对象</param>
        /// <param name="operatorType">操作类型</param>
        protected override void OnPrepareSave(DataOperatorType operatorType, TData entity)
        {
            var context = IocHelper.Create <IBusinessContext>();

            switch (operatorType)
            {
            case DataOperatorType.Insert:
            {
                entity.AddDate  = DateTime.Now;
                entity.AuthorId = context.LoginUserId;
                break;
            }

            default:
                entity.LastModifyDate = DateTime.Now;
                entity.LastReviserId  = context.LoginUserId;
                break;
            }
        }
コード例 #7
0
        //private static int count, error, success;
        /// <summary>
        ///     开始计数
        /// </summary>
        /// <returns></returns>
        private static void CountApi(RouteData data)
        {
            var counter = IocHelper.Create <IApiCounter>();

            if (counter == null || !counter.IsEnable)
            {
                return;
            }
            counter.Count(new CountData
            {
                Start     = data.Start.Ticks,
                End       = DateTime.Now.Ticks,
                HostName  = data.HostName,
                ApiName   = data.ApiName,
                Status    = data.Status,
                Requester = $"http_route={GlobalContext.RequestInfo.Ip}:{GlobalContext.RequestInfo.Port}"
            });
            //ZeroTrace.WriteLoop("Run", $"count:{count} success{success} error{error}");
        }
コード例 #8
0
ファイル: BearerChecker.cs プロジェクト: pingbc/EntityModel
        /// <summary>
        ///     还原调用上下文
        /// </summary>
        private int RevertCallContext(HttpRequestMessage request, string token)
        {
            ApiContext context;

            using (var proxy = new RedisProxy())
            {
                context = proxy.Get <ApiContext>(ApiContext.GetCacheKey(token));
            }
            if (context?.Request == null || context.LoginUser == null)
            {
                return(ErrorCode.DenyAccess);
            }
            var checker = IocHelper.Create <IBearValidater>();
            var result  = checker.ValidateServiceKey(context.Request.ServiceKey);

            if (!result.Result)
            {
                return(result.Status.ErrorCode);
            }
            ApiContext.SetContext(context);
            return(0);
        }
コード例 #9
0
ファイル: BearerChecker.cs プロジェクト: pingbc/EntityModel
        /// <summary>
        ///     检查设备标识
        /// </summary>
        /// <returns>
        ///     0:表示通过验证,可以继续
        ///     1:令牌为空
        ///     2:令牌是伪造的
        /// </returns>
        private int CheckDeviceId(HttpRequestMessage request, string token)
        {
            var checker = IocHelper.Create <IBearValidater>();
            ApiResult <LoginUserInfo> result;

            try
            {
                result = checker.ValidateDeviceId(token);
            }
            catch (Exception e)
            {
                LogRecorder.Exception(e);
                return(0); //ErrorCode.Auth_Device_Unknow;
            }
            if (!result.Result)
            {
                return(result.Status.ErrorCode);
            }
            CreateApiContext(result.ResultData, token);
            LogRecorder.MonitorTrace("Authorization:匿名用户");
            return(0);
        }