示例#1
0
        internal WCFReturnInfo Execute <TResult>(Guid pushDataId, Func <TResult> func)
        {
            if (pushDataId == Guid.Empty)
            {
                return(new WCFReturnInfo(false, false, pushDataId, null, "方法:" + func.Method.Name + ",推送数据ID不能为空!"));
            }

            lock (this)
            {
                //如果commandid存在,且已执行成功,则直接返回true,表示该命令已经被执行;否则操作
                if (PUSH.Core.Instance.ExistExecuted(pushDataId))
                {
                    return(new WCFReturnInfo(true, true, pushDataId, null, "服务验证方法已经执行!"));
                }
            }

            string message = string.Empty;

            try
            {
                TResult result = func();
                lock (this)
                {
                    PUSH.Core.Instance.AddExecuted(pushDataId);
                }
                var returnInfo = new WCFReturnInfo(true, PUSH.Core.Instance.ExistExecuted(pushDataId), pushDataId,
                                                   result,
                                                   message);
                return(returnInfo);
            }
            catch (Exception exp)
            {
                message = exp.Message;
                if (exp.InnerException != null)
                {
                    message += @"\r\n" + exp.InnerException.Message;
                }
                SAL.LogCenter.LogService.LogError(string.Format("执行失败:{0}, pushDataId={1}", exp.Message, pushDataId), "基础服务", exp);
                return(new WCFReturnInfo(false, false, pushDataId, null, message));
            }
        }
示例#2
0
        internal WCFReturnInfo Execute(Guid pushDataId, Action act)
        {
            if (pushDataId == Guid.Empty)
            {
                return(new WCFReturnInfo(false, false, pushDataId, null, "方法:" + act.Method.Name + ",推送数据ID不能为空!"));
            }

            //如果commandid存在,且已执行成功,则直接返回true,表示该命令已经被执行;否则操作
            if (PUSH.Core.Instance.ExistExecuted(pushDataId))
            {
                return(new WCFReturnInfo(true, true, pushDataId, null, "服务验证方法已经执行!"));
            }
            string message = string.Empty;

            //using (var tran = new System.Transactions.TransactionScope())
            //{
            try
            {
                act();
                PUSH.Core.Instance.AddExecuted(pushDataId);
                var returnInfo = new WCFReturnInfo(true, PUSH.Core.Instance.ExistExecuted(pushDataId), pushDataId,
                                                   null,
                                                   message);
                //tran.Complete();
                return(returnInfo);
            }
            catch (Exception exp)
            {
                message = exp.Message;
                if (exp.InnerException != null)
                {
                    message += @"\r\n" + exp.InnerException.Message;
                }
                SAL.LogCenter.LogService.LogError(string.Format("执行失败:{0}, pushDataId={1}", exp.Message, pushDataId), "基础服务", exp);
                return(new WCFReturnInfo(false, false, pushDataId, null, message));
            }
            //}
        }