Example #1
0
        public override void DoSelfDuty()
        {
            //从中介者拿到所需资源
            ARes aRes = this.mediator.GetARes();
            //生产
            AProduct aProduct = ProcessA(aRes);

            //将产品交给中介者
            this.mediator.OutputAProduct(aProduct);
        }
Example #2
0
        private async Task Auth(ManagingConnectionInfo connectionInfo, Message msg, string userId)
        {
            var sw = new Stopwatch();

            sw.Start();

            var aReq = msg.Payload.ConvertValue <AReq>();

            if (connectionInfo.UserInfo != null)
            {
                return;
            }

            var userInfo = await dataCache.GetUserInfo(userId);

            connectionInfo.UserInfo = userInfo;

            var aRes = new ARes
            {
                Error = AuthUser(userInfo, aReq)
            };

            if (aRes.Error == null)
            {
                aRes.Status = ResStatus.Ok;
                connectionInfo.notAuthTimeOut.Dispose();
            }
            else
            {
                aRes.Status = ResStatus.Error;
            }

            sw.Stop();

            var result = new Message
            {
                CorrelationId     = msg.CorrelationId,
                Type              = "ARes",
                Payload           = aRes,
                TimeStamp         = DateTime.UtcNow,
                ExecutionDuration = sw.Elapsed
            };

            await SendMessage(connectionInfo, result);
        }
Example #3
0
 private AProduct ProcessA(ARes aRes)
 {
     //这里简略了资源变为产品的加工过程
     return(new AProduct());
 }