コード例 #1
0
        public object BeforeDo(ref Message request, IClientChannel channel, InstanceContext instanceContext,
                               U9ActionCorrelationState u9ActionCorrelationState)
        {
            if (WebOperationContext.Current == null)
            {
                throw new WebFaultException(HttpStatusCode.BadRequest);
            }
            ContextInfo contextInfo;

            if (ContextInfoManager.Instance.MultiEnterprise)
            {
                string enterpriseID =
                    WebOperationContext.Current.IncomingRequest.Headers[ContextConstant.HeaderEnterpriseIDName];
                if (string.IsNullOrWhiteSpace(enterpriseID))
                {
                    throw new U9ContextException("配置中指定为多企业,请求Headers需指定EnterpriseID");
                }
                contextInfo = ContextInfoManager.Instance.GetContext(enterpriseID);
                if (contextInfo == null)
                {
                    throw new U9ContextException(string.Format("EnterpriseID:{0} no exists", enterpriseID));
                }
            }
            else
            {
                contextInfo = ContextInfoManager.Instance.GetContext();
                if (contextInfo == null)
                {
                    throw new U9ContextException("no default enterprise exists");
                }
            }
            return(new ContextObject(contextInfo));
        }
コード例 #2
0
        public void AfterDo(ref Message reply, object beforeReturnObj, U9ActionCorrelationState u9ActionCorrelationState)
        {
            if (beforeReturnObj == null)
            {
                return;
            }
            WSLog wsLog = beforeReturnObj as WSLog;

            try
            {
                if (wsLog == null)
                {
                    throw new Exception("AfterDo WSLog is null exception");
                }
                ReturnMessage <object> returnMessage = new ReturnMessage <object>();
                wsLog.EndTime         = DateTime.Now;
                wsLog.ResponseContent = this.MessageToString(ref reply, true, ref returnMessage);
                wsLog.CallResult      = returnMessage.IsSuccess ? CallResultEnum.Success : CallResultEnum.Failure;
                wsLog.ErrorMessage    = returnMessage.ErrMsg;
                //发送调用完日志
                wsLog.DoAfterCallLog();
            }
            catch (Exception ex)
            {
                if (wsLog != null)
                {
                    Logger.Error("日志记录异常,LogID:{0}", wsLog.LogID);
                }
                Logger.Error("日志记录异常:{0}", ex);
            }
        }
コード例 #3
0
        public void AfterDo(ref Message reply, object beforeReturnObj, U9ActionCorrelationState u9ActionCorrelationState)
        {
            ContextObject obj = beforeReturnObj as ContextObject;

            if (obj == null)
            {
                return;
            }
            //清空上下文
            obj.ClearContext();
        }
コード例 #4
0
        public object BeforeDo(ref Message request, IClientChannel channel, InstanceContext instanceContext,
                               U9ActionCorrelationState u9ActionCorrelationState)
        {
            if (WebOperationContext.Current == null)
            {
                throw new WebFaultException(HttpStatusCode.BadRequest);
            }
            WSLog wsLog = new WSLog();

            try
            {
                string actionName =
                    OperationContext.Current.IncomingMessageProperties["HttpOperationName"] as string;
                if (string.IsNullOrEmpty(actionName))
                {
                    return(null);
                }
                Type       hostType = OperationContext.Current.Host.Description.ServiceType;
                MethodInfo method   = hostType.GetMethod(actionName);
                if (method == null)
                {
                    return(null);
                }
                //日志属性
                WSLogAttribute attribute =
                    method.GetCustomAttribute(typeof(WSLogAttribute)) as
                    WSLogAttribute;
                if (attribute == null)
                {
                    return(null);
                }
                string logID = WebOperationContext.Current.IncomingRequest.Headers[HeaderLogIDName];
                if (!string.IsNullOrWhiteSpace(logID))
                {
                    wsLog.LogID = long.Parse(logID);
                }
                Uri requestUri = request.Headers.To;
                wsLog.RequestUrl        = requestUri.AbsoluteUri;
                wsLog.EnterpriseID      = PlatformContext.Current.EnterpriseID;
                wsLog.ClassName         = hostType.FullName;
                wsLog.MethodName        = actionName;
                wsLog.MethodDescription = attribute.MethodDescription;
                wsLog.StartTime         = DateTime.Now;
                ReturnMessage <object> returnMessage = new ReturnMessage <object>();
                wsLog.RequestContent = this.MessageToString(ref request, false, ref returnMessage);
                //发送调用前日志
                wsLog.DoBeforeCallLog();
            }
            catch (Exception ex)
            {
                Logger.Error("日志记录异常:{0}", ex);
            }
            return(wsLog);
        }
コード例 #5
0
        public object BeforeDo(ref Message request, IClientChannel channel, InstanceContext instanceContext,
                               U9ActionCorrelationState u9ActionCorrelationState)
        {
            if (WebOperationContext.Current == null)
            {
                throw new WebFaultException(HttpStatusCode.BadRequest);
            }
            string tokenStr =
                WebOperationContext.Current.IncomingRequest.Headers[TokenConstant.HeaderAccessTokenName];

            if (string.IsNullOrWhiteSpace(tokenStr))
            {
                throw new UnauthorizedTokenException("未认证身份信息");
            }
            WS.Token.Token token = TokenManagement.Instance.Get(tokenStr);
            if (token == null)
            {
                throw new ForbiddenTokenException("认证失败或认证已失效");
            }
            return(new ContextObject(token));
        }
コード例 #6
0
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            if (WebOperationContext.Current == null)
            {
                throw new WebFaultException(HttpStatusCode.BadRequest);
            }
            U9ActionCorrelationState correlationState = new U9ActionCorrelationState();
            U9ActionSectionGroup     group            = U9ActionSectionGroup.GetConfig();

            for (int i = 0; i < group.Actions.Count; i++)
            {
                U9ActionSection   section = group.Actions[i];
                IU9BehaviorAction action  = Activator.CreateInstance(section.LoadType) as IU9BehaviorAction;
                if (action == null)
                {
                    throw new Exception("u9Action must inherit IU9BehaviorAction");
                }
                object result = action.BeforeDo(ref request, channel, instanceContext, correlationState);
                correlationState.AddAction(action, result);
            }
            return(correlationState);
        }
コード例 #7
0
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            U9ActionCorrelationState u9ActionCorrelationState = correlationState as U9ActionCorrelationState;

            if (u9ActionCorrelationState == null)
            {
                return;
            }
            for (int i = u9ActionCorrelationState.Actions.Count - 1; i >= 0; i--)
            {
                try
                {
                    IU9BehaviorAction action          = u9ActionCorrelationState.Actions[i];
                    object            beforeReturnObj = u9ActionCorrelationState.GetActionCorrelationState(action);
                    action.AfterDo(ref reply, beforeReturnObj, u9ActionCorrelationState);
                }
                catch (Exception ex)
                {
                    Logger.Debug("执行U9 Action后事件失败:{0}", i);
                    Logger.Debug(ex);
                }
            }
        }