Пример #1
0
        public static int Call(
            Procedure procdure,
            Net.Protocol from = null,
            Action <Net.Protocol, int> actionWhenError = null)
        {
            bool?isRequestSaved = from?.IsRequest;

            try
            {
                // 日志在Call里面记录。因为要支持嵌套。
                // 统计在Call里面实现。
                int result = procdure.Call();
                if (result != 0 && null != isRequestSaved && isRequestSaved.Value)
                {
                    actionWhenError?.Invoke(from, result);
                }
                return(result);
            }
            catch (Exception ex)
            {
                // Procedure.Call处理了所有错误。应该不会到这里。除非内部错误。
                if (null != isRequestSaved && isRequestSaved.Value)
                {
                    actionWhenError?.Invoke(from, Procedure.Excption);
                }
                logger.Error(ex, procdure.ActionName);
                return(Procedure.Excption);
            }
        }